Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1313)

Side by Side Diff: content/renderer/shared_worker/embedded_shared_worker_stub.cc

Issue 2733283004: Expose WebServiceWorkerNetworkProvider on DataSource (Closed)
Patch Set: consistency Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/appcache_info.h" 21 #include "content/public/common/appcache_info.h"
22 #include "content/public/common/origin_util.h" 22 #include "content/public/common/origin_util.h"
23 #include "content/renderer/devtools/devtools_agent.h" 23 #include "content/renderer/devtools/devtools_agent.h"
24 #include "content/renderer/render_thread_impl.h" 24 #include "content/renderer/render_thread_impl.h"
25 #include "content/renderer/shared_worker/embedded_shared_worker_content_settings _client_proxy.h" 25 #include "content/renderer/shared_worker/embedded_shared_worker_content_settings _client_proxy.h"
26 #include "ipc/ipc_message_macros.h" 26 #include "ipc/ipc_message_macros.h"
27 #include "third_party/WebKit/public/platform/URLConversion.h" 27 #include "third_party/WebKit/public/platform/URLConversion.h"
28 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" 28 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
29 #include "third_party/WebKit/public/web/WebDataSource.h" 29 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerNetworkProvider.h"
30 #include "third_party/WebKit/public/web/WebSharedWorker.h" 30 #include "third_party/WebKit/public/web/WebSharedWorker.h"
31 #include "third_party/WebKit/public/web/WebSharedWorkerClient.h" 31 #include "third_party/WebKit/public/web/WebSharedWorkerClient.h"
32 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerNe tworkProvider.h"
33 #include "url/origin.h" 32 #include "url/origin.h"
34 33
35 namespace content { 34 namespace content {
36 35
37 namespace { 36 namespace {
38 37
39 class SharedWorkerWebApplicationCacheHostImpl 38 class SharedWorkerWebApplicationCacheHostImpl
40 : public WebApplicationCacheHostImpl { 39 : public WebApplicationCacheHostImpl {
41 public: 40 public:
42 SharedWorkerWebApplicationCacheHostImpl( 41 SharedWorkerWebApplicationCacheHostImpl(
(...skipping 16 matching lines...) Expand all
59 58
60 // Cache selection is also different for workers. We know at construction 59 // Cache selection is also different for workers. We know at construction
61 // time what cache to select and do so then. 60 // time what cache to select and do so then.
62 // These overrides are stubbed out. 61 // These overrides are stubbed out.
63 void selectCacheWithoutManifest() override {} 62 void selectCacheWithoutManifest() override {}
64 bool selectCacheWithManifest(const blink::WebURL& manifestURL) override { 63 bool selectCacheWithManifest(const blink::WebURL& manifestURL) override {
65 return true; 64 return true;
66 } 65 }
67 }; 66 };
68 67
69 // We store an instance of this class in the "extra data" of the WebDataSource
70 // and attach a ServiceWorkerNetworkProvider to it as base::UserData.
71 // (see createServiceWorkerNetworkProvider).
72 class DataSourceExtraData
73 : public blink::WebDataSource::ExtraData,
74 public base::SupportsUserData {
75 public:
76 DataSourceExtraData() {}
77 ~DataSourceExtraData() override {}
78 bool is_secure_context = false;
79 };
80
81 // Called on the main thread only and blink owns it. 68 // Called on the main thread only and blink owns it.
82 class WebServiceWorkerNetworkProviderImpl 69 class WebServiceWorkerNetworkProviderImpl
83 : public blink::WebServiceWorkerNetworkProvider { 70 : public blink::WebServiceWorkerNetworkProvider {
84 public: 71 public:
72 WebServiceWorkerNetworkProviderImpl(
73 std::unique_ptr<ServiceWorkerNetworkProvider> provider,
74 bool is_secure_context)
75 : provider_(std::move(provider)), is_secure_context_(is_secure_context) {}
76
85 // Blink calls this method for each request starting with the main script, 77 // Blink calls this method for each request starting with the main script,
86 // we tag them with the provider id. 78 // we tag them with the provider id.
87 void willSendRequest(blink::WebDataSource* data_source, 79 void willSendRequest(blink::WebURLRequest& request) override {
88 blink::WebURLRequest& request) override {
89 ServiceWorkerNetworkProvider* provider =
90 GetNetworkProviderFromDataSource(data_source);
91 std::unique_ptr<RequestExtraData> extra_data(new RequestExtraData); 80 std::unique_ptr<RequestExtraData> extra_data(new RequestExtraData);
92 extra_data->set_service_worker_provider_id(provider->provider_id()); 81 extra_data->set_service_worker_provider_id(provider_->provider_id());
93 extra_data->set_initiated_in_secure_context( 82 extra_data->set_initiated_in_secure_context(is_secure_context_);
94 static_cast<DataSourceExtraData*>(data_source->getExtraData())
95 ->is_secure_context);
96 request.setExtraData(extra_data.release()); 83 request.setExtraData(extra_data.release());
97 // If the provider does not have a controller at this point, the renderer 84 // If the provider does not have a controller at this point, the renderer
98 // expects subresource requests to never be handled by a controlling service 85 // expects subresource requests to never be handled by a controlling service
99 // worker, so set the ServiceWorkerMode to skip local workers here. 86 // worker, so set the ServiceWorkerMode to skip local workers here.
100 // Otherwise, a service worker that is in the process of becoming the 87 // Otherwise, a service worker that is in the process of becoming the
101 // controller (i.e., via claim()) on the browser-side could handle the 88 // controller (i.e., via claim()) on the browser-side could handle the
102 // request and break the assumptions of the renderer. 89 // request and break the assumptions of the renderer.
103 if (request.getRequestContext() != 90 if (request.getRequestContext() !=
104 blink::WebURLRequest::RequestContextSharedWorker && 91 blink::WebURLRequest::RequestContextSharedWorker &&
105 !provider->IsControlledByServiceWorker() && 92 !provider_->IsControlledByServiceWorker() &&
106 request.getServiceWorkerMode() != 93 request.getServiceWorkerMode() !=
107 blink::WebURLRequest::ServiceWorkerMode::None) { 94 blink::WebURLRequest::ServiceWorkerMode::None) {
108 request.setServiceWorkerMode( 95 request.setServiceWorkerMode(
109 blink::WebURLRequest::ServiceWorkerMode::Foreign); 96 blink::WebURLRequest::ServiceWorkerMode::Foreign);
110 } 97 }
111 } 98 }
112 99
113 bool isControlledByServiceWorker(blink::WebDataSource& data_source) override { 100 bool isControlledByServiceWorker() override {
114 ServiceWorkerNetworkProvider* provider = 101 return provider_->IsControlledByServiceWorker();
115 GetNetworkProviderFromDataSource(&data_source);
116 return provider->IsControlledByServiceWorker();
117 } 102 }
118 103
119 int64_t serviceWorkerID(blink::WebDataSource& data_source) override { 104 int64_t serviceWorkerID() override {
120 ServiceWorkerNetworkProvider* provider = 105 if (provider_->context()->controller())
121 GetNetworkProviderFromDataSource(&data_source); 106 return provider_->context()->controller()->version_id();
122 if (provider->context()->controller())
123 return provider->context()->controller()->version_id();
124 return kInvalidServiceWorkerVersionId; 107 return kInvalidServiceWorkerVersionId;
125 } 108 }
126 109
127 private: 110 private:
128 ServiceWorkerNetworkProvider* GetNetworkProviderFromDataSource( 111 std::unique_ptr<ServiceWorkerNetworkProvider> provider_;
129 const blink::WebDataSource* data_source) { 112 const bool is_secure_context_;
130 return ServiceWorkerNetworkProvider::FromDocumentState(
131 static_cast<DataSourceExtraData*>(data_source->getExtraData()));
132 }
133 }; 113 };
134 114
135 } // namespace 115 } // namespace
136 116
137 EmbeddedSharedWorkerStub::EmbeddedSharedWorkerStub( 117 EmbeddedSharedWorkerStub::EmbeddedSharedWorkerStub(
138 const GURL& url, 118 const GURL& url,
139 const base::string16& name, 119 const base::string16& name,
140 const base::string16& content_security_policy, 120 const base::string16& content_security_policy,
141 blink::WebContentSecurityPolicyType security_policy_type, 121 blink::WebContentSecurityPolicyType security_policy_type,
142 blink::WebAddressSpace creation_address_space, 122 blink::WebAddressSpace creation_address_space,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 218
239 blink::WebWorkerContentSettingsClientProxy* 219 blink::WebWorkerContentSettingsClientProxy*
240 EmbeddedSharedWorkerStub::createWorkerContentSettingsClientProxy( 220 EmbeddedSharedWorkerStub::createWorkerContentSettingsClientProxy(
241 const blink::WebSecurityOrigin& origin) { 221 const blink::WebSecurityOrigin& origin) {
242 return new EmbeddedSharedWorkerContentSettingsClientProxy( 222 return new EmbeddedSharedWorkerContentSettingsClientProxy(
243 url::Origin(origin).GetURL(), origin.isUnique(), route_id_, 223 url::Origin(origin).GetURL(), origin.isUnique(), route_id_,
244 ChildThreadImpl::current()->thread_safe_sender()); 224 ChildThreadImpl::current()->thread_safe_sender());
245 } 225 }
246 226
247 blink::WebServiceWorkerNetworkProvider* 227 blink::WebServiceWorkerNetworkProvider*
248 EmbeddedSharedWorkerStub::createServiceWorkerNetworkProvider( 228 EmbeddedSharedWorkerStub::createServiceWorkerNetworkProvider() {
249 blink::WebDataSource* data_source) {
250 // Create a content::ServiceWorkerNetworkProvider for this data source so 229 // Create a content::ServiceWorkerNetworkProvider for this data source so
251 // we can observe its requests. 230 // we can observe its requests.
252 std::unique_ptr<ServiceWorkerNetworkProvider> provider( 231 std::unique_ptr<ServiceWorkerNetworkProvider> provider(
253 new ServiceWorkerNetworkProvider( 232 new ServiceWorkerNetworkProvider(
254 route_id_, SERVICE_WORKER_PROVIDER_FOR_SHARED_WORKER, 233 route_id_, SERVICE_WORKER_PROVIDER_FOR_SHARED_WORKER,
255 true /* is_parent_frame_secure */)); 234 true /* is_parent_frame_secure */));
256 235
257 // The provider is kept around for the lifetime of the DataSource
258 // and ownership is transferred to the DataSource.
259 DataSourceExtraData* extra_data = new DataSourceExtraData();
260 extra_data->is_secure_context = IsOriginSecure(url_);
261 data_source->setExtraData(extra_data);
262 ServiceWorkerNetworkProvider::AttachToDocumentState(extra_data,
263 std::move(provider));
264
265 // Blink is responsible for deleting the returned object. 236 // Blink is responsible for deleting the returned object.
266 return new WebServiceWorkerNetworkProviderImpl(); 237 return new WebServiceWorkerNetworkProviderImpl(std::move(provider),
238 IsOriginSecure(url_));
267 } 239 }
268 240
269 void EmbeddedSharedWorkerStub::sendDevToolsMessage( 241 void EmbeddedSharedWorkerStub::sendDevToolsMessage(
270 int session_id, 242 int session_id,
271 int call_id, 243 int call_id,
272 const blink::WebString& message, 244 const blink::WebString& message,
273 const blink::WebString& state) { 245 const blink::WebString& state) {
274 worker_devtools_agent_->SendDevToolsMessage( 246 worker_devtools_agent_->SendDevToolsMessage(
275 session_id, call_id, message, state); 247 session_id, call_id, message, state);
276 } 248 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 } 285 }
314 } 286 }
315 287
316 void EmbeddedSharedWorkerStub::OnTerminateWorkerContext() { 288 void EmbeddedSharedWorkerStub::OnTerminateWorkerContext() {
317 // After this we wouldn't get any IPC for this stub. 289 // After this we wouldn't get any IPC for this stub.
318 running_ = false; 290 running_ = false;
319 impl_->terminateWorkerContext(); 291 impl_->terminateWorkerContext();
320 } 292 }
321 293
322 } // namespace content 294 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/shared_worker/embedded_shared_worker_stub.h ('k') | third_party/WebKit/Source/core/frame/LocalFrameClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698