Chromium Code Reviews| 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/request_extra_data.h" | |
| 8 #include "content/child/resource_dispatcher.h" | |
| 9 #include "content/child/web_url_loader_impl.h" | |
| 10 #include "mojo/public/cpp/bindings/associated_binding.h" | |
| 11 | |
| 12 namespace content { | |
| 13 | |
| 14 WorkerFetchContextImpl::WorkerFetchContextImpl( | |
| 15 mojom::WorkerURLLoaderFactoryProviderPtrInfo provider_info) | |
| 16 : provider_info_(std::move(provider_info)) {} | |
| 17 | |
| 18 WorkerFetchContextImpl::~WorkerFetchContextImpl() {} | |
| 19 | |
| 20 void WorkerFetchContextImpl::InitializeOnWorkerThread( | |
| 21 base::SingleThreadTaskRunner* loading_task_runner) { | |
|
kinuko
2017/04/18 08:00:31
DCHECK(loading_task_runner->RunsTasksOnCurrentThre
horo
2017/04/18 12:53:34
Done.
| |
| 22 resource_dispatcher_ = | |
| 23 base::MakeUnique<ResourceDispatcher>(nullptr, loading_task_runner); | |
| 24 binding_ = base::MakeUnique< | |
| 25 mojo::AssociatedBinding<mojom::ServiceWorkerWorkerClient>>(this); | |
| 26 DCHECK(provider_info_.is_valid()); | |
| 27 provider_.Bind(std::move(provider_info_)); | |
| 28 mojom::ServiceWorkerWorkerClientAssociatedPtrInfo ptr_info; | |
| 29 binding_->Bind(&ptr_info); | |
| 30 provider_->CreateWorkerFetchContext(mojo::MakeRequest(&url_loader_factory_), | |
| 31 std::move(ptr_info), | |
| 32 service_worker_provider_id_); | |
| 33 } | |
| 34 | |
| 35 blink::WebURLLoader* WorkerFetchContextImpl::CreateURLLoader() { | |
| 36 return new content::WebURLLoaderImpl(resource_dispatcher_.get(), | |
| 37 url_loader_factory_.get()); | |
| 38 } | |
| 39 | |
| 40 void WorkerFetchContextImpl::WillSendRequest(blink::WebURLRequest& request) { | |
| 41 RequestExtraData* extra_data = new RequestExtraData(); | |
| 42 extra_data->set_service_worker_provider_id(service_worker_provider_id_); | |
| 43 request.SetExtraData(extra_data); | |
| 44 | |
| 45 if (!IsControlledByServiceWorker() && | |
| 46 request.GetServiceWorkerMode() != | |
| 47 blink::WebURLRequest::ServiceWorkerMode::kNone) { | |
| 48 request.SetServiceWorkerMode( | |
| 49 blink::WebURLRequest::ServiceWorkerMode::kForeign); | |
| 50 } | |
| 51 } | |
| 52 | |
| 53 bool WorkerFetchContextImpl::IsControlledByServiceWorker() const { | |
| 54 return is_controlled_by_service_worker_ || | |
| 55 (controller_version_id_ != kInvalidServiceWorkerVersionId); | |
| 56 } | |
| 57 | |
| 58 void WorkerFetchContextImpl::SetServiceWorkerProviderID(int id) { | |
| 59 service_worker_provider_id_ = id; | |
| 60 } | |
| 61 | |
| 62 void WorkerFetchContextImpl::SetIsControlledByServiceWorker(bool flag) { | |
| 63 is_controlled_by_service_worker_ = flag; | |
| 64 } | |
| 65 | |
| 66 void WorkerFetchContextImpl::SetControllerServiceWorker( | |
| 67 int64_t controller_version_id) { | |
| 68 controller_version_id_ = controller_version_id; | |
| 69 } | |
| 70 | |
| 71 } // namespace content | |
| OLD | NEW |