| 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 25 matching lines...) Expand all Loading... |
| 36 #include "content/public/renderer/content_renderer_client.h" | 36 #include "content/public/renderer/content_renderer_client.h" |
| 37 #include "content/public/renderer/document_state.h" | 37 #include "content/public/renderer/document_state.h" |
| 38 #include "content/renderer/background_sync/background_sync_client_impl.h" | 38 #include "content/renderer/background_sync/background_sync_client_impl.h" |
| 39 #include "content/renderer/devtools/devtools_agent.h" | 39 #include "content/renderer/devtools/devtools_agent.h" |
| 40 #include "content/renderer/render_thread_impl.h" | 40 #include "content/renderer/render_thread_impl.h" |
| 41 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" | 41 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" |
| 42 #include "content/renderer/service_worker/service_worker_type_util.h" | 42 #include "content/renderer/service_worker/service_worker_type_util.h" |
| 43 #include "ipc/ipc_message.h" | 43 #include "ipc/ipc_message.h" |
| 44 #include "ipc/ipc_message_macros.h" | 44 #include "ipc/ipc_message_macros.h" |
| 45 #include "mojo/public/cpp/bindings/interface_request.h" | 45 #include "mojo/public/cpp/bindings/interface_request.h" |
| 46 #include "services/shell/public/cpp/interface_provider.h" | |
| 47 #include "services/shell/public/cpp/interface_registry.h" | |
| 48 #include "third_party/WebKit/public/platform/URLConversion.h" | 46 #include "third_party/WebKit/public/platform/URLConversion.h" |
| 49 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" | 47 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" |
| 50 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" | 48 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" |
| 51 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 49 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
| 52 #include "third_party/WebKit/public/platform/WebString.h" | 50 #include "third_party/WebKit/public/platform/WebString.h" |
| 53 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncRegi
stration.h" | 51 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncRegi
stration.h" |
| 54 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onData.h" | 52 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onData.h" |
| 55 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerClientQueryOptions.h" | 53 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerClientQueryOptions.h" |
| 56 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerRequest.h" | 54 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerRequest.h" |
| 57 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerResponse.h" | 55 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerResponse.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 struct ServiceWorkerContextClient::WorkerContextData { | 167 struct ServiceWorkerContextClient::WorkerContextData { |
| 170 using ClientsCallbacksMap = | 168 using ClientsCallbacksMap = |
| 171 IDMap<blink::WebServiceWorkerClientsCallbacks, IDMapOwnPointer>; | 169 IDMap<blink::WebServiceWorkerClientsCallbacks, IDMapOwnPointer>; |
| 172 using ClaimClientsCallbacksMap = | 170 using ClaimClientsCallbacksMap = |
| 173 IDMap<blink::WebServiceWorkerClientsClaimCallbacks, IDMapOwnPointer>; | 171 IDMap<blink::WebServiceWorkerClientsClaimCallbacks, IDMapOwnPointer>; |
| 174 using ClientCallbacksMap = | 172 using ClientCallbacksMap = |
| 175 IDMap<blink::WebServiceWorkerClientCallbacks, IDMapOwnPointer>; | 173 IDMap<blink::WebServiceWorkerClientCallbacks, IDMapOwnPointer>; |
| 176 using SkipWaitingCallbacksMap = | 174 using SkipWaitingCallbacksMap = |
| 177 IDMap<blink::WebServiceWorkerSkipWaitingCallbacks, IDMapOwnPointer>; | 175 IDMap<blink::WebServiceWorkerSkipWaitingCallbacks, IDMapOwnPointer>; |
| 178 using SyncEventCallbacksMap = | 176 using SyncEventCallbacksMap = |
| 179 IDMap<const base::Callback<void(blink::mojom::ServiceWorkerEventStatus)>, | 177 IDMap<const ServiceWorkerContextClient::SyncCallback, IDMapOwnPointer>; |
| 180 IDMapOwnPointer>; | |
| 181 | 178 |
| 182 explicit WorkerContextData(ServiceWorkerContextClient* owner) | 179 explicit WorkerContextData(ServiceWorkerContextClient* owner) |
| 183 : interface_registry(nullptr), | 180 : weak_factory(owner), |
| 184 weak_factory(owner), | 181 proxy_weak_factory(owner->proxy_), |
| 185 proxy_weak_factory(owner->proxy_) {} | 182 interface_registry(nullptr), |
| 183 blink_service_registry(remote_interfaces.GetWeakPtr()) {} |
| 186 | 184 |
| 187 ~WorkerContextData() { | 185 ~WorkerContextData() { |
| 188 DCHECK(thread_checker.CalledOnValidThread()); | 186 DCHECK(thread_checker.CalledOnValidThread()); |
| 189 } | 187 } |
| 190 | 188 |
| 191 // Pending callbacks for GetClientDocuments(). | 189 // Pending callbacks for GetClientDocuments(). |
| 192 ClientsCallbacksMap clients_callbacks; | 190 ClientsCallbacksMap clients_callbacks; |
| 193 | 191 |
| 194 // Pending callbacks for OpenWindow() and FocusClient(). | 192 // Pending callbacks for OpenWindow() and FocusClient(). |
| 195 ClientCallbacksMap client_callbacks; | 193 ClientCallbacksMap client_callbacks; |
| 196 | 194 |
| 197 // Pending callbacks for SkipWaiting(). | 195 // Pending callbacks for SkipWaiting(). |
| 198 SkipWaitingCallbacksMap skip_waiting_callbacks; | 196 SkipWaitingCallbacksMap skip_waiting_callbacks; |
| 199 | 197 |
| 200 // Pending callbacks for ClaimClients(). | 198 // Pending callbacks for ClaimClients(). |
| 201 ClaimClientsCallbacksMap claim_clients_callbacks; | 199 ClaimClientsCallbacksMap claim_clients_callbacks; |
| 202 | 200 |
| 203 // Pending callbacks for Background Sync Events | 201 // Pending callbacks for Background Sync Events |
| 204 SyncEventCallbacksMap sync_event_callbacks; | 202 SyncEventCallbacksMap sync_event_callbacks; |
| 205 | 203 |
| 206 shell::InterfaceRegistry interface_registry; | |
| 207 shell::InterfaceProvider remote_interfaces; | |
| 208 | |
| 209 base::ThreadChecker thread_checker; | 204 base::ThreadChecker thread_checker; |
| 210 base::WeakPtrFactory<ServiceWorkerContextClient> weak_factory; | 205 base::WeakPtrFactory<ServiceWorkerContextClient> weak_factory; |
| 211 base::WeakPtrFactory<blink::WebServiceWorkerContextProxy> proxy_weak_factory; | 206 base::WeakPtrFactory<blink::WebServiceWorkerContextProxy> proxy_weak_factory; |
| 207 |
| 208 // Mojo |
| 209 shell::InterfaceRegistry interface_registry; |
| 210 shell::InterfaceProvider remote_interfaces; |
| 211 BlinkServiceRegistryImpl blink_service_registry; |
| 212 }; | 212 }; |
| 213 | 213 |
| 214 ServiceWorkerContextClient* | 214 ServiceWorkerContextClient* |
| 215 ServiceWorkerContextClient::ThreadSpecificInstance() { | 215 ServiceWorkerContextClient::ThreadSpecificInstance() { |
| 216 return g_worker_client_tls.Pointer()->Get(); | 216 return g_worker_client_tls.Pointer()->Get(); |
| 217 } | 217 } |
| 218 | 218 |
| 219 ServiceWorkerContextClient::ServiceWorkerContextClient( | 219 ServiceWorkerContextClient::ServiceWorkerContextClient( |
| 220 int embedded_worker_id, | 220 int embedded_worker_id, |
| 221 int64_t service_worker_version_id, | 221 int64_t service_worker_version_id, |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 } | 568 } |
| 569 | 569 |
| 570 void ServiceWorkerContextClient::didHandleSyncEvent( | 570 void ServiceWorkerContextClient::didHandleSyncEvent( |
| 571 int request_id, | 571 int request_id, |
| 572 blink::WebServiceWorkerEventResult result) { | 572 blink::WebServiceWorkerEventResult result) { |
| 573 const SyncCallback* callback = | 573 const SyncCallback* callback = |
| 574 context_->sync_event_callbacks.Lookup(request_id); | 574 context_->sync_event_callbacks.Lookup(request_id); |
| 575 if (!callback) | 575 if (!callback) |
| 576 return; | 576 return; |
| 577 if (result == blink::WebServiceWorkerEventResultCompleted) { | 577 if (result == blink::WebServiceWorkerEventResultCompleted) { |
| 578 callback->Run(blink::mojom::ServiceWorkerEventStatus::COMPLETED); | 578 callback->Run(SERVICE_WORKER_OK); |
| 579 } else { | 579 } else { |
| 580 callback->Run(blink::mojom::ServiceWorkerEventStatus::REJECTED); | 580 callback->Run(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED); |
| 581 } | 581 } |
| 582 context_->sync_event_callbacks.Remove(request_id); | 582 context_->sync_event_callbacks.Remove(request_id); |
| 583 } | 583 } |
| 584 | 584 |
| 585 blink::WebServiceWorkerNetworkProvider* | 585 blink::WebServiceWorkerNetworkProvider* |
| 586 ServiceWorkerContextClient::createServiceWorkerNetworkProvider( | 586 ServiceWorkerContextClient::createServiceWorkerNetworkProvider( |
| 587 blink::WebDataSource* data_source) { | 587 blink::WebDataSource* data_source) { |
| 588 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); | 588 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); |
| 589 | 589 |
| 590 // Create a content::ServiceWorkerNetworkProvider for this data source so | 590 // Create a content::ServiceWorkerNetworkProvider for this data source so |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 } | 680 } |
| 681 | 681 |
| 682 void ServiceWorkerContextClient::registerForeignFetchScopes( | 682 void ServiceWorkerContextClient::registerForeignFetchScopes( |
| 683 const blink::WebVector<blink::WebURL>& sub_scopes, | 683 const blink::WebVector<blink::WebURL>& sub_scopes, |
| 684 const blink::WebVector<blink::WebSecurityOrigin>& origins) { | 684 const blink::WebVector<blink::WebSecurityOrigin>& origins) { |
| 685 Send(new ServiceWorkerHostMsg_RegisterForeignFetchScopes( | 685 Send(new ServiceWorkerHostMsg_RegisterForeignFetchScopes( |
| 686 GetRoutingID(), std::vector<GURL>(sub_scopes.begin(), sub_scopes.end()), | 686 GetRoutingID(), std::vector<GURL>(sub_scopes.begin(), sub_scopes.end()), |
| 687 std::vector<url::Origin>(origins.begin(), origins.end()))); | 687 std::vector<url::Origin>(origins.begin(), origins.end()))); |
| 688 } | 688 } |
| 689 | 689 |
| 690 blink::ServiceRegistry* ServiceWorkerContextClient::serviceRegistry() { |
| 691 return &context_->blink_service_registry; |
| 692 } |
| 693 |
| 690 void ServiceWorkerContextClient::DispatchSyncEvent( | 694 void ServiceWorkerContextClient::DispatchSyncEvent( |
| 691 const std::string& tag, | 695 const std::string& tag, |
| 692 blink::WebServiceWorkerContextProxy::LastChanceOption last_chance, | 696 blink::WebServiceWorkerContextProxy::LastChanceOption last_chance, |
| 693 const SyncCallback& callback) { | 697 const SyncCallback& callback) { |
| 694 TRACE_EVENT0("ServiceWorker", | 698 TRACE_EVENT0("ServiceWorker", |
| 695 "ServiceWorkerContextClient::DispatchSyncEvent"); | 699 "ServiceWorkerContextClient::DispatchSyncEvent"); |
| 696 int request_id = | 700 int request_id = |
| 697 context_->sync_event_callbacks.Add(new SyncCallback(callback)); | 701 context_->sync_event_callbacks.Add(new SyncCallback(callback)); |
| 698 | 702 |
| 699 // TODO(jkarlin): Make this blink::WebString::FromUTF8Lenient once | 703 // TODO(jkarlin): Make this blink::WebString::FromUTF8Lenient once |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 } | 1041 } |
| 1038 | 1042 |
| 1039 base::WeakPtr<ServiceWorkerContextClient> | 1043 base::WeakPtr<ServiceWorkerContextClient> |
| 1040 ServiceWorkerContextClient::GetWeakPtr() { | 1044 ServiceWorkerContextClient::GetWeakPtr() { |
| 1041 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 1045 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
| 1042 DCHECK(context_); | 1046 DCHECK(context_); |
| 1043 return context_->weak_factory.GetWeakPtr(); | 1047 return context_->weak_factory.GetWeakPtr(); |
| 1044 } | 1048 } |
| 1045 | 1049 |
| 1046 } // namespace content | 1050 } // namespace content |
| OLD | NEW |