Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: content/renderer/service_worker/service_worker_context_client.h

Issue 2490623005: Remove InterfaceRegistry/Provider from service workers (Closed)
Patch Set: review Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CLIENT_H_ 5 #ifndef CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CLIENT_H_
6 #define CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CLIENT_H_ 6 #define CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CLIENT_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <map> 11 #include <map>
12 #include <memory> 12 #include <memory>
13 #include <string> 13 #include <string>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/callback.h" 16 #include "base/callback.h"
17 #include "base/id_map.h" 17 #include "base/id_map.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/memory/ref_counted.h" 19 #include "base/memory/ref_counted.h"
20 #include "base/strings/string16.h" 20 #include "base/strings/string16.h"
21 #include "base/time/time.h" 21 #include "base/time/time.h"
22 #include "content/child/webmessageportchannel_impl.h" 22 #include "content/child/webmessageportchannel_impl.h"
23 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h"
23 #include "content/common/service_worker/service_worker_status_code.h" 24 #include "content/common/service_worker/service_worker_status_code.h"
24 #include "content/common/service_worker/service_worker_types.h" 25 #include "content/common/service_worker/service_worker_types.h"
25 #include "ipc/ipc_listener.h" 26 #include "ipc/ipc_listener.h"
26 #include "services/service_manager/public/interfaces/interface_provider.mojom.h" 27 #include "mojo/public/cpp/bindings/binding.h"
27 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" 28 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h"
28 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerError.h" 29 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerError.h"
29 #include "third_party/WebKit/public/platform/modules/serviceworker/service_worke r_event_status.mojom.h" 30 #include "third_party/WebKit/public/platform/modules/serviceworker/service_worke r_event_status.mojom.h"
30 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo ntextClient.h" 31 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo ntextClient.h"
31 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo ntextProxy.h" 32 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo ntextProxy.h"
32 #include "v8/include/v8.h" 33 #include "v8/include/v8.h"
33 34
34 struct ServiceWorkerMsg_ExtendableMessageEvent_Params; 35 struct ServiceWorkerMsg_ExtendableMessageEvent_Params;
35 36
36 namespace base { 37 namespace base {
(...skipping 19 matching lines...) Expand all
56 struct PlatformNotificationData; 57 struct PlatformNotificationData;
57 struct PushEventPayload; 58 struct PushEventPayload;
58 struct ServiceWorkerClientInfo; 59 struct ServiceWorkerClientInfo;
59 class ServiceWorkerProviderContext; 60 class ServiceWorkerProviderContext;
60 class ServiceWorkerContextClient; 61 class ServiceWorkerContextClient;
61 class ThreadSafeSender; 62 class ThreadSafeSender;
62 class EmbeddedWorkerInstanceClientImpl; 63 class EmbeddedWorkerInstanceClientImpl;
63 64
64 // This class provides access to/from an ServiceWorker's WorkerGlobalScope. 65 // This class provides access to/from an ServiceWorker's WorkerGlobalScope.
65 // Unless otherwise noted, all methods are called on the worker thread. 66 // Unless otherwise noted, all methods are called on the worker thread.
66 class ServiceWorkerContextClient 67 class ServiceWorkerContextClient : public blink::WebServiceWorkerContextClient,
67 : public blink::WebServiceWorkerContextClient { 68 public mojom::ServiceWorkerEventDispatcher {
68 public: 69 public:
69 using SyncCallback = 70 using SyncCallback =
70 base::Callback<void(blink::mojom::ServiceWorkerEventStatus, 71 base::Callback<void(ServiceWorkerStatusCode,
71 base::Time /* dispatch_event_time */)>; 72 base::Time /* dispatch_event_time */)>;
72 using FetchCallback = 73 using FetchCallback =
73 base::Callback<void(ServiceWorkerStatusCode, 74 base::Callback<void(ServiceWorkerStatusCode,
74 base::Time /* dispatch_event_time */)>; 75 base::Time /* dispatch_event_time */)>;
75 76
76 // Returns a thread-specific client instance. This does NOT create a 77 // Returns a thread-specific client instance. This does NOT create a
77 // new instance. 78 // new instance.
78 static ServiceWorkerContextClient* ThreadSpecificInstance(); 79 static ServiceWorkerContextClient* ThreadSpecificInstance();
79 80
80 // Called on the main thread. 81 // Called on the main thread.
81 ServiceWorkerContextClient( 82 ServiceWorkerContextClient(
82 int embedded_worker_id, 83 int embedded_worker_id,
83 int64_t service_worker_version_id, 84 int64_t service_worker_version_id,
84 const GURL& service_worker_scope, 85 const GURL& service_worker_scope,
85 const GURL& script_url, 86 const GURL& script_url,
86 int worker_devtools_agent_route_id, 87 int worker_devtools_agent_route_id,
88 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request,
87 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> embedded_worker_client); 89 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> embedded_worker_client);
90 ServiceWorkerContextClient(int embedded_worker_id,
91 int64_t service_worker_version_id,
92 const GURL& service_worker_scope,
93 const GURL& script_url,
94 int worker_devtools_agent_route_id);
88 ~ServiceWorkerContextClient() override; 95 ~ServiceWorkerContextClient() override;
89 96
90 void OnMessageReceived(int thread_id, 97 void OnMessageReceived(int thread_id,
91 int embedded_worker_id, 98 int embedded_worker_id,
92 const IPC::Message& message); 99 const IPC::Message& message);
93 100
94 // Called some time after the worker has started. 101 // Called after the worker has started.
95 void BindInterfaceProviders( 102 void BindEventDispatcher(mojom::ServiceWorkerEventDispatcherRequest request);
96 service_manager::mojom::InterfaceProviderRequest request,
97 service_manager::mojom::InterfaceProviderPtr remote_interfaces);
98 103
99 // WebServiceWorkerContextClient overrides. 104 // WebServiceWorkerContextClient overrides.
100 blink::WebURL scope() const override; 105 blink::WebURL scope() const override;
101 void getClient(const blink::WebString&, 106 void getClient(const blink::WebString&,
102 blink::WebServiceWorkerClientCallbacks*) override; 107 blink::WebServiceWorkerClientCallbacks*) override;
103 void getClients(const blink::WebServiceWorkerClientQueryOptions&, 108 void getClients(const blink::WebServiceWorkerClientQueryOptions&,
104 blink::WebServiceWorkerClientsCallbacks*) override; 109 blink::WebServiceWorkerClientsCallbacks*) override;
105 void openWindow(const blink::WebURL&, 110 void openWindow(const blink::WebURL&,
106 blink::WebServiceWorkerClientCallbacks*) override; 111 blink::WebServiceWorkerClientCallbacks*) override;
107 void setCachedMetadata(const blink::WebURL&, 112 void setCachedMetadata(const blink::WebURL&,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 void navigate(const blink::WebString& uuid, 192 void navigate(const blink::WebString& uuid,
188 const blink::WebURL&, 193 const blink::WebURL&,
189 blink::WebServiceWorkerClientCallbacks*) override; 194 blink::WebServiceWorkerClientCallbacks*) override;
190 void skipWaiting( 195 void skipWaiting(
191 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) override; 196 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) override;
192 void claim(blink::WebServiceWorkerClientsClaimCallbacks* callbacks) override; 197 void claim(blink::WebServiceWorkerClientsClaimCallbacks* callbacks) override;
193 void registerForeignFetchScopes( 198 void registerForeignFetchScopes(
194 const blink::WebVector<blink::WebURL>& sub_scopes, 199 const blink::WebVector<blink::WebURL>& sub_scopes,
195 const blink::WebVector<blink::WebSecurityOrigin>& origins) override; 200 const blink::WebVector<blink::WebSecurityOrigin>& origins) override;
196 201
197 virtual void DispatchSyncEvent(
198 const std::string& tag,
199 blink::WebServiceWorkerContextProxy::LastChanceOption last_chance,
200 const SyncCallback& callback);
201
202 private: 202 private:
203 struct WorkerContextData; 203 struct WorkerContextData;
204 class FetchEventDispatcherImpl;
205 class NavigationPreloadRequest; 204 class NavigationPreloadRequest;
206 205
207 // Get routing_id for sending message to the ServiceWorkerVersion 206 // Get routing_id for sending message to the ServiceWorkerVersion
208 // in the browser process. 207 // in the browser process.
209 int GetRoutingID() const { return embedded_worker_id_; } 208 int GetRoutingID() const { return embedded_worker_id_; }
210 209
211 void Send(IPC::Message* message); 210 void Send(IPC::Message* message);
212 void SendWorkerStarted(); 211 void SendWorkerStarted();
213 void SetRegistrationInServiceWorkerGlobalScope( 212 void SetRegistrationInServiceWorkerGlobalScope(
214 const ServiceWorkerRegistrationObjectInfo& info, 213 const ServiceWorkerRegistrationObjectInfo& info,
215 const ServiceWorkerVersionAttributes& attrs); 214 const ServiceWorkerVersionAttributes& attrs);
216 215
217 void OnActivateEvent(int request_id); 216 void OnActivateEvent(int request_id);
218 void OnExtendableMessageEvent( 217 void OnExtendableMessageEvent(
219 int request_id, 218 int request_id,
220 const ServiceWorkerMsg_ExtendableMessageEvent_Params& params); 219 const ServiceWorkerMsg_ExtendableMessageEvent_Params& params);
221 void OnInstallEvent(int request_id); 220 void OnInstallEvent(int request_id);
222 void DispatchFetchEvent( 221 // mojom::ServiceWorkerEventDispatcher
223 int fetch_event_id, 222 void DispatchFetchEvent(int fetch_event_id,
dcheng 2016/11/22 07:59:04 Nit: we should probably use int32_t consistently h
shimazu 2016/11/24 06:47:32 Thanks, I'll do it when I move all of events to SW
224 const ServiceWorkerFetchRequest& request, 223 const ServiceWorkerFetchRequest& request,
225 std::unique_ptr<NavigationPreloadRequest> preload_request, 224 mojom::FetchEventPreloadHandlePtr preload_handle,
226 const FetchCallback& callback); 225 const DispatchFetchEventCallback& callback) override;
227 void OnNotificationClickEvent( 226 void OnNotificationClickEvent(
228 int request_id, 227 int request_id,
229 const std::string& notification_id, 228 const std::string& notification_id,
230 const PlatformNotificationData& notification_data, 229 const PlatformNotificationData& notification_data,
231 int action_index, 230 int action_index,
232 const base::NullableString16& reply); 231 const base::NullableString16& reply);
233 void OnPushEvent(int request_id, const PushEventPayload& payload); 232 void OnPushEvent(int request_id, const PushEventPayload& payload);
234 void OnNotificationCloseEvent( 233 void OnNotificationCloseEvent(
235 int request_id, 234 int request_id,
236 const std::string& notification_id, 235 const std::string& notification_id,
237 const PlatformNotificationData& notification_data); 236 const PlatformNotificationData& notification_data);
237 // mojom::ServiceWorkerEventDispatcher
falken 2016/11/23 14:32:31 nit: DispatchFetchEvent and DispatchSyncEvent shou
shimazu 2016/11/24 06:47:32 Done.
238 void DispatchSyncEvent(
239 const std::string& tag,
240 blink::mojom::BackgroundSyncEventLastChance last_chance,
241 const DispatchSyncEventCallback& callback) override;
238 242
239 void OnDidGetClient(int request_id, const ServiceWorkerClientInfo& client); 243 void OnDidGetClient(int request_id, const ServiceWorkerClientInfo& client);
240 void OnDidGetClients( 244 void OnDidGetClients(
241 int request_id, const std::vector<ServiceWorkerClientInfo>& clients); 245 int request_id, const std::vector<ServiceWorkerClientInfo>& clients);
242 void OnOpenWindowResponse(int request_id, 246 void OnOpenWindowResponse(int request_id,
243 const ServiceWorkerClientInfo& client); 247 const ServiceWorkerClientInfo& client);
244 void OnOpenWindowError(int request_id, const std::string& message); 248 void OnOpenWindowError(int request_id, const std::string& message);
245 void OnFocusClientResponse(int request_id, 249 void OnFocusClientResponse(int request_id,
246 const ServiceWorkerClientInfo& client); 250 const ServiceWorkerClientInfo& client);
247 void OnNavigateClientResponse(int request_id, 251 void OnNavigateClientResponse(int request_id,
(...skipping 23 matching lines...) Expand all
271 const int worker_devtools_agent_route_id_; 275 const int worker_devtools_agent_route_id_;
272 scoped_refptr<ThreadSafeSender> sender_; 276 scoped_refptr<ThreadSafeSender> sender_;
273 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; 277 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
274 scoped_refptr<base::TaskRunner> worker_task_runner_; 278 scoped_refptr<base::TaskRunner> worker_task_runner_;
275 279
276 scoped_refptr<ServiceWorkerProviderContext> provider_context_; 280 scoped_refptr<ServiceWorkerProviderContext> provider_context_;
277 281
278 // Not owned; this object is destroyed when proxy_ becomes invalid. 282 // Not owned; this object is destroyed when proxy_ becomes invalid.
279 blink::WebServiceWorkerContextProxy* proxy_; 283 blink::WebServiceWorkerContextProxy* proxy_;
280 284
285 // This should be bound on the worker thread.
falken 2016/11/23 14:32:31 "should be" is unclear... "This is bound on the wo
shimazu 2016/11/24 06:47:32 Thanks, fixed it:)
286 mojom::ServiceWorkerEventDispatcherRequest pending_dispatcher_request_;
287
281 // Renderer-side object corresponding to WebEmbeddedWorkerInstance 288 // Renderer-side object corresponding to WebEmbeddedWorkerInstance
282 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> embedded_worker_client_; 289 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> embedded_worker_client_;
283 290
284 // Initialized on the worker thread in workerContextStarted and 291 // Initialized on the worker thread in workerContextStarted and
285 // destructed on the worker thread in willDestroyWorkerContext. 292 // destructed on the worker thread in willDestroyWorkerContext.
286 std::unique_ptr<WorkerContextData> context_; 293 std::unique_ptr<WorkerContextData> context_;
287 294
288 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContextClient); 295 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContextClient);
289 }; 296 };
290 297
291 } // namespace content 298 } // namespace content
292 299
293 #endif // CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CLIENT_H_ 300 #endif // CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698