OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/service_worker_context_client.h" | 5 #include "content/renderer/service_worker/service_worker_context_client.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "content/child/service_worker/service_worker_dispatcher.h" | 23 #include "content/child/service_worker/service_worker_dispatcher.h" |
24 #include "content/child/service_worker/service_worker_handle_reference.h" | 24 #include "content/child/service_worker/service_worker_handle_reference.h" |
25 #include "content/child/service_worker/service_worker_network_provider.h" | 25 #include "content/child/service_worker/service_worker_network_provider.h" |
26 #include "content/child/service_worker/service_worker_provider_context.h" | 26 #include "content/child/service_worker/service_worker_provider_context.h" |
27 #include "content/child/service_worker/service_worker_registration_handle_refere
nce.h" | 27 #include "content/child/service_worker/service_worker_registration_handle_refere
nce.h" |
28 #include "content/child/service_worker/web_service_worker_impl.h" | 28 #include "content/child/service_worker/web_service_worker_impl.h" |
29 #include "content/child/service_worker/web_service_worker_provider_impl.h" | 29 #include "content/child/service_worker/web_service_worker_provider_impl.h" |
30 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 30 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
31 #include "content/child/thread_safe_sender.h" | 31 #include "content/child/thread_safe_sender.h" |
32 #include "content/child/web_data_consumer_handle_impl.h" | 32 #include "content/child/web_data_consumer_handle_impl.h" |
| 33 #include "content/child/web_url_loader_impl.h" |
33 #include "content/child/webmessageportchannel_impl.h" | 34 #include "content/child/webmessageportchannel_impl.h" |
34 #include "content/common/devtools_messages.h" | 35 #include "content/common/devtools_messages.h" |
35 #include "content/common/message_port_messages.h" | 36 #include "content/common/message_port_messages.h" |
36 #include "content/common/service_worker/embedded_worker_messages.h" | 37 #include "content/common/service_worker/embedded_worker_messages.h" |
37 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h" | 38 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h" |
38 #include "content/common/service_worker/service_worker_messages.h" | 39 #include "content/common/service_worker/service_worker_messages.h" |
39 #include "content/common/service_worker/service_worker_status_code.h" | 40 #include "content/common/service_worker/service_worker_status_code.h" |
40 #include "content/common/service_worker/service_worker_utils.h" | 41 #include "content/common/service_worker/service_worker_utils.h" |
41 #include "content/public/common/push_event_payload.h" | 42 #include "content/public/common/push_event_payload.h" |
42 #include "content/public/common/referrer.h" | 43 #include "content/public/common/referrer.h" |
43 #include "content/public/renderer/content_renderer_client.h" | 44 #include "content/public/renderer/content_renderer_client.h" |
44 #include "content/public/renderer/document_state.h" | 45 #include "content/public/renderer/document_state.h" |
45 #include "content/renderer/devtools/devtools_agent.h" | 46 #include "content/renderer/devtools/devtools_agent.h" |
46 #include "content/renderer/render_thread_impl.h" | 47 #include "content/renderer/render_thread_impl.h" |
47 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" | 48 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" |
48 #include "content/renderer/service_worker/embedded_worker_instance_client_impl.h
" | 49 #include "content/renderer/service_worker/embedded_worker_instance_client_impl.h
" |
49 #include "content/renderer/service_worker/service_worker_type_util.h" | 50 #include "content/renderer/service_worker/service_worker_type_util.h" |
50 #include "ipc/ipc_message.h" | 51 #include "ipc/ipc_message.h" |
51 #include "ipc/ipc_message_macros.h" | 52 #include "ipc/ipc_message_macros.h" |
52 #include "third_party/WebKit/public/platform/URLConversion.h" | 53 #include "third_party/WebKit/public/platform/URLConversion.h" |
53 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" | 54 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" |
54 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" | 55 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" |
55 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 56 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
56 #include "third_party/WebKit/public/platform/WebString.h" | 57 #include "third_party/WebKit/public/platform/WebString.h" |
| 58 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
57 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onData.h" | 59 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onData.h" |
58 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerClientQueryOptions.h" | 60 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerClientQueryOptions.h" |
59 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerError.h" | 61 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerError.h" |
60 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerRequest.h" | 62 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerRequest.h" |
61 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerResponse.h" | 63 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerResponse.h" |
62 #include "third_party/WebKit/public/web/WebDataSource.h" | 64 #include "third_party/WebKit/public/web/WebDataSource.h" |
63 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo
ntextClient.h" | 65 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo
ntextClient.h" |
64 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo
ntextProxy.h" | 66 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo
ntextProxy.h" |
65 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerNe
tworkProvider.h" | 67 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerNe
tworkProvider.h" |
66 | 68 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 blink::WebString::fromASCII( | 253 blink::WebString::fromASCII( |
252 "Service Worker navigation preload aborted. Need to guard with " | 254 "Service Worker navigation preload aborted. Need to guard with " |
253 "respondWith or waitUntil."))); | 255 "respondWith or waitUntil."))); |
254 } | 256 } |
255 | 257 |
256 void OnReceiveResponse( | 258 void OnReceiveResponse( |
257 const ResourceResponseHead& response_head, | 259 const ResourceResponseHead& response_head, |
258 mojom::DownloadedTempFilePtr downloaded_file) override { | 260 mojom::DownloadedTempFilePtr downloaded_file) override { |
259 DCHECK(!response_); | 261 DCHECK(!response_); |
260 DCHECK(!downloaded_file); | 262 DCHECK(!downloaded_file); |
261 response_ = base::MakeUnique<blink::WebServiceWorkerResponse>(); | 263 response_ = base::MakeUnique<blink::WebURLResponse>(); |
262 response_->setURLList(std::vector<blink::WebURL>({url_})); | 264 // TODO(horo): Set report_security_info to true when DevTools is attached. |
263 DCHECK(response_head.headers); | 265 const bool report_security_info = false; |
264 response_->setStatus(response_head.headers->response_code()); | 266 WebURLLoaderImpl::PopulateURLResponse(url_, response_head, response_.get(), |
265 response_->setStatusText( | 267 report_security_info); |
266 blink::WebString::fromUTF8(response_head.headers->GetStatusText())); | |
267 response_->setResponseType(blink::WebServiceWorkerResponseTypeBasic); | |
268 size_t iter = 0; | |
269 std::string header_name; | |
270 std::string header_value; | |
271 while (response_head.headers->EnumerateHeaderLines(&iter, &header_name, | |
272 &header_value)) { | |
273 response_->appendHeader(blink::WebString::fromUTF8(header_name), | |
274 blink::WebString::fromUTF8(header_value)); | |
275 } | |
276 response_->setResponseTime(response_head.response_time.ToInternalValue()); | |
277 MaybeReportResponseToClient(); | 268 MaybeReportResponseToClient(); |
278 } | 269 } |
279 | 270 |
280 void OnReceiveRedirect(const net::RedirectInfo& redirect_info, | 271 void OnReceiveRedirect(const net::RedirectInfo& redirect_info, |
281 const ResourceResponseHead& response_head) override { | 272 const ResourceResponseHead& response_head) override { |
282 // Cancel the request. | 273 // Cancel the request. |
283 url_loader_ = nullptr; | 274 url_loader_ = nullptr; |
284 ReportErrorToClient( | 275 ReportErrorToClient( |
285 "Service Worker navigation preload doesn't suport redirect."); | 276 "Service Worker navigation preload doesn't suport redirect."); |
286 } | 277 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 blink::WebServiceWorkerError::ErrorTypeNetwork, | 327 blink::WebServiceWorkerError::ErrorTypeNetwork, |
337 blink::WebString::fromUTF8(error_message))); | 328 blink::WebString::fromUTF8(error_message))); |
338 result_reported_ = true; | 329 result_reported_ = true; |
339 } | 330 } |
340 | 331 |
341 const int fetch_event_id_; | 332 const int fetch_event_id_; |
342 const GURL url_; | 333 const GURL url_; |
343 mojom::URLLoaderPtr url_loader_; | 334 mojom::URLLoaderPtr url_loader_; |
344 mojo::Binding<mojom::URLLoaderClient> binding_; | 335 mojo::Binding<mojom::URLLoaderClient> binding_; |
345 | 336 |
346 std::unique_ptr<blink::WebServiceWorkerResponse> response_; | 337 std::unique_ptr<blink::WebURLResponse> response_; |
347 mojo::ScopedDataPipeConsumerHandle body_; | 338 mojo::ScopedDataPipeConsumerHandle body_; |
348 bool result_reported_ = false; | 339 bool result_reported_ = false; |
349 }; | 340 }; |
350 | 341 |
351 ServiceWorkerContextClient* | 342 ServiceWorkerContextClient* |
352 ServiceWorkerContextClient::ThreadSpecificInstance() { | 343 ServiceWorkerContextClient::ThreadSpecificInstance() { |
353 return g_worker_client_tls.Pointer()->Get(); | 344 return g_worker_client_tls.Pointer()->Get(); |
354 } | 345 } |
355 | 346 |
356 ServiceWorkerContextClient::ServiceWorkerContextClient( | 347 ServiceWorkerContextClient::ServiceWorkerContextClient( |
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1253 error_type, blink::WebString::fromUTF16(message))); | 1244 error_type, blink::WebString::fromUTF16(message))); |
1254 context_->claim_clients_callbacks.Remove(request_id); | 1245 context_->claim_clients_callbacks.Remove(request_id); |
1255 } | 1246 } |
1256 | 1247 |
1257 void ServiceWorkerContextClient::OnPing() { | 1248 void ServiceWorkerContextClient::OnPing() { |
1258 Send(new ServiceWorkerHostMsg_Pong(GetRoutingID())); | 1249 Send(new ServiceWorkerHostMsg_Pong(GetRoutingID())); |
1259 } | 1250 } |
1260 | 1251 |
1261 void ServiceWorkerContextClient::OnNavigationPreloadResponse( | 1252 void ServiceWorkerContextClient::OnNavigationPreloadResponse( |
1262 int fetch_event_id, | 1253 int fetch_event_id, |
1263 std::unique_ptr<blink::WebServiceWorkerResponse> response, | 1254 std::unique_ptr<blink::WebURLResponse> response, |
1264 std::unique_ptr<blink::WebDataConsumerHandle> data_consumer_handle) { | 1255 std::unique_ptr<blink::WebDataConsumerHandle> data_consumer_handle) { |
1265 proxy_->onNavigationPreloadResponse(fetch_event_id, std::move(response), | 1256 proxy_->onNavigationPreloadResponse(fetch_event_id, std::move(response), |
1266 std::move(data_consumer_handle)); | 1257 std::move(data_consumer_handle)); |
1267 } | 1258 } |
1268 | 1259 |
1269 void ServiceWorkerContextClient::OnNavigationPreloadError( | 1260 void ServiceWorkerContextClient::OnNavigationPreloadError( |
1270 int fetch_event_id, | 1261 int fetch_event_id, |
1271 std::unique_ptr<blink::WebServiceWorkerError> error) { | 1262 std::unique_ptr<blink::WebServiceWorkerError> error) { |
1272 proxy_->onNavigationPreloadError(fetch_event_id, std::move(error)); | 1263 proxy_->onNavigationPreloadError(fetch_event_id, std::move(error)); |
1273 } | 1264 } |
1274 | 1265 |
1275 void ServiceWorkerContextClient::BindEventDispatcher( | 1266 void ServiceWorkerContextClient::BindEventDispatcher( |
1276 mojom::ServiceWorkerEventDispatcherRequest request) { | 1267 mojom::ServiceWorkerEventDispatcherRequest request) { |
1277 DCHECK(context_); | 1268 DCHECK(context_); |
1278 DCHECK(!context_->event_dispatcher_binding.is_bound()); | 1269 DCHECK(!context_->event_dispatcher_binding.is_bound()); |
1279 context_->event_dispatcher_binding.Bind(std::move(request)); | 1270 context_->event_dispatcher_binding.Bind(std::move(request)); |
1280 } | 1271 } |
1281 | 1272 |
1282 base::WeakPtr<ServiceWorkerContextClient> | 1273 base::WeakPtr<ServiceWorkerContextClient> |
1283 ServiceWorkerContextClient::GetWeakPtr() { | 1274 ServiceWorkerContextClient::GetWeakPtr() { |
1284 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 1275 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
1285 DCHECK(context_); | 1276 DCHECK(context_); |
1286 return context_->weak_factory.GetWeakPtr(); | 1277 return context_->weak_factory.GetWeakPtr(); |
1287 } | 1278 } |
1288 | 1279 |
1289 } // namespace content | 1280 } // namespace content |
OLD | NEW |