Chromium Code Reviews| 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 |
| 253 bool WorkerMightHandleMessage(const IPC::Message& message) { | |
|
Devlin
2017/05/24 17:58:25
Do we need this when the WorkerThreadDispatcher al
lazyboy
2017/05/25 01:33:43
Removed.
| |
| 254 return message.type() == ExtensionMsg_DispatchEvent::ID; | |
| 255 } | |
| 256 | |
| 252 base::LazyInstance<WorkerScriptContextSet>::DestructorAtExit | 257 base::LazyInstance<WorkerScriptContextSet>::DestructorAtExit |
| 253 g_worker_script_context_set = LAZY_INSTANCE_INITIALIZER; | 258 g_worker_script_context_set = LAZY_INSTANCE_INITIALIZER; |
| 254 | 259 |
| 255 } // namespace | 260 } // namespace |
| 256 | 261 |
| 257 // Note that we can't use Blink public APIs in the constructor becase Blink | 262 // Note that we can't use Blink public APIs in the constructor becase Blink |
| 258 // is not initialized at the point we create Dispatcher. | 263 // is not initialized at the point we create Dispatcher. |
| 259 Dispatcher::Dispatcher(DispatcherDelegate* delegate) | 264 Dispatcher::Dispatcher(DispatcherDelegate* delegate) |
| 260 : delegate_(delegate), | 265 : delegate_(delegate), |
| 261 content_watcher_(new ContentWatcher()), | 266 content_watcher_(new ContentWatcher()), |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 return; | 468 return; |
| 464 } | 469 } |
| 465 | 470 |
| 466 ScriptContext* context = new ScriptContext( | 471 ScriptContext* context = new ScriptContext( |
| 467 v8_context, nullptr, extension, Feature::SERVICE_WORKER_CONTEXT, | 472 v8_context, nullptr, extension, Feature::SERVICE_WORKER_CONTEXT, |
| 468 extension, Feature::SERVICE_WORKER_CONTEXT); | 473 extension, Feature::SERVICE_WORKER_CONTEXT); |
| 469 context->set_url(url); | 474 context->set_url(url); |
| 470 | 475 |
| 471 if (ExtensionsClient::Get()->ExtensionAPIEnabledInExtensionServiceWorkers()) { | 476 if (ExtensionsClient::Get()->ExtensionAPIEnabledInExtensionServiceWorkers()) { |
| 472 WorkerThreadDispatcher::Get()->AddWorkerData(service_worker_version_id, | 477 WorkerThreadDispatcher::Get()->AddWorkerData(service_worker_version_id, |
| 473 &source_map_); | 478 context, &source_map_); |
| 474 | 479 |
| 475 // TODO(lazyboy): Make sure accessing |source_map_| in worker thread is | 480 // TODO(lazyboy): Make sure accessing |source_map_| in worker thread is |
| 476 // safe. | 481 // safe. |
| 477 context->set_module_system( | 482 context->set_module_system( |
| 478 base::MakeUnique<ModuleSystem>(context, &source_map_)); | 483 base::MakeUnique<ModuleSystem>(context, &source_map_)); |
| 479 | 484 |
| 480 ModuleSystem* module_system = context->module_system(); | 485 ModuleSystem* module_system = context->module_system(); |
| 481 // Enable natives in startup. | 486 // Enable natives in startup. |
| 482 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system); | 487 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system); |
| 483 ExtensionBindingsSystem* worker_bindings_system = | 488 ExtensionBindingsSystem* worker_bindings_system = |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 880 std::unique_ptr<NativeHandler>(new IdGeneratorCustomBindings(context))); | 885 std::unique_ptr<NativeHandler>(new IdGeneratorCustomBindings(context))); |
| 881 module_system->RegisterNativeHandler( | 886 module_system->RegisterNativeHandler( |
| 882 "runtime", | 887 "runtime", |
| 883 std::unique_ptr<NativeHandler>(new RuntimeCustomBindings(context))); | 888 std::unique_ptr<NativeHandler>(new RuntimeCustomBindings(context))); |
| 884 module_system->RegisterNativeHandler( | 889 module_system->RegisterNativeHandler( |
| 885 "display_source", | 890 "display_source", |
| 886 base::MakeUnique<DisplaySourceCustomBindings>(context, bindings_system)); | 891 base::MakeUnique<DisplaySourceCustomBindings>(context, bindings_system)); |
| 887 } | 892 } |
| 888 | 893 |
| 889 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { | 894 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { |
| 895 if (WorkerMightHandleMessage(message) && | |
| 896 WorkerThreadDispatcher::Get()->OnControlMessageReceived(message)) { | |
| 897 return true; | |
| 898 } | |
| 899 | |
| 890 bool handled = true; | 900 bool handled = true; |
| 891 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) | 901 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) |
| 892 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) | 902 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) |
| 893 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelSuspend, OnCancelSuspend) | 903 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelSuspend, OnCancelSuspend) |
| 894 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) | 904 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) |
| 895 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect) | 905 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect) |
| 896 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, OnDispatchOnDisconnect) | 906 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, OnDispatchOnDisconnect) |
| 897 IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnLoaded) | 907 IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnLoaded) |
| 898 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnMessageInvoke) | 908 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnMessageInvoke) |
| 899 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchEvent, OnDispatchEvent) | 909 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchEvent, OnDispatchEvent) |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1473 // The "guestViewDeny" module must always be loaded last. It registers | 1483 // The "guestViewDeny" module must always be loaded last. It registers |
| 1474 // error-providing custom elements for the GuestView types that are not | 1484 // error-providing custom elements for the GuestView types that are not |
| 1475 // available, and thus all of those types must have been checked and loaded | 1485 // available, and thus all of those types must have been checked and loaded |
| 1476 // (or not loaded) beforehand. | 1486 // (or not loaded) beforehand. |
| 1477 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { | 1487 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { |
| 1478 module_system->Require("guestViewDeny"); | 1488 module_system->Require("guestViewDeny"); |
| 1479 } | 1489 } |
| 1480 } | 1490 } |
| 1481 | 1491 |
| 1482 } // namespace extensions | 1492 } // namespace extensions |
| OLD | NEW |