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/strings/utf_string_conversions.h"
10 #include "base/trace_event/trace_event.h"
11 #include "content/child/notifications/notification_data_conversions.h"
12 #include "content/child/service_worker/web_service_worker_registration_impl.h"
13 #include "content/child/thread_safe_sender.h"
14 #include "content/child/webmessageportchannel_impl.h"
15 #include "content/common/message_port_messages.h"
16 #include "content/common/service_worker/service_worker_messages.h"
17 #include "content/public/common/referrer.h"
18 #include "content/renderer/service_worker/embedded_worker_context_client.h"
19 #include "content/renderer/service_worker/webserviceworkercachestorage_impl.h"
20 #include "ipc/ipc_message.h"
21 #include "third_party/WebKit/public/platform/WebCrossOriginServiceWorkerClient.h"
22 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
23 #include "third_party/WebKit/public/platform/WebServiceWorkerClientQueryOptions.h"
24 #include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h"
25 #include "third_party/WebKit/public/platform/WebString.h"
26 #include "third_party/WebKit/public/platform/WebURL.h"
27 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificationData.h"
28 #include "third_party/WebKit/public/web/WebServiceWorkerContextClient.h"
29 #include "third_party/WebKit/public/web/WebServiceWorkerContextProxy.h"
35 void SendPostMessageToClientOnMainThread(
36 ThreadSafeSender
* sender
,
38 const std::string
& uuid
,
39 const base::string16
& message
,
40 scoped_ptr
<blink::WebMessagePortChannelArray
> channels
) {
41 sender
->Send(new ServiceWorkerHostMsg_PostMessageToClient(
42 routing_id
, uuid
, message
,
43 WebMessagePortChannelImpl::ExtractMessagePortIDs(channels
.release())));
46 void SendCrossOriginMessageToClientOnMainThread(
47 ThreadSafeSender
* sender
,
49 const base::string16
& message
,
50 scoped_ptr
<blink::WebMessagePortChannelArray
> channels
) {
51 sender
->Send(new MessagePortHostMsg_PostMessage(
53 MessagePortMessage(message
),
54 WebMessagePortChannelImpl::ExtractMessagePortIDs(
55 channels
.release())));
58 blink::WebURLRequest::FetchRequestMode
GetBlinkFetchRequestMode(
59 FetchRequestMode mode
) {
60 return static_cast<blink::WebURLRequest::FetchRequestMode
>(mode
);
63 blink::WebURLRequest::FetchCredentialsMode
GetBlinkFetchCredentialsMode(
64 FetchCredentialsMode credentials_mode
) {
65 return static_cast<blink::WebURLRequest::FetchCredentialsMode
>(
69 blink::WebURLRequest::RequestContext
GetBlinkRequestContext(
70 RequestContextType request_context_type
) {
71 return static_cast<blink::WebURLRequest::RequestContext
>(
72 request_context_type
);
75 blink::WebURLRequest::FrameType
GetBlinkFrameType(
76 RequestContextFrameType frame_type
) {
77 return static_cast<blink::WebURLRequest::FrameType
>(frame_type
);
80 blink::WebServiceWorkerClientInfo
81 ToWebServiceWorkerClientInfo(const ServiceWorkerClientInfo
& client_info
) {
82 DCHECK(client_info
.IsValid());
84 blink::WebServiceWorkerClientInfo web_client_info
;
86 web_client_info
.uuid
= base::UTF8ToUTF16(client_info
.client_uuid
);
87 web_client_info
.pageVisibilityState
= client_info
.page_visibility_state
;
88 web_client_info
.isFocused
= client_info
.is_focused
;
89 web_client_info
.url
= client_info
.url
;
90 web_client_info
.frameType
= GetBlinkFrameType(client_info
.frame_type
);
91 web_client_info
.clientType
= client_info
.client_type
;
93 return web_client_info
;
98 ServiceWorkerScriptContext::ServiceWorkerScriptContext(
99 EmbeddedWorkerContextClient
* embedded_context
,
100 blink::WebServiceWorkerContextProxy
* proxy
)
101 : embedded_context_(embedded_context
),
102 cache_storage_(new WebServiceWorkerCacheStorageImpl(
103 embedded_context
->thread_safe_sender(),
104 embedded_context
->origin())),
108 ServiceWorkerScriptContext::~ServiceWorkerScriptContext() {}
110 void ServiceWorkerScriptContext::OnMessageReceived(
111 const IPC::Message
& message
) {
113 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerScriptContext
, message
)
114 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent
, OnActivateEvent
)
115 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FetchEvent
, OnFetchEvent
)
116 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent
, OnInstallEvent
)
117 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SyncEvent
, OnSyncEvent
)
118 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationClickEvent
,
119 OnNotificationClickEvent
)
120 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent
, OnPushEvent
)
121 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GeofencingEvent
, OnGeofencingEvent
)
122 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginConnectEvent
,
123 OnCrossOriginConnectEvent
)
124 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker
, OnPostMessage
)
125 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker
,
126 OnCrossOriginMessageToWorker
)
127 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients
,
129 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse
,
130 OnOpenWindowResponse
)
131 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError
,
133 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse
,
134 OnFocusClientResponse
)
135 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting
, OnDidSkipWaiting
)
136 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidClaimClients
, OnDidClaimClients
)
137 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ClaimClientsError
, OnClaimClientsError
)
138 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Ping
, OnPing
);
139 IPC_MESSAGE_UNHANDLED(handled
= false)
140 IPC_END_MESSAGE_MAP()
145 void ServiceWorkerScriptContext::SetRegistrationInServiceWorkerGlobalScope(
146 scoped_ptr
<WebServiceWorkerRegistrationImpl
> registration
) {
147 proxy_
->setRegistration(registration
.release());
150 void ServiceWorkerScriptContext::DidHandleActivateEvent(
152 blink::WebServiceWorkerEventResult result
) {
154 "ServiceWorker.ActivateEventExecutionTime",
155 base::TimeTicks::Now() - activate_start_timings_
[request_id
]);
156 activate_start_timings_
.erase(request_id
);
158 Send(new ServiceWorkerHostMsg_ActivateEventFinished(
159 GetRoutingID(), request_id
, result
));
162 void ServiceWorkerScriptContext::DidHandleInstallEvent(
164 blink::WebServiceWorkerEventResult result
) {
166 "ServiceWorker.InstallEventExecutionTime",
167 base::TimeTicks::Now() - install_start_timings_
[request_id
]);
168 install_start_timings_
.erase(request_id
);
170 Send(new ServiceWorkerHostMsg_InstallEventFinished(
171 GetRoutingID(), request_id
, result
));
174 void ServiceWorkerScriptContext::DidHandleFetchEvent(
176 ServiceWorkerFetchEventResult result
,
177 const ServiceWorkerResponse
& response
) {
179 "ServiceWorker.FetchEventExecutionTime",
180 base::TimeTicks::Now() - fetch_start_timings_
[request_id
]);
181 fetch_start_timings_
.erase(request_id
);
183 Send(new ServiceWorkerHostMsg_FetchEventFinished(
184 GetRoutingID(), request_id
, result
, response
));
187 void ServiceWorkerScriptContext::DidHandleNotificationClickEvent(
189 blink::WebServiceWorkerEventResult result
) {
191 "ServiceWorker.NotificationClickEventExecutionTime",
192 base::TimeTicks::Now() - notification_click_start_timings_
[request_id
]);
193 notification_click_start_timings_
.erase(request_id
);
195 Send(new ServiceWorkerHostMsg_NotificationClickEventFinished(
196 GetRoutingID(), request_id
));
199 void ServiceWorkerScriptContext::DidHandlePushEvent(
201 blink::WebServiceWorkerEventResult result
) {
202 if (result
== blink::WebServiceWorkerEventResultCompleted
) {
204 "ServiceWorker.PushEventExecutionTime",
205 base::TimeTicks::Now() - push_start_timings_
[request_id
]);
207 push_start_timings_
.erase(request_id
);
209 Send(new ServiceWorkerHostMsg_PushEventFinished(
210 GetRoutingID(), request_id
, result
));
213 void ServiceWorkerScriptContext::DidHandleSyncEvent(int request_id
) {
214 Send(new ServiceWorkerHostMsg_SyncEventFinished(
215 GetRoutingID(), request_id
));
218 void ServiceWorkerScriptContext::DidHandleCrossOriginConnectEvent(
220 bool accept_connection
) {
221 Send(new ServiceWorkerHostMsg_CrossOriginConnectEventFinished(
222 GetRoutingID(), request_id
, accept_connection
));
225 void ServiceWorkerScriptContext::GetClients(
226 const blink::WebServiceWorkerClientQueryOptions
& weboptions
,
227 blink::WebServiceWorkerClientsCallbacks
* callbacks
) {
229 int request_id
= pending_clients_callbacks_
.Add(callbacks
);
230 ServiceWorkerClientQueryOptions options
;
231 options
.client_type
= weboptions
.clientType
;
232 options
.include_uncontrolled
= weboptions
.includeUncontrolled
;
233 Send(new ServiceWorkerHostMsg_GetClients(
234 GetRoutingID(), request_id
, options
));
237 void ServiceWorkerScriptContext::OpenWindow(
238 const GURL
& url
, blink::WebServiceWorkerClientCallbacks
* callbacks
) {
240 int request_id
= pending_client_callbacks_
.Add(callbacks
);
241 Send(new ServiceWorkerHostMsg_OpenWindow(GetRoutingID(), request_id
, url
));
244 void ServiceWorkerScriptContext::SetCachedMetadata(const GURL
& url
,
247 std::vector
<char> copy(data
, data
+ size
);
248 Send(new ServiceWorkerHostMsg_SetCachedMetadata(GetRoutingID(), url
, copy
));
251 void ServiceWorkerScriptContext::ClearCachedMetadata(const GURL
& url
) {
252 Send(new ServiceWorkerHostMsg_ClearCachedMetadata(GetRoutingID(), url
));
255 void ServiceWorkerScriptContext::PostMessageToClient(
256 const base::string16
& uuid
,
257 const base::string16
& message
,
258 scoped_ptr
<blink::WebMessagePortChannelArray
> channels
) {
259 // This may send channels for MessagePorts, and all internal book-keeping
260 // messages for MessagePort (e.g. QueueMessages) are sent from main thread
261 // (with thread hopping), so we need to do the same thread hopping here not
262 // to overtake those messages.
263 embedded_context_
->main_thread_task_runner()->PostTask(
265 base::Bind(&SendPostMessageToClientOnMainThread
,
266 make_scoped_refptr(embedded_context_
->thread_safe_sender()),
268 base::UTF16ToUTF8(uuid
),
269 message
, base::Passed(&channels
)));
272 void ServiceWorkerScriptContext::PostCrossOriginMessageToClient(
273 const blink::WebCrossOriginServiceWorkerClient
& client
,
274 const base::string16
& message
,
275 scoped_ptr
<blink::WebMessagePortChannelArray
> channels
) {
276 // This may send channels for MessagePorts, and all internal book-keeping
277 // messages for MessagePort (e.g. QueueMessages) are sent from main thread
278 // (with thread hopping), so we need to do the same thread hopping here not
279 // to overtake those messages.
280 embedded_context_
->main_thread_task_runner()->PostTask(
282 base::Bind(&SendCrossOriginMessageToClientOnMainThread
,
283 make_scoped_refptr(embedded_context_
->thread_safe_sender()),
284 client
.clientID
, message
, base::Passed(&channels
)));
287 void ServiceWorkerScriptContext::FocusClient(
288 const base::string16
& uuid
,
289 blink::WebServiceWorkerClientCallbacks
* callback
) {
291 int request_id
= pending_client_callbacks_
.Add(callback
);
292 Send(new ServiceWorkerHostMsg_FocusClient(GetRoutingID(), request_id
,
293 base::UTF16ToUTF8(uuid
)));
296 void ServiceWorkerScriptContext::ClaimClients(
297 blink::WebServiceWorkerClientsClaimCallbacks
* callbacks
) {
299 int request_id
= pending_claim_clients_callbacks_
.Add(callbacks
);
300 Send(new ServiceWorkerHostMsg_ClaimClients(GetRoutingID(), request_id
));
303 void ServiceWorkerScriptContext::SkipWaiting(
304 blink::WebServiceWorkerSkipWaitingCallbacks
* callbacks
) {
306 int request_id
= pending_skip_waiting_callbacks_
.Add(callbacks
);
307 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id
));
310 void ServiceWorkerScriptContext::Send(IPC::Message
* message
) {
311 embedded_context_
->Send(message
);
314 int ServiceWorkerScriptContext::GetRoutingID() const {
315 return embedded_context_
->embedded_worker_id();
318 void ServiceWorkerScriptContext::OnActivateEvent(int request_id
) {
319 TRACE_EVENT0("ServiceWorker",
320 "ServiceWorkerScriptContext::OnActivateEvent");
321 activate_start_timings_
[request_id
] = base::TimeTicks::Now();
322 proxy_
->dispatchActivateEvent(request_id
);
325 void ServiceWorkerScriptContext::OnInstallEvent(int request_id
) {
326 TRACE_EVENT0("ServiceWorker",
327 "ServiceWorkerScriptContext::OnInstallEvent");
328 install_start_timings_
[request_id
] = base::TimeTicks::Now();
329 proxy_
->dispatchInstallEvent(request_id
);
332 void ServiceWorkerScriptContext::OnFetchEvent(
334 const ServiceWorkerFetchRequest
& request
) {
335 blink::WebServiceWorkerRequest webRequest
;
336 TRACE_EVENT0("ServiceWorker",
337 "ServiceWorkerScriptContext::OnFetchEvent");
338 webRequest
.setURL(blink::WebURL(request
.url
));
339 webRequest
.setMethod(blink::WebString::fromUTF8(request
.method
));
340 for (ServiceWorkerHeaderMap::const_iterator it
= request
.headers
.begin();
341 it
!= request
.headers
.end();
343 webRequest
.setHeader(blink::WebString::fromUTF8(it
->first
),
344 blink::WebString::fromUTF8(it
->second
));
346 if (!request
.blob_uuid
.empty()) {
347 webRequest
.setBlob(blink::WebString::fromUTF8(request
.blob_uuid
),
350 webRequest
.setReferrer(
351 blink::WebString::fromUTF8(request
.referrer
.url
.spec()),
352 request
.referrer
.policy
);
353 webRequest
.setMode(GetBlinkFetchRequestMode(request
.mode
));
354 webRequest
.setCredentialsMode(
355 GetBlinkFetchCredentialsMode(request
.credentials_mode
));
356 webRequest
.setRequestContext(
357 GetBlinkRequestContext(request
.request_context_type
));
358 webRequest
.setFrameType(GetBlinkFrameType(request
.frame_type
));
359 webRequest
.setIsReload(request
.is_reload
);
360 fetch_start_timings_
[request_id
] = base::TimeTicks::Now();
361 proxy_
->dispatchFetchEvent(request_id
, webRequest
);
364 void ServiceWorkerScriptContext::OnSyncEvent(int request_id
) {
365 TRACE_EVENT0("ServiceWorker",
366 "ServiceWorkerScriptContext::OnSyncEvent");
367 proxy_
->dispatchSyncEvent(request_id
);
370 void ServiceWorkerScriptContext::OnNotificationClickEvent(
372 const std::string
& notification_id
,
373 const PlatformNotificationData
& notification_data
) {
374 TRACE_EVENT0("ServiceWorker",
375 "ServiceWorkerScriptContext::OnNotificationClickEvent");
376 notification_click_start_timings_
[request_id
] = base::TimeTicks::Now();
377 proxy_
->dispatchNotificationClickEvent(
379 blink::WebString::fromUTF8(notification_id
),
380 ToWebNotificationData(notification_data
));
383 void ServiceWorkerScriptContext::OnPushEvent(int request_id
,
384 const std::string
& data
) {
385 TRACE_EVENT0("ServiceWorker",
386 "ServiceWorkerScriptContext::OnPushEvent");
387 push_start_timings_
[request_id
] = base::TimeTicks::Now();
388 proxy_
->dispatchPushEvent(request_id
, blink::WebString::fromUTF8(data
));
391 void ServiceWorkerScriptContext::OnGeofencingEvent(
393 blink::WebGeofencingEventType event_type
,
394 const std::string
& region_id
,
395 const blink::WebCircularGeofencingRegion
& region
) {
396 TRACE_EVENT0("ServiceWorker",
397 "ServiceWorkerScriptContext::OnGeofencingEvent");
398 proxy_
->dispatchGeofencingEvent(
399 request_id
, event_type
, blink::WebString::fromUTF8(region_id
), region
);
400 Send(new ServiceWorkerHostMsg_GeofencingEventFinished(GetRoutingID(),
404 void ServiceWorkerScriptContext::OnCrossOriginConnectEvent(
406 const NavigatorConnectClient
& client
) {
407 TRACE_EVENT0("ServiceWorker",
408 "ServiceWorkerScriptContext::OnCrossOriginConnectEvent");
409 blink::WebCrossOriginServiceWorkerClient web_client
;
410 web_client
.origin
= client
.origin
;
411 web_client
.targetURL
= client
.target_url
;
412 web_client
.clientID
= client
.message_port_id
;
413 proxy_
->dispatchCrossOriginConnectEvent(request_id
, web_client
);
416 void ServiceWorkerScriptContext::OnPostMessage(
417 const base::string16
& message
,
418 const std::vector
<TransferredMessagePort
>& sent_message_ports
,
419 const std::vector
<int>& new_routing_ids
) {
420 TRACE_EVENT0("ServiceWorker",
421 "ServiceWorkerScriptContext::OnPostEvent");
422 blink::WebMessagePortChannelArray ports
=
423 WebMessagePortChannelImpl::CreatePorts(
424 sent_message_ports
, new_routing_ids
,
425 embedded_context_
->main_thread_task_runner());
427 // dispatchMessageEvent is expected to execute onmessage function
429 base::TimeTicks before
= base::TimeTicks::Now();
430 proxy_
->dispatchMessageEvent(message
, ports
);
432 "ServiceWorker.MessageEventExecutionTime",
433 base::TimeTicks::Now() - before
);
436 void ServiceWorkerScriptContext::OnCrossOriginMessageToWorker(
437 const NavigatorConnectClient
& client
,
438 const base::string16
& message
,
439 const std::vector
<TransferredMessagePort
>& sent_message_ports
,
440 const std::vector
<int>& new_routing_ids
) {
441 TRACE_EVENT0("ServiceWorker",
442 "ServiceWorkerScriptContext::OnCrossOriginMessageToWorker");
443 blink::WebMessagePortChannelArray ports
=
444 WebMessagePortChannelImpl::CreatePorts(
445 sent_message_ports
, new_routing_ids
,
446 embedded_context_
->main_thread_task_runner());
448 blink::WebCrossOriginServiceWorkerClient web_client
;
449 web_client
.origin
= client
.origin
;
450 web_client
.targetURL
= client
.target_url
;
451 web_client
.clientID
= client
.message_port_id
;
452 proxy_
->dispatchCrossOriginMessageEvent(web_client
, message
, ports
);
455 void ServiceWorkerScriptContext::OnDidGetClients(
456 int request_id
, const std::vector
<ServiceWorkerClientInfo
>& clients
) {
457 TRACE_EVENT0("ServiceWorker",
458 "ServiceWorkerScriptContext::OnDidGetClients");
459 blink::WebServiceWorkerClientsCallbacks
* callbacks
=
460 pending_clients_callbacks_
.Lookup(request_id
);
462 NOTREACHED() << "Got stray response: " << request_id
;
465 scoped_ptr
<blink::WebServiceWorkerClientsInfo
> info(
466 new blink::WebServiceWorkerClientsInfo
);
467 blink::WebVector
<blink::WebServiceWorkerClientInfo
> convertedClients(
469 for (size_t i
= 0; i
< clients
.size(); ++i
)
470 convertedClients
[i
] = ToWebServiceWorkerClientInfo(clients
[i
]);
471 info
->clients
.swap(convertedClients
);
472 callbacks
->onSuccess(info
.release());
473 pending_clients_callbacks_
.Remove(request_id
);
476 void ServiceWorkerScriptContext::OnOpenWindowResponse(
478 const ServiceWorkerClientInfo
& client
) {
479 TRACE_EVENT0("ServiceWorker",
480 "ServiceWorkerScriptContext::OnOpenWindowResponse");
481 blink::WebServiceWorkerClientCallbacks
* callbacks
=
482 pending_client_callbacks_
.Lookup(request_id
);
484 NOTREACHED() << "Got stray response: " << request_id
;
487 scoped_ptr
<blink::WebServiceWorkerClientInfo
> web_client
;
488 if (!client
.IsEmpty()) {
489 DCHECK(client
.IsValid());
490 web_client
.reset(new blink::WebServiceWorkerClientInfo(
491 ToWebServiceWorkerClientInfo(client
)));
493 callbacks
->onSuccess(web_client
.release());
494 pending_client_callbacks_
.Remove(request_id
);
497 void ServiceWorkerScriptContext::OnOpenWindowError(
499 const std::string
& message
) {
500 TRACE_EVENT0("ServiceWorker",
501 "ServiceWorkerScriptContext::OnOpenWindowError");
502 blink::WebServiceWorkerClientCallbacks
* callbacks
=
503 pending_client_callbacks_
.Lookup(request_id
);
505 NOTREACHED() << "Got stray response: " << request_id
;
508 scoped_ptr
<blink::WebServiceWorkerError
> error(
509 new blink::WebServiceWorkerError(
510 blink::WebServiceWorkerError::ErrorTypeUnknown
,
511 blink::WebString::fromUTF8(message
)));
512 callbacks
->onError(error
.release());
513 pending_client_callbacks_
.Remove(request_id
);
516 void ServiceWorkerScriptContext::OnFocusClientResponse(
517 int request_id
, const ServiceWorkerClientInfo
& client
) {
518 TRACE_EVENT0("ServiceWorker",
519 "ServiceWorkerScriptContext::OnFocusClientResponse");
520 blink::WebServiceWorkerClientCallbacks
* callback
=
521 pending_client_callbacks_
.Lookup(request_id
);
523 NOTREACHED() << "Got stray response: " << request_id
;
526 if (!client
.IsEmpty()) {
527 DCHECK(client
.IsValid());
528 scoped_ptr
<blink::WebServiceWorkerClientInfo
> web_client (
529 new blink::WebServiceWorkerClientInfo(
530 ToWebServiceWorkerClientInfo(client
)));
531 callback
->onSuccess(web_client
.release());
533 scoped_ptr
<blink::WebServiceWorkerError
> error(
534 new blink::WebServiceWorkerError(
535 blink::WebServiceWorkerError::ErrorTypeNotFound
,
536 "The WindowClient was not found."));
537 callback
->onError(error
.release());
540 pending_client_callbacks_
.Remove(request_id
);
543 void ServiceWorkerScriptContext::OnDidSkipWaiting(int request_id
) {
544 TRACE_EVENT0("ServiceWorker",
545 "ServiceWorkerScriptContext::OnDidSkipWaiting");
546 blink::WebServiceWorkerSkipWaitingCallbacks
* callbacks
=
547 pending_skip_waiting_callbacks_
.Lookup(request_id
);
549 NOTREACHED() << "Got stray response: " << request_id
;
552 callbacks
->onSuccess();
553 pending_skip_waiting_callbacks_
.Remove(request_id
);
556 void ServiceWorkerScriptContext::OnDidClaimClients(int request_id
) {
557 TRACE_EVENT0("ServiceWorker",
558 "ServiceWorkerScriptContext::OnDidClaimClients");
559 blink::WebServiceWorkerClientsClaimCallbacks
* callbacks
=
560 pending_claim_clients_callbacks_
.Lookup(request_id
);
562 NOTREACHED() << "Got stray response: " << request_id
;
565 callbacks
->onSuccess();
566 pending_claim_clients_callbacks_
.Remove(request_id
);
569 void ServiceWorkerScriptContext::OnClaimClientsError(
571 blink::WebServiceWorkerError::ErrorType error_type
,
572 const base::string16
& message
) {
573 TRACE_EVENT0("ServiceWorker",
574 "ServiceWorkerScriptContext::OnClaimClientsError");
575 blink::WebServiceWorkerClientsClaimCallbacks
* callbacks
=
576 pending_claim_clients_callbacks_
.Lookup(request_id
);
578 NOTREACHED() << "Got stray response: " << request_id
;
581 scoped_ptr
<blink::WebServiceWorkerError
> error(
582 new blink::WebServiceWorkerError(error_type
, message
));
583 callbacks
->onError(error
.release());
584 pending_claim_clients_callbacks_
.Remove(request_id
);
587 void ServiceWorkerScriptContext::OnPing() {
588 Send(new ServiceWorkerHostMsg_Pong(GetRoutingID()));
591 } // namespace content