OLD | NEW |
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 "extensions/renderer/dispatcher.h" | 5 #include "extensions/renderer/dispatcher.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 // last removed listener, rather than for each subsequent listener; the browser | 210 // last removed listener, rather than for each subsequent listener; the browser |
211 // only cares if an event has >0 associated listeners. | 211 // only cares if an event has >0 associated listeners. |
212 // TODO(devlin): Use this in EventBindings, too, and add logic for lazy | 212 // TODO(devlin): Use this in EventBindings, too, and add logic for lazy |
213 // background pages. | 213 // background pages. |
214 void SendEventListenersIPC(binding::EventListenersChanged changed, | 214 void SendEventListenersIPC(binding::EventListenersChanged changed, |
215 ScriptContext* context, | 215 ScriptContext* context, |
216 const std::string& event_name, | 216 const std::string& event_name, |
217 const base::DictionaryValue* filter, | 217 const base::DictionaryValue* filter, |
218 bool was_manual) { | 218 bool was_manual) { |
219 bool lazy = ExtensionFrameHelper::IsContextForEventPage(context); | 219 bool lazy = ExtensionFrameHelper::IsContextForEventPage(context); |
| 220 const int worker_thread_id = content::WorkerThread::GetCurrentId(); |
220 std::string extension_id = context->GetExtensionID(); | 221 std::string extension_id = context->GetExtensionID(); |
221 content::RenderThread* render_thread = content::RenderThread::Get(); | 222 content::RenderThread* render_thread = content::RenderThread::Get(); |
222 | 223 |
223 if (filter) { | 224 if (filter) { |
224 if (changed == binding::EventListenersChanged::HAS_LISTENERS) { | 225 if (changed == binding::EventListenersChanged::HAS_LISTENERS) { |
225 render_thread->Send(new ExtensionHostMsg_AddFilteredListener( | 226 render_thread->Send(new ExtensionHostMsg_AddFilteredListener( |
226 extension_id, event_name, *filter, lazy)); | 227 extension_id, event_name, *filter, lazy)); |
227 } else { | 228 } else { |
228 DCHECK_EQ(binding::EventListenersChanged::NO_LISTENERS, changed); | 229 DCHECK_EQ(binding::EventListenersChanged::NO_LISTENERS, changed); |
229 render_thread->Send(new ExtensionHostMsg_RemoveFilteredListener( | 230 render_thread->Send(new ExtensionHostMsg_RemoveFilteredListener( |
230 extension_id, event_name, *filter, lazy)); | 231 extension_id, event_name, *filter, lazy)); |
231 } | 232 } |
232 } else { | 233 } else { |
233 if (changed == binding::EventListenersChanged::HAS_LISTENERS) { | 234 if (changed == binding::EventListenersChanged::HAS_LISTENERS) { |
234 render_thread->Send(new ExtensionHostMsg_AddListener( | 235 render_thread->Send(new ExtensionHostMsg_AddListener( |
235 extension_id, context->url(), event_name)); | 236 extension_id, context->url(), event_name, worker_thread_id)); |
236 if (lazy) { | 237 if (lazy) { |
237 render_thread->Send( | 238 render_thread->Send(new ExtensionHostMsg_AddLazyListener( |
238 new ExtensionHostMsg_AddLazyListener(extension_id, event_name)); | 239 extension_id, event_name, worker_thread_id)); |
239 } | 240 } |
240 } else { | 241 } else { |
241 DCHECK_EQ(binding::EventListenersChanged::NO_LISTENERS, changed); | 242 DCHECK_EQ(binding::EventListenersChanged::NO_LISTENERS, changed); |
242 render_thread->Send(new ExtensionHostMsg_RemoveListener( | 243 render_thread->Send(new ExtensionHostMsg_RemoveListener( |
243 extension_id, context->url(), event_name)); | 244 extension_id, context->url(), event_name, worker_thread_id)); |
244 if (lazy && was_manual) { | 245 if (lazy && was_manual) { |
245 render_thread->Send( | 246 render_thread->Send(new ExtensionHostMsg_RemoveLazyListener( |
246 new ExtensionHostMsg_RemoveLazyListener(extension_id, event_name)); | 247 extension_id, event_name, worker_thread_id)); |
247 } | 248 } |
248 } | 249 } |
249 } | 250 } |
250 } | 251 } |
251 | 252 |
252 base::LazyInstance<WorkerScriptContextSet>::DestructorAtExit | 253 base::LazyInstance<WorkerScriptContextSet>::DestructorAtExit |
253 g_worker_script_context_set = LAZY_INSTANCE_INITIALIZER; | 254 g_worker_script_context_set = LAZY_INSTANCE_INITIALIZER; |
254 | 255 |
255 } // namespace | 256 } // namespace |
256 | 257 |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 return; | 464 return; |
464 } | 465 } |
465 | 466 |
466 ScriptContext* context = new ScriptContext( | 467 ScriptContext* context = new ScriptContext( |
467 v8_context, nullptr, extension, Feature::SERVICE_WORKER_CONTEXT, | 468 v8_context, nullptr, extension, Feature::SERVICE_WORKER_CONTEXT, |
468 extension, Feature::SERVICE_WORKER_CONTEXT); | 469 extension, Feature::SERVICE_WORKER_CONTEXT); |
469 context->set_url(url); | 470 context->set_url(url); |
470 | 471 |
471 if (ExtensionsClient::Get()->ExtensionAPIEnabledInExtensionServiceWorkers()) { | 472 if (ExtensionsClient::Get()->ExtensionAPIEnabledInExtensionServiceWorkers()) { |
472 WorkerThreadDispatcher::Get()->AddWorkerData(service_worker_version_id, | 473 WorkerThreadDispatcher::Get()->AddWorkerData(service_worker_version_id, |
473 &source_map_); | 474 context, &source_map_); |
474 | 475 |
475 // TODO(lazyboy): Make sure accessing |source_map_| in worker thread is | 476 // TODO(lazyboy): Make sure accessing |source_map_| in worker thread is |
476 // safe. | 477 // safe. |
477 context->set_module_system( | 478 context->set_module_system( |
478 base::MakeUnique<ModuleSystem>(context, &source_map_)); | 479 base::MakeUnique<ModuleSystem>(context, &source_map_)); |
479 | 480 |
480 ModuleSystem* module_system = context->module_system(); | 481 ModuleSystem* module_system = context->module_system(); |
481 // Enable natives in startup. | 482 // Enable natives in startup. |
482 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system); | 483 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system); |
483 ExtensionBindingsSystem* worker_bindings_system = | 484 ExtensionBindingsSystem* worker_bindings_system = |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 std::unique_ptr<NativeHandler>(new IdGeneratorCustomBindings(context))); | 883 std::unique_ptr<NativeHandler>(new IdGeneratorCustomBindings(context))); |
883 module_system->RegisterNativeHandler( | 884 module_system->RegisterNativeHandler( |
884 "runtime", | 885 "runtime", |
885 std::unique_ptr<NativeHandler>(new RuntimeCustomBindings(context))); | 886 std::unique_ptr<NativeHandler>(new RuntimeCustomBindings(context))); |
886 module_system->RegisterNativeHandler( | 887 module_system->RegisterNativeHandler( |
887 "display_source", | 888 "display_source", |
888 base::MakeUnique<DisplaySourceCustomBindings>(context, bindings_system)); | 889 base::MakeUnique<DisplaySourceCustomBindings>(context, bindings_system)); |
889 } | 890 } |
890 | 891 |
891 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { | 892 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { |
| 893 if (WorkerThreadDispatcher::Get()->OnControlMessageReceived(message)) |
| 894 return true; |
| 895 |
892 bool handled = true; | 896 bool handled = true; |
893 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) | 897 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) |
894 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) | 898 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) |
895 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelSuspend, OnCancelSuspend) | 899 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelSuspend, OnCancelSuspend) |
896 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) | 900 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) |
897 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect) | 901 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect) |
898 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, OnDispatchOnDisconnect) | 902 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, OnDispatchOnDisconnect) |
899 IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnLoaded) | 903 IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnLoaded) |
900 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnMessageInvoke) | 904 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnMessageInvoke) |
901 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchEvent, OnDispatchEvent) | 905 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchEvent, OnDispatchEvent) |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1475 // The "guestViewDeny" module must always be loaded last. It registers | 1479 // The "guestViewDeny" module must always be loaded last. It registers |
1476 // error-providing custom elements for the GuestView types that are not | 1480 // error-providing custom elements for the GuestView types that are not |
1477 // available, and thus all of those types must have been checked and loaded | 1481 // available, and thus all of those types must have been checked and loaded |
1478 // (or not loaded) beforehand. | 1482 // (or not loaded) beforehand. |
1479 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { | 1483 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { |
1480 module_system->Require("guestViewDeny"); | 1484 module_system->Require("guestViewDeny"); |
1481 } | 1485 } |
1482 } | 1486 } |
1483 | 1487 |
1484 } // namespace extensions | 1488 } // namespace extensions |
OLD | NEW |