1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/service_worker/service_worker_script_context.h"
7 #include "base/logging.h"
8 #include "base/metrics/histogram.h"
9 #include "base/trace_event/trace_event.h"
10 #include "content/child/notifications/notification_data_conversions.h"
11 #include "content/child/service_worker/web_service_worker_registration_impl.h"
12 #include "content/child/thread_safe_sender.h"
13 #include "content/child/webmessageportchannel_impl.h"
14 #include "content/common/message_port_messages.h"
15 #include "content/common/service_worker/service_worker_messages.h"
16 #include "content/public/common/referrer.h"
17 #include "content/renderer/service_worker/embedded_worker_context_client.h"
18 #include "ipc/ipc_message.h"
19 #include "third_party/WebKit/public/platform/WebCrossOriginServiceWorkerClient.h"
20 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
21 #include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h"
22 #include "third_party/WebKit/public/platform/WebString.h"
23 #include "third_party/WebKit/public/platform/WebURL.h"
24 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificationData.h"
25 #include "third_party/WebKit/public/web/WebServiceWorkerContextClient.h"
26 #include "third_party/WebKit/public/web/WebServiceWorkerContextProxy.h"
32 void SendPostMessageToDocumentOnMainThread(
33 ThreadSafeSender
* sender
,
36 const base::string16
& message
,
37 scoped_ptr
<blink::WebMessagePortChannelArray
> channels
) {
38 sender
->Send(new ServiceWorkerHostMsg_PostMessageToDocument(
39 routing_id
, client_id
, message
,
40 WebMessagePortChannelImpl::ExtractMessagePortIDs(channels
.release())));
43 void SendCrossOriginMessageToClientOnMainThread(
44 ThreadSafeSender
* sender
,
46 const base::string16
& message
,
47 scoped_ptr
<blink::WebMessagePortChannelArray
> channels
) {
48 sender
->Send(new MessagePortHostMsg_PostMessage(
49 message_port_id
, message
,
50 WebMessagePortChannelImpl::ExtractMessagePortIDs(channels
.release())));
53 blink::WebURLRequest::FetchRequestMode
GetBlinkFetchRequestMode(
54 FetchRequestMode mode
) {
55 return static_cast<blink::WebURLRequest::FetchRequestMode
>(mode
);
58 blink::WebURLRequest::FetchCredentialsMode
GetBlinkFetchCredentialsMode(
59 FetchCredentialsMode credentials_mode
) {
60 return static_cast<blink::WebURLRequest::FetchCredentialsMode
>(
64 blink::WebURLRequest::RequestContext
GetBlinkRequestContext(
65 RequestContextType request_context_type
) {
66 return static_cast<blink::WebURLRequest::RequestContext
>(
67 request_context_type
);
70 blink::WebURLRequest::FrameType
GetBlinkFrameType(
71 RequestContextFrameType frame_type
) {
72 return static_cast<blink::WebURLRequest::FrameType
>(frame_type
);
75 blink::WebServiceWorkerClientInfo
76 ToWebServiceWorkerClientInfo(const ServiceWorkerClientInfo
& client_info
) {
77 DCHECK(client_info
.IsValid());
79 blink::WebServiceWorkerClientInfo web_client_info
;
81 web_client_info
.clientID
= client_info
.client_id
;
82 web_client_info
.pageVisibilityState
= client_info
.page_visibility_state
;
83 web_client_info
.isFocused
= client_info
.is_focused
;
84 web_client_info
.url
= client_info
.url
;
85 web_client_info
.frameType
= GetBlinkFrameType(client_info
.frame_type
);
87 return web_client_info
;
92 ServiceWorkerScriptContext::ServiceWorkerScriptContext(
93 EmbeddedWorkerContextClient
* embedded_context
,
94 blink::WebServiceWorkerContextProxy
* proxy
)
95 : cache_storage_dispatcher_(new ServiceWorkerCacheStorageDispatcher(this)),
96 embedded_context_(embedded_context
),
100 ServiceWorkerScriptContext::~ServiceWorkerScriptContext() {}
102 void ServiceWorkerScriptContext::OnMessageReceived(
103 const IPC::Message
& message
) {
105 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerScriptContext
, message
)
106 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent
, OnActivateEvent
)
107 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FetchEvent
, OnFetchEvent
)
108 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent
, OnInstallEvent
)
109 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SyncEvent
, OnSyncEvent
)
110 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationClickEvent
,
111 OnNotificationClickEvent
)
112 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent
, OnPushEvent
)
113 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GeofencingEvent
, OnGeofencingEvent
)
114 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginConnectEvent
,
115 OnCrossOriginConnectEvent
)
116 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker
, OnPostMessage
)
117 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker
,
118 OnCrossOriginMessageToWorker
)
119 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClientDocuments
,
120 OnDidGetClientDocuments
)
121 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse
,
122 OnOpenWindowResponse
)
123 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError
,
125 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse
,
126 OnFocusClientResponse
)
127 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting
, OnDidSkipWaiting
)
128 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidClaimClients
, OnDidClaimClients
)
129 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ClaimClientsError
, OnClaimClientsError
)
130 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Ping
, OnPing
);
131 IPC_MESSAGE_UNHANDLED(handled
= false)
132 IPC_END_MESSAGE_MAP()
134 // TODO(gavinp): Would it be preferable to put an AddListener() method to
135 // EmbeddedWorkerContextClient?
137 handled
= cache_storage_dispatcher_
->OnMessageReceived(message
);
142 void ServiceWorkerScriptContext::SetRegistrationInServiceWorkerGlobalScope(
143 scoped_ptr
<WebServiceWorkerRegistrationImpl
> registration
) {
144 proxy_
->setRegistration(registration
.release());
147 void ServiceWorkerScriptContext::DidHandleActivateEvent(
149 blink::WebServiceWorkerEventResult result
) {
151 "ServiceWorker.ActivateEventExecutionTime",
152 base::TimeTicks::Now() - activate_start_timings_
[request_id
]);
153 activate_start_timings_
.erase(request_id
);
155 Send(new ServiceWorkerHostMsg_ActivateEventFinished(
156 GetRoutingID(), request_id
, result
));
159 void ServiceWorkerScriptContext::DidHandleInstallEvent(
161 blink::WebServiceWorkerEventResult result
) {
163 "ServiceWorker.InstallEventExecutionTime",
164 base::TimeTicks::Now() - install_start_timings_
[request_id
]);
165 install_start_timings_
.erase(request_id
);
167 Send(new ServiceWorkerHostMsg_InstallEventFinished(
168 GetRoutingID(), request_id
, result
));
171 void ServiceWorkerScriptContext::DidHandleFetchEvent(
173 ServiceWorkerFetchEventResult result
,
174 const ServiceWorkerResponse
& response
) {
176 "ServiceWorker.FetchEventExecutionTime",
177 base::TimeTicks::Now() - fetch_start_timings_
[request_id
]);
178 fetch_start_timings_
.erase(request_id
);
180 Send(new ServiceWorkerHostMsg_FetchEventFinished(
181 GetRoutingID(), request_id
, result
, response
));
184 void ServiceWorkerScriptContext::DidHandleNotificationClickEvent(
186 blink::WebServiceWorkerEventResult result
) {
188 "ServiceWorker.NotificationClickEventExecutionTime",
189 base::TimeTicks::Now() - notification_click_start_timings_
[request_id
]);
190 notification_click_start_timings_
.erase(request_id
);
192 Send(new ServiceWorkerHostMsg_NotificationClickEventFinished(
193 GetRoutingID(), request_id
));
196 void ServiceWorkerScriptContext::DidHandlePushEvent(
198 blink::WebServiceWorkerEventResult result
) {
199 if (result
== blink::WebServiceWorkerEventResultCompleted
) {
201 "ServiceWorker.PushEventExecutionTime",
202 base::TimeTicks::Now() - push_start_timings_
[request_id
]);
204 push_start_timings_
.erase(request_id
);
206 Send(new ServiceWorkerHostMsg_PushEventFinished(
207 GetRoutingID(), request_id
, result
));
210 void ServiceWorkerScriptContext::DidHandleSyncEvent(int request_id
) {
211 Send(new ServiceWorkerHostMsg_SyncEventFinished(
212 GetRoutingID(), request_id
));
215 void ServiceWorkerScriptContext::DidHandleCrossOriginConnectEvent(
217 bool accept_connection
) {
218 Send(new ServiceWorkerHostMsg_CrossOriginConnectEventFinished(
219 GetRoutingID(), request_id
, accept_connection
));
222 void ServiceWorkerScriptContext::GetClientDocuments(
223 blink::WebServiceWorkerClientsCallbacks
* callbacks
) {
225 int request_id
= pending_clients_callbacks_
.Add(callbacks
);
226 Send(new ServiceWorkerHostMsg_GetClientDocuments(
227 GetRoutingID(), request_id
));
230 void ServiceWorkerScriptContext::OpenWindow(
231 const GURL
& url
, blink::WebServiceWorkerClientCallbacks
* callbacks
) {
233 int request_id
= pending_client_callbacks_
.Add(callbacks
);
234 Send(new ServiceWorkerHostMsg_OpenWindow(GetRoutingID(), request_id
, url
));
237 void ServiceWorkerScriptContext::SetCachedMetadata(const GURL
& url
,
240 std::vector
<char> copy(data
, data
+ size
);
241 Send(new ServiceWorkerHostMsg_SetCachedMetadata(GetRoutingID(), url
, copy
));
244 void ServiceWorkerScriptContext::ClearCachedMetadata(const GURL
& url
) {
245 Send(new ServiceWorkerHostMsg_ClearCachedMetadata(GetRoutingID(), url
));
248 void ServiceWorkerScriptContext::PostMessageToDocument(
250 const base::string16
& message
,
251 scoped_ptr
<blink::WebMessagePortChannelArray
> channels
) {
252 // This may send channels for MessagePorts, and all internal book-keeping
253 // messages for MessagePort (e.g. QueueMessages) are sent from main thread
254 // (with thread hopping), so we need to do the same thread hopping here not
255 // to overtake those messages.
256 embedded_context_
->main_thread_task_runner()->PostTask(
258 base::Bind(&SendPostMessageToDocumentOnMainThread
,
259 make_scoped_refptr(embedded_context_
->thread_safe_sender()),
260 GetRoutingID(), client_id
, message
, base::Passed(&channels
)));
263 void ServiceWorkerScriptContext::PostCrossOriginMessageToClient(
264 const blink::WebCrossOriginServiceWorkerClient
& client
,
265 const base::string16
& message
,
266 scoped_ptr
<blink::WebMessagePortChannelArray
> channels
) {
267 // This may send channels for MessagePorts, and all internal book-keeping
268 // messages for MessagePort (e.g. QueueMessages) are sent from main thread
269 // (with thread hopping), so we need to do the same thread hopping here not
270 // to overtake those messages.
271 embedded_context_
->main_thread_task_runner()->PostTask(
273 base::Bind(&SendCrossOriginMessageToClientOnMainThread
,
274 make_scoped_refptr(embedded_context_
->thread_safe_sender()),
275 client
.clientID
, message
, base::Passed(&channels
)));
278 void ServiceWorkerScriptContext::FocusClient(
279 int client_id
, blink::WebServiceWorkerClientCallbacks
* callback
) {
281 int request_id
= pending_client_callbacks_
.Add(callback
);
282 Send(new ServiceWorkerHostMsg_FocusClient(
283 GetRoutingID(), request_id
, client_id
));
286 void ServiceWorkerScriptContext::ClaimClients(
287 blink::WebServiceWorkerClientsClaimCallbacks
* callbacks
) {
289 int request_id
= pending_claim_clients_callbacks_
.Add(callbacks
);
290 Send(new ServiceWorkerHostMsg_ClaimClients(GetRoutingID(), request_id
));
293 void ServiceWorkerScriptContext::SkipWaiting(
294 blink::WebServiceWorkerSkipWaitingCallbacks
* callbacks
) {
296 int request_id
= pending_skip_waiting_callbacks_
.Add(callbacks
);
297 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id
));
300 void ServiceWorkerScriptContext::Send(IPC::Message
* message
) {
301 embedded_context_
->Send(message
);
304 int ServiceWorkerScriptContext::GetRoutingID() const {
305 return embedded_context_
->embedded_worker_id();
308 void ServiceWorkerScriptContext::OnActivateEvent(int request_id
) {
309 TRACE_EVENT0("ServiceWorker",
310 "ServiceWorkerScriptContext::OnActivateEvent");
311 activate_start_timings_
[request_id
] = base::TimeTicks::Now();
312 proxy_
->dispatchActivateEvent(request_id
);
315 void ServiceWorkerScriptContext::OnInstallEvent(int request_id
,
316 int active_version_id
) {
317 TRACE_EVENT0("ServiceWorker",
318 "ServiceWorkerScriptContext::OnInstallEvent");
319 install_start_timings_
[request_id
] = base::TimeTicks::Now();
320 proxy_
->dispatchInstallEvent(request_id
);
323 void ServiceWorkerScriptContext::OnFetchEvent(
325 const ServiceWorkerFetchRequest
& request
) {
326 blink::WebServiceWorkerRequest webRequest
;
327 TRACE_EVENT0("ServiceWorker",
328 "ServiceWorkerScriptContext::OnFetchEvent");
329 webRequest
.setURL(blink::WebURL(request
.url
));
330 webRequest
.setMethod(blink::WebString::fromUTF8(request
.method
));
331 for (ServiceWorkerHeaderMap::const_iterator it
= request
.headers
.begin();
332 it
!= request
.headers
.end();
334 webRequest
.setHeader(blink::WebString::fromUTF8(it
->first
),
335 blink::WebString::fromUTF8(it
->second
));
337 if (!request
.blob_uuid
.empty()) {
338 webRequest
.setBlob(blink::WebString::fromUTF8(request
.blob_uuid
),
341 webRequest
.setReferrer(
342 blink::WebString::fromUTF8(request
.referrer
.url
.spec()),
343 request
.referrer
.policy
);
344 webRequest
.setMode(GetBlinkFetchRequestMode(request
.mode
));
345 webRequest
.setCredentialsMode(
346 GetBlinkFetchCredentialsMode(request
.credentials_mode
));
347 webRequest
.setRequestContext(
348 GetBlinkRequestContext(request
.request_context_type
));
349 webRequest
.setFrameType(GetBlinkFrameType(request
.frame_type
));
350 webRequest
.setIsReload(request
.is_reload
);
351 fetch_start_timings_
[request_id
] = base::TimeTicks::Now();
352 proxy_
->dispatchFetchEvent(request_id
, webRequest
);
355 void ServiceWorkerScriptContext::OnSyncEvent(int request_id
) {
356 TRACE_EVENT0("ServiceWorker",
357 "ServiceWorkerScriptContext::OnSyncEvent");
358 proxy_
->dispatchSyncEvent(request_id
);
361 void ServiceWorkerScriptContext::OnNotificationClickEvent(
363 const std::string
& notification_id
,
364 const PlatformNotificationData
& notification_data
) {
365 TRACE_EVENT0("ServiceWorker",
366 "ServiceWorkerScriptContext::OnNotificationClickEvent");
367 notification_click_start_timings_
[request_id
] = base::TimeTicks::Now();
368 proxy_
->dispatchNotificationClickEvent(
370 blink::WebString::fromUTF8(notification_id
),
371 ToWebNotificationData(notification_data
));
374 void ServiceWorkerScriptContext::OnPushEvent(int request_id
,
375 const std::string
& data
) {
376 TRACE_EVENT0("ServiceWorker",
377 "ServiceWorkerScriptContext::OnPushEvent");
378 push_start_timings_
[request_id
] = base::TimeTicks::Now();
379 proxy_
->dispatchPushEvent(request_id
, blink::WebString::fromUTF8(data
));
382 void ServiceWorkerScriptContext::OnGeofencingEvent(
384 blink::WebGeofencingEventType event_type
,
385 const std::string
& region_id
,
386 const blink::WebCircularGeofencingRegion
& region
) {
387 TRACE_EVENT0("ServiceWorker",
388 "ServiceWorkerScriptContext::OnGeofencingEvent");
389 proxy_
->dispatchGeofencingEvent(
390 request_id
, event_type
, blink::WebString::fromUTF8(region_id
), region
);
391 Send(new ServiceWorkerHostMsg_GeofencingEventFinished(GetRoutingID(),
395 void ServiceWorkerScriptContext::OnCrossOriginConnectEvent(
397 const NavigatorConnectClient
& client
) {
398 TRACE_EVENT0("ServiceWorker",
399 "ServiceWorkerScriptContext::OnCrossOriginConnectEvent");
400 blink::WebCrossOriginServiceWorkerClient web_client
;
401 web_client
.origin
= client
.origin
;
402 web_client
.targetURL
= client
.target_url
;
403 web_client
.clientID
= client
.message_port_id
;
404 proxy_
->dispatchCrossOriginConnectEvent(request_id
, web_client
);
407 void ServiceWorkerScriptContext::OnPostMessage(
408 const base::string16
& message
,
409 const std::vector
<int>& sent_message_port_ids
,
410 const std::vector
<int>& new_routing_ids
) {
411 TRACE_EVENT0("ServiceWorker",
412 "ServiceWorkerScriptContext::OnPostEvent");
413 std::vector
<WebMessagePortChannelImpl
*> ports
;
414 if (!sent_message_port_ids
.empty()) {
415 base::SingleThreadTaskRunner
* task_runner
=
416 embedded_context_
->main_thread_task_runner();
417 ports
.resize(sent_message_port_ids
.size());
418 for (size_t i
= 0; i
< sent_message_port_ids
.size(); ++i
) {
419 ports
[i
] = new WebMessagePortChannelImpl(
420 new_routing_ids
[i
], sent_message_port_ids
[i
], task_runner
);
424 // dispatchMessageEvent is expected to execute onmessage function
426 base::TimeTicks before
= base::TimeTicks::Now();
427 proxy_
->dispatchMessageEvent(message
, ports
);
429 "ServiceWorker.MessageEventExecutionTime",
430 base::TimeTicks::Now() - before
);
433 void ServiceWorkerScriptContext::OnCrossOriginMessageToWorker(
434 const NavigatorConnectClient
& client
,
435 const base::string16
& message
,
436 const std::vector
<int>& sent_message_port_ids
,
437 const std::vector
<int>& new_routing_ids
) {
438 TRACE_EVENT0("ServiceWorker",
439 "ServiceWorkerScriptContext::OnCrossOriginMessageToWorker");
440 std::vector
<WebMessagePortChannelImpl
*> ports
;
441 if (!sent_message_port_ids
.empty()) {
442 base::SingleThreadTaskRunner
* task_runner
=
443 embedded_context_
->main_thread_task_runner();
444 ports
.resize(sent_message_port_ids
.size());
445 for (size_t i
= 0; i
< sent_message_port_ids
.size(); ++i
) {
446 ports
[i
] = new WebMessagePortChannelImpl(
447 new_routing_ids
[i
], sent_message_port_ids
[i
], task_runner
);
451 blink::WebCrossOriginServiceWorkerClient web_client
;
452 web_client
.origin
= client
.origin
;
453 web_client
.targetURL
= client
.target_url
;
454 web_client
.clientID
= client
.message_port_id
;
455 proxy_
->dispatchCrossOriginMessageEvent(web_client
, message
, ports
);
458 void ServiceWorkerScriptContext::OnDidGetClientDocuments(
459 int request_id
, const std::vector
<ServiceWorkerClientInfo
>& clients
) {
460 TRACE_EVENT0("ServiceWorker",
461 "ServiceWorkerScriptContext::OnDidGetClientDocuments");
462 blink::WebServiceWorkerClientsCallbacks
* callbacks
=
463 pending_clients_callbacks_
.Lookup(request_id
);
465 NOTREACHED() << "Got stray response: " << request_id
;
468 scoped_ptr
<blink::WebServiceWorkerClientsInfo
> info(
469 new blink::WebServiceWorkerClientsInfo
);
470 blink::WebVector
<blink::WebServiceWorkerClientInfo
> convertedClients(
472 for (size_t i
= 0; i
< clients
.size(); ++i
)
473 convertedClients
[i
] = ToWebServiceWorkerClientInfo(clients
[i
]);
474 info
->clients
.swap(convertedClients
);
475 callbacks
->onSuccess(info
.release());
476 pending_clients_callbacks_
.Remove(request_id
);
479 void ServiceWorkerScriptContext::OnOpenWindowResponse(
481 const ServiceWorkerClientInfo
& client
) {
482 TRACE_EVENT0("ServiceWorker",
483 "ServiceWorkerScriptContext::OnOpenWindowResponse");
484 blink::WebServiceWorkerClientCallbacks
* callbacks
=
485 pending_client_callbacks_
.Lookup(request_id
);
487 NOTREACHED() << "Got stray response: " << request_id
;
490 scoped_ptr
<blink::WebServiceWorkerClientInfo
> web_client
;
491 if (!client
.IsEmpty()) {
492 DCHECK(client
.IsValid());
493 web_client
.reset(new blink::WebServiceWorkerClientInfo(
494 ToWebServiceWorkerClientInfo(client
)));
496 callbacks
->onSuccess(web_client
.release());
497 pending_client_callbacks_
.Remove(request_id
);
500 void ServiceWorkerScriptContext::OnOpenWindowError(int request_id
) {
501 TRACE_EVENT0("ServiceWorker",
502 "ServiceWorkerScriptContext::OnOpenWindowError");
503 blink::WebServiceWorkerClientCallbacks
* callbacks
=
504 pending_client_callbacks_
.Lookup(request_id
);
506 NOTREACHED() << "Got stray response: " << request_id
;
509 scoped_ptr
<blink::WebServiceWorkerError
> error(
510 new blink::WebServiceWorkerError(
511 blink::WebServiceWorkerError::ErrorTypeUnknown
,
512 "Something went wrong while trying to open the window."));
513 callbacks
->onError(error
.release());
514 pending_client_callbacks_
.Remove(request_id
);
517 void ServiceWorkerScriptContext::OnFocusClientResponse(
518 int request_id
, const ServiceWorkerClientInfo
& client
) {
519 TRACE_EVENT0("ServiceWorker",
520 "ServiceWorkerScriptContext::OnFocusClientResponse");
521 blink::WebServiceWorkerClientCallbacks
* callback
=
522 pending_client_callbacks_
.Lookup(request_id
);
524 NOTREACHED() << "Got stray response: " << request_id
;
527 if (!client
.IsEmpty()) {
528 DCHECK(client
.IsValid());
529 scoped_ptr
<blink::WebServiceWorkerClientInfo
> web_client (
530 new blink::WebServiceWorkerClientInfo(
531 ToWebServiceWorkerClientInfo(client
)));
532 callback
->onSuccess(web_client
.release());
534 scoped_ptr
<blink::WebServiceWorkerError
> error(
535 new blink::WebServiceWorkerError(
536 blink::WebServiceWorkerError::ErrorTypeNotFound
,
537 "The WindowClient was not found."));
538 callback
->onError(error
.release());
541 pending_client_callbacks_
.Remove(request_id
);
544 void ServiceWorkerScriptContext::OnDidSkipWaiting(int request_id
) {
545 TRACE_EVENT0("ServiceWorker",
546 "ServiceWorkerScriptContext::OnDidSkipWaiting");
547 blink::WebServiceWorkerSkipWaitingCallbacks
* callbacks
=
548 pending_skip_waiting_callbacks_
.Lookup(request_id
);
550 NOTREACHED() << "Got stray response: " << request_id
;
553 callbacks
->onSuccess();
554 pending_skip_waiting_callbacks_
.Remove(request_id
);
557 void ServiceWorkerScriptContext::OnDidClaimClients(int request_id
) {
558 TRACE_EVENT0("ServiceWorker",
559 "ServiceWorkerScriptContext::OnDidClaimClients");
560 blink::WebServiceWorkerClientsClaimCallbacks
* callbacks
=
561 pending_claim_clients_callbacks_
.Lookup(request_id
);
563 NOTREACHED() << "Got stray response: " << request_id
;
566 callbacks
->onSuccess();
567 pending_claim_clients_callbacks_
.Remove(request_id
);
570 void ServiceWorkerScriptContext::OnClaimClientsError(
572 blink::WebServiceWorkerError::ErrorType error_type
,
573 const base::string16
& message
) {
574 TRACE_EVENT0("ServiceWorker",
575 "ServiceWorkerScriptContext::OnClaimClientsError");
576 blink::WebServiceWorkerClientsClaimCallbacks
* callbacks
=
577 pending_claim_clients_callbacks_
.Lookup(request_id
);
579 NOTREACHED() << "Got stray response: " << request_id
;
582 scoped_ptr
<blink::WebServiceWorkerError
> error(
583 new blink::WebServiceWorkerError(error_type
, message
));
584 callbacks
->onError(error
.release());
585 pending_claim_clients_callbacks_
.Remove(request_id
);
588 void ServiceWorkerScriptContext::OnPing() {
589 Send(new ServiceWorkerHostMsg_Pong(GetRoutingID()));
592 } // namespace content