| Index: content/renderer/service_worker/service_worker_context_client.cc
|
| diff --git a/content/renderer/service_worker/service_worker_context_client.cc b/content/renderer/service_worker/service_worker_context_client.cc
|
| index dd792b32d59d2b9374983ce4364ff83092949818..45a0e715b54e16441bd2edfceb2045f5dd666260 100644
|
| --- a/content/renderer/service_worker/service_worker_context_client.cc
|
| +++ b/content/renderer/service_worker/service_worker_context_client.cc
|
| @@ -248,6 +248,8 @@ struct ServiceWorkerContextClient::WorkerContextData {
|
| IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>;
|
| using SkipWaitingCallbacksMap =
|
| IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>;
|
| + using InstallEventCallbacksMap =
|
| + IDMap<std::unique_ptr<const DispatchInstallEventCallback>>;
|
| using ActivateEventCallbacksMap =
|
| IDMap<std::unique_ptr<const DispatchActivateEventCallback>>;
|
| using BackgroundFetchAbortEventCallbacksMap =
|
| @@ -294,6 +296,9 @@ struct ServiceWorkerContextClient::WorkerContextData {
|
| // Pending callbacks for ClaimClients().
|
| ClaimClientsCallbacksMap claim_clients_callbacks;
|
|
|
| + // Pending callbacks for Install Events.
|
| + InstallEventCallbacksMap install_event_callbacks;
|
| +
|
| // Pending callbacks for Activate Events.
|
| ActivateEventCallbacksMap activate_event_callbacks;
|
|
|
| @@ -535,7 +540,6 @@ void ServiceWorkerContextClient::OnMessageReceived(
|
| CHECK_EQ(embedded_worker_id_, embedded_worker_id);
|
| bool handled = true;
|
| IPC_BEGIN_MESSAGE_MAP(ServiceWorkerContextClient, message)
|
| - IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent)
|
| IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClient, OnDidGetClient)
|
| IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients)
|
| IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse,
|
| @@ -697,7 +701,18 @@ void ServiceWorkerContextClient::WillDestroyWorkerContext(
|
| // (while we're still on the worker thread).
|
| proxy_ = NULL;
|
|
|
| - // Aborts all the pending events callbacks.
|
| + // Clear all install event methods.
|
| + install_methods_map_.clear();
|
| +
|
| + // Aborts the all pending install event callbacks which has three
|
| + // parameters so that here can't use AbortPendingEventCallbacks.
|
| + for (WorkerContextData::InstallEventCallbacksMap::iterator it(
|
| + &context_->install_event_callbacks);
|
| + !it.IsAtEnd(); it.Advance()) {
|
| + it.GetCurrentValue()->Run(SERVICE_WORKER_ERROR_ABORT, false,
|
| + base::Time::Now());
|
| + }
|
| + // Aborts all other pending events callbacks.
|
| AbortPendingEventCallbacks(context_->activate_event_callbacks);
|
| AbortPendingEventCallbacks(context_->background_fetch_abort_event_callbacks);
|
| AbortPendingEventCallbacks(context_->background_fetch_click_event_callbacks);
|
| @@ -867,9 +882,13 @@ void ServiceWorkerContextClient::DidHandleInstallEvent(
|
| int request_id,
|
| blink::WebServiceWorkerEventResult result,
|
| double event_dispatch_time) {
|
| - Send(new ServiceWorkerHostMsg_InstallEventFinished(
|
| - GetRoutingID(), request_id, result, proxy_->HasFetchEventHandler(),
|
| - base::Time::FromDoubleT(event_dispatch_time)));
|
| + const DispatchInstallEventCallback* callback =
|
| + context_->install_event_callbacks.Lookup(request_id);
|
| + DCHECK(callback);
|
| + callback->Run(EventResultToStatus(result), proxy_->HasFetchEventHandler(),
|
| + base::Time::FromDoubleT(event_dispatch_time));
|
| + context_->install_event_callbacks.Remove(request_id);
|
| + install_methods_map_.erase(request_id);
|
| }
|
|
|
| void ServiceWorkerContextClient::RespondToFetchEvent(
|
| @@ -1054,11 +1073,18 @@ void ServiceWorkerContextClient::Claim(
|
| }
|
|
|
| void ServiceWorkerContextClient::RegisterForeignFetchScopes(
|
| + const int event_id,
|
| const blink::WebVector<blink::WebURL>& sub_scopes,
|
| const blink::WebVector<blink::WebSecurityOrigin>& origins) {
|
| - Send(new ServiceWorkerHostMsg_RegisterForeignFetchScopes(
|
| - GetRoutingID(), std::vector<GURL>(sub_scopes.begin(), sub_scopes.end()),
|
| - std::vector<url::Origin>(origins.begin(), origins.end())));
|
| + std::vector<GURL> urls;
|
| + for (const auto& url : sub_scopes)
|
| + urls.push_back(url);
|
| +
|
| + std::vector<url::Origin> url_origins;
|
| + for (const auto& origin : origins)
|
| + url_origins.push_back(origin);
|
| +
|
| + install_methods_map_[event_id]->RegisterForeignFetchScopes(urls, url_origins);
|
| }
|
|
|
| void ServiceWorkerContextClient::DispatchSyncEvent(
|
| @@ -1206,6 +1232,24 @@ void ServiceWorkerContextClient::DispatchBackgroundFetchedEvent(
|
| request_id, blink::WebString::FromUTF8(tag), web_fetches);
|
| }
|
|
|
| +void ServiceWorkerContextClient::DispatchInstallEvent(
|
| + mojom::ServiceWorkerInstallEventMethodsAssociatedPtrInfo client,
|
| + const DispatchInstallEventCallback& callback) {
|
| + TRACE_EVENT0("ServiceWorker",
|
| + "ServiceWorkerContextClient::DispatchInstallEvent");
|
| +
|
| + int request_id = context_->install_event_callbacks.Add(
|
| + base::MakeUnique<DispatchInstallEventCallback>(callback));
|
| +
|
| + auto it = install_methods_map_.find(request_id);
|
| + DCHECK(it == install_methods_map_.end());
|
| + mojom::ServiceWorkerInstallEventMethodsAssociatedPtr install_method_client_;
|
| + install_method_client_.Bind(std::move(client));
|
| + install_methods_map_[request_id] = std::move(install_method_client_);
|
| +
|
| + proxy_->DispatchInstallEvent(request_id);
|
| +}
|
| +
|
| void ServiceWorkerContextClient::DispatchExtendableMessageEvent(
|
| mojom::ExtendableMessageEventPtr event,
|
| const DispatchExtendableMessageEventCallback& callback) {
|
| @@ -1241,12 +1285,6 @@ void ServiceWorkerContextClient::DispatchExtendableMessageEvent(
|
| WebServiceWorkerImpl::CreateHandle(worker));
|
| }
|
|
|
| -void ServiceWorkerContextClient::OnInstallEvent(int request_id) {
|
| - TRACE_EVENT0("ServiceWorker",
|
| - "ServiceWorkerContextClient::OnInstallEvent");
|
| - proxy_->DispatchInstallEvent(request_id);
|
| -}
|
| -
|
| void ServiceWorkerContextClient::DispatchFetchEvent(
|
| int fetch_event_id,
|
| const ServiceWorkerFetchRequest& request,
|
|
|