| OLD | NEW |
| 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_status_code.h" | 23 #include "content/common/service_worker/service_worker_status_code.h" |
| 24 #include "content/common/service_worker/service_worker_types.h" | 24 #include "content/common/service_worker/service_worker_types.h" |
| 25 #include "content/renderer/mojo/blink_interface_registry_impl.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 "services/service_manager/public/interfaces/interface_provider.mojom.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 { |
| 37 class SingleThreadTaskRunner; | 38 class SingleThreadTaskRunner; |
| 38 class TaskRunner; | 39 class TaskRunner; |
| 39 } | 40 } |
| 40 | 41 |
| 41 namespace blink { | 42 namespace blink { |
| 42 class WebDataConsumerHandle; | 43 class WebDataConsumerHandle; |
| 43 class WebDataSource; | 44 class WebDataSource; |
| 44 struct WebServiceWorkerClientQueryOptions; | 45 struct WebServiceWorkerClientQueryOptions; |
| 45 class WebServiceWorkerContextProxy; | 46 class WebServiceWorkerContextProxy; |
| 46 class WebServiceWorkerProvider; | 47 class WebServiceWorkerProvider; |
| 47 class WebServiceWorkerResponse; | 48 class WebServiceWorkerResponse; |
| 49 class InterfaceRegistry; |
| 48 } | 50 } |
| 49 | 51 |
| 50 namespace IPC { | 52 namespace IPC { |
| 51 class Message; | 53 class Message; |
| 52 } | 54 } |
| 53 | 55 |
| 54 namespace content { | 56 namespace content { |
| 55 | 57 |
| 56 struct PlatformNotificationData; | 58 struct PlatformNotificationData; |
| 57 struct PushEventPayload; | 59 struct PushEventPayload; |
| 58 struct ServiceWorkerClientInfo; | 60 struct ServiceWorkerClientInfo; |
| 59 class ServiceWorkerProviderContext; | 61 class ServiceWorkerProviderContext; |
| 60 class ServiceWorkerContextClient; | 62 class ServiceWorkerContextClient; |
| 61 class ThreadSafeSender; | 63 class ThreadSafeSender; |
| 62 class EmbeddedWorkerInstanceClientImpl; | 64 class EmbeddedWorkerInstanceClientImpl; |
| 63 | 65 |
| 64 // This class provides access to/from an ServiceWorker's WorkerGlobalScope. | 66 // This class provides access to/from an ServiceWorker's WorkerGlobalScope. |
| 65 // Unless otherwise noted, all methods are called on the worker thread. | 67 // Unless otherwise noted, all methods are called on the worker thread. |
| 66 class ServiceWorkerContextClient | 68 class ServiceWorkerContextClient |
| 67 : public blink::WebServiceWorkerContextClient { | 69 : public blink::WebServiceWorkerContextClient { |
| 68 public: | 70 public: |
| 69 using SyncCallback = | |
| 70 base::Callback<void(blink::mojom::ServiceWorkerEventStatus, | |
| 71 base::Time /* dispatch_event_time */)>; | |
| 72 using FetchCallback = | 71 using FetchCallback = |
| 73 base::Callback<void(ServiceWorkerStatusCode, | 72 base::Callback<void(ServiceWorkerStatusCode, |
| 74 base::Time /* dispatch_event_time */)>; | 73 base::Time /* dispatch_event_time */)>; |
| 75 | 74 |
| 76 // Returns a thread-specific client instance. This does NOT create a | 75 // Returns a thread-specific client instance. This does NOT create a |
| 77 // new instance. | 76 // new instance. |
| 78 static ServiceWorkerContextClient* ThreadSpecificInstance(); | 77 static ServiceWorkerContextClient* ThreadSpecificInstance(); |
| 79 | 78 |
| 80 // Called on the main thread. | 79 // Called on the main thread. |
| 81 ServiceWorkerContextClient( | 80 ServiceWorkerContextClient( |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 int request_id, | 157 int request_id, |
| 159 blink::WebServiceWorkerEventResult result, | 158 blink::WebServiceWorkerEventResult result, |
| 160 double dispatch_event_time) override; | 159 double dispatch_event_time) override; |
| 161 void didHandleNotificationCloseEvent( | 160 void didHandleNotificationCloseEvent( |
| 162 int request_id, | 161 int request_id, |
| 163 blink::WebServiceWorkerEventResult result, | 162 blink::WebServiceWorkerEventResult result, |
| 164 double dispatch_event_time) override; | 163 double dispatch_event_time) override; |
| 165 void didHandlePushEvent(int request_id, | 164 void didHandlePushEvent(int request_id, |
| 166 blink::WebServiceWorkerEventResult result, | 165 blink::WebServiceWorkerEventResult result, |
| 167 double dispatch_event_time) override; | 166 double dispatch_event_time) override; |
| 168 void didHandleSyncEvent(int request_id, | |
| 169 blink::WebServiceWorkerEventResult result, | |
| 170 double dispatch_event_time) override; | |
| 171 | 167 |
| 172 // Called on the main thread. | 168 // Called on the main thread. |
| 173 blink::WebServiceWorkerNetworkProvider* createServiceWorkerNetworkProvider( | 169 blink::WebServiceWorkerNetworkProvider* createServiceWorkerNetworkProvider( |
| 174 blink::WebDataSource* data_source) override; | 170 blink::WebDataSource* data_source) override; |
| 175 blink::WebServiceWorkerProvider* createServiceWorkerProvider() override; | 171 blink::WebServiceWorkerProvider* createServiceWorkerProvider() override; |
| 176 | 172 |
| 177 void postMessageToClient( | 173 void postMessageToClient( |
| 178 const blink::WebString& uuid, | 174 const blink::WebString& uuid, |
| 179 const blink::WebString& message, | 175 const blink::WebString& message, |
| 180 blink::WebMessagePortChannelArray* channels) override; | 176 blink::WebMessagePortChannelArray* channels) override; |
| 181 void postMessageToCrossOriginClient( | 177 void postMessageToCrossOriginClient( |
| 182 const blink::WebCrossOriginServiceWorkerClient&, | 178 const blink::WebCrossOriginServiceWorkerClient&, |
| 183 const blink::WebString&, | 179 const blink::WebString&, |
| 184 blink::WebMessagePortChannelArray*) override; | 180 blink::WebMessagePortChannelArray*) override; |
| 185 void focus(const blink::WebString& uuid, | 181 void focus(const blink::WebString& uuid, |
| 186 blink::WebServiceWorkerClientCallbacks*) override; | 182 blink::WebServiceWorkerClientCallbacks*) override; |
| 187 void navigate(const blink::WebString& uuid, | 183 void navigate(const blink::WebString& uuid, |
| 188 const blink::WebURL&, | 184 const blink::WebURL&, |
| 189 blink::WebServiceWorkerClientCallbacks*) override; | 185 blink::WebServiceWorkerClientCallbacks*) override; |
| 190 void skipWaiting( | 186 void skipWaiting( |
| 191 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) override; | 187 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) override; |
| 192 void claim(blink::WebServiceWorkerClientsClaimCallbacks* callbacks) override; | 188 void claim(blink::WebServiceWorkerClientsClaimCallbacks* callbacks) override; |
| 193 void registerForeignFetchScopes( | 189 void registerForeignFetchScopes( |
| 194 const blink::WebVector<blink::WebURL>& sub_scopes, | 190 const blink::WebVector<blink::WebURL>& sub_scopes, |
| 195 const blink::WebVector<blink::WebSecurityOrigin>& origins) override; | 191 const blink::WebVector<blink::WebSecurityOrigin>& origins) override; |
| 196 | 192 blink::InterfaceRegistry* interfaceRegistry() override; |
| 197 virtual void DispatchSyncEvent( | |
| 198 const std::string& tag, | |
| 199 blink::WebServiceWorkerContextProxy::LastChanceOption last_chance, | |
| 200 const SyncCallback& callback); | |
| 201 | 193 |
| 202 private: | 194 private: |
| 203 struct WorkerContextData; | 195 struct WorkerContextData; |
| 204 class FetchEventDispatcherImpl; | 196 class FetchEventDispatcherImpl; |
| 205 class NavigationPreloadRequest; | 197 class NavigationPreloadRequest; |
| 206 | 198 |
| 207 // Get routing_id for sending message to the ServiceWorkerVersion | 199 // Get routing_id for sending message to the ServiceWorkerVersion |
| 208 // in the browser process. | 200 // in the browser process. |
| 209 int GetRoutingID() const { return embedded_worker_id_; } | 201 int GetRoutingID() const { return embedded_worker_id_; } |
| 210 | 202 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 // Not owned; this object is destroyed when proxy_ becomes invalid. | 270 // Not owned; this object is destroyed when proxy_ becomes invalid. |
| 279 blink::WebServiceWorkerContextProxy* proxy_; | 271 blink::WebServiceWorkerContextProxy* proxy_; |
| 280 | 272 |
| 281 // Renderer-side object corresponding to WebEmbeddedWorkerInstance | 273 // Renderer-side object corresponding to WebEmbeddedWorkerInstance |
| 282 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> embedded_worker_client_; | 274 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> embedded_worker_client_; |
| 283 | 275 |
| 284 // Initialized on the worker thread in workerContextStarted and | 276 // Initialized on the worker thread in workerContextStarted and |
| 285 // destructed on the worker thread in willDestroyWorkerContext. | 277 // destructed on the worker thread in willDestroyWorkerContext. |
| 286 std::unique_ptr<WorkerContextData> context_; | 278 std::unique_ptr<WorkerContextData> context_; |
| 287 | 279 |
| 280 std::unique_ptr<BlinkInterfaceRegistryImpl> blink_interface_registry_; |
| 281 |
| 288 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContextClient); | 282 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContextClient); |
| 289 }; | 283 }; |
| 290 | 284 |
| 291 } // namespace content | 285 } // namespace content |
| 292 | 286 |
| 293 #endif // CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CLIENT_H_ | 287 #endif // CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CLIENT_H_ |
| OLD | NEW |