no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / ipc / TabContext.h
blob00bf69c2a265b9376dd5dc3c074c976b76aa74aa
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 #ifndef mozilla_dom_TabContext_h
8 #define mozilla_dom_TabContext_h
10 #include "nsCOMPtr.h"
11 #include "mozilla/BasePrincipal.h"
12 #include "nsPIDOMWindow.h"
13 #include "nsPIWindowRoot.h"
15 namespace mozilla::dom {
17 class IPCTabContext;
19 /**
20 * TabContext encapsulates information about an iframe.
22 * BrowserParent and BrowserChild both inherit from TabContext, and you can also
23 * have standalone TabContext objects.
25 * This class is immutable except by calling one of the protected
26 * SetTabContext*() methods (and those methods can only be called once). See
27 * also MutableTabContext.
29 class TabContext {
30 public:
31 TabContext();
33 /* (The implicit copy-constructor and operator= are fine.) */
35 /**
36 * Generates IPCTabContext of type BrowserFrameIPCTabContext from this
37 * TabContext's information.
39 IPCTabContext AsIPCTabContext() const;
41 uint64_t ChromeOuterWindowID() const;
43 uint32_t MaxTouchPoints() const { return mMaxTouchPoints; }
45 protected:
46 friend class MaybeInvalidTabContext;
48 /**
49 * These protected mutator methods let you modify a TabContext once. Further
50 * attempts to modify a given TabContext will fail (the method will return
51 * false).
53 * These mutators will also fail if the TabContext was created with anything
54 * other than the no-args constructor.
57 /**
58 * Set this TabContext to match the given TabContext.
60 bool SetTabContext(const TabContext& aContext);
62 bool SetTabContext(uint64_t aChromeOuterWindowID, uint32_t aMaxTouchPoints);
64 /**
65 * Modify this TabContext to match the given TabContext. This is a special
66 * case triggered by nsFrameLoader::SwapWithOtherRemoteLoader which may have
67 * caused the owner content to change.
69 * This special case only allows the field `mChromeOuterWindowID` to be
70 * changed. If any other fields have changed, the update is ignored and
71 * returns false.
73 bool UpdateTabContextAfterSwap(const TabContext& aContext);
75 void SetMaxTouchPoints(uint32_t aMaxTouchPoints) {
76 mMaxTouchPoints = aMaxTouchPoints;
79 private:
80 /**
81 * Has this TabContext been initialized? If so, mutator methods will fail.
83 bool mInitialized;
85 /**
86 * The outerWindowID of the window hosting the remote frameloader.
88 uint64_t mChromeOuterWindowID;
90 /**
91 * Maximum number of touch points.
93 uint32_t mMaxTouchPoints;
96 /**
97 * MutableTabContext is the same as MaybeInvalidTabContext, except the mutation
98 * methods are public instead of protected. You can still only call these
99 * mutation methods once on a given object.
101 class MutableTabContext : public TabContext {
102 public:
103 bool SetTabContext(const TabContext& aContext) {
104 return TabContext::SetTabContext(aContext);
107 bool SetTabContext(uint64_t aChromeOuterWindowID, uint32_t aMaxTouchPoints) {
108 return TabContext::SetTabContext(aChromeOuterWindowID, aMaxTouchPoints);
113 * MaybeInvalidTabContext is a simple class that lets you transform an
114 * IPCTabContext into a TabContext.
116 * The issue is that an IPCTabContext is not necessarily valid. So to convert
117 * an IPCTabContext into a TabContext, you construct a MaybeInvalidTabContext,
118 * check whether it's valid, and, if so, read out your TabContext.
120 * Example usage:
122 * void UseTabContext(const TabContext& aTabContext);
124 * void CreateTab(const IPCTabContext& aContext) {
125 * MaybeInvalidTabContext tc(aContext);
126 * if (!tc.IsValid()) {
127 * NS_ERROR(nsPrintfCString("Got an invalid IPCTabContext: %s",
128 * tc.GetInvalidReason()));
129 * return;
131 * UseTabContext(tc.GetTabContext());
134 class MaybeInvalidTabContext {
135 public:
137 * This constructor copies the information in aContext and sets IsValid() as
138 * appropriate.
140 explicit MaybeInvalidTabContext(const IPCTabContext& aContext);
143 * Was the IPCTabContext we received in our constructor valid?
145 bool IsValid();
148 * If IsValid(), this function returns null. Otherwise, it returns a
149 * human-readable string indicating why the IPCTabContext passed to our
150 * constructor was not valid.
152 const char* GetInvalidReason();
155 * If IsValid(), this function returns a reference to a TabContext
156 * corresponding to the IPCTabContext passed to our constructor. If
157 * !IsValid(), this function crashes.
159 const TabContext& GetTabContext();
161 private:
162 MaybeInvalidTabContext(const MaybeInvalidTabContext&) = delete;
163 MaybeInvalidTabContext& operator=(const MaybeInvalidTabContext&) = delete;
165 const char* mInvalidReason;
166 MutableTabContext mTabContext;
169 } // namespace mozilla::dom
171 #endif