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),
25 bool TabContext::IsJSPlugin() const { return mJSPluginID
>= 0; }
27 int32_t TabContext::JSPluginId() const { return mJSPluginID
; }
29 uint64_t TabContext::ChromeOuterWindowID() const {
30 return mChromeOuterWindowID
;
33 bool TabContext::SetTabContext(const TabContext
& aContext
) {
34 NS_ENSURE_FALSE(mInitialized
, false);
42 bool TabContext::UpdateTabContextAfterSwap(const TabContext
& aContext
) {
43 // This is only used after already initialized.
44 MOZ_ASSERT(mInitialized
);
46 // The only permissable changes are to mChromeOuterWindowID. All other fields
47 // must match for the change to be accepted.
49 mChromeOuterWindowID
= aContext
.mChromeOuterWindowID
;
53 bool TabContext::SetTabContext(uint64_t aChromeOuterWindowID
,
54 uint32_t aMaxTouchPoints
) {
55 NS_ENSURE_FALSE(mInitialized
, false);
58 mChromeOuterWindowID
= aChromeOuterWindowID
;
59 mMaxTouchPoints
= aMaxTouchPoints
;
63 bool TabContext::SetTabContextForJSPluginFrame(int32_t aJSPluginID
) {
64 NS_ENSURE_FALSE(mInitialized
, false);
67 mJSPluginID
= aJSPluginID
;
71 IPCTabContext
TabContext::AsIPCTabContext() const {
73 return IPCTabContext(JSPluginFrameIPCTabContext(mJSPluginID
));
77 FrameIPCTabContext(mChromeOuterWindowID
, mMaxTouchPoints
));
80 MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext
& aParams
)
81 : mInvalidReason(nullptr) {
82 uint64_t chromeOuterWindowID
= 0;
83 int32_t jsPluginId
= -1;
84 uint32_t maxTouchPoints
= 0;
86 switch (aParams
.type()) {
87 case IPCTabContext::TPopupIPCTabContext
: {
88 const PopupIPCTabContext
& ipcContext
= aParams
.get_PopupIPCTabContext();
90 chromeOuterWindowID
= ipcContext
.chromeOuterWindowID();
93 case IPCTabContext::TJSPluginFrameIPCTabContext
: {
94 const JSPluginFrameIPCTabContext
& ipcContext
=
95 aParams
.get_JSPluginFrameIPCTabContext();
97 jsPluginId
= ipcContext
.jsPluginId();
100 case IPCTabContext::TFrameIPCTabContext
: {
101 const FrameIPCTabContext
& ipcContext
= aParams
.get_FrameIPCTabContext();
103 chromeOuterWindowID
= ipcContext
.chromeOuterWindowID();
104 maxTouchPoints
= ipcContext
.maxTouchPoints();
113 if (jsPluginId
>= 0) {
114 rv
= mTabContext
.SetTabContextForJSPluginFrame(jsPluginId
);
116 rv
= mTabContext
.SetTabContext(chromeOuterWindowID
, maxTouchPoints
);
119 mInvalidReason
= "Couldn't initialize TabContext.";
123 bool MaybeInvalidTabContext::IsValid() { return mInvalidReason
== nullptr; }
125 const char* MaybeInvalidTabContext::GetInvalidReason() {
126 return mInvalidReason
;
129 const TabContext
& MaybeInvalidTabContext::GetTabContext() {
131 MOZ_CRASH("Can't GetTabContext() if !IsValid().");
137 } // namespace mozilla::dom