| 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" | |
| 24 #include "content/common/service_worker/service_worker_types.h" | 23 #include "content/common/service_worker/service_worker_types.h" |
| 25 #include "ipc/ipc_listener.h" | 24 #include "ipc/ipc_listener.h" |
| 26 #include "services/shell/public/interfaces/interface_provider.mojom.h" | 25 #include "services/shell/public/interfaces/interface_provider.mojom.h" |
| 27 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" | 26 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" |
| 28 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerError.h" | 27 #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" | 28 #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" | 29 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo
ntextClient.h" |
| 31 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo
ntextProxy.h" | 30 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo
ntextProxy.h" |
| 32 #include "v8/include/v8.h" | 31 #include "v8/include/v8.h" |
| 33 | 32 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 61 class WebServiceWorkerRegistrationImpl; | 60 class WebServiceWorkerRegistrationImpl; |
| 62 | 61 |
| 63 // This class provides access to/from an ServiceWorker's WorkerGlobalScope. | 62 // This class provides access to/from an ServiceWorker's WorkerGlobalScope. |
| 64 // Unless otherwise noted, all methods are called on the worker thread. | 63 // Unless otherwise noted, all methods are called on the worker thread. |
| 65 class ServiceWorkerContextClient | 64 class ServiceWorkerContextClient |
| 66 : public blink::WebServiceWorkerContextClient { | 65 : public blink::WebServiceWorkerContextClient { |
| 67 public: | 66 public: |
| 68 using SyncCallback = | 67 using SyncCallback = |
| 69 base::Callback<void(blink::mojom::ServiceWorkerEventStatus, | 68 base::Callback<void(blink::mojom::ServiceWorkerEventStatus, |
| 70 base::Time /* dispatch_event_time */)>; | 69 base::Time /* dispatch_event_time */)>; |
| 71 using FetchCallback = | |
| 72 base::Callback<void(ServiceWorkerStatusCode, | |
| 73 base::Time /* dispatch_event_time */)>; | |
| 74 | 70 |
| 75 // Returns a thread-specific client instance. This does NOT create a | 71 // Returns a thread-specific client instance. This does NOT create a |
| 76 // new instance. | 72 // new instance. |
| 77 static ServiceWorkerContextClient* ThreadSpecificInstance(); | 73 static ServiceWorkerContextClient* ThreadSpecificInstance(); |
| 78 | 74 |
| 79 // Called on the main thread. | 75 // Called on the main thread. |
| 80 ServiceWorkerContextClient(int embedded_worker_id, | 76 ServiceWorkerContextClient(int embedded_worker_id, |
| 81 int64_t service_worker_version_id, | 77 int64_t service_worker_version_id, |
| 82 const GURL& service_worker_scope, | 78 const GURL& service_worker_scope, |
| 83 const GURL& script_url, | 79 const GURL& script_url, |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 const blink::WebVector<blink::WebURL>& sub_scopes, | 187 const blink::WebVector<blink::WebURL>& sub_scopes, |
| 192 const blink::WebVector<blink::WebSecurityOrigin>& origins) override; | 188 const blink::WebVector<blink::WebSecurityOrigin>& origins) override; |
| 193 | 189 |
| 194 virtual void DispatchSyncEvent( | 190 virtual void DispatchSyncEvent( |
| 195 const std::string& tag, | 191 const std::string& tag, |
| 196 blink::WebServiceWorkerContextProxy::LastChanceOption last_chance, | 192 blink::WebServiceWorkerContextProxy::LastChanceOption last_chance, |
| 197 const SyncCallback& callback); | 193 const SyncCallback& callback); |
| 198 | 194 |
| 199 private: | 195 private: |
| 200 struct WorkerContextData; | 196 struct WorkerContextData; |
| 201 class FetchEventDispatcherImpl; | |
| 202 | 197 |
| 203 // Get routing_id for sending message to the ServiceWorkerVersion | 198 // Get routing_id for sending message to the ServiceWorkerVersion |
| 204 // in the browser process. | 199 // in the browser process. |
| 205 int GetRoutingID() const { return embedded_worker_id_; } | 200 int GetRoutingID() const { return embedded_worker_id_; } |
| 206 | 201 |
| 207 void Send(IPC::Message* message); | 202 void Send(IPC::Message* message); |
| 208 void SendWorkerStarted(); | 203 void SendWorkerStarted(); |
| 209 void SetRegistrationInServiceWorkerGlobalScope( | 204 void SetRegistrationInServiceWorkerGlobalScope( |
| 210 const ServiceWorkerRegistrationObjectInfo& info, | 205 const ServiceWorkerRegistrationObjectInfo& info, |
| 211 const ServiceWorkerVersionAttributes& attrs); | 206 const ServiceWorkerVersionAttributes& attrs); |
| 212 | 207 |
| 213 void OnActivateEvent(int request_id); | 208 void OnActivateEvent(int request_id); |
| 214 void OnExtendableMessageEvent( | 209 void OnExtendableMessageEvent( |
| 215 int request_id, | 210 int request_id, |
| 216 const ServiceWorkerMsg_ExtendableMessageEvent_Params& params); | 211 const ServiceWorkerMsg_ExtendableMessageEvent_Params& params); |
| 217 void OnInstallEvent(int request_id); | 212 void OnInstallEvent(int request_id); |
| 218 void DispatchFetchEvent(int response_id, | 213 void OnFetchEvent(int response_id, |
| 219 const ServiceWorkerFetchRequest& request, | 214 int event_finish_id, |
| 220 const FetchCallback& callback); | 215 const ServiceWorkerFetchRequest& request); |
| 221 void OnNotificationClickEvent( | 216 void OnNotificationClickEvent( |
| 222 int request_id, | 217 int request_id, |
| 223 const std::string& notification_id, | 218 const std::string& notification_id, |
| 224 const PlatformNotificationData& notification_data, | 219 const PlatformNotificationData& notification_data, |
| 225 int action_index); | 220 int action_index); |
| 226 void OnPushEvent(int request_id, const PushEventPayload& payload); | 221 void OnPushEvent(int request_id, const PushEventPayload& payload); |
| 227 void OnNotificationCloseEvent( | 222 void OnNotificationCloseEvent( |
| 228 int request_id, | 223 int request_id, |
| 229 const std::string& notification_id, | 224 const std::string& notification_id, |
| 230 const PlatformNotificationData& notification_data); | 225 const PlatformNotificationData& notification_data); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 // Initialized on the worker thread in workerContextStarted and | 261 // Initialized on the worker thread in workerContextStarted and |
| 267 // destructed on the worker thread in willDestroyWorkerContext. | 262 // destructed on the worker thread in willDestroyWorkerContext. |
| 268 std::unique_ptr<WorkerContextData> context_; | 263 std::unique_ptr<WorkerContextData> context_; |
| 269 | 264 |
| 270 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContextClient); | 265 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContextClient); |
| 271 }; | 266 }; |
| 272 | 267 |
| 273 } // namespace content | 268 } // namespace content |
| 274 | 269 |
| 275 #endif // CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CLIENT_H_ | 270 #endif // CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CLIENT_H_ |
| OLD | NEW |