tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

FxRWindowManager.cpp (1622B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #include "FxRWindowManager.h"
      7 #include "mozilla/Assertions.h"
      8 #include "nsPIDOMWindow.h"
      9 #include "mozilla/ClearOnShutdown.h"
     10 #include "mozilla/WidgetUtils.h"
     11 
     12 #include "nsWindow.h"
     13 
     14 static mozilla::StaticAutoPtr<FxRWindowManager> sFxrWinMgrInstance;
     15 
     16 FxRWindowManager* FxRWindowManager::GetInstance() {
     17  if (sFxrWinMgrInstance == nullptr) {
     18    sFxrWinMgrInstance = new FxRWindowManager();
     19    ClearOnShutdown(&sFxrWinMgrInstance);
     20  }
     21 
     22  return sFxrWinMgrInstance;
     23 }
     24 
     25 FxRWindowManager::FxRWindowManager() : mWindow(nullptr) {}
     26 
     27 // Track this new Firefox Reality window instance
     28 void FxRWindowManager::AddWindow(nsPIDOMWindowOuter* aWindow) {
     29  if (mWindow != nullptr) {
     30    MOZ_CRASH("Only one window is supported");
     31  }
     32 
     33  mWindow = aWindow;
     34 }
     35 
     36 // Returns true if the window at the provided ID was created for Firefox Reality
     37 bool FxRWindowManager::IsFxRWindow(uint64_t aOuterWindowID) {
     38  return (mWindow != nullptr) && (mWindow->WindowID() == aOuterWindowID);
     39 }
     40 
     41 // Returns true if the window was created for Firefox Reality
     42 bool FxRWindowManager::IsFxRWindow(const nsWindow* aWindow) const {
     43  return (mWindow != nullptr) &&
     44         (aWindow ==
     45          mozilla::widget::WidgetUtils::DOMWindowToWidget(mWindow).take());
     46 }
     47 
     48 uint64_t FxRWindowManager::GetWindowID() const {
     49  MOZ_ASSERT(mWindow);
     50  return mWindow->WindowID();
     51 }