tor-browser

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

TabContext.cpp (2993B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "mozilla/dom/TabContext.h"
      8 
      9 #include "mozilla/StaticPrefs_dom.h"
     10 #include "mozilla/dom/BrowserChild.h"
     11 #include "mozilla/dom/BrowserParent.h"
     12 #include "mozilla/dom/PTabContext.h"
     13 #include "nsServiceManagerUtils.h"
     14 
     15 using namespace mozilla::dom::ipc;
     16 using namespace mozilla::layout;
     17 
     18 namespace mozilla::dom {
     19 
     20 TabContext::TabContext()
     21    : mInitialized(false), mChromeOuterWindowID(0), mMaxTouchPoints(0) {}
     22 
     23 uint64_t TabContext::ChromeOuterWindowID() const {
     24  return mChromeOuterWindowID;
     25 }
     26 
     27 bool TabContext::SetTabContext(const TabContext& aContext) {
     28  NS_ENSURE_FALSE(mInitialized, false);
     29 
     30  *this = aContext;
     31  mInitialized = true;
     32 
     33  return true;
     34 }
     35 
     36 bool TabContext::UpdateTabContextAfterSwap(const TabContext& aContext) {
     37  // This is only used after already initialized.
     38  MOZ_ASSERT(mInitialized);
     39 
     40  // The only permissable changes are to mChromeOuterWindowID.  All other fields
     41  // must match for the change to be accepted.
     42 
     43  mChromeOuterWindowID = aContext.mChromeOuterWindowID;
     44  return true;
     45 }
     46 
     47 bool TabContext::SetTabContext(uint64_t aChromeOuterWindowID,
     48                               uint32_t aMaxTouchPoints) {
     49  NS_ENSURE_FALSE(mInitialized, false);
     50 
     51  mInitialized = true;
     52  mChromeOuterWindowID = aChromeOuterWindowID;
     53  mMaxTouchPoints = aMaxTouchPoints;
     54  return true;
     55 }
     56 
     57 IPCTabContext TabContext::AsIPCTabContext() const {
     58  return IPCTabContext(
     59      FrameIPCTabContext(mChromeOuterWindowID, mMaxTouchPoints));
     60 }
     61 
     62 MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams)
     63    : mInvalidReason(nullptr) {
     64  uint64_t chromeOuterWindowID = 0;
     65  uint32_t maxTouchPoints = 0;
     66 
     67  switch (aParams.type()) {
     68    case IPCTabContext::TPopupIPCTabContext: {
     69      const PopupIPCTabContext& ipcContext = aParams.get_PopupIPCTabContext();
     70 
     71      chromeOuterWindowID = ipcContext.chromeOuterWindowID();
     72      break;
     73    }
     74    case IPCTabContext::TFrameIPCTabContext: {
     75      const FrameIPCTabContext& ipcContext = aParams.get_FrameIPCTabContext();
     76 
     77      chromeOuterWindowID = ipcContext.chromeOuterWindowID();
     78      maxTouchPoints = ipcContext.maxTouchPoints();
     79      break;
     80    }
     81    default: {
     82      MOZ_CRASH();
     83    }
     84  }
     85 
     86  if (!mTabContext.SetTabContext(chromeOuterWindowID, maxTouchPoints)) {
     87    mInvalidReason = "Couldn't initialize TabContext.";
     88  }
     89 }
     90 
     91 bool MaybeInvalidTabContext::IsValid() { return mInvalidReason == nullptr; }
     92 
     93 const char* MaybeInvalidTabContext::GetInvalidReason() {
     94  return mInvalidReason;
     95 }
     96 
     97 const TabContext& MaybeInvalidTabContext::GetTabContext() {
     98  if (!IsValid()) {
     99    MOZ_CRASH("Can't GetTabContext() if !IsValid().");
    100  }
    101 
    102  return mTabContext;
    103 }
    104 
    105 }  // namespace mozilla::dom