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 #include "content/renderer/service_worker/worker_fetch_context_impl.h" | 5 #include "content/renderer/service_worker/worker_fetch_context_impl.h" |
6 | 6 |
| 7 #include "content/child/child_thread_impl.h" |
7 #include "content/child/request_extra_data.h" | 8 #include "content/child/request_extra_data.h" |
8 #include "content/child/resource_dispatcher.h" | 9 #include "content/child/resource_dispatcher.h" |
| 10 #include "content/child/thread_safe_sender.h" |
9 #include "content/child/web_url_loader_impl.h" | 11 #include "content/child/web_url_loader_impl.h" |
| 12 #include "content/common/frame_messages.h" |
10 #include "mojo/public/cpp/bindings/associated_binding.h" | 13 #include "mojo/public/cpp/bindings/associated_binding.h" |
| 14 #include "third_party/WebKit/public/platform/WebWorkerFetchContext.h" |
11 | 15 |
12 namespace content { | 16 namespace content { |
13 | 17 |
14 WorkerFetchContextImpl::WorkerFetchContextImpl( | 18 WorkerFetchContextImpl::WorkerFetchContextImpl( |
15 mojom::WorkerURLLoaderFactoryProviderPtrInfo provider_info) | 19 mojom::WorkerURLLoaderFactoryProviderPtrInfo provider_info) |
16 : provider_info_(std::move(provider_info)) {} | 20 : provider_info_(std::move(provider_info)), |
| 21 thread_safe_sender_(ChildThreadImpl::current()->thread_safe_sender()) {} |
17 | 22 |
18 WorkerFetchContextImpl::~WorkerFetchContextImpl() {} | 23 WorkerFetchContextImpl::~WorkerFetchContextImpl() {} |
19 | 24 |
20 void WorkerFetchContextImpl::InitializeOnWorkerThread( | 25 void WorkerFetchContextImpl::InitializeOnWorkerThread( |
21 base::SingleThreadTaskRunner* loading_task_runner) { | 26 base::SingleThreadTaskRunner* loading_task_runner) { |
22 DCHECK(loading_task_runner->RunsTasksOnCurrentThread()); | 27 DCHECK(loading_task_runner->RunsTasksOnCurrentThread()); |
23 DCHECK(!resource_dispatcher_); | 28 DCHECK(!resource_dispatcher_); |
24 DCHECK(!binding_); | 29 DCHECK(!binding_); |
25 resource_dispatcher_ = | 30 resource_dispatcher_ = |
26 base::MakeUnique<ResourceDispatcher>(nullptr, loading_task_runner); | 31 base::MakeUnique<ResourceDispatcher>(nullptr, loading_task_runner); |
27 binding_ = base::MakeUnique< | 32 binding_ = base::MakeUnique< |
28 mojo::AssociatedBinding<mojom::ServiceWorkerWorkerClient>>(this); | 33 mojo::AssociatedBinding<mojom::ServiceWorkerWorkerClient>>(this); |
29 DCHECK(provider_info_.is_valid()); | 34 DCHECK(provider_info_.is_valid()); |
30 provider_.Bind(std::move(provider_info_)); | 35 provider_.Bind(std::move(provider_info_)); |
31 mojom::ServiceWorkerWorkerClientAssociatedPtrInfo ptr_info; | 36 mojom::ServiceWorkerWorkerClientAssociatedPtrInfo ptr_info; |
32 binding_->Bind(&ptr_info); | 37 binding_->Bind(&ptr_info); |
33 provider_->GetURLLoaderFactoryAndRegisterClient( | 38 provider_->GetURLLoaderFactoryAndRegisterClient( |
34 mojo::MakeRequest(&url_loader_factory_), std::move(ptr_info), | 39 mojo::MakeRequest(&url_loader_factory_), std::move(ptr_info), |
35 service_worker_provider_id_); | 40 service_worker_provider_id_); |
36 } | 41 } |
37 | 42 |
38 std::unique_ptr<blink::WebURLLoader> WorkerFetchContextImpl::CreateURLLoader() { | 43 std::unique_ptr<blink::WebURLLoader> WorkerFetchContextImpl::CreateURLLoader() { |
39 return base::MakeUnique<content::WebURLLoaderImpl>(resource_dispatcher_.get(), | 44 return base::MakeUnique<content::WebURLLoaderImpl>(resource_dispatcher_.get(), |
40 url_loader_factory_.get()); | 45 url_loader_factory_.get()); |
41 } | 46 } |
42 | 47 |
43 void WorkerFetchContextImpl::WillSendRequest(blink::WebURLRequest& request) { | 48 void WorkerFetchContextImpl::WillSendRequest(blink::WebURLRequest& request) { |
44 RequestExtraData* extra_data = new RequestExtraData(); | 49 RequestExtraData* extra_data = new RequestExtraData(); |
45 extra_data->set_service_worker_provider_id(service_worker_provider_id_); | 50 extra_data->set_service_worker_provider_id(service_worker_provider_id_); |
| 51 extra_data->set_render_frame_id(parent_frame_id_); |
| 52 extra_data->set_initiated_in_secure_context(is_secure_context_); |
46 request.SetExtraData(extra_data); | 53 request.SetExtraData(extra_data); |
47 | 54 |
| 55 if (data_saver_enabled_) |
| 56 request.SetHTTPHeaderField("Save-Data", "on"); |
| 57 |
48 if (!IsControlledByServiceWorker() && | 58 if (!IsControlledByServiceWorker() && |
49 request.GetServiceWorkerMode() != | 59 request.GetServiceWorkerMode() != |
50 blink::WebURLRequest::ServiceWorkerMode::kNone) { | 60 blink::WebURLRequest::ServiceWorkerMode::kNone) { |
51 request.SetServiceWorkerMode( | 61 request.SetServiceWorkerMode( |
52 blink::WebURLRequest::ServiceWorkerMode::kForeign); | 62 blink::WebURLRequest::ServiceWorkerMode::kForeign); |
53 } | 63 } |
54 } | 64 } |
55 | 65 |
56 bool WorkerFetchContextImpl::IsControlledByServiceWorker() const { | 66 bool WorkerFetchContextImpl::IsControlledByServiceWorker() const { |
57 return is_controlled_by_service_worker_ || | 67 return is_controlled_by_service_worker_ || |
58 (controller_version_id_ != kInvalidServiceWorkerVersionId); | 68 (controller_version_id_ != kInvalidServiceWorkerVersionId); |
59 } | 69 } |
60 | 70 |
| 71 int64_t WorkerFetchContextImpl::ServiceWorkerID() const { |
| 72 return controller_version_id_; |
| 73 } |
| 74 |
| 75 void WorkerFetchContextImpl::DidRunContentWithCertificateErrors( |
| 76 const blink::WebURL& url) { |
| 77 Send(new FrameHostMsg_DidRunContentWithCertificateErrors(parent_frame_id_, |
| 78 url)); |
| 79 } |
| 80 |
| 81 void WorkerFetchContextImpl::DidDisplayContentWithCertificateErrors( |
| 82 const blink::WebURL& url) { |
| 83 Send(new FrameHostMsg_DidDisplayContentWithCertificateErrors(parent_frame_id_, |
| 84 url)); |
| 85 } |
| 86 |
| 87 bool WorkerFetchContextImpl::Send(IPC::Message* message) { |
| 88 return thread_safe_sender_->Send(message); |
| 89 } |
| 90 |
| 91 void WorkerFetchContextImpl::SetAppCacheHostID(int id) { |
| 92 appcache_host_id_ = id; |
| 93 } |
| 94 |
| 95 void WorkerFetchContextImpl::set_parent_frame_id(int id) { |
| 96 parent_frame_id_ = id; |
| 97 } |
| 98 |
61 void WorkerFetchContextImpl::set_service_worker_provider_id(int id) { | 99 void WorkerFetchContextImpl::set_service_worker_provider_id(int id) { |
62 service_worker_provider_id_ = id; | 100 service_worker_provider_id_ = id; |
63 } | 101 } |
64 | 102 |
65 void WorkerFetchContextImpl::set_is_controlled_by_service_worker(bool flag) { | 103 void WorkerFetchContextImpl::set_is_controlled_by_service_worker(bool flag) { |
66 is_controlled_by_service_worker_ = flag; | 104 is_controlled_by_service_worker_ = flag; |
67 } | 105 } |
68 | 106 |
| 107 void WorkerFetchContextImpl::set_is_secure_context(bool flag) { |
| 108 is_secure_context_ = flag; |
| 109 } |
| 110 |
| 111 void WorkerFetchContextImpl::SetDataSaverEnabled(bool flag) { |
| 112 data_saver_enabled_ = flag; |
| 113 } |
| 114 |
69 void WorkerFetchContextImpl::SetControllerServiceWorker( | 115 void WorkerFetchContextImpl::SetControllerServiceWorker( |
70 int64_t controller_version_id) { | 116 int64_t controller_version_id) { |
71 controller_version_id_ = controller_version_id; | 117 controller_version_id_ = controller_version_id; |
72 } | 118 } |
73 | 119 |
74 } // namespace content | 120 } // namespace content |
OLD | NEW |