| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_WORKER_FETCH_CONTEXT_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_SERVICE_WORKER_WORKER_FETCH_CONTEXT_IMPL_H_ |
| 6 #define CONTENT_RENDERER_SERVICE_WORKER_WORKER_FETCH_CONTEXT_IMPL_H_ | 6 #define CONTENT_RENDERER_SERVICE_WORKER_WORKER_FETCH_CONTEXT_IMPL_H_ |
| 7 | 7 |
| 8 #include "content/common/service_worker/service_worker_types.h" | 8 #include "content/common/service_worker/service_worker_types.h" |
| 9 #include "content/common/worker_url_loader_factory_provider.mojom.h" | 9 #include "content/common/worker_url_loader_factory_provider.mojom.h" |
| 10 #include "ipc/ipc_message.h" | 10 #include "ipc/ipc_message.h" |
| 11 #include "mojo/public/cpp/bindings/associated_binding.h" | 11 #include "mojo/public/cpp/bindings/associated_binding.h" |
| 12 #include "third_party/WebKit/public/platform/WebWorkerFetchContext.h" | 12 #include "third_party/WebKit/public/platform/WebWorkerFetchContext.h" |
| 13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 14 | 14 |
| 15 namespace base { | 15 namespace base { |
| 16 class SingleThreadTaskRunner; | 16 class SingleThreadTaskRunner; |
| 17 } // namespace base | 17 } // namespace base |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 | 20 |
| 21 class ResourceDispatcher; | 21 class ResourceDispatcher; |
| 22 | 22 |
| 23 // This class is used while fetching resource requests on workers (dedicated |
| 24 // worker and shared worker) when off-main-thread-fetch is enabled. This class |
| 25 // is created on the main thread and passed to the worker thread. |
| 26 // This class is not used for service workers. For service workers, |
| 27 // ServiceWorkerFetchContextImpl class is used instead. |
| 23 class WorkerFetchContextImpl : public blink::WebWorkerFetchContext, | 28 class WorkerFetchContextImpl : public blink::WebWorkerFetchContext, |
| 24 public mojom::ServiceWorkerWorkerClient { | 29 public mojom::ServiceWorkerWorkerClient { |
| 25 public: | 30 public: |
| 26 explicit WorkerFetchContextImpl( | 31 explicit WorkerFetchContextImpl( |
| 27 mojom::WorkerURLLoaderFactoryProviderPtrInfo provider_info); | 32 mojom::WorkerURLLoaderFactoryProviderPtrInfo provider_info); |
| 28 ~WorkerFetchContextImpl() override; | 33 ~WorkerFetchContextImpl() override; |
| 29 | 34 |
| 30 // blink::WebWorkerFetchContext implementation: | 35 // blink::WebWorkerFetchContext implementation: |
| 31 void InitializeOnWorkerThread(base::SingleThreadTaskRunner*) override; | 36 void InitializeOnWorkerThread(base::SingleThreadTaskRunner*) override; |
| 32 std::unique_ptr<blink::WebURLLoader> CreateURLLoader() override; | 37 std::unique_ptr<blink::WebURLLoader> CreateURLLoader() override; |
| 33 void WillSendRequest(blink::WebURLRequest&) override; | 38 void WillSendRequest(blink::WebURLRequest&) override; |
| 34 bool IsControlledByServiceWorker() const override; | 39 bool IsControlledByServiceWorker() const override; |
| 35 void SetDataSaverEnabled(bool) override; | 40 void SetDataSaverEnabled(bool) override; |
| 36 bool IsDataSaverEnabled() const override; | 41 bool IsDataSaverEnabled() const override; |
| 37 blink::WebURL FirstPartyForCookies() const override; | 42 blink::WebURL FirstPartyForCookies() const override; |
| 38 | 43 |
| 39 // mojom::ServiceWorkerWorkerClient implementation: | 44 // mojom::ServiceWorkerWorkerClient implementation: |
| 40 void SetControllerServiceWorker(int64_t controller_version_id) override; | 45 void SetControllerServiceWorker(int64_t controller_version_id) override; |
| 41 | 46 |
| 42 // Sets the fetch context status of the parent frame. | 47 // Sets the fetch context status copied from the frame; the parent frame for a |
| 48 // dedicated worker, the main frame of the shadow page for a shared worker. |
| 43 void set_service_worker_provider_id(int id); | 49 void set_service_worker_provider_id(int id); |
| 44 void set_is_controlled_by_service_worker(bool flag); | 50 void set_is_controlled_by_service_worker(bool flag); |
| 45 void set_parent_frame_id(int id); | 51 void set_parent_frame_id(int id); |
| 46 void set_first_party_for_cookies( | 52 void set_first_party_for_cookies( |
| 47 const blink::WebURL& first_party_for_cookies); | 53 const blink::WebURL& first_party_for_cookies); |
| 54 // Sets whether the worker context is a secure context. |
| 55 // https://w3c.github.io/webappsec-secure-contexts/ |
| 56 void set_is_secure_context(bool flag); |
| 48 | 57 |
| 49 private: | 58 private: |
| 50 mojom::WorkerURLLoaderFactoryProviderPtrInfo provider_info_; | 59 mojom::WorkerURLLoaderFactoryProviderPtrInfo provider_info_; |
| 51 int service_worker_provider_id_ = kInvalidServiceWorkerProviderId; | 60 int service_worker_provider_id_ = kInvalidServiceWorkerProviderId; |
| 52 bool is_controlled_by_service_worker_ = false; | 61 bool is_controlled_by_service_worker_ = false; |
| 53 | 62 |
| 54 // Initialized on the worker thread when InitializeOnWorkerThread() is called. | 63 // Initialized on the worker thread when InitializeOnWorkerThread() is called. |
| 55 std::unique_ptr<ResourceDispatcher> resource_dispatcher_; | 64 std::unique_ptr<ResourceDispatcher> resource_dispatcher_; |
| 56 std::unique_ptr<mojo::AssociatedBinding<mojom::ServiceWorkerWorkerClient>> | 65 std::unique_ptr<mojo::AssociatedBinding<mojom::ServiceWorkerWorkerClient>> |
| 57 binding_; | 66 binding_; |
| 58 mojom::WorkerURLLoaderFactoryProviderPtr provider_; | 67 mojom::WorkerURLLoaderFactoryProviderPtr provider_; |
| 59 mojom::URLLoaderFactoryAssociatedPtr url_loader_factory_; | 68 mojom::URLLoaderFactoryAssociatedPtr url_loader_factory_; |
| 60 | 69 |
| 61 // Updated when mojom::ServiceWorkerWorkerClient::SetControllerServiceWorker() | 70 // Updated when mojom::ServiceWorkerWorkerClient::SetControllerServiceWorker() |
| 62 // is called from the browser process via mojo IPC. | 71 // is called from the browser process via mojo IPC. |
| 63 int controller_version_id_ = kInvalidServiceWorkerVersionId; | 72 int controller_version_id_ = kInvalidServiceWorkerVersionId; |
| 64 | 73 |
| 65 bool is_data_saver_enabled_ = false; | 74 bool is_data_saver_enabled_ = false; |
| 66 int parent_frame_id_ = MSG_ROUTING_NONE; | 75 int parent_frame_id_ = MSG_ROUTING_NONE; |
| 67 GURL first_party_for_cookies_; | 76 GURL first_party_for_cookies_; |
| 77 bool is_secure_context_ = false; |
| 68 }; | 78 }; |
| 69 | 79 |
| 70 } // namespace content | 80 } // namespace content |
| 71 | 81 |
| 72 #endif // CONTENT_RENDERER_SERVICE_WORKER_WORKER_FETCH_CONTEXT_IMPL_H_ | 82 #endif // CONTENT_RENDERER_SERVICE_WORKER_WORKER_FETCH_CONTEXT_IMPL_H_ |
| OLD | NEW |