OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/renderer/service_worker/worker_fetch_context_impl.h" |
| 6 |
| 7 #include "content/child/child_thread_impl.h" |
| 8 #include "content/child/request_extra_data.h" |
| 9 #include "content/child/resource_dispatcher.h" |
| 10 #include "content/child/thread_safe_sender.h" |
| 11 #include "content/child/web_url_loader_impl.h" |
| 12 #include "content/common/frame_messages.h" |
| 13 #include "mojo/public/cpp/bindings/associated_binding.h" |
| 14 #include "third_party/WebKit/public/platform/WebWorkerFetchContext.h" |
| 15 |
| 16 namespace content { |
| 17 |
| 18 WorkerFetchContextImpl::WorkerFetchContextImpl( |
| 19 mojom::WorkerURLLoaderFactoryProviderPtrInfo provider_info) |
| 20 : provider_info_(std::move(provider_info)), |
| 21 thread_safe_sender_(ChildThreadImpl::current()->thread_safe_sender()) {} |
| 22 |
| 23 WorkerFetchContextImpl::~WorkerFetchContextImpl() {} |
| 24 |
| 25 void WorkerFetchContextImpl::InitializeOnWorkerThread( |
| 26 base::SingleThreadTaskRunner* loading_task_runner) { |
| 27 DCHECK(loading_task_runner->RunsTasksOnCurrentThread()); |
| 28 DCHECK(!resource_dispatcher_); |
| 29 DCHECK(!binding_); |
| 30 resource_dispatcher_ = |
| 31 base::MakeUnique<ResourceDispatcher>(nullptr, loading_task_runner); |
| 32 binding_ = base::MakeUnique< |
| 33 mojo::AssociatedBinding<mojom::ServiceWorkerWorkerClient>>(this); |
| 34 DCHECK(provider_info_.is_valid()); |
| 35 provider_.Bind(std::move(provider_info_)); |
| 36 mojom::ServiceWorkerWorkerClientAssociatedPtrInfo ptr_info; |
| 37 binding_->Bind(&ptr_info); |
| 38 provider_->CreateWorkerFetchContext(mojo::MakeRequest(&url_loader_factory_), |
| 39 std::move(ptr_info), |
| 40 service_worker_provider_id_); |
| 41 } |
| 42 |
| 43 blink::WebURLLoader* WorkerFetchContextImpl::CreateURLLoader() { |
| 44 return new content::WebURLLoaderImpl(resource_dispatcher_.get(), |
| 45 url_loader_factory_.get()); |
| 46 } |
| 47 |
| 48 void WorkerFetchContextImpl::WillSendRequest(blink::WebURLRequest& request) { |
| 49 RequestExtraData* extra_data = new RequestExtraData(); |
| 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_); |
| 53 request.SetExtraData(extra_data); |
| 54 |
| 55 if (data_saver_enabled_) |
| 56 request.SetHTTPHeaderField("Save-Data", "on"); |
| 57 |
| 58 if (!IsControlledByServiceWorker() && |
| 59 request.GetServiceWorkerMode() != |
| 60 blink::WebURLRequest::ServiceWorkerMode::kNone) { |
| 61 request.SetServiceWorkerMode( |
| 62 blink::WebURLRequest::ServiceWorkerMode::kForeign); |
| 63 } |
| 64 } |
| 65 |
| 66 bool WorkerFetchContextImpl::IsControlledByServiceWorker() const { |
| 67 return is_controlled_by_service_worker_ || |
| 68 (controller_version_id_ != kInvalidServiceWorkerVersionId); |
| 69 } |
| 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::SetParentFrameID(int id) { |
| 96 parent_frame_id_ = id; |
| 97 } |
| 98 |
| 99 void WorkerFetchContextImpl::SetServiceWorkerProviderID(int id) { |
| 100 service_worker_provider_id_ = id; |
| 101 } |
| 102 |
| 103 void WorkerFetchContextImpl::SetIsSecureContext(bool flag) { |
| 104 is_secure_context_ = flag; |
| 105 } |
| 106 |
| 107 void WorkerFetchContextImpl::SetIsControlledByServiceWorker(bool flag) { |
| 108 is_controlled_by_service_worker_ = flag; |
| 109 } |
| 110 |
| 111 void WorkerFetchContextImpl::SetDataSaverEnabled(bool flag) { |
| 112 data_saver_enabled_ = flag; |
| 113 } |
| 114 |
| 115 void WorkerFetchContextImpl::SetStrictMixedContentCheckingEnabled( |
| 116 bool enabled) { |
| 117 strict_mixed_content_checking_enabled_ = enabled; |
| 118 } |
| 119 |
| 120 void WorkerFetchContextImpl::SetControllerServiceWorker( |
| 121 int64_t controller_version_id) { |
| 122 controller_version_id_ = controller_version_id; |
| 123 } |
| 124 |
| 125 } // namespace content |
OLD | NEW |