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