Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/browser/message_port_message_filter.h" | |
| 9 #include "content/browser/message_port_service.h" | |
| 8 #include "content/browser/service_worker/embedded_worker_registry.h" | 10 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 9 #include "content/browser/service_worker/service_worker_context_core.h" | 11 #include "content/browser/service_worker/service_worker_context_core.h" |
| 10 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 12 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 11 #include "content/browser/service_worker/service_worker_provider_host.h" | 13 #include "content/browser/service_worker/service_worker_registration.h" |
| 12 #include "content/common/service_worker/embedded_worker_messages.h" | 14 #include "content/common/service_worker/embedded_worker_messages.h" |
| 13 #include "content/common/service_worker/service_worker_messages.h" | 15 #include "content/common/service_worker/service_worker_messages.h" |
| 14 #include "ipc/ipc_message_macros.h" | 16 #include "ipc/ipc_message_macros.h" |
| 15 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h" | 17 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h" |
| 16 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 17 | 19 |
| 18 using blink::WebServiceWorkerError; | 20 using blink::WebServiceWorkerError; |
| 19 | 21 |
| 20 namespace { | 22 namespace { |
| 21 | 23 |
| 22 const char kDisabledErrorMessage[] = | 24 const char kDisabledErrorMessage[] = |
| 23 "ServiceWorker is disabled"; | 25 "ServiceWorker is disabled"; |
| 24 const char kDomainMismatchErrorMessage[] = | 26 const char kDomainMismatchErrorMessage[] = |
| 25 "Scope and scripts do not have the same origin"; | 27 "Scope and scripts do not have the same origin"; |
| 26 | 28 |
| 27 const uint32 kFilteredMessageClasses[] = { | 29 const uint32 kFilteredMessageClasses[] = { |
| 28 ServiceWorkerMsgStart, | 30 ServiceWorkerMsgStart, |
| 29 EmbeddedWorkerMsgStart, | 31 EmbeddedWorkerMsgStart, |
| 30 }; | 32 }; |
| 31 | 33 |
| 32 } // namespace | 34 } // namespace |
| 33 | 35 |
| 34 namespace content { | 36 namespace content { |
| 35 | 37 |
| 36 ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( | 38 ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( |
| 37 int render_process_id) | 39 int render_process_id, |
| 38 : BrowserMessageFilter( | 40 MessagePortMessageFilter* message_port_message_filter) |
| 39 kFilteredMessageClasses, arraysize(kFilteredMessageClasses)), | 41 : BrowserMessageFilter(kFilteredMessageClasses, |
| 40 render_process_id_(render_process_id) { | 42 arraysize(kFilteredMessageClasses)), |
| 43 render_process_id_(render_process_id), | |
| 44 message_port_message_filter_(message_port_message_filter) { | |
| 41 } | 45 } |
| 42 | 46 |
| 43 ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() { | 47 ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() { |
| 44 if (context_) { | 48 if (context_) { |
| 45 context_->RemoveAllProviderHostsForProcess(render_process_id_); | 49 context_->RemoveAllProviderHostsForProcess(render_process_id_); |
| 46 context_->embedded_worker_registry()->RemoveChildProcessSender( | 50 context_->embedded_worker_registry()->RemoveChildProcessSender( |
| 47 render_process_id_); | 51 render_process_id_); |
| 48 } | 52 } |
| 49 } | 53 } |
| 50 | 54 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 77 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker, | 81 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker, |
| 78 OnUnregisterServiceWorker) | 82 OnUnregisterServiceWorker) |
| 79 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated, | 83 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated, |
| 80 OnProviderCreated) | 84 OnProviderCreated) |
| 81 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderDestroyed, | 85 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderDestroyed, |
| 82 OnProviderDestroyed) | 86 OnProviderDestroyed) |
| 83 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_AddScriptClient, | 87 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_AddScriptClient, |
| 84 OnAddScriptClient) | 88 OnAddScriptClient) |
| 85 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RemoveScriptClient, | 89 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RemoveScriptClient, |
| 86 OnRemoveScriptClient) | 90 OnRemoveScriptClient) |
| 91 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessage, | |
| 92 OnPostMessage) | |
| 87 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerStarted, | 93 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerStarted, |
| 88 OnWorkerStarted) | 94 OnWorkerStarted) |
| 89 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerStopped, | 95 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerStopped, |
| 90 OnWorkerStopped) | 96 OnWorkerStopped) |
| 91 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_SendMessageToBrowser, | 97 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_SendMessageToBrowser, |
| 92 OnSendMessageToBrowser) | 98 OnSendMessageToBrowser) |
| 93 IPC_MESSAGE_UNHANDLED(handled = false) | 99 IPC_MESSAGE_UNHANDLED(handled = false) |
| 94 IPC_END_MESSAGE_MAP() | 100 IPC_END_MESSAGE_MAP() |
| 95 | 101 |
| 96 return handled; | 102 return handled; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 | 156 |
| 151 context_->UnregisterServiceWorker( | 157 context_->UnregisterServiceWorker( |
| 152 pattern, | 158 pattern, |
| 153 render_process_id_, | 159 render_process_id_, |
| 154 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete, | 160 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete, |
| 155 this, | 161 this, |
| 156 thread_id, | 162 thread_id, |
| 157 request_id)); | 163 request_id)); |
| 158 } | 164 } |
| 159 | 165 |
| 166 void ServiceWorkerDispatcherHost::OnPostMessage( | |
| 167 int64 registration_id, | |
| 168 base::string16 message, | |
|
michaeln
2014/03/11 23:17:34
const ref here
jsbell
2014/03/12 18:16:16
Done.
| |
| 169 std::vector<int> sent_message_port_ids) { | |
|
michaeln
2014/03/11 23:17:34
ditto here and in the next method sig too
jsbell
2014/03/12 18:16:16
Done.
| |
| 170 if (!context_ || !context_->IsEnabled()) | |
| 171 return; | |
| 172 | |
| 173 context_->storage()->FindRegistrationForId( | |
| 174 registration_id, | |
| 175 base::Bind(&ServiceWorkerDispatcherHost::PostMessageFoundRegistration, | |
| 176 this, | |
| 177 message, | |
| 178 sent_message_port_ids)); | |
| 179 } | |
| 180 | |
| 181 static void NoOpStatusCallback(ServiceWorkerStatusCode status) {} | |
| 182 | |
| 183 void ServiceWorkerDispatcherHost::PostMessageFoundRegistration( | |
| 184 base::string16 message, | |
| 185 std::vector<int> sent_message_port_ids, | |
| 186 ServiceWorkerStatusCode status, | |
| 187 const scoped_refptr<ServiceWorkerRegistration>& result) { | |
| 188 // TODO(jsbell): Can we assert anything here? | |
| 189 if (status == SERVICE_WORKER_ERROR_NOT_FOUND) | |
| 190 return; | |
| 191 | |
| 192 std::vector<int> new_routing_ids(sent_message_port_ids.size()); | |
| 193 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { | |
| 194 new_routing_ids[i] = message_port_message_filter_->GetNextRoutingID(); | |
| 195 MessagePortService::GetInstance()->UpdateMessagePort( | |
|
michaeln
2014/03/11 23:17:34
i have no clue about msgport voodoo, but tests pas
| |
| 196 sent_message_port_ids[i], | |
| 197 message_port_message_filter_, | |
| 198 new_routing_ids[i]); | |
| 199 } | |
| 200 | |
| 201 // TODO(jsbell): Need version_id passed along to disambiguate? | |
|
jsbell
2014/03/11 22:01:50
This is probably the biggest issue with this CL. T
michaeln
2014/03/11 23:17:34
This was my main question too. I think there are t
kinuko
2014/03/12 08:19:05
In the current code it'd work for both cases, thou
jsbell
2014/03/12 18:16:16
Agreed, that's the failure case I was thinking of.
| |
| 202 result->active_version()->SendMessage( | |
| 203 ServiceWorkerMsg_Message(message, sent_message_port_ids, new_routing_ids), | |
| 204 base::Bind(&NoOpStatusCallback)); | |
| 205 } | |
| 206 | |
| 160 void ServiceWorkerDispatcherHost::OnProviderCreated(int provider_id) { | 207 void ServiceWorkerDispatcherHost::OnProviderCreated(int provider_id) { |
| 161 if (!context_) | 208 if (!context_) |
| 162 return; | 209 return; |
| 163 if (context_->GetProviderHost(render_process_id_, provider_id)) { | 210 if (context_->GetProviderHost(render_process_id_, provider_id)) { |
| 164 BadMessageReceived(); | 211 BadMessageReceived(); |
| 165 return; | 212 return; |
| 166 } | 213 } |
| 167 scoped_ptr<ServiceWorkerProviderHost> provider_host( | 214 scoped_ptr<ServiceWorkerProviderHost> provider_host( |
| 168 new ServiceWorkerProviderHost(render_process_id_, provider_id)); | 215 new ServiceWorkerProviderHost(render_process_id_, provider_id)); |
| 169 context_->AddProviderHost(provider_host.Pass()); | 216 context_->AddProviderHost(provider_host.Pass()); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 ServiceWorkerStatusCode status) { | 305 ServiceWorkerStatusCode status) { |
| 259 base::string16 error_message; | 306 base::string16 error_message; |
| 260 blink::WebServiceWorkerError::ErrorType error_type; | 307 blink::WebServiceWorkerError::ErrorType error_type; |
| 261 GetServiceWorkerRegistrationStatusResponse( | 308 GetServiceWorkerRegistrationStatusResponse( |
| 262 status, &error_type, &error_message); | 309 status, &error_type, &error_message); |
| 263 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 310 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
| 264 thread_id, request_id, error_type, error_message)); | 311 thread_id, request_id, error_type, error_message)); |
| 265 } | 312 } |
| 266 | 313 |
| 267 } // namespace content | 314 } // namespace content |
| OLD | NEW |