| 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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 IPC_END_MESSAGE_MAP() | 422 IPC_END_MESSAGE_MAP() |
| 423 DCHECK(handled); | 423 DCHECK(handled); |
| 424 } | 424 } |
| 425 | 425 |
| 426 blink::WebURL ServiceWorkerContextClient::scope() const { | 426 blink::WebURL ServiceWorkerContextClient::scope() const { |
| 427 return service_worker_scope_; | 427 return service_worker_scope_; |
| 428 } | 428 } |
| 429 | 429 |
| 430 void ServiceWorkerContextClient::getClient( | 430 void ServiceWorkerContextClient::getClient( |
| 431 const blink::WebString& id, | 431 const blink::WebString& id, |
| 432 blink::WebServiceWorkerClientCallbacks* callbacks) { | 432 std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callbacks) { |
| 433 DCHECK(callbacks); | 433 DCHECK(callbacks); |
| 434 int request_id = context_->client_callbacks.Add(callbacks); | 434 int request_id = context_->client_callbacks.Add(std::move(callbacks)); |
| 435 Send(new ServiceWorkerHostMsg_GetClient( | 435 Send(new ServiceWorkerHostMsg_GetClient( |
| 436 GetRoutingID(), request_id, base::UTF16ToUTF8(base::StringPiece16(id)))); | 436 GetRoutingID(), request_id, base::UTF16ToUTF8(base::StringPiece16(id)))); |
| 437 } | 437 } |
| 438 | 438 |
| 439 void ServiceWorkerContextClient::getClients( | 439 void ServiceWorkerContextClient::getClients( |
| 440 const blink::WebServiceWorkerClientQueryOptions& weboptions, | 440 const blink::WebServiceWorkerClientQueryOptions& weboptions, |
| 441 blink::WebServiceWorkerClientsCallbacks* callbacks) { | 441 std::unique_ptr<blink::WebServiceWorkerClientsCallbacks> callbacks) { |
| 442 DCHECK(callbacks); | 442 DCHECK(callbacks); |
| 443 int request_id = context_->clients_callbacks.Add(callbacks); | 443 int request_id = context_->clients_callbacks.Add(std::move(callbacks)); |
| 444 ServiceWorkerClientQueryOptions options; | 444 ServiceWorkerClientQueryOptions options; |
| 445 options.client_type = weboptions.clientType; | 445 options.client_type = weboptions.clientType; |
| 446 options.include_uncontrolled = weboptions.includeUncontrolled; | 446 options.include_uncontrolled = weboptions.includeUncontrolled; |
| 447 Send(new ServiceWorkerHostMsg_GetClients( | 447 Send(new ServiceWorkerHostMsg_GetClients( |
| 448 GetRoutingID(), request_id, options)); | 448 GetRoutingID(), request_id, options)); |
| 449 } | 449 } |
| 450 | 450 |
| 451 void ServiceWorkerContextClient::openWindow( | 451 void ServiceWorkerContextClient::openWindow( |
| 452 const blink::WebURL& url, | 452 const blink::WebURL& url, |
| 453 blink::WebServiceWorkerClientCallbacks* callbacks) { | 453 std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callbacks) { |
| 454 DCHECK(callbacks); | 454 DCHECK(callbacks); |
| 455 int request_id = context_->client_callbacks.Add(callbacks); | 455 int request_id = context_->client_callbacks.Add(std::move(callbacks)); |
| 456 Send(new ServiceWorkerHostMsg_OpenWindow( | 456 Send(new ServiceWorkerHostMsg_OpenWindow( |
| 457 GetRoutingID(), request_id, url)); | 457 GetRoutingID(), request_id, url)); |
| 458 } | 458 } |
| 459 | 459 |
| 460 void ServiceWorkerContextClient::setCachedMetadata(const blink::WebURL& url, | 460 void ServiceWorkerContextClient::setCachedMetadata(const blink::WebURL& url, |
| 461 const char* data, | 461 const char* data, |
| 462 size_t size) { | 462 size_t size) { |
| 463 std::vector<char> copy(data, data + size); | 463 std::vector<char> copy(data, data + size); |
| 464 Send(new ServiceWorkerHostMsg_SetCachedMetadata(GetRoutingID(), url, copy)); | 464 Send(new ServiceWorkerHostMsg_SetCachedMetadata(GetRoutingID(), url, copy)); |
| 465 } | 465 } |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 | 834 |
| 835 void ServiceWorkerContextClient::postMessageToCrossOriginClient( | 835 void ServiceWorkerContextClient::postMessageToCrossOriginClient( |
| 836 const blink::WebCrossOriginServiceWorkerClient&, | 836 const blink::WebCrossOriginServiceWorkerClient&, |
| 837 const blink::WebString&, | 837 const blink::WebString&, |
| 838 blink::WebMessagePortChannelArray*) { | 838 blink::WebMessagePortChannelArray*) { |
| 839 NOTREACHED(); | 839 NOTREACHED(); |
| 840 } | 840 } |
| 841 | 841 |
| 842 void ServiceWorkerContextClient::focus( | 842 void ServiceWorkerContextClient::focus( |
| 843 const blink::WebString& uuid, | 843 const blink::WebString& uuid, |
| 844 blink::WebServiceWorkerClientCallbacks* callback) { | 844 std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callback) { |
| 845 DCHECK(callback); | 845 DCHECK(callback); |
| 846 int request_id = context_->client_callbacks.Add(callback); | 846 int request_id = context_->client_callbacks.Add(std::move(callback)); |
| 847 Send(new ServiceWorkerHostMsg_FocusClient( | 847 Send(new ServiceWorkerHostMsg_FocusClient( |
| 848 GetRoutingID(), request_id, | 848 GetRoutingID(), request_id, |
| 849 base::UTF16ToUTF8(base::StringPiece16(uuid)))); | 849 base::UTF16ToUTF8(base::StringPiece16(uuid)))); |
| 850 } | 850 } |
| 851 | 851 |
| 852 void ServiceWorkerContextClient::navigate( | 852 void ServiceWorkerContextClient::navigate( |
| 853 const blink::WebString& uuid, | 853 const blink::WebString& uuid, |
| 854 const blink::WebURL& url, | 854 const blink::WebURL& url, |
| 855 blink::WebServiceWorkerClientCallbacks* callback) { | 855 std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callback) { |
| 856 DCHECK(callback); | 856 DCHECK(callback); |
| 857 int request_id = context_->client_callbacks.Add(callback); | 857 int request_id = context_->client_callbacks.Add(std::move(callback)); |
| 858 Send(new ServiceWorkerHostMsg_NavigateClient( | 858 Send(new ServiceWorkerHostMsg_NavigateClient( |
| 859 GetRoutingID(), request_id, base::UTF16ToUTF8(base::StringPiece16(uuid)), | 859 GetRoutingID(), request_id, base::UTF16ToUTF8(base::StringPiece16(uuid)), |
| 860 url)); | 860 url)); |
| 861 } | 861 } |
| 862 | 862 |
| 863 void ServiceWorkerContextClient::skipWaiting( | 863 void ServiceWorkerContextClient::skipWaiting( |
| 864 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) { | 864 std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks> callbacks) { |
| 865 DCHECK(callbacks); | 865 DCHECK(callbacks); |
| 866 int request_id = context_->skip_waiting_callbacks.Add(callbacks); | 866 int request_id = context_->skip_waiting_callbacks.Add(std::move(callbacks)); |
| 867 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id)); | 867 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id)); |
| 868 } | 868 } |
| 869 | 869 |
| 870 void ServiceWorkerContextClient::claim( | 870 void ServiceWorkerContextClient::claim( |
| 871 blink::WebServiceWorkerClientsClaimCallbacks* callbacks) { | 871 std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks> callbacks) { |
| 872 DCHECK(callbacks); | 872 DCHECK(callbacks); |
| 873 int request_id = context_->claim_clients_callbacks.Add(callbacks); | 873 int request_id = context_->claim_clients_callbacks.Add(std::move(callbacks)); |
| 874 Send(new ServiceWorkerHostMsg_ClaimClients(GetRoutingID(), request_id)); | 874 Send(new ServiceWorkerHostMsg_ClaimClients(GetRoutingID(), request_id)); |
| 875 } | 875 } |
| 876 | 876 |
| 877 void ServiceWorkerContextClient::registerForeignFetchScopes( | 877 void ServiceWorkerContextClient::registerForeignFetchScopes( |
| 878 const blink::WebVector<blink::WebURL>& sub_scopes, | 878 const blink::WebVector<blink::WebURL>& sub_scopes, |
| 879 const blink::WebVector<blink::WebSecurityOrigin>& origins) { | 879 const blink::WebVector<blink::WebSecurityOrigin>& origins) { |
| 880 Send(new ServiceWorkerHostMsg_RegisterForeignFetchScopes( | 880 Send(new ServiceWorkerHostMsg_RegisterForeignFetchScopes( |
| 881 GetRoutingID(), std::vector<GURL>(sub_scopes.begin(), sub_scopes.end()), | 881 GetRoutingID(), std::vector<GURL>(sub_scopes.begin(), sub_scopes.end()), |
| 882 std::vector<url::Origin>(origins.begin(), origins.end()))); | 882 std::vector<url::Origin>(origins.begin(), origins.end()))); |
| 883 } | 883 } |
| 884 | 884 |
| 885 void ServiceWorkerContextClient::DispatchSyncEvent( | 885 void ServiceWorkerContextClient::DispatchSyncEvent( |
| 886 const std::string& tag, | 886 const std::string& tag, |
| 887 blink::mojom::BackgroundSyncEventLastChance last_chance, | 887 blink::mojom::BackgroundSyncEventLastChance last_chance, |
| 888 const DispatchSyncEventCallback& callback) { | 888 const DispatchSyncEventCallback& callback) { |
| 889 TRACE_EVENT0("ServiceWorker", | 889 TRACE_EVENT0("ServiceWorker", |
| 890 "ServiceWorkerContextClient::DispatchSyncEvent"); | 890 "ServiceWorkerContextClient::DispatchSyncEvent"); |
| 891 int request_id = | 891 int request_id = context_->sync_event_callbacks.Add( |
| 892 context_->sync_event_callbacks.Add(new SyncCallback(callback)); | 892 base::MakeUnique<SyncCallback>(callback)); |
| 893 | 893 |
| 894 // TODO(shimazu): Use typemap when this is moved to blink-side. | 894 // TODO(shimazu): Use typemap when this is moved to blink-side. |
| 895 blink::WebServiceWorkerContextProxy::LastChanceOption web_last_chance = | 895 blink::WebServiceWorkerContextProxy::LastChanceOption web_last_chance = |
| 896 mojo::ConvertTo<blink::WebServiceWorkerContextProxy::LastChanceOption>( | 896 mojo::ConvertTo<blink::WebServiceWorkerContextProxy::LastChanceOption>( |
| 897 last_chance); | 897 last_chance); |
| 898 | 898 |
| 899 // TODO(jkarlin): Make this blink::WebString::FromUTF8Lenient once | 899 // TODO(jkarlin): Make this blink::WebString::FromUTF8Lenient once |
| 900 // https://crrev.com/1768063002/ lands. | 900 // https://crrev.com/1768063002/ lands. |
| 901 proxy_->dispatchSyncEvent(request_id, blink::WebString::fromUTF8(tag), | 901 proxy_->dispatchSyncEvent(request_id, blink::WebString::fromUTF8(tag), |
| 902 web_last_chance); | 902 web_last_chance); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 const DispatchFetchEventCallback& callback) { | 981 const DispatchFetchEventCallback& callback) { |
| 982 std::unique_ptr<NavigationPreloadRequest> preload_request = | 982 std::unique_ptr<NavigationPreloadRequest> preload_request = |
| 983 preload_handle | 983 preload_handle |
| 984 ? base::MakeUnique<NavigationPreloadRequest>( | 984 ? base::MakeUnique<NavigationPreloadRequest>( |
| 985 fetch_event_id, request.url, std::move(preload_handle)) | 985 fetch_event_id, request.url, std::move(preload_handle)) |
| 986 : nullptr; | 986 : nullptr; |
| 987 const bool navigation_preload_sent = !!preload_request; | 987 const bool navigation_preload_sent = !!preload_request; |
| 988 blink::WebServiceWorkerRequest webRequest; | 988 blink::WebServiceWorkerRequest webRequest; |
| 989 TRACE_EVENT0("ServiceWorker", | 989 TRACE_EVENT0("ServiceWorker", |
| 990 "ServiceWorkerContextClient::DispatchFetchEvent"); | 990 "ServiceWorkerContextClient::DispatchFetchEvent"); |
| 991 context_->fetch_event_callbacks.AddWithID(new FetchCallback(callback), | 991 context_->fetch_event_callbacks.AddWithID( |
| 992 fetch_event_id); | 992 base::MakeUnique<FetchCallback>(callback), fetch_event_id); |
| 993 if (preload_request) { | 993 if (preload_request) { |
| 994 context_->preload_requests.AddWithID(std::move(preload_request), | 994 context_->preload_requests.AddWithID(std::move(preload_request), |
| 995 fetch_event_id); | 995 fetch_event_id); |
| 996 } | 996 } |
| 997 | 997 |
| 998 webRequest.setURL(blink::WebURL(request.url)); | 998 webRequest.setURL(blink::WebURL(request.url)); |
| 999 webRequest.setMethod(blink::WebString::fromUTF8(request.method)); | 999 webRequest.setMethod(blink::WebString::fromUTF8(request.method)); |
| 1000 for (ServiceWorkerHeaderMap::const_iterator it = request.headers.begin(); | 1000 for (ServiceWorkerHeaderMap::const_iterator it = request.headers.begin(); |
| 1001 it != request.headers.end(); | 1001 it != request.headers.end(); |
| 1002 ++it) { | 1002 ++it) { |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1273 } | 1273 } |
| 1274 | 1274 |
| 1275 base::WeakPtr<ServiceWorkerContextClient> | 1275 base::WeakPtr<ServiceWorkerContextClient> |
| 1276 ServiceWorkerContextClient::GetWeakPtr() { | 1276 ServiceWorkerContextClient::GetWeakPtr() { |
| 1277 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 1277 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
| 1278 DCHECK(context_); | 1278 DCHECK(context_); |
| 1279 return context_->weak_factory.GetWeakPtr(); | 1279 return context_->weak_factory.GetWeakPtr(); |
| 1280 } | 1280 } |
| 1281 | 1281 |
| 1282 } // namespace content | 1282 } // namespace content |
| OLD | NEW |