/work/obj-fuzz/dist/include/mozilla/dom/ClientSource.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 | | #ifndef _mozilla_dom_ClientSource_h |
7 | | #define _mozilla_dom_ClientSource_h |
8 | | |
9 | | #include "mozilla/dom/ClientInfo.h" |
10 | | #include "mozilla/dom/ClientOpPromise.h" |
11 | | #include "mozilla/dom/ClientThing.h" |
12 | | #include "mozilla/dom/ServiceWorkerDescriptor.h" |
13 | | #include "mozilla/Variant.h" |
14 | | |
15 | | #ifdef XP_WIN |
16 | | #undef PostMessage |
17 | | #endif |
18 | | |
19 | | class nsIDocShell; |
20 | | class nsIGlobalObject; |
21 | | class nsISerialEventTarget; |
22 | | class nsPIDOMWindowInner; |
23 | | |
24 | | namespace mozilla { |
25 | | namespace dom { |
26 | | |
27 | | class ClientClaimArgs; |
28 | | class ClientControlledArgs; |
29 | | class ClientFocusArgs; |
30 | | class ClientGetInfoAndStateArgs; |
31 | | class ClientManager; |
32 | | class ClientPostMessageArgs; |
33 | | class ClientSourceChild; |
34 | | class ClientSourceConstructorArgs; |
35 | | class ClientSourceExecutionReadyArgs; |
36 | | class ClientState; |
37 | | class ClientWindowState; |
38 | | class PClientManagerChild; |
39 | | class WorkerPrivate; |
40 | | |
41 | | // ClientSource is an RAII style class that is designed to be held via |
42 | | // a UniquePtr<>. When created ClientSource will register the existence |
43 | | // of a client in the cross-process ClientManagerService. When the |
44 | | // ClientSource is destroyed then client entry will be removed. Code |
45 | | // that represents globals or browsing environments, such as nsGlobalWindow |
46 | | // or WorkerPrivate, should use ClientManager to create a ClientSource. |
47 | | class ClientSource final : public ClientThing<ClientSourceChild> |
48 | | { |
49 | | friend class ClientManager; |
50 | | |
51 | | NS_DECL_OWNINGTHREAD |
52 | | |
53 | | RefPtr<ClientManager> mManager; |
54 | | nsCOMPtr<nsISerialEventTarget> mEventTarget; |
55 | | |
56 | | Variant<Nothing, |
57 | | RefPtr<nsPIDOMWindowInner>, |
58 | | nsCOMPtr<nsIDocShell>, |
59 | | WorkerPrivate*> mOwner; |
60 | | |
61 | | ClientInfo mClientInfo; |
62 | | Maybe<ServiceWorkerDescriptor> mController; |
63 | | |
64 | | // Contained a de-duplicated list of ServiceWorker scope strings |
65 | | // for which this client has called navigator.serviceWorker.register(). |
66 | | // Typically there will be either be zero or one scope strings, but |
67 | | // there could be more. We keep this list until the client is closed. |
68 | | AutoTArray<nsCString, 1> mRegisteringScopeList; |
69 | | |
70 | | void |
71 | | Shutdown(); |
72 | | |
73 | | void |
74 | | ExecutionReady(const ClientSourceExecutionReadyArgs& aArgs); |
75 | | |
76 | | WorkerPrivate* |
77 | | GetWorkerPrivate() const; |
78 | | |
79 | | nsIDocShell* |
80 | | GetDocShell() const; |
81 | | |
82 | | nsIGlobalObject* |
83 | | GetGlobal() const; |
84 | | |
85 | | void |
86 | | MaybeCreateInitialDocument(); |
87 | | |
88 | | nsresult |
89 | | SnapshotWindowState(ClientState* aStateOut); |
90 | | |
91 | | // Private methods called by ClientManager |
92 | | ClientSource(ClientManager* aManager, |
93 | | nsISerialEventTarget* aEventTarget, |
94 | | const ClientSourceConstructorArgs& aArgs); |
95 | | |
96 | | void |
97 | | Activate(PClientManagerChild* aActor); |
98 | | |
99 | | public: |
100 | | ~ClientSource(); |
101 | | |
102 | | nsPIDOMWindowInner* |
103 | | GetInnerWindow() const; |
104 | | |
105 | | void |
106 | | WorkerExecutionReady(WorkerPrivate* aWorkerPrivate); |
107 | | |
108 | | nsresult |
109 | | WindowExecutionReady(nsPIDOMWindowInner* aInnerWindow); |
110 | | |
111 | | nsresult |
112 | | DocShellExecutionReady(nsIDocShell* aDocShell); |
113 | | |
114 | | void |
115 | | Freeze(); |
116 | | |
117 | | void |
118 | | Thaw(); |
119 | | |
120 | | const ClientInfo& |
121 | | Info() const; |
122 | | |
123 | | // Trigger a synchronous IPC ping to the parent process to confirm that |
124 | | // the ClientSource actor has been created. This should only be used |
125 | | // by the WorkerPrivate startup code to deal with a ClientHandle::Control() |
126 | | // call racing on the main thread. Do not call this in other circumstances! |
127 | | void |
128 | | WorkerSyncPing(WorkerPrivate* aWorkerPrivate); |
129 | | |
130 | | // Synchronously mark the ClientSource as controlled by the given service |
131 | | // worker. This can happen as a result of a remote operation or directly |
132 | | // by local code. For example, if a client's initial network load is |
133 | | // intercepted by a controlling service worker then this should be called |
134 | | // immediately. |
135 | | // |
136 | | // Note, there is no way to clear the controlling service worker because |
137 | | // the specification does not allow that operation. |
138 | | void |
139 | | SetController(const ServiceWorkerDescriptor& aServiceWorker); |
140 | | |
141 | | // Mark the ClientSource as controlled using the remote operation arguments. |
142 | | // This will in turn call SetController(). |
143 | | RefPtr<ClientOpPromise> |
144 | | Control(const ClientControlledArgs& aArgs); |
145 | | |
146 | | // Inherit the controller from a local parent client. This requires both |
147 | | // setting our immediate controller field and also updating the parent-side |
148 | | // data structure. |
149 | | void |
150 | | InheritController(const ServiceWorkerDescriptor& aServiceWorker); |
151 | | |
152 | | // Get the ClientSource's current controlling service worker, if one has |
153 | | // been set. |
154 | | const Maybe<ServiceWorkerDescriptor>& |
155 | | GetController() const; |
156 | | |
157 | | // Note that the client has reached DOMContentLoaded. Only applies to window |
158 | | // clients. |
159 | | void |
160 | | NoteDOMContentLoaded(); |
161 | | |
162 | | RefPtr<ClientOpPromise> |
163 | | Focus(const ClientFocusArgs& aArgs); |
164 | | |
165 | | RefPtr<ClientOpPromise> |
166 | | PostMessage(const ClientPostMessageArgs& aArgs); |
167 | | |
168 | | RefPtr<ClientOpPromise> |
169 | | Claim(const ClientClaimArgs& aArgs); |
170 | | |
171 | | RefPtr<ClientOpPromise> |
172 | | GetInfoAndState(const ClientGetInfoAndStateArgs& aArgs); |
173 | | |
174 | | nsresult |
175 | | SnapshotState(ClientState* aStateOut); |
176 | | |
177 | | nsISerialEventTarget* |
178 | | EventTarget() const; |
179 | | |
180 | | void |
181 | | Traverse(nsCycleCollectionTraversalCallback& aCallback, |
182 | | const char* aName, |
183 | | uint32_t aFlags); |
184 | | |
185 | | void |
186 | | NoteCalledRegisterForServiceWorkerScope(const nsACString& aScope); |
187 | | |
188 | | bool |
189 | | CalledRegisterForServiceWorkerScope(const nsACString& aScope); |
190 | | }; |
191 | | |
192 | | inline void |
193 | | ImplCycleCollectionUnlink(UniquePtr<ClientSource>& aField) |
194 | 0 | { |
195 | 0 | aField.reset(); |
196 | 0 | } |
197 | | |
198 | | inline void |
199 | | ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, |
200 | | UniquePtr<ClientSource>& aField, |
201 | | const char* aName, |
202 | | uint32_t aFlags) |
203 | 0 | { |
204 | 0 | if (aField) { |
205 | 0 | aField->Traverse(aCallback, aName, aFlags); |
206 | 0 | } |
207 | 0 | } |
208 | | |
209 | | } // namespace dom |
210 | | } // namespace mozilla |
211 | | |
212 | | #endif // _mozilla_dom_ClientSource_h |