| 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 #include "content/renderer/shared_worker/embedded_shared_worker_stub.h" | 5 #include "content/renderer/shared_worker/embedded_shared_worker_stub.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "content/child/appcache/appcache_dispatcher.h" | 11 #include "content/child/appcache/appcache_dispatcher.h" |
| 12 #include "content/child/appcache/web_application_cache_host_impl.h" | 12 #include "content/child/appcache/web_application_cache_host_impl.h" |
| 13 #include "content/child/request_extra_data.h" | 13 #include "content/child/request_extra_data.h" |
| 14 #include "content/child/scoped_child_process_reference.h" | 14 #include "content/child/scoped_child_process_reference.h" |
| 15 #include "content/child/service_worker/service_worker_handle_reference.h" | 15 #include "content/child/service_worker/service_worker_handle_reference.h" |
| 16 #include "content/child/service_worker/service_worker_network_provider.h" | 16 #include "content/child/service_worker/service_worker_network_provider.h" |
| 17 #include "content/child/service_worker/service_worker_provider_context.h" | 17 #include "content/child/service_worker/service_worker_provider_context.h" |
| 18 #include "content/child/shared_worker_devtools_agent.h" | 18 #include "content/child/shared_worker_devtools_agent.h" |
| 19 #include "content/child/webmessageportchannel_impl.h" | 19 #include "content/child/webmessageportchannel_impl.h" |
| 20 #include "content/common/worker_messages.h" | 20 #include "content/common/worker_messages.h" |
| 21 #include "content/public/common/origin_util.h" |
| 21 #include "content/renderer/devtools/devtools_agent.h" | 22 #include "content/renderer/devtools/devtools_agent.h" |
| 22 #include "content/renderer/render_thread_impl.h" | 23 #include "content/renderer/render_thread_impl.h" |
| 23 #include "content/renderer/shared_worker/embedded_shared_worker_content_settings
_client_proxy.h" | 24 #include "content/renderer/shared_worker/embedded_shared_worker_content_settings
_client_proxy.h" |
| 24 #include "ipc/ipc_message_macros.h" | 25 #include "ipc/ipc_message_macros.h" |
| 25 #include "third_party/WebKit/public/platform/URLConversion.h" | 26 #include "third_party/WebKit/public/platform/URLConversion.h" |
| 26 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 27 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
| 27 #include "third_party/WebKit/public/web/WebDataSource.h" | 28 #include "third_party/WebKit/public/web/WebDataSource.h" |
| 28 #include "third_party/WebKit/public/web/WebSharedWorker.h" | 29 #include "third_party/WebKit/public/web/WebSharedWorker.h" |
| 29 #include "third_party/WebKit/public/web/WebSharedWorkerClient.h" | 30 #include "third_party/WebKit/public/web/WebSharedWorkerClient.h" |
| 30 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerNe
tworkProvider.h" | 31 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerNe
tworkProvider.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 66 |
| 66 // We store an instance of this class in the "extra data" of the WebDataSource | 67 // We store an instance of this class in the "extra data" of the WebDataSource |
| 67 // and attach a ServiceWorkerNetworkProvider to it as base::UserData. | 68 // and attach a ServiceWorkerNetworkProvider to it as base::UserData. |
| 68 // (see createServiceWorkerNetworkProvider). | 69 // (see createServiceWorkerNetworkProvider). |
| 69 class DataSourceExtraData | 70 class DataSourceExtraData |
| 70 : public blink::WebDataSource::ExtraData, | 71 : public blink::WebDataSource::ExtraData, |
| 71 public base::SupportsUserData { | 72 public base::SupportsUserData { |
| 72 public: | 73 public: |
| 73 DataSourceExtraData() {} | 74 DataSourceExtraData() {} |
| 74 ~DataSourceExtraData() override {} | 75 ~DataSourceExtraData() override {} |
| 76 bool is_secure_context = false; |
| 75 }; | 77 }; |
| 76 | 78 |
| 77 // Called on the main thread only and blink owns it. | 79 // Called on the main thread only and blink owns it. |
| 78 class WebServiceWorkerNetworkProviderImpl | 80 class WebServiceWorkerNetworkProviderImpl |
| 79 : public blink::WebServiceWorkerNetworkProvider { | 81 : public blink::WebServiceWorkerNetworkProvider { |
| 80 public: | 82 public: |
| 81 // Blink calls this method for each request starting with the main script, | 83 // Blink calls this method for each request starting with the main script, |
| 82 // we tag them with the provider id. | 84 // we tag them with the provider id. |
| 83 void willSendRequest(blink::WebDataSource* data_source, | 85 void willSendRequest(blink::WebDataSource* data_source, |
| 84 blink::WebURLRequest& request) override { | 86 blink::WebURLRequest& request) override { |
| 85 ServiceWorkerNetworkProvider* provider = | 87 ServiceWorkerNetworkProvider* provider = |
| 86 GetNetworkProviderFromDataSource(data_source); | 88 GetNetworkProviderFromDataSource(data_source); |
| 87 std::unique_ptr<RequestExtraData> extra_data(new RequestExtraData); | 89 std::unique_ptr<RequestExtraData> extra_data(new RequestExtraData); |
| 88 extra_data->set_service_worker_provider_id(provider->provider_id()); | 90 extra_data->set_service_worker_provider_id(provider->provider_id()); |
| 91 extra_data->set_initiated_in_secure_context( |
| 92 static_cast<DataSourceExtraData*>(data_source->getExtraData()) |
| 93 ->is_secure_context); |
| 89 request.setExtraData(extra_data.release()); | 94 request.setExtraData(extra_data.release()); |
| 90 // Explicitly set the SkipServiceWorker flag for subresources here if the | 95 // Explicitly set the SkipServiceWorker flag for subresources here if the |
| 91 // renderer process hasn't received SetControllerServiceWorker message. | 96 // renderer process hasn't received SetControllerServiceWorker message. |
| 92 if (request.getRequestContext() != | 97 if (request.getRequestContext() != |
| 93 blink::WebURLRequest::RequestContextSharedWorker && | 98 blink::WebURLRequest::RequestContextSharedWorker && |
| 94 !provider->IsControlledByServiceWorker() && | 99 !provider->IsControlledByServiceWorker() && |
| 95 request.skipServiceWorker() != | 100 request.skipServiceWorker() != |
| 96 blink::WebURLRequest::SkipServiceWorker::All) { | 101 blink::WebURLRequest::SkipServiceWorker::All) { |
| 97 request.setSkipServiceWorker( | 102 request.setSkipServiceWorker( |
| 98 blink::WebURLRequest::SkipServiceWorker::Controlling); | 103 blink::WebURLRequest::SkipServiceWorker::Controlling); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 // Create a content::ServiceWorkerNetworkProvider for this data source so | 249 // Create a content::ServiceWorkerNetworkProvider for this data source so |
| 245 // we can observe its requests. | 250 // we can observe its requests. |
| 246 std::unique_ptr<ServiceWorkerNetworkProvider> provider( | 251 std::unique_ptr<ServiceWorkerNetworkProvider> provider( |
| 247 new ServiceWorkerNetworkProvider( | 252 new ServiceWorkerNetworkProvider( |
| 248 route_id_, SERVICE_WORKER_PROVIDER_FOR_SHARED_WORKER, | 253 route_id_, SERVICE_WORKER_PROVIDER_FOR_SHARED_WORKER, |
| 249 true /* is_parent_frame_secure */)); | 254 true /* is_parent_frame_secure */)); |
| 250 | 255 |
| 251 // The provider is kept around for the lifetime of the DataSource | 256 // The provider is kept around for the lifetime of the DataSource |
| 252 // and ownership is transferred to the DataSource. | 257 // and ownership is transferred to the DataSource. |
| 253 DataSourceExtraData* extra_data = new DataSourceExtraData(); | 258 DataSourceExtraData* extra_data = new DataSourceExtraData(); |
| 259 extra_data->is_secure_context = IsOriginSecure(url_); |
| 254 data_source->setExtraData(extra_data); | 260 data_source->setExtraData(extra_data); |
| 255 ServiceWorkerNetworkProvider::AttachToDocumentState(extra_data, | 261 ServiceWorkerNetworkProvider::AttachToDocumentState(extra_data, |
| 256 std::move(provider)); | 262 std::move(provider)); |
| 257 | 263 |
| 258 // Blink is responsible for deleting the returned object. | 264 // Blink is responsible for deleting the returned object. |
| 259 return new WebServiceWorkerNetworkProviderImpl(); | 265 return new WebServiceWorkerNetworkProviderImpl(); |
| 260 } | 266 } |
| 261 | 267 |
| 262 void EmbeddedSharedWorkerStub::sendDevToolsMessage( | 268 void EmbeddedSharedWorkerStub::sendDevToolsMessage( |
| 263 int session_id, | 269 int session_id, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 } | 312 } |
| 307 } | 313 } |
| 308 | 314 |
| 309 void EmbeddedSharedWorkerStub::OnTerminateWorkerContext() { | 315 void EmbeddedSharedWorkerStub::OnTerminateWorkerContext() { |
| 310 // After this we wouldn't get any IPC for this stub. | 316 // After this we wouldn't get any IPC for this stub. |
| 311 running_ = false; | 317 running_ = false; |
| 312 impl_->terminateWorkerContext(); | 318 impl_->terminateWorkerContext(); |
| 313 } | 319 } |
| 314 | 320 |
| 315 } // namespace content | 321 } // namespace content |
| OLD | NEW |