/work/obj-fuzz/dist/include/mozilla/dom/TabContext.h
Line | Count | Source (jump to first uncovered line) |
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 | | #ifndef mozilla_dom_TabContext_h |
8 | | #define mozilla_dom_TabContext_h |
9 | | |
10 | | #include "nsCOMPtr.h" |
11 | | #include "mozilla/BasePrincipal.h" |
12 | | #include "nsPIDOMWindow.h" |
13 | | #include "nsPIWindowRoot.h" |
14 | | |
15 | | namespace mozilla { |
16 | | namespace dom { |
17 | | |
18 | | class IPCTabContext; |
19 | | |
20 | | /** |
21 | | * TabContext encapsulates information about an iframe that may be a mozbrowser. |
22 | | * |
23 | | * TabParent and TabChild both inherit from TabContext, and you can also have |
24 | | * standalone TabContext objects. |
25 | | * |
26 | | * This class is immutable except by calling one of the protected |
27 | | * SetTabContext*() methods (and those methods can only be called once). See |
28 | | * also MutableTabContext. |
29 | | */ |
30 | | class TabContext |
31 | | { |
32 | | public: |
33 | | TabContext(); |
34 | | |
35 | | /* (The implicit copy-constructor and operator= are fine.) */ |
36 | | |
37 | | /** |
38 | | * Generates IPCTabContext of type BrowserFrameIPCTabContext from this |
39 | | * TabContext's information. |
40 | | */ |
41 | | IPCTabContext AsIPCTabContext() const; |
42 | | |
43 | | /** |
44 | | * Does this TabContext correspond to a mozbrowser? |
45 | | * |
46 | | * <iframe mozbrowser> is a mozbrowser element, but <xul:browser> is not. |
47 | | */ |
48 | | bool IsMozBrowserElement() const; |
49 | | |
50 | | /** |
51 | | * Does this TabContext correspond to an isolated mozbrowser? |
52 | | * |
53 | | * <iframe mozbrowser> is a mozbrowser element, but <xul:browser> is not. |
54 | | * <iframe mozbrowser noisolation> does not count as isolated since isolation |
55 | | * is disabled. Isolation can only be disabled by chrome pages. |
56 | | */ |
57 | | bool IsIsolatedMozBrowserElement() const; |
58 | | |
59 | | /** |
60 | | * Does this TabContext correspond to a mozbrowser? This is equivalent to |
61 | | * IsMozBrowserElement(). Returns false for <xul:browser>, which isn't a |
62 | | * mozbrowser. |
63 | | */ |
64 | | bool IsMozBrowser() const; |
65 | | |
66 | | bool IsJSPlugin() const; |
67 | | int32_t JSPluginId() const; |
68 | | |
69 | | uint64_t ChromeOuterWindowID() const; |
70 | | |
71 | | /** |
72 | | * OriginAttributesRef() returns the OriginAttributes of this frame to |
73 | | * the caller. This is used to store any attribute associated with the frame's |
74 | | * docshell. |
75 | | */ |
76 | | const OriginAttributes& OriginAttributesRef() const; |
77 | | |
78 | | /** |
79 | | * Returns the presentation URL associated with the tab if this tab is |
80 | | * created for presented content |
81 | | */ |
82 | | const nsAString& PresentationURL() const; |
83 | | |
84 | | UIStateChangeType ShowAccelerators() const; |
85 | | UIStateChangeType ShowFocusRings() const; |
86 | | |
87 | | protected: |
88 | | friend class MaybeInvalidTabContext; |
89 | | |
90 | | /** |
91 | | * These protected mutator methods let you modify a TabContext once. Further |
92 | | * attempts to modify a given TabContext will fail (the method will return |
93 | | * false). |
94 | | * |
95 | | * These mutators will also fail if the TabContext was created with anything |
96 | | * other than the no-args constructor. |
97 | | */ |
98 | | |
99 | | /** |
100 | | * Set this TabContext to match the given TabContext. |
101 | | */ |
102 | | bool SetTabContext(const TabContext& aContext); |
103 | | |
104 | | /** |
105 | | * Set the tab context's origin attributes to a private browsing value. |
106 | | */ |
107 | | void SetPrivateBrowsingAttributes(bool aIsPrivateBrowsing); |
108 | | |
109 | | bool SetTabContext(bool aIsMozBrowserElement, |
110 | | uint64_t aChromeOuterWindowID, |
111 | | UIStateChangeType aShowAccelerators, |
112 | | UIStateChangeType aShowFocusRings, |
113 | | const OriginAttributes& aOriginAttributes, |
114 | | const nsAString& aPresentationURL); |
115 | | |
116 | | /** |
117 | | * Modify this TabContext to match the given TabContext. This is a special |
118 | | * case triggered by nsFrameLoader::SwapWithOtherRemoteLoader which may have |
119 | | * caused the owner content to change. |
120 | | * |
121 | | * This special case only allows the field `mIsMozBrowserElement` to be |
122 | | * changed. If any other fields have changed, the update is ignored and |
123 | | * returns false. |
124 | | */ |
125 | | bool UpdateTabContextAfterSwap(const TabContext& aContext); |
126 | | |
127 | | /** |
128 | | * Set this TabContext to be for a JS plugin. aPluginID is the id of the JS plugin |
129 | | * (@see nsFakePlugin::mId). |
130 | | * As with the other protected mutator methods, this lets you modify a TabContext once. |
131 | | * (@see TabContext::SetTabContext above for more details). |
132 | | */ |
133 | | bool SetTabContextForJSPluginFrame(int32_t aJSPluginID); |
134 | | |
135 | | private: |
136 | | /** |
137 | | * Has this TabContext been initialized? If so, mutator methods will fail. |
138 | | */ |
139 | | bool mInitialized; |
140 | | |
141 | | /** |
142 | | * Whether this TabContext corresponds to a mozbrowser. |
143 | | * |
144 | | * <iframe mozbrowser> and <xul:browser> are not considered to be |
145 | | * mozbrowser elements. |
146 | | */ |
147 | | bool mIsMozBrowserElement; |
148 | | |
149 | | /** |
150 | | * The outerWindowID of the window hosting the remote frameloader. |
151 | | */ |
152 | | uint64_t mChromeOuterWindowID; |
153 | | |
154 | | int32_t mJSPluginID; |
155 | | |
156 | | /** |
157 | | * OriginAttributes of the top level tab docShell |
158 | | */ |
159 | | OriginAttributes mOriginAttributes; |
160 | | |
161 | | /** |
162 | | * The requested presentation URL. |
163 | | */ |
164 | | nsString mPresentationURL; |
165 | | |
166 | | /** |
167 | | * Keyboard indicator state (focus rings, accelerators). |
168 | | */ |
169 | | UIStateChangeType mShowAccelerators; |
170 | | UIStateChangeType mShowFocusRings; |
171 | | }; |
172 | | |
173 | | /** |
174 | | * MutableTabContext is the same as MaybeInvalidTabContext, except the mutation |
175 | | * methods are public instead of protected. You can still only call these |
176 | | * mutation methods once on a given object. |
177 | | */ |
178 | | class MutableTabContext : public TabContext |
179 | | { |
180 | | public: |
181 | | bool SetTabContext(const TabContext& aContext) |
182 | 0 | { |
183 | 0 | return TabContext::SetTabContext(aContext); |
184 | 0 | } |
185 | | |
186 | | bool |
187 | | SetTabContext(bool aIsMozBrowserElement, |
188 | | uint64_t aChromeOuterWindowID, |
189 | | UIStateChangeType aShowAccelerators, |
190 | | UIStateChangeType aShowFocusRings, |
191 | | const OriginAttributes& aOriginAttributes, |
192 | | const nsAString& aPresentationURL = EmptyString()) |
193 | 0 | { |
194 | 0 | return TabContext::SetTabContext(aIsMozBrowserElement, |
195 | 0 | aChromeOuterWindowID, |
196 | 0 | aShowAccelerators, |
197 | 0 | aShowFocusRings, |
198 | 0 | aOriginAttributes, |
199 | 0 | aPresentationURL); |
200 | 0 | } |
201 | | |
202 | | bool SetTabContextForJSPluginFrame(uint32_t aJSPluginID) |
203 | 0 | { |
204 | 0 | return TabContext::SetTabContextForJSPluginFrame(aJSPluginID); |
205 | 0 | } |
206 | | |
207 | | }; |
208 | | |
209 | | /** |
210 | | * MaybeInvalidTabContext is a simple class that lets you transform an |
211 | | * IPCTabContext into a TabContext. |
212 | | * |
213 | | * The issue is that an IPCTabContext is not necessarily valid. So to convert |
214 | | * an IPCTabContext into a TabContext, you construct a MaybeInvalidTabContext, |
215 | | * check whether it's valid, and, if so, read out your TabContext. |
216 | | * |
217 | | * Example usage: |
218 | | * |
219 | | * void UseTabContext(const TabContext& aTabContext); |
220 | | * |
221 | | * void CreateTab(const IPCTabContext& aContext) { |
222 | | * MaybeInvalidTabContext tc(aContext); |
223 | | * if (!tc.IsValid()) { |
224 | | * NS_ERROR(nsPrintfCString("Got an invalid IPCTabContext: %s", |
225 | | * tc.GetInvalidReason())); |
226 | | * return; |
227 | | * } |
228 | | * UseTabContext(tc.GetTabContext()); |
229 | | * } |
230 | | */ |
231 | | class MaybeInvalidTabContext |
232 | | { |
233 | | public: |
234 | | /** |
235 | | * This constructor copies the information in aContext and sets IsValid() as |
236 | | * appropriate. |
237 | | */ |
238 | | explicit MaybeInvalidTabContext(const IPCTabContext& aContext); |
239 | | |
240 | | /** |
241 | | * Was the IPCTabContext we received in our constructor valid? |
242 | | */ |
243 | | bool IsValid(); |
244 | | |
245 | | /** |
246 | | * If IsValid(), this function returns null. Otherwise, it returns a |
247 | | * human-readable string indicating why the IPCTabContext passed to our |
248 | | * constructor was not valid. |
249 | | */ |
250 | | const char* GetInvalidReason(); |
251 | | |
252 | | /** |
253 | | * If IsValid(), this function returns a reference to a TabContext |
254 | | * corresponding to the IPCTabContext passed to our constructor. If |
255 | | * !IsValid(), this function crashes. |
256 | | */ |
257 | | const TabContext& GetTabContext(); |
258 | | |
259 | | private: |
260 | | MaybeInvalidTabContext(const MaybeInvalidTabContext&) = delete; |
261 | | MaybeInvalidTabContext& operator=(const MaybeInvalidTabContext&) = delete; |
262 | | |
263 | | const char* mInvalidReason; |
264 | | MutableTabContext mTabContext; |
265 | | }; |
266 | | |
267 | | } // namespace dom |
268 | | } // namespace mozilla |
269 | | |
270 | | #endif |