ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / content / renderer / service_worker / service_worker_script_context.cc
blob14661847051a74b91dcb8f6c4c6e3ae4b4e6ccb1
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"
28 namespace content {
30 namespace {
32 void SendPostMessageToDocumentOnMainThread(
33 ThreadSafeSender* sender,
34 int routing_id,
35 int client_id,
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,
45 int message_port_id,
46 const base::string16& message,
47 scoped_ptr<blink::WebMessagePortChannelArray> channels) {
48 sender->Send(new MessagePortHostMsg_PostMessage(
49 message_port_id,
50 MessagePortMessage(message),
51 WebMessagePortChannelImpl::ExtractMessagePortIDs(
52 channels.release())));
55 blink::WebURLRequest::FetchRequestMode GetBlinkFetchRequestMode(
56 FetchRequestMode mode) {
57 return static_cast<blink::WebURLRequest::FetchRequestMode>(mode);
60 blink::WebURLRequest::FetchCredentialsMode GetBlinkFetchCredentialsMode(
61 FetchCredentialsMode credentials_mode) {
62 return static_cast<blink::WebURLRequest::FetchCredentialsMode>(
63 credentials_mode);
66 blink::WebURLRequest::RequestContext GetBlinkRequestContext(
67 RequestContextType request_context_type) {
68 return static_cast<blink::WebURLRequest::RequestContext>(
69 request_context_type);
72 blink::WebURLRequest::FrameType GetBlinkFrameType(
73 RequestContextFrameType frame_type) {
74 return static_cast<blink::WebURLRequest::FrameType>(frame_type);
77 blink::WebServiceWorkerClientInfo
78 ToWebServiceWorkerClientInfo(const ServiceWorkerClientInfo& client_info) {
79 DCHECK(client_info.IsValid());
81 blink::WebServiceWorkerClientInfo web_client_info;
83 web_client_info.clientID = client_info.client_id;
84 web_client_info.pageVisibilityState = client_info.page_visibility_state;
85 web_client_info.isFocused = client_info.is_focused;
86 web_client_info.url = client_info.url;
87 web_client_info.frameType = GetBlinkFrameType(client_info.frame_type);
89 return web_client_info;
92 } // namespace
94 ServiceWorkerScriptContext::ServiceWorkerScriptContext(
95 EmbeddedWorkerContextClient* embedded_context,
96 blink::WebServiceWorkerContextProxy* proxy)
97 : cache_storage_dispatcher_(new ServiceWorkerCacheStorageDispatcher(this)),
98 embedded_context_(embedded_context),
99 proxy_(proxy) {
102 ServiceWorkerScriptContext::~ServiceWorkerScriptContext() {}
104 void ServiceWorkerScriptContext::OnMessageReceived(
105 const IPC::Message& message) {
106 bool handled = true;
107 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerScriptContext, message)
108 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent, OnActivateEvent)
109 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FetchEvent, OnFetchEvent)
110 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent)
111 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SyncEvent, OnSyncEvent)
112 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationClickEvent,
113 OnNotificationClickEvent)
114 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent, OnPushEvent)
115 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GeofencingEvent, OnGeofencingEvent)
116 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginConnectEvent,
117 OnCrossOriginConnectEvent)
118 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage)
119 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker,
120 OnCrossOriginMessageToWorker)
121 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClientDocuments,
122 OnDidGetClientDocuments)
123 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse,
124 OnOpenWindowResponse)
125 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError,
126 OnOpenWindowError)
127 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse,
128 OnFocusClientResponse)
129 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting)
130 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidClaimClients, OnDidClaimClients)
131 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ClaimClientsError, OnClaimClientsError)
132 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Ping, OnPing);
133 IPC_MESSAGE_UNHANDLED(handled = false)
134 IPC_END_MESSAGE_MAP()
136 // TODO(gavinp): Would it be preferable to put an AddListener() method to
137 // EmbeddedWorkerContextClient?
138 if (!handled)
139 handled = cache_storage_dispatcher_->OnMessageReceived(message);
141 DCHECK(handled);
144 void ServiceWorkerScriptContext::SetRegistrationInServiceWorkerGlobalScope(
145 scoped_ptr<WebServiceWorkerRegistrationImpl> registration) {
146 proxy_->setRegistration(registration.release());
149 void ServiceWorkerScriptContext::DidHandleActivateEvent(
150 int request_id,
151 blink::WebServiceWorkerEventResult result) {
152 UMA_HISTOGRAM_TIMES(
153 "ServiceWorker.ActivateEventExecutionTime",
154 base::TimeTicks::Now() - activate_start_timings_[request_id]);
155 activate_start_timings_.erase(request_id);
157 Send(new ServiceWorkerHostMsg_ActivateEventFinished(
158 GetRoutingID(), request_id, result));
161 void ServiceWorkerScriptContext::DidHandleInstallEvent(
162 int request_id,
163 blink::WebServiceWorkerEventResult result) {
164 UMA_HISTOGRAM_TIMES(
165 "ServiceWorker.InstallEventExecutionTime",
166 base::TimeTicks::Now() - install_start_timings_[request_id]);
167 install_start_timings_.erase(request_id);
169 Send(new ServiceWorkerHostMsg_InstallEventFinished(
170 GetRoutingID(), request_id, result));
173 void ServiceWorkerScriptContext::DidHandleFetchEvent(
174 int request_id,
175 ServiceWorkerFetchEventResult result,
176 const ServiceWorkerResponse& response) {
177 UMA_HISTOGRAM_TIMES(
178 "ServiceWorker.FetchEventExecutionTime",
179 base::TimeTicks::Now() - fetch_start_timings_[request_id]);
180 fetch_start_timings_.erase(request_id);
182 Send(new ServiceWorkerHostMsg_FetchEventFinished(
183 GetRoutingID(), request_id, result, response));
186 void ServiceWorkerScriptContext::DidHandleNotificationClickEvent(
187 int request_id,
188 blink::WebServiceWorkerEventResult result) {
189 UMA_HISTOGRAM_TIMES(
190 "ServiceWorker.NotificationClickEventExecutionTime",
191 base::TimeTicks::Now() - notification_click_start_timings_[request_id]);
192 notification_click_start_timings_.erase(request_id);
194 Send(new ServiceWorkerHostMsg_NotificationClickEventFinished(
195 GetRoutingID(), request_id));
198 void ServiceWorkerScriptContext::DidHandlePushEvent(
199 int request_id,
200 blink::WebServiceWorkerEventResult result) {
201 if (result == blink::WebServiceWorkerEventResultCompleted) {
202 UMA_HISTOGRAM_TIMES(
203 "ServiceWorker.PushEventExecutionTime",
204 base::TimeTicks::Now() - push_start_timings_[request_id]);
206 push_start_timings_.erase(request_id);
208 Send(new ServiceWorkerHostMsg_PushEventFinished(
209 GetRoutingID(), request_id, result));
212 void ServiceWorkerScriptContext::DidHandleSyncEvent(int request_id) {
213 Send(new ServiceWorkerHostMsg_SyncEventFinished(
214 GetRoutingID(), request_id));
217 void ServiceWorkerScriptContext::DidHandleCrossOriginConnectEvent(
218 int request_id,
219 bool accept_connection) {
220 Send(new ServiceWorkerHostMsg_CrossOriginConnectEventFinished(
221 GetRoutingID(), request_id, accept_connection));
224 void ServiceWorkerScriptContext::GetClientDocuments(
225 blink::WebServiceWorkerClientsCallbacks* callbacks) {
226 DCHECK(callbacks);
227 int request_id = pending_clients_callbacks_.Add(callbacks);
228 Send(new ServiceWorkerHostMsg_GetClientDocuments(
229 GetRoutingID(), request_id));
232 void ServiceWorkerScriptContext::OpenWindow(
233 const GURL& url, blink::WebServiceWorkerClientCallbacks* callbacks) {
234 DCHECK(callbacks);
235 int request_id = pending_client_callbacks_.Add(callbacks);
236 Send(new ServiceWorkerHostMsg_OpenWindow(GetRoutingID(), request_id, url));
239 void ServiceWorkerScriptContext::SetCachedMetadata(const GURL& url,
240 const char* data,
241 size_t size) {
242 std::vector<char> copy(data, data + size);
243 Send(new ServiceWorkerHostMsg_SetCachedMetadata(GetRoutingID(), url, copy));
246 void ServiceWorkerScriptContext::ClearCachedMetadata(const GURL& url) {
247 Send(new ServiceWorkerHostMsg_ClearCachedMetadata(GetRoutingID(), url));
250 void ServiceWorkerScriptContext::PostMessageToDocument(
251 int client_id,
252 const base::string16& message,
253 scoped_ptr<blink::WebMessagePortChannelArray> channels) {
254 // This may send channels for MessagePorts, and all internal book-keeping
255 // messages for MessagePort (e.g. QueueMessages) are sent from main thread
256 // (with thread hopping), so we need to do the same thread hopping here not
257 // to overtake those messages.
258 embedded_context_->main_thread_task_runner()->PostTask(
259 FROM_HERE,
260 base::Bind(&SendPostMessageToDocumentOnMainThread,
261 make_scoped_refptr(embedded_context_->thread_safe_sender()),
262 GetRoutingID(), client_id, message, base::Passed(&channels)));
265 void ServiceWorkerScriptContext::PostCrossOriginMessageToClient(
266 const blink::WebCrossOriginServiceWorkerClient& client,
267 const base::string16& message,
268 scoped_ptr<blink::WebMessagePortChannelArray> channels) {
269 // This may send channels for MessagePorts, and all internal book-keeping
270 // messages for MessagePort (e.g. QueueMessages) are sent from main thread
271 // (with thread hopping), so we need to do the same thread hopping here not
272 // to overtake those messages.
273 embedded_context_->main_thread_task_runner()->PostTask(
274 FROM_HERE,
275 base::Bind(&SendCrossOriginMessageToClientOnMainThread,
276 make_scoped_refptr(embedded_context_->thread_safe_sender()),
277 client.clientID, message, base::Passed(&channels)));
280 void ServiceWorkerScriptContext::FocusClient(
281 int client_id, blink::WebServiceWorkerClientCallbacks* callback) {
282 DCHECK(callback);
283 int request_id = pending_client_callbacks_.Add(callback);
284 Send(new ServiceWorkerHostMsg_FocusClient(
285 GetRoutingID(), request_id, client_id));
288 void ServiceWorkerScriptContext::ClaimClients(
289 blink::WebServiceWorkerClientsClaimCallbacks* callbacks) {
290 DCHECK(callbacks);
291 int request_id = pending_claim_clients_callbacks_.Add(callbacks);
292 Send(new ServiceWorkerHostMsg_ClaimClients(GetRoutingID(), request_id));
295 void ServiceWorkerScriptContext::SkipWaiting(
296 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) {
297 DCHECK(callbacks);
298 int request_id = pending_skip_waiting_callbacks_.Add(callbacks);
299 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id));
302 void ServiceWorkerScriptContext::Send(IPC::Message* message) {
303 embedded_context_->Send(message);
306 int ServiceWorkerScriptContext::GetRoutingID() const {
307 return embedded_context_->embedded_worker_id();
310 void ServiceWorkerScriptContext::OnActivateEvent(int request_id) {
311 TRACE_EVENT0("ServiceWorker",
312 "ServiceWorkerScriptContext::OnActivateEvent");
313 activate_start_timings_[request_id] = base::TimeTicks::Now();
314 proxy_->dispatchActivateEvent(request_id);
317 void ServiceWorkerScriptContext::OnInstallEvent(int request_id,
318 int active_version_id) {
319 TRACE_EVENT0("ServiceWorker",
320 "ServiceWorkerScriptContext::OnInstallEvent");
321 install_start_timings_[request_id] = base::TimeTicks::Now();
322 proxy_->dispatchInstallEvent(request_id);
325 void ServiceWorkerScriptContext::OnFetchEvent(
326 int request_id,
327 const ServiceWorkerFetchRequest& request) {
328 blink::WebServiceWorkerRequest webRequest;
329 TRACE_EVENT0("ServiceWorker",
330 "ServiceWorkerScriptContext::OnFetchEvent");
331 webRequest.setURL(blink::WebURL(request.url));
332 webRequest.setMethod(blink::WebString::fromUTF8(request.method));
333 for (ServiceWorkerHeaderMap::const_iterator it = request.headers.begin();
334 it != request.headers.end();
335 ++it) {
336 webRequest.setHeader(blink::WebString::fromUTF8(it->first),
337 blink::WebString::fromUTF8(it->second));
339 if (!request.blob_uuid.empty()) {
340 webRequest.setBlob(blink::WebString::fromUTF8(request.blob_uuid),
341 request.blob_size);
343 webRequest.setReferrer(
344 blink::WebString::fromUTF8(request.referrer.url.spec()),
345 request.referrer.policy);
346 webRequest.setMode(GetBlinkFetchRequestMode(request.mode));
347 webRequest.setCredentialsMode(
348 GetBlinkFetchCredentialsMode(request.credentials_mode));
349 webRequest.setRequestContext(
350 GetBlinkRequestContext(request.request_context_type));
351 webRequest.setFrameType(GetBlinkFrameType(request.frame_type));
352 webRequest.setIsReload(request.is_reload);
353 fetch_start_timings_[request_id] = base::TimeTicks::Now();
354 proxy_->dispatchFetchEvent(request_id, webRequest);
357 void ServiceWorkerScriptContext::OnSyncEvent(int request_id) {
358 TRACE_EVENT0("ServiceWorker",
359 "ServiceWorkerScriptContext::OnSyncEvent");
360 proxy_->dispatchSyncEvent(request_id);
363 void ServiceWorkerScriptContext::OnNotificationClickEvent(
364 int request_id,
365 const std::string& notification_id,
366 const PlatformNotificationData& notification_data) {
367 TRACE_EVENT0("ServiceWorker",
368 "ServiceWorkerScriptContext::OnNotificationClickEvent");
369 notification_click_start_timings_[request_id] = base::TimeTicks::Now();
370 proxy_->dispatchNotificationClickEvent(
371 request_id,
372 blink::WebString::fromUTF8(notification_id),
373 ToWebNotificationData(notification_data));
376 void ServiceWorkerScriptContext::OnPushEvent(int request_id,
377 const std::string& data) {
378 TRACE_EVENT0("ServiceWorker",
379 "ServiceWorkerScriptContext::OnPushEvent");
380 push_start_timings_[request_id] = base::TimeTicks::Now();
381 proxy_->dispatchPushEvent(request_id, blink::WebString::fromUTF8(data));
384 void ServiceWorkerScriptContext::OnGeofencingEvent(
385 int request_id,
386 blink::WebGeofencingEventType event_type,
387 const std::string& region_id,
388 const blink::WebCircularGeofencingRegion& region) {
389 TRACE_EVENT0("ServiceWorker",
390 "ServiceWorkerScriptContext::OnGeofencingEvent");
391 proxy_->dispatchGeofencingEvent(
392 request_id, event_type, blink::WebString::fromUTF8(region_id), region);
393 Send(new ServiceWorkerHostMsg_GeofencingEventFinished(GetRoutingID(),
394 request_id));
397 void ServiceWorkerScriptContext::OnCrossOriginConnectEvent(
398 int request_id,
399 const NavigatorConnectClient& client) {
400 TRACE_EVENT0("ServiceWorker",
401 "ServiceWorkerScriptContext::OnCrossOriginConnectEvent");
402 blink::WebCrossOriginServiceWorkerClient web_client;
403 web_client.origin = client.origin;
404 web_client.targetURL = client.target_url;
405 web_client.clientID = client.message_port_id;
406 proxy_->dispatchCrossOriginConnectEvent(request_id, web_client);
409 void ServiceWorkerScriptContext::OnPostMessage(
410 const base::string16& message,
411 const std::vector<TransferredMessagePort>& sent_message_ports,
412 const std::vector<int>& new_routing_ids) {
413 TRACE_EVENT0("ServiceWorker",
414 "ServiceWorkerScriptContext::OnPostEvent");
415 blink::WebMessagePortChannelArray ports =
416 WebMessagePortChannelImpl::CreatePorts(
417 sent_message_ports, new_routing_ids,
418 embedded_context_->main_thread_task_runner());
420 // dispatchMessageEvent is expected to execute onmessage function
421 // synchronously.
422 base::TimeTicks before = base::TimeTicks::Now();
423 proxy_->dispatchMessageEvent(message, ports);
424 UMA_HISTOGRAM_TIMES(
425 "ServiceWorker.MessageEventExecutionTime",
426 base::TimeTicks::Now() - before);
429 void ServiceWorkerScriptContext::OnCrossOriginMessageToWorker(
430 const NavigatorConnectClient& client,
431 const base::string16& message,
432 const std::vector<TransferredMessagePort>& sent_message_ports,
433 const std::vector<int>& new_routing_ids) {
434 TRACE_EVENT0("ServiceWorker",
435 "ServiceWorkerScriptContext::OnCrossOriginMessageToWorker");
436 blink::WebMessagePortChannelArray ports =
437 WebMessagePortChannelImpl::CreatePorts(
438 sent_message_ports, new_routing_ids,
439 embedded_context_->main_thread_task_runner());
441 blink::WebCrossOriginServiceWorkerClient web_client;
442 web_client.origin = client.origin;
443 web_client.targetURL = client.target_url;
444 web_client.clientID = client.message_port_id;
445 proxy_->dispatchCrossOriginMessageEvent(web_client, message, ports);
448 void ServiceWorkerScriptContext::OnDidGetClientDocuments(
449 int request_id, const std::vector<ServiceWorkerClientInfo>& clients) {
450 TRACE_EVENT0("ServiceWorker",
451 "ServiceWorkerScriptContext::OnDidGetClientDocuments");
452 blink::WebServiceWorkerClientsCallbacks* callbacks =
453 pending_clients_callbacks_.Lookup(request_id);
454 if (!callbacks) {
455 NOTREACHED() << "Got stray response: " << request_id;
456 return;
458 scoped_ptr<blink::WebServiceWorkerClientsInfo> info(
459 new blink::WebServiceWorkerClientsInfo);
460 blink::WebVector<blink::WebServiceWorkerClientInfo> convertedClients(
461 clients.size());
462 for (size_t i = 0; i < clients.size(); ++i)
463 convertedClients[i] = ToWebServiceWorkerClientInfo(clients[i]);
464 info->clients.swap(convertedClients);
465 callbacks->onSuccess(info.release());
466 pending_clients_callbacks_.Remove(request_id);
469 void ServiceWorkerScriptContext::OnOpenWindowResponse(
470 int request_id,
471 const ServiceWorkerClientInfo& client) {
472 TRACE_EVENT0("ServiceWorker",
473 "ServiceWorkerScriptContext::OnOpenWindowResponse");
474 blink::WebServiceWorkerClientCallbacks* callbacks =
475 pending_client_callbacks_.Lookup(request_id);
476 if (!callbacks) {
477 NOTREACHED() << "Got stray response: " << request_id;
478 return;
480 scoped_ptr<blink::WebServiceWorkerClientInfo> web_client;
481 if (!client.IsEmpty()) {
482 DCHECK(client.IsValid());
483 web_client.reset(new blink::WebServiceWorkerClientInfo(
484 ToWebServiceWorkerClientInfo(client)));
486 callbacks->onSuccess(web_client.release());
487 pending_client_callbacks_.Remove(request_id);
490 void ServiceWorkerScriptContext::OnOpenWindowError(int request_id) {
491 TRACE_EVENT0("ServiceWorker",
492 "ServiceWorkerScriptContext::OnOpenWindowError");
493 blink::WebServiceWorkerClientCallbacks* callbacks =
494 pending_client_callbacks_.Lookup(request_id);
495 if (!callbacks) {
496 NOTREACHED() << "Got stray response: " << request_id;
497 return;
499 scoped_ptr<blink::WebServiceWorkerError> error(
500 new blink::WebServiceWorkerError(
501 blink::WebServiceWorkerError::ErrorTypeUnknown,
502 "Something went wrong while trying to open the window."));
503 callbacks->onError(error.release());
504 pending_client_callbacks_.Remove(request_id);
507 void ServiceWorkerScriptContext::OnFocusClientResponse(
508 int request_id, const ServiceWorkerClientInfo& client) {
509 TRACE_EVENT0("ServiceWorker",
510 "ServiceWorkerScriptContext::OnFocusClientResponse");
511 blink::WebServiceWorkerClientCallbacks* callback =
512 pending_client_callbacks_.Lookup(request_id);
513 if (!callback) {
514 NOTREACHED() << "Got stray response: " << request_id;
515 return;
517 if (!client.IsEmpty()) {
518 DCHECK(client.IsValid());
519 scoped_ptr<blink::WebServiceWorkerClientInfo> web_client (
520 new blink::WebServiceWorkerClientInfo(
521 ToWebServiceWorkerClientInfo(client)));
522 callback->onSuccess(web_client.release());
523 } else {
524 scoped_ptr<blink::WebServiceWorkerError> error(
525 new blink::WebServiceWorkerError(
526 blink::WebServiceWorkerError::ErrorTypeNotFound,
527 "The WindowClient was not found."));
528 callback->onError(error.release());
531 pending_client_callbacks_.Remove(request_id);
534 void ServiceWorkerScriptContext::OnDidSkipWaiting(int request_id) {
535 TRACE_EVENT0("ServiceWorker",
536 "ServiceWorkerScriptContext::OnDidSkipWaiting");
537 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks =
538 pending_skip_waiting_callbacks_.Lookup(request_id);
539 if (!callbacks) {
540 NOTREACHED() << "Got stray response: " << request_id;
541 return;
543 callbacks->onSuccess();
544 pending_skip_waiting_callbacks_.Remove(request_id);
547 void ServiceWorkerScriptContext::OnDidClaimClients(int request_id) {
548 TRACE_EVENT0("ServiceWorker",
549 "ServiceWorkerScriptContext::OnDidClaimClients");
550 blink::WebServiceWorkerClientsClaimCallbacks* callbacks =
551 pending_claim_clients_callbacks_.Lookup(request_id);
552 if (!callbacks) {
553 NOTREACHED() << "Got stray response: " << request_id;
554 return;
556 callbacks->onSuccess();
557 pending_claim_clients_callbacks_.Remove(request_id);
560 void ServiceWorkerScriptContext::OnClaimClientsError(
561 int request_id,
562 blink::WebServiceWorkerError::ErrorType error_type,
563 const base::string16& message) {
564 TRACE_EVENT0("ServiceWorker",
565 "ServiceWorkerScriptContext::OnClaimClientsError");
566 blink::WebServiceWorkerClientsClaimCallbacks* callbacks =
567 pending_claim_clients_callbacks_.Lookup(request_id);
568 if (!callbacks) {
569 NOTREACHED() << "Got stray response: " << request_id;
570 return;
572 scoped_ptr<blink::WebServiceWorkerError> error(
573 new blink::WebServiceWorkerError(error_type, message));
574 callbacks->onError(error.release());
575 pending_claim_clients_callbacks_.Remove(request_id);
578 void ServiceWorkerScriptContext::OnPing() {
579 Send(new ServiceWorkerHostMsg_Pong(GetRoutingID()));
582 } // namespace content