| 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/embedded_worker.mojom.h" | 23 #include "content/common/service_worker/embedded_worker.mojom.h" |
| 24 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h" | 24 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h" |
| 25 #include "content/common/service_worker/service_worker_provider.mojom.h" |
| 25 #include "content/common/service_worker/service_worker_status_code.h" | 26 #include "content/common/service_worker/service_worker_status_code.h" |
| 26 #include "content/common/service_worker/service_worker_types.h" | 27 #include "content/common/service_worker/service_worker_types.h" |
| 27 #include "ipc/ipc_listener.h" | 28 #include "ipc/ipc_listener.h" |
| 28 #include "mojo/public/cpp/bindings/binding.h" | 29 #include "mojo/public/cpp/bindings/binding.h" |
| 29 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" | 30 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" |
| 30 #include "third_party/WebKit/public/platform/modules/payments/payment_app.mojom.
h" | 31 #include "third_party/WebKit/public/platform/modules/payments/payment_app.mojom.
h" |
| 31 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerError.h" | 32 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerError.h" |
| 32 #include "third_party/WebKit/public/platform/modules/serviceworker/service_worke
r_event_status.mojom.h" | 33 #include "third_party/WebKit/public/platform/modules/serviceworker/service_worke
r_event_status.mojom.h" |
| 33 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo
ntextClient.h" | 34 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo
ntextClient.h" |
| 34 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo
ntextProxy.h" | 35 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo
ntextProxy.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 50 | 51 |
| 51 namespace IPC { | 52 namespace IPC { |
| 52 class Message; | 53 class Message; |
| 53 } | 54 } |
| 54 | 55 |
| 55 namespace content { | 56 namespace content { |
| 56 | 57 |
| 57 struct PlatformNotificationData; | 58 struct PlatformNotificationData; |
| 58 struct PushEventPayload; | 59 struct PushEventPayload; |
| 59 struct ServiceWorkerClientInfo; | 60 struct ServiceWorkerClientInfo; |
| 61 class ServiceWorkerNetworkProvider; |
| 60 class ServiceWorkerProviderContext; | 62 class ServiceWorkerProviderContext; |
| 61 class ServiceWorkerContextClient; | |
| 62 class ThreadSafeSender; | 63 class ThreadSafeSender; |
| 63 class EmbeddedWorkerInstanceClientImpl; | 64 class EmbeddedWorkerInstanceClientImpl; |
| 64 class WebWorkerFetchContext; | 65 class WebWorkerFetchContext; |
| 65 | 66 |
| 66 // This class provides access to/from an ServiceWorker's WorkerGlobalScope. | 67 // This class provides access to/from an ServiceWorker's WorkerGlobalScope. |
| 67 // Unless otherwise noted, all methods are called on the worker thread. | 68 // Unless otherwise noted, all methods are called on the worker thread. |
| 68 class ServiceWorkerContextClient : public blink::WebServiceWorkerContextClient, | 69 class ServiceWorkerContextClient : public blink::WebServiceWorkerContextClient, |
| 69 public mojom::ServiceWorkerEventDispatcher { | 70 public mojom::ServiceWorkerEventDispatcher { |
| 70 public: | 71 public: |
| 71 using SyncCallback = | 72 using SyncCallback = |
| 72 base::OnceCallback<void(ServiceWorkerStatusCode, | 73 base::OnceCallback<void(ServiceWorkerStatusCode, |
| 73 base::Time /* dispatch_event_time */)>; | 74 base::Time /* dispatch_event_time */)>; |
| 74 using FetchCallback = | 75 using FetchCallback = |
| 75 base::OnceCallback<void(ServiceWorkerStatusCode, | 76 base::OnceCallback<void(ServiceWorkerStatusCode, |
| 76 base::Time /* dispatch_event_time */)>; | 77 base::Time /* dispatch_event_time */)>; |
| 77 | 78 |
| 78 // Returns a thread-specific client instance. This does NOT create a | 79 // Returns a thread-specific client instance. This does NOT create a |
| 79 // new instance. | 80 // new instance. |
| 80 static ServiceWorkerContextClient* ThreadSpecificInstance(); | 81 static ServiceWorkerContextClient* ThreadSpecificInstance(); |
| 81 | 82 |
| 82 // Called on the main thread. | 83 // Called on the main thread. |
| 83 ServiceWorkerContextClient( | 84 ServiceWorkerContextClient( |
| 84 int embedded_worker_id, | 85 int embedded_worker_id, |
| 85 int64_t service_worker_version_id, | 86 int64_t service_worker_version_id, |
| 86 const GURL& service_worker_scope, | 87 const GURL& service_worker_scope, |
| 87 const GURL& script_url, | 88 const GURL& script_url, |
| 88 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request, | 89 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request, |
| 89 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host, | 90 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host, |
| 91 mojom::ServiceWorkerProviderClientInfoPtr provider_client_info, |
| 90 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> embedded_worker_client); | 92 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> embedded_worker_client); |
| 91 ~ServiceWorkerContextClient() override; | 93 ~ServiceWorkerContextClient() override; |
| 92 | 94 |
| 93 void OnMessageReceived(int thread_id, | 95 void OnMessageReceived(int thread_id, |
| 94 int embedded_worker_id, | 96 int embedded_worker_id, |
| 95 const IPC::Message& message); | 97 const IPC::Message& message); |
| 96 | 98 |
| 97 // WebServiceWorkerContextClient overrides. | 99 // WebServiceWorkerContextClient overrides. |
| 98 blink::WebURL Scope() const override; | 100 blink::WebURL Scope() const override; |
| 99 void GetClient( | 101 void GetClient( |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 void OnNavigationPreloadError( | 337 void OnNavigationPreloadError( |
| 336 int fetch_event_id, | 338 int fetch_event_id, |
| 337 std::unique_ptr<blink::WebServiceWorkerError> error); | 339 std::unique_ptr<blink::WebServiceWorkerError> error); |
| 338 | 340 |
| 339 base::WeakPtr<ServiceWorkerContextClient> GetWeakPtr(); | 341 base::WeakPtr<ServiceWorkerContextClient> GetWeakPtr(); |
| 340 | 342 |
| 341 const int embedded_worker_id_; | 343 const int embedded_worker_id_; |
| 342 const int64_t service_worker_version_id_; | 344 const int64_t service_worker_version_id_; |
| 343 const GURL service_worker_scope_; | 345 const GURL service_worker_scope_; |
| 344 const GURL script_url_; | 346 const GURL script_url_; |
| 345 int network_provider_id_ = kInvalidServiceWorkerProviderId; | |
| 346 scoped_refptr<ThreadSafeSender> sender_; | 347 scoped_refptr<ThreadSafeSender> sender_; |
| 347 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | 348 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
| 348 scoped_refptr<base::TaskRunner> worker_task_runner_; | 349 scoped_refptr<base::TaskRunner> worker_task_runner_; |
| 349 | 350 |
| 350 scoped_refptr<ServiceWorkerProviderContext> provider_context_; | 351 scoped_refptr<ServiceWorkerProviderContext> provider_context_; |
| 351 | 352 |
| 352 // Not owned; this object is destroyed when proxy_ becomes invalid. | 353 // Not owned; this object is destroyed when proxy_ becomes invalid. |
| 353 blink::WebServiceWorkerContextProxy* proxy_; | 354 blink::WebServiceWorkerContextProxy* proxy_; |
| 354 | 355 |
| 355 // This is bound on the worker thread. | 356 // This is bound on the worker thread. |
| 356 mojom::ServiceWorkerEventDispatcherRequest pending_dispatcher_request_; | 357 mojom::ServiceWorkerEventDispatcherRequest pending_dispatcher_request_; |
| 357 | 358 |
| 358 // This is bound on the main thread. | 359 // This is bound on the main thread. |
| 359 scoped_refptr<mojom::ThreadSafeEmbeddedWorkerInstanceHostAssociatedPtr> | 360 scoped_refptr<mojom::ThreadSafeEmbeddedWorkerInstanceHostAssociatedPtr> |
| 360 instance_host_; | 361 instance_host_; |
| 361 | 362 |
| 363 // This is passed to ServiceWorkerNetworkProvider when |
| 364 // createServiceWorkerNetworkProvider is called. |
| 365 std::unique_ptr<ServiceWorkerNetworkProvider> pending_network_provider_; |
| 366 |
| 362 // Renderer-side object corresponding to WebEmbeddedWorkerInstance. | 367 // Renderer-side object corresponding to WebEmbeddedWorkerInstance. |
| 363 // This is valid from the ctor to workerContextDestroyed. | 368 // This is valid from the ctor to workerContextDestroyed. |
| 364 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> embedded_worker_client_; | 369 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> embedded_worker_client_; |
| 365 | 370 |
| 366 // Initialized on the worker thread in workerContextStarted and | 371 // Initialized on the worker thread in workerContextStarted and |
| 367 // destructed on the worker thread in willDestroyWorkerContext. | 372 // destructed on the worker thread in willDestroyWorkerContext. |
| 368 std::unique_ptr<WorkerContextData> context_; | 373 std::unique_ptr<WorkerContextData> context_; |
| 369 | 374 |
| 370 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContextClient); | 375 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContextClient); |
| 371 }; | 376 }; |
| 372 | 377 |
| 373 } // namespace content | 378 } // namespace content |
| 374 | 379 |
| 375 #endif // CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CLIENT_H_ | 380 #endif // CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CLIENT_H_ |
| OLD | NEW |