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/. */
7 #include "mozilla/dom/TabContext.h"
8 #include "mozilla/dom/PTabContext.h"
9 #include "mozilla/dom/BrowserParent.h"
10 #include "mozilla/dom/BrowserChild.h"
11 #include "mozilla/StaticPrefs_dom.h"
12 #include "nsServiceManagerUtils.h"
14 using namespace mozilla::dom::ipc
;
15 using namespace mozilla::layout
;
17 namespace mozilla::dom
{
19 TabContext::TabContext()
20 : mInitialized(false),
21 mChromeOuterWindowID(0),
24 uint64_t TabContext::ChromeOuterWindowID() const {
25 return mChromeOuterWindowID
;
28 bool TabContext::SetTabContext(const TabContext
& aContext
) {
29 NS_ENSURE_FALSE(mInitialized
, false);
37 bool TabContext::UpdateTabContextAfterSwap(const TabContext
& aContext
) {
38 // This is only used after already initialized.
39 MOZ_ASSERT(mInitialized
);
41 // The only permissable changes are to mChromeOuterWindowID. All other fields
42 // must match for the change to be accepted.
44 mChromeOuterWindowID
= aContext
.mChromeOuterWindowID
;
48 bool TabContext::SetTabContext(uint64_t aChromeOuterWindowID
,
49 uint32_t aMaxTouchPoints
) {
50 NS_ENSURE_FALSE(mInitialized
, false);
53 mChromeOuterWindowID
= aChromeOuterWindowID
;
54 mMaxTouchPoints
= aMaxTouchPoints
;
58 IPCTabContext
TabContext::AsIPCTabContext() const {
60 FrameIPCTabContext(mChromeOuterWindowID
, mMaxTouchPoints
));
63 MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext
& aParams
)
64 : mInvalidReason(nullptr) {
65 uint64_t chromeOuterWindowID
= 0;
66 uint32_t maxTouchPoints
= 0;
68 switch (aParams
.type()) {
69 case IPCTabContext::TPopupIPCTabContext
: {
70 const PopupIPCTabContext
& ipcContext
= aParams
.get_PopupIPCTabContext();
72 chromeOuterWindowID
= ipcContext
.chromeOuterWindowID();
75 case IPCTabContext::TFrameIPCTabContext
: {
76 const FrameIPCTabContext
& ipcContext
= aParams
.get_FrameIPCTabContext();
78 chromeOuterWindowID
= ipcContext
.chromeOuterWindowID();
79 maxTouchPoints
= ipcContext
.maxTouchPoints();
87 if (!mTabContext
.SetTabContext(chromeOuterWindowID
, maxTouchPoints
)) {
88 mInvalidReason
= "Couldn't initialize TabContext.";
92 bool MaybeInvalidTabContext::IsValid() { return mInvalidReason
== nullptr; }
94 const char* MaybeInvalidTabContext::GetInvalidReason() {
95 return mInvalidReason
;
98 const TabContext
& MaybeInvalidTabContext::GetTabContext() {
100 MOZ_CRASH("Can't GetTabContext() if !IsValid().");
106 } // namespace mozilla::dom