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

Side by Side Diff: content/browser/service_worker/service_worker_dispatcher_host.cc

Issue 246023007: Chromium-side plumbing for ServiceWorker -> Document postMessage (2/3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added browser -> document code Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/browser/service_worker/service_worker_dispatcher_host.h" 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "content/browser/message_port_message_filter.h" 9 #include "content/browser/message_port_message_filter.h"
10 #include "content/browser/message_port_service.h" 10 #include "content/browser/message_port_service.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker, 93 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker,
94 OnRegisterServiceWorker) 94 OnRegisterServiceWorker)
95 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker, 95 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker,
96 OnUnregisterServiceWorker) 96 OnUnregisterServiceWorker)
97 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated, 97 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated,
98 OnProviderCreated) 98 OnProviderCreated)
99 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderDestroyed, 99 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderDestroyed,
100 OnProviderDestroyed) 100 OnProviderDestroyed)
101 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetVersionId, 101 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetVersionId,
102 OnSetHostedVersionId) 102 OnSetHostedVersionId)
103 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessage, 103 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToWorker,
104 OnPostMessage) 104 OnPostMessageToWorker)
105 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerStarted, 105 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerStarted,
106 OnWorkerStarted) 106 OnWorkerStarted)
107 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerStopped, 107 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerStopped,
108 OnWorkerStopped) 108 OnWorkerStopped)
109 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_ReportException, 109 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_ReportException,
110 OnReportException) 110 OnReportException)
111 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_ReportConsoleMessage, 111 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_ReportConsoleMessage,
112 OnReportConsoleMessage) 112 OnReportConsoleMessage)
113 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_IncrementServiceWorkerRefCount, 113 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_IncrementServiceWorkerRefCount,
114 OnIncrementServiceWorkerRefCount) 114 OnIncrementServiceWorkerRefCount)
(...skipping 21 matching lines...) Expand all
136 pending_messages_.push_back(message); 136 pending_messages_.push_back(message);
137 return true; 137 return true;
138 } 138 }
139 139
140 void ServiceWorkerDispatcherHost::RegisterServiceWorkerHandle( 140 void ServiceWorkerDispatcherHost::RegisterServiceWorkerHandle(
141 scoped_ptr<ServiceWorkerHandle> handle) { 141 scoped_ptr<ServiceWorkerHandle> handle) {
142 int handle_id = handle->handle_id(); 142 int handle_id = handle->handle_id();
143 handles_.AddWithID(handle.release(), handle_id); 143 handles_.AddWithID(handle.release(), handle_id);
144 } 144 }
145 145
146 void ServiceWorkerDispatcherHost::UpdateMessagePorts(
147 const std::vector<int>& message_port_ids,
148 std::vector<int>* new_routing_ids) {
149 DCHECK(new_routing_ids);
150 new_routing_ids->clear();
151 new_routing_ids->resize(message_port_ids.size());
152
153 for (size_t i = 0; i < message_port_ids.size(); ++i) {
marja 2014/05/06 16:34:30 This looks very similar to what WebContentsImpl::R
kinuko 2014/05/07 05:56:21 Done.
154 (*new_routing_ids)[i] = message_port_message_filter_->GetNextRoutingID();
155 MessagePortService::GetInstance()->UpdateMessagePort(
156 message_port_ids[i],
157 message_port_message_filter_,
158 (*new_routing_ids)[i]);
159 }
160 }
161
146 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( 162 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker(
147 int thread_id, 163 int thread_id,
148 int request_id, 164 int request_id,
149 int provider_id, 165 int provider_id,
150 const GURL& pattern, 166 const GURL& pattern,
151 const GURL& script_url) { 167 const GURL& script_url) {
152 if (!context_ || !ServiceWorkerUtils::IsFeatureEnabled()) { 168 if (!context_ || !ServiceWorkerUtils::IsFeatureEnabled()) {
153 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( 169 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError(
154 thread_id, 170 thread_id,
155 request_id, 171 request_id,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } 229 }
214 230
215 context_->UnregisterServiceWorker( 231 context_->UnregisterServiceWorker(
216 pattern, 232 pattern,
217 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete, 233 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete,
218 this, 234 this,
219 thread_id, 235 thread_id,
220 request_id)); 236 request_id));
221 } 237 }
222 238
223 void ServiceWorkerDispatcherHost::OnPostMessage( 239 void ServiceWorkerDispatcherHost::OnPostMessageToWorker(
224 int handle_id, 240 int handle_id,
225 const base::string16& message, 241 const base::string16& message,
226 const std::vector<int>& sent_message_port_ids) { 242 const std::vector<int>& sent_message_port_ids) {
227 if (!context_ || !ServiceWorkerUtils::IsFeatureEnabled()) 243 if (!context_ || !ServiceWorkerUtils::IsFeatureEnabled())
228 return; 244 return;
229 245
230 std::vector<int> new_routing_ids(sent_message_port_ids.size());
231 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) {
232 new_routing_ids[i] = message_port_message_filter_->GetNextRoutingID();
233 MessagePortService::GetInstance()->UpdateMessagePort(
234 sent_message_port_ids[i],
235 message_port_message_filter_,
236 new_routing_ids[i]);
237 }
238
239 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); 246 ServiceWorkerHandle* handle = handles_.Lookup(handle_id);
240 if (!handle) { 247 if (!handle) {
241 BadMessageReceived(); 248 BadMessageReceived();
242 return; 249 return;
243 } 250 }
244 251
252 std::vector<int> new_routing_ids;
253 UpdateMessagePorts(sent_message_port_ids, &new_routing_ids);
254
245 handle->version()->SendMessage( 255 handle->version()->SendMessage(
246 ServiceWorkerMsg_Message(message, sent_message_port_ids, new_routing_ids), 256 ServiceWorkerMsg_MessageToWorker(message,
257 sent_message_port_ids,
258 new_routing_ids),
247 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 259 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
248 } 260 }
249 261
250 void ServiceWorkerDispatcherHost::OnProviderCreated(int provider_id) { 262 void ServiceWorkerDispatcherHost::OnProviderCreated(int provider_id) {
251 if (!context_) 263 if (!context_)
252 return; 264 return;
253 if (context_->GetProviderHost(render_process_id_, provider_id)) { 265 if (context_->GetProviderHost(render_process_id_, provider_id)) {
254 BadMessageReceived(); 266 BadMessageReceived();
255 return; 267 return;
256 } 268 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 ServiceWorkerStatusCode status) { 402 ServiceWorkerStatusCode status) {
391 base::string16 error_message; 403 base::string16 error_message;
392 blink::WebServiceWorkerError::ErrorType error_type; 404 blink::WebServiceWorkerError::ErrorType error_type;
393 GetServiceWorkerRegistrationStatusResponse( 405 GetServiceWorkerRegistrationStatusResponse(
394 status, &error_type, &error_message); 406 status, &error_type, &error_message);
395 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( 407 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError(
396 thread_id, request_id, error_type, error_message)); 408 thread_id, request_id, error_type, error_message));
397 } 409 }
398 410
399 } // namespace content 411 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698