Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: content/renderer/service_worker/service_worker_script_context.cc

Issue 843583005: [ServiceWorker] Implement WebServiceWorkerContextClient::openWindow(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@content_browser_client_openurl
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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_script_context.h" 5 #include "content/renderer/service_worker/service_worker_script_context.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "content/child/notifications/notification_data_conversions.h" 10 #include "content/child/notifications/notification_data_conversions.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 RequestContextType request_context_type) { 63 RequestContextType request_context_type) {
64 return static_cast<blink::WebURLRequest::RequestContext>( 64 return static_cast<blink::WebURLRequest::RequestContext>(
65 request_context_type); 65 request_context_type);
66 } 66 }
67 67
68 blink::WebURLRequest::FrameType GetBlinkFrameType( 68 blink::WebURLRequest::FrameType GetBlinkFrameType(
69 RequestContextFrameType frame_type) { 69 RequestContextFrameType frame_type) {
70 return static_cast<blink::WebURLRequest::FrameType>(frame_type); 70 return static_cast<blink::WebURLRequest::FrameType>(frame_type);
71 } 71 }
72 72
73 blink::WebServiceWorkerClientInfo ToWebServiceWorkerClientInfo(
74 const ServiceWorkerClientInfo& client) {
75 blink::WebServiceWorkerClientInfo web_client;
76
77 web_client.clientID = client.client_id;
78 web_client.pageVisibilityState = client.page_visibility_state;
79 web_client.isFocused = client.is_focused;
80 web_client.url = client.url;
81 web_client.frameType = GetBlinkFrameType(client.frame_type);
82
83 return web_client;
84 }
85
73 } // namespace 86 } // namespace
74 87
75 ServiceWorkerScriptContext::ServiceWorkerScriptContext( 88 ServiceWorkerScriptContext::ServiceWorkerScriptContext(
76 EmbeddedWorkerContextClient* embedded_context, 89 EmbeddedWorkerContextClient* embedded_context,
77 blink::WebServiceWorkerContextProxy* proxy) 90 blink::WebServiceWorkerContextProxy* proxy)
78 : cache_storage_dispatcher_(new ServiceWorkerCacheStorageDispatcher(this)), 91 : cache_storage_dispatcher_(new ServiceWorkerCacheStorageDispatcher(this)),
79 embedded_context_(embedded_context), 92 embedded_context_(embedded_context),
80 proxy_(proxy) { 93 proxy_(proxy) {
81 } 94 }
82 95
(...skipping 11 matching lines...) Expand all
94 OnNotificationClickEvent) 107 OnNotificationClickEvent)
95 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent, OnPushEvent) 108 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent, OnPushEvent)
96 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GeofencingEvent, OnGeofencingEvent) 109 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GeofencingEvent, OnGeofencingEvent)
97 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginConnectEvent, 110 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginConnectEvent,
98 OnCrossOriginConnectEvent) 111 OnCrossOriginConnectEvent)
99 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage) 112 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage)
100 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker, 113 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker,
101 OnCrossOriginMessageToWorker) 114 OnCrossOriginMessageToWorker)
102 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClientDocuments, 115 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClientDocuments,
103 OnDidGetClientDocuments) 116 OnDidGetClientDocuments)
117 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse,
118 OnOpenWindowResponse)
119 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError,
120 OnOpenWindowError)
104 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, 121 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse,
105 OnFocusClientResponse) 122 OnFocusClientResponse)
106 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting) 123 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting)
107 IPC_MESSAGE_UNHANDLED(handled = false) 124 IPC_MESSAGE_UNHANDLED(handled = false)
108 IPC_END_MESSAGE_MAP() 125 IPC_END_MESSAGE_MAP()
109 126
110 // TODO(gavinp): Would it be preferable to put an AddListener() method to 127 // TODO(gavinp): Would it be preferable to put an AddListener() method to
111 // EmbeddedWorkerContextClient? 128 // EmbeddedWorkerContextClient?
112 if (!handled) 129 if (!handled)
113 handled = cache_storage_dispatcher_->OnMessageReceived(message); 130 handled = cache_storage_dispatcher_->OnMessageReceived(message);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 } 208 }
192 209
193 void ServiceWorkerScriptContext::GetClientDocuments( 210 void ServiceWorkerScriptContext::GetClientDocuments(
194 blink::WebServiceWorkerClientsCallbacks* callbacks) { 211 blink::WebServiceWorkerClientsCallbacks* callbacks) {
195 DCHECK(callbacks); 212 DCHECK(callbacks);
196 int request_id = pending_clients_callbacks_.Add(callbacks); 213 int request_id = pending_clients_callbacks_.Add(callbacks);
197 Send(new ServiceWorkerHostMsg_GetClientDocuments( 214 Send(new ServiceWorkerHostMsg_GetClientDocuments(
198 GetRoutingID(), request_id)); 215 GetRoutingID(), request_id));
199 } 216 }
200 217
218 void ServiceWorkerScriptContext::OpenWindow(
219 const GURL& url,
220 const GURL& referrer,
221 blink::WebServiceWorkerClientCallbacks* callbacks) {
222 DCHECK(callbacks);
223 int request_id = pending_client_callbacks_.Add(callbacks);
224 Send(new ServiceWorkerHostMsg_OpenWindow(
225 GetRoutingID(), request_id, url, referrer));
226 }
227
201 void ServiceWorkerScriptContext::PostMessageToDocument( 228 void ServiceWorkerScriptContext::PostMessageToDocument(
202 int client_id, 229 int client_id,
203 const base::string16& message, 230 const base::string16& message,
204 scoped_ptr<blink::WebMessagePortChannelArray> channels) { 231 scoped_ptr<blink::WebMessagePortChannelArray> channels) {
205 // This may send channels for MessagePorts, and all internal book-keeping 232 // This may send channels for MessagePorts, and all internal book-keeping
206 // messages for MessagePort (e.g. QueueMessages) are sent from main thread 233 // messages for MessagePort (e.g. QueueMessages) are sent from main thread
207 // (with thread hopping), so we need to do the same thread hopping here not 234 // (with thread hopping), so we need to do the same thread hopping here not
208 // to overtake those messages. 235 // to overtake those messages.
209 embedded_context_->main_thread_proxy()->PostTask( 236 embedded_context_->main_thread_proxy()->PostTask(
210 FROM_HERE, 237 FROM_HERE,
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 blink::WebServiceWorkerClientsCallbacks* callbacks = 432 blink::WebServiceWorkerClientsCallbacks* callbacks =
406 pending_clients_callbacks_.Lookup(request_id); 433 pending_clients_callbacks_.Lookup(request_id);
407 if (!callbacks) { 434 if (!callbacks) {
408 NOTREACHED() << "Got stray response: " << request_id; 435 NOTREACHED() << "Got stray response: " << request_id;
409 return; 436 return;
410 } 437 }
411 scoped_ptr<blink::WebServiceWorkerClientsInfo> info( 438 scoped_ptr<blink::WebServiceWorkerClientsInfo> info(
412 new blink::WebServiceWorkerClientsInfo); 439 new blink::WebServiceWorkerClientsInfo);
413 blink::WebVector<blink::WebServiceWorkerClientInfo> convertedClients( 440 blink::WebVector<blink::WebServiceWorkerClientInfo> convertedClients(
414 clients.size()); 441 clients.size());
415 for (size_t i = 0; i < clients.size(); ++i) { 442 for (size_t i = 0; i < clients.size(); ++i)
416 convertedClients[i].clientID = clients[i].client_id; 443 convertedClients[i] = ToWebServiceWorkerClientInfo(clients[i]);
417 convertedClients[i].pageVisibilityState = clients[i].page_visibility_state;
418 convertedClients[i].isFocused = clients[i].is_focused;
419 convertedClients[i].url = clients[i].url;
420 convertedClients[i].frameType =
421 static_cast<blink::WebURLRequest::FrameType>(clients[i].frame_type);
422 }
423 info->clients.swap(convertedClients); 444 info->clients.swap(convertedClients);
424 callbacks->onSuccess(info.release()); 445 callbacks->onSuccess(info.release());
425 pending_clients_callbacks_.Remove(request_id); 446 pending_clients_callbacks_.Remove(request_id);
426 } 447 }
427 448
449 void ServiceWorkerScriptContext::OnOpenWindowResponse(
450 int request_id, const ServiceWorkerClientInfo& client, bool dummy_client) {
nasko 2015/01/17 00:05:28 nit: if params don't fit on the line of the method
mlamouri (slow - plz ping) 2015/01/26 13:19:08 Done.
451 TRACE_EVENT0("ServiceWorker",
452 "ServiceWorkerScriptContext::OnOpenWindowResponse");
453 blink::WebServiceWorkerClientCallbacks* callbacks =
454 pending_client_callbacks_.Lookup(request_id);
455 if (!callbacks) {
456 NOTREACHED() << "Got stray response: " << request_id;
457 return;
458 }
459 scoped_ptr<blink::WebServiceWorkerClientInfo> web_client(
460 new blink::WebServiceWorkerClientInfo(
461 ToWebServiceWorkerClientInfo(client)));
462 callbacks->onSuccess(dummy_client ? nullptr : web_client.release());
463 pending_client_callbacks_.Remove(request_id);
464 }
465
466 void ServiceWorkerScriptContext::OnOpenWindowError(int request_id) {
467 TRACE_EVENT0("ServiceWorker",
468 "ServiceWorkerScriptContext::OnOpenWindowError");
469 blink::WebServiceWorkerClientCallbacks* callbacks =
470 pending_client_callbacks_.Lookup(request_id);
471 if (!callbacks) {
472 NOTREACHED() << "Got stray response: " << request_id;
473 return;
474 }
475 scoped_ptr<blink::WebServiceWorkerError> error(
476 new blink::WebServiceWorkerError(
477 blink::WebServiceWorkerError::ErrorTypeUnknown,
478 "Something went wrong while trying to open the window."));
479 callbacks->onError(error.release());
480 pending_client_callbacks_.Remove(request_id);
481 }
482
428 void ServiceWorkerScriptContext::OnFocusClientResponse(int request_id, 483 void ServiceWorkerScriptContext::OnFocusClientResponse(int request_id,
429 bool result) { 484 bool result) {
430 TRACE_EVENT0("ServiceWorker", 485 TRACE_EVENT0("ServiceWorker",
431 "ServiceWorkerScriptContext::OnFocusClientResponse"); 486 "ServiceWorkerScriptContext::OnFocusClientResponse");
432 blink::WebServiceWorkerClientFocusCallback* callback = 487 blink::WebServiceWorkerClientFocusCallback* callback =
433 pending_focus_client_callbacks_.Lookup(request_id); 488 pending_focus_client_callbacks_.Lookup(request_id);
434 if (!callback) { 489 if (!callback) {
435 NOTREACHED() << "Got stray response: " << request_id; 490 NOTREACHED() << "Got stray response: " << request_id;
436 return; 491 return;
437 } 492 }
438 callback->onSuccess(&result); 493 callback->onSuccess(&result);
439 pending_focus_client_callbacks_.Remove(request_id); 494 pending_focus_client_callbacks_.Remove(request_id);
440 } 495 }
441 496
442 void ServiceWorkerScriptContext::OnDidSkipWaiting(int request_id) { 497 void ServiceWorkerScriptContext::OnDidSkipWaiting(int request_id) {
443 TRACE_EVENT0("ServiceWorker", 498 TRACE_EVENT0("ServiceWorker",
444 "ServiceWorkerScriptContext::OnDidSkipWaiting"); 499 "ServiceWorkerScriptContext::OnDidSkipWaiting");
445 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks = 500 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks =
446 pending_skip_waiting_callbacks_.Lookup(request_id); 501 pending_skip_waiting_callbacks_.Lookup(request_id);
447 if (!callbacks) { 502 if (!callbacks) {
448 NOTREACHED() << "Got stray response: " << request_id; 503 NOTREACHED() << "Got stray response: " << request_id;
449 return; 504 return;
450 } 505 }
451 callbacks->onSuccess(); 506 callbacks->onSuccess();
452 pending_skip_waiting_callbacks_.Remove(request_id); 507 pending_skip_waiting_callbacks_.Remove(request_id);
453 } 508 }
454 509
455 } // namespace content 510 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698