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 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 } | 451 } |
452 | 452 |
453 blink::WebURL ServiceWorkerContextClient::scope() const { | 453 blink::WebURL ServiceWorkerContextClient::scope() const { |
454 return service_worker_scope_; | 454 return service_worker_scope_; |
455 } | 455 } |
456 | 456 |
457 void ServiceWorkerContextClient::getClient( | 457 void ServiceWorkerContextClient::getClient( |
458 const blink::WebString& id, | 458 const blink::WebString& id, |
459 blink::WebServiceWorkerClientCallbacks* callbacks) { | 459 blink::WebServiceWorkerClientCallbacks* callbacks) { |
460 DCHECK(callbacks); | 460 DCHECK(callbacks); |
461 int request_id = context_->client_callbacks.Add(callbacks); | 461 int request_id = context_->client_callbacks.Add( |
| 462 std::unique_ptr<blink::WebServiceWorkerClientCallbacks>(callbacks)); |
462 Send(new ServiceWorkerHostMsg_GetClient( | 463 Send(new ServiceWorkerHostMsg_GetClient( |
463 GetRoutingID(), request_id, base::UTF16ToUTF8(base::StringPiece16(id)))); | 464 GetRoutingID(), request_id, base::UTF16ToUTF8(base::StringPiece16(id)))); |
464 } | 465 } |
465 | 466 |
466 void ServiceWorkerContextClient::getClients( | 467 void ServiceWorkerContextClient::getClients( |
467 const blink::WebServiceWorkerClientQueryOptions& weboptions, | 468 const blink::WebServiceWorkerClientQueryOptions& weboptions, |
468 blink::WebServiceWorkerClientsCallbacks* callbacks) { | 469 blink::WebServiceWorkerClientsCallbacks* callbacks) { |
469 DCHECK(callbacks); | 470 DCHECK(callbacks); |
470 int request_id = context_->clients_callbacks.Add(callbacks); | 471 int request_id = context_->clients_callbacks.Add( |
| 472 std::unique_ptr<blink::WebServiceWorkerClientsCallbacks>(callbacks)); |
471 ServiceWorkerClientQueryOptions options; | 473 ServiceWorkerClientQueryOptions options; |
472 options.client_type = weboptions.clientType; | 474 options.client_type = weboptions.clientType; |
473 options.include_uncontrolled = weboptions.includeUncontrolled; | 475 options.include_uncontrolled = weboptions.includeUncontrolled; |
474 Send(new ServiceWorkerHostMsg_GetClients( | 476 Send(new ServiceWorkerHostMsg_GetClients( |
475 GetRoutingID(), request_id, options)); | 477 GetRoutingID(), request_id, options)); |
476 } | 478 } |
477 | 479 |
478 void ServiceWorkerContextClient::openWindow( | 480 void ServiceWorkerContextClient::openWindow( |
479 const blink::WebURL& url, | 481 const blink::WebURL& url, |
480 blink::WebServiceWorkerClientCallbacks* callbacks) { | 482 blink::WebServiceWorkerClientCallbacks* callbacks) { |
481 DCHECK(callbacks); | 483 DCHECK(callbacks); |
482 int request_id = context_->client_callbacks.Add(callbacks); | 484 int request_id = context_->client_callbacks.Add( |
| 485 std::unique_ptr<blink::WebServiceWorkerClientCallbacks>(callbacks)); |
483 Send(new ServiceWorkerHostMsg_OpenWindow( | 486 Send(new ServiceWorkerHostMsg_OpenWindow( |
484 GetRoutingID(), request_id, url)); | 487 GetRoutingID(), request_id, url)); |
485 } | 488 } |
486 | 489 |
487 void ServiceWorkerContextClient::setCachedMetadata(const blink::WebURL& url, | 490 void ServiceWorkerContextClient::setCachedMetadata(const blink::WebURL& url, |
488 const char* data, | 491 const char* data, |
489 size_t size) { | 492 size_t size) { |
490 std::vector<char> copy(data, data + size); | 493 std::vector<char> copy(data, data + size); |
491 Send(new ServiceWorkerHostMsg_SetCachedMetadata(GetRoutingID(), url, copy)); | 494 Send(new ServiceWorkerHostMsg_SetCachedMetadata(GetRoutingID(), url, copy)); |
492 } | 495 } |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 const blink::WebCrossOriginServiceWorkerClient&, | 874 const blink::WebCrossOriginServiceWorkerClient&, |
872 const blink::WebString&, | 875 const blink::WebString&, |
873 blink::WebMessagePortChannelArray*) { | 876 blink::WebMessagePortChannelArray*) { |
874 NOTREACHED(); | 877 NOTREACHED(); |
875 } | 878 } |
876 | 879 |
877 void ServiceWorkerContextClient::focus( | 880 void ServiceWorkerContextClient::focus( |
878 const blink::WebString& uuid, | 881 const blink::WebString& uuid, |
879 blink::WebServiceWorkerClientCallbacks* callback) { | 882 blink::WebServiceWorkerClientCallbacks* callback) { |
880 DCHECK(callback); | 883 DCHECK(callback); |
881 int request_id = context_->client_callbacks.Add(callback); | 884 int request_id = context_->client_callbacks.Add( |
| 885 std::unique_ptr<blink::WebServiceWorkerClientCallbacks>(callback)); |
882 Send(new ServiceWorkerHostMsg_FocusClient( | 886 Send(new ServiceWorkerHostMsg_FocusClient( |
883 GetRoutingID(), request_id, | 887 GetRoutingID(), request_id, |
884 base::UTF16ToUTF8(base::StringPiece16(uuid)))); | 888 base::UTF16ToUTF8(base::StringPiece16(uuid)))); |
885 } | 889 } |
886 | 890 |
887 void ServiceWorkerContextClient::navigate( | 891 void ServiceWorkerContextClient::navigate( |
888 const blink::WebString& uuid, | 892 const blink::WebString& uuid, |
889 const blink::WebURL& url, | 893 const blink::WebURL& url, |
890 blink::WebServiceWorkerClientCallbacks* callback) { | 894 blink::WebServiceWorkerClientCallbacks* callback) { |
891 DCHECK(callback); | 895 DCHECK(callback); |
892 int request_id = context_->client_callbacks.Add(callback); | 896 int request_id = context_->client_callbacks.Add( |
| 897 std::unique_ptr<blink::WebServiceWorkerClientCallbacks>(callback)); |
893 Send(new ServiceWorkerHostMsg_NavigateClient( | 898 Send(new ServiceWorkerHostMsg_NavigateClient( |
894 GetRoutingID(), request_id, base::UTF16ToUTF8(base::StringPiece16(uuid)), | 899 GetRoutingID(), request_id, base::UTF16ToUTF8(base::StringPiece16(uuid)), |
895 url)); | 900 url)); |
896 } | 901 } |
897 | 902 |
898 void ServiceWorkerContextClient::skipWaiting( | 903 void ServiceWorkerContextClient::skipWaiting( |
899 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) { | 904 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) { |
900 DCHECK(callbacks); | 905 DCHECK(callbacks); |
901 int request_id = context_->skip_waiting_callbacks.Add(callbacks); | 906 int request_id = context_->skip_waiting_callbacks.Add( |
| 907 std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>(callbacks)); |
902 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id)); | 908 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id)); |
903 } | 909 } |
904 | 910 |
905 void ServiceWorkerContextClient::claim( | 911 void ServiceWorkerContextClient::claim( |
906 blink::WebServiceWorkerClientsClaimCallbacks* callbacks) { | 912 blink::WebServiceWorkerClientsClaimCallbacks* callbacks) { |
907 DCHECK(callbacks); | 913 DCHECK(callbacks); |
908 int request_id = context_->claim_clients_callbacks.Add(callbacks); | 914 int request_id = context_->claim_clients_callbacks.Add( |
| 915 std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks>(callbacks)); |
909 Send(new ServiceWorkerHostMsg_ClaimClients(GetRoutingID(), request_id)); | 916 Send(new ServiceWorkerHostMsg_ClaimClients(GetRoutingID(), request_id)); |
910 } | 917 } |
911 | 918 |
912 void ServiceWorkerContextClient::registerForeignFetchScopes( | 919 void ServiceWorkerContextClient::registerForeignFetchScopes( |
913 const blink::WebVector<blink::WebURL>& sub_scopes, | 920 const blink::WebVector<blink::WebURL>& sub_scopes, |
914 const blink::WebVector<blink::WebSecurityOrigin>& origins) { | 921 const blink::WebVector<blink::WebSecurityOrigin>& origins) { |
915 Send(new ServiceWorkerHostMsg_RegisterForeignFetchScopes( | 922 Send(new ServiceWorkerHostMsg_RegisterForeignFetchScopes( |
916 GetRoutingID(), std::vector<GURL>(sub_scopes.begin(), sub_scopes.end()), | 923 GetRoutingID(), std::vector<GURL>(sub_scopes.begin(), sub_scopes.end()), |
917 std::vector<url::Origin>(origins.begin(), origins.end()))); | 924 std::vector<url::Origin>(origins.begin(), origins.end()))); |
918 } | 925 } |
919 | 926 |
920 void ServiceWorkerContextClient::DispatchSyncEvent( | 927 void ServiceWorkerContextClient::DispatchSyncEvent( |
921 const std::string& tag, | 928 const std::string& tag, |
922 blink::WebServiceWorkerContextProxy::LastChanceOption last_chance, | 929 blink::WebServiceWorkerContextProxy::LastChanceOption last_chance, |
923 const SyncCallback& callback) { | 930 const SyncCallback& callback) { |
924 TRACE_EVENT0("ServiceWorker", | 931 TRACE_EVENT0("ServiceWorker", |
925 "ServiceWorkerContextClient::DispatchSyncEvent"); | 932 "ServiceWorkerContextClient::DispatchSyncEvent"); |
926 int request_id = | 933 int request_id = context_->sync_event_callbacks.Add( |
927 context_->sync_event_callbacks.Add(new SyncCallback(callback)); | 934 base::MakeUnique<SyncCallback>(callback)); |
928 | 935 |
929 // TODO(jkarlin): Make this blink::WebString::FromUTF8Lenient once | 936 // TODO(jkarlin): Make this blink::WebString::FromUTF8Lenient once |
930 // https://crrev.com/1768063002/ lands. | 937 // https://crrev.com/1768063002/ lands. |
931 proxy_->dispatchSyncEvent(request_id, blink::WebString::fromUTF8(tag), | 938 proxy_->dispatchSyncEvent(request_id, blink::WebString::fromUTF8(tag), |
932 last_chance); | 939 last_chance); |
933 } | 940 } |
934 | 941 |
935 void ServiceWorkerContextClient::Send(IPC::Message* message) { | 942 void ServiceWorkerContextClient::Send(IPC::Message* message) { |
936 sender_->Send(message); | 943 sender_->Send(message); |
937 } | 944 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1006 | 1013 |
1007 void ServiceWorkerContextClient::DispatchFetchEvent( | 1014 void ServiceWorkerContextClient::DispatchFetchEvent( |
1008 int fetch_event_id, | 1015 int fetch_event_id, |
1009 const ServiceWorkerFetchRequest& request, | 1016 const ServiceWorkerFetchRequest& request, |
1010 std::unique_ptr<NavigationPreloadRequest> preload_request, | 1017 std::unique_ptr<NavigationPreloadRequest> preload_request, |
1011 const FetchCallback& callback) { | 1018 const FetchCallback& callback) { |
1012 const bool navigation_preload_sent = !!preload_request; | 1019 const bool navigation_preload_sent = !!preload_request; |
1013 blink::WebServiceWorkerRequest webRequest; | 1020 blink::WebServiceWorkerRequest webRequest; |
1014 TRACE_EVENT0("ServiceWorker", | 1021 TRACE_EVENT0("ServiceWorker", |
1015 "ServiceWorkerContextClient::DispatchFetchEvent"); | 1022 "ServiceWorkerContextClient::DispatchFetchEvent"); |
1016 context_->fetch_event_callbacks.AddWithID(new FetchCallback(callback), | 1023 context_->fetch_event_callbacks.AddWithID( |
1017 fetch_event_id); | 1024 base::MakeUnique<FetchCallback>(callback), fetch_event_id); |
1018 if (preload_request) { | 1025 if (preload_request) { |
1019 context_->preload_requests.AddWithID(std::move(preload_request), | 1026 context_->preload_requests.AddWithID(std::move(preload_request), |
1020 fetch_event_id); | 1027 fetch_event_id); |
1021 } | 1028 } |
1022 | 1029 |
1023 webRequest.setURL(blink::WebURL(request.url)); | 1030 webRequest.setURL(blink::WebURL(request.url)); |
1024 webRequest.setMethod(blink::WebString::fromUTF8(request.method)); | 1031 webRequest.setMethod(blink::WebString::fromUTF8(request.method)); |
1025 for (ServiceWorkerHeaderMap::const_iterator it = request.headers.begin(); | 1032 for (ServiceWorkerHeaderMap::const_iterator it = request.headers.begin(); |
1026 it != request.headers.end(); | 1033 it != request.headers.end(); |
1027 ++it) { | 1034 ++it) { |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1291 } | 1298 } |
1292 | 1299 |
1293 base::WeakPtr<ServiceWorkerContextClient> | 1300 base::WeakPtr<ServiceWorkerContextClient> |
1294 ServiceWorkerContextClient::GetWeakPtr() { | 1301 ServiceWorkerContextClient::GetWeakPtr() { |
1295 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 1302 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
1296 DCHECK(context_); | 1303 DCHECK(context_); |
1297 return context_->weak_factory.GetWeakPtr(); | 1304 return context_->weak_factory.GetWeakPtr(); |
1298 } | 1305 } |
1299 | 1306 |
1300 } // namespace content | 1307 } // namespace content |
OLD | NEW |