| 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 // TODO(lazyboy): For service workers, use worker specific IPC::Sender |
| 221 // instead of |render_thread|. |
| 222 const int worker_thread_id = content::WorkerThread::GetCurrentId(); |
| 220 std::string extension_id = context->GetExtensionID(); | 223 std::string extension_id = context->GetExtensionID(); |
| 221 content::RenderThread* render_thread = content::RenderThread::Get(); | 224 content::RenderThread* render_thread = content::RenderThread::Get(); |
| 222 | 225 |
| 223 if (filter) { | 226 if (filter) { |
| 224 if (changed == binding::EventListenersChanged::HAS_LISTENERS) { | 227 if (changed == binding::EventListenersChanged::HAS_LISTENERS) { |
| 225 render_thread->Send(new ExtensionHostMsg_AddFilteredListener( | 228 render_thread->Send(new ExtensionHostMsg_AddFilteredListener( |
| 226 extension_id, event_name, *filter, lazy)); | 229 extension_id, event_name, *filter, lazy)); |
| 227 } else { | 230 } else { |
| 228 DCHECK_EQ(binding::EventListenersChanged::NO_LISTENERS, changed); | 231 DCHECK_EQ(binding::EventListenersChanged::NO_LISTENERS, changed); |
| 229 render_thread->Send(new ExtensionHostMsg_RemoveFilteredListener( | 232 render_thread->Send(new ExtensionHostMsg_RemoveFilteredListener( |
| 230 extension_id, event_name, *filter, lazy)); | 233 extension_id, event_name, *filter, lazy)); |
| 231 } | 234 } |
| 232 } else { | 235 } else { |
| 233 if (changed == binding::EventListenersChanged::HAS_LISTENERS) { | 236 if (changed == binding::EventListenersChanged::HAS_LISTENERS) { |
| 234 render_thread->Send(new ExtensionHostMsg_AddListener( | 237 render_thread->Send(new ExtensionHostMsg_AddListener( |
| 235 extension_id, context->url(), event_name)); | 238 extension_id, context->url(), event_name, worker_thread_id)); |
| 236 if (lazy) { | 239 if (lazy) { |
| 237 render_thread->Send( | 240 render_thread->Send(new ExtensionHostMsg_AddLazyListener( |
| 238 new ExtensionHostMsg_AddLazyListener(extension_id, event_name)); | 241 extension_id, event_name, worker_thread_id)); |
| 239 } | 242 } |
| 240 } else { | 243 } else { |
| 241 DCHECK_EQ(binding::EventListenersChanged::NO_LISTENERS, changed); | 244 DCHECK_EQ(binding::EventListenersChanged::NO_LISTENERS, changed); |
| 242 render_thread->Send(new ExtensionHostMsg_RemoveListener( | 245 render_thread->Send(new ExtensionHostMsg_RemoveListener( |
| 243 extension_id, context->url(), event_name)); | 246 extension_id, context->url(), event_name, worker_thread_id)); |
| 244 if (lazy && was_manual) { | 247 if (lazy && was_manual) { |
| 245 render_thread->Send( | 248 render_thread->Send(new ExtensionHostMsg_RemoveLazyListener( |
| 246 new ExtensionHostMsg_RemoveLazyListener(extension_id, event_name)); | 249 extension_id, event_name, worker_thread_id)); |
| 247 } | 250 } |
| 248 } | 251 } |
| 249 } | 252 } |
| 250 } | 253 } |
| 251 | 254 |
| 252 base::LazyInstance<WorkerScriptContextSet>::DestructorAtExit | 255 base::LazyInstance<WorkerScriptContextSet>::DestructorAtExit |
| 253 g_worker_script_context_set = LAZY_INSTANCE_INITIALIZER; | 256 g_worker_script_context_set = LAZY_INSTANCE_INITIALIZER; |
| 254 | 257 |
| 255 } // namespace | 258 } // namespace |
| 256 | 259 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 return; | 468 return; |
| 466 } | 469 } |
| 467 | 470 |
| 468 ScriptContext* context = new ScriptContext( | 471 ScriptContext* context = new ScriptContext( |
| 469 v8_context, nullptr, extension, Feature::SERVICE_WORKER_CONTEXT, | 472 v8_context, nullptr, extension, Feature::SERVICE_WORKER_CONTEXT, |
| 470 extension, Feature::SERVICE_WORKER_CONTEXT); | 473 extension, Feature::SERVICE_WORKER_CONTEXT); |
| 471 context->set_url(url); | 474 context->set_url(url); |
| 472 | 475 |
| 473 if (ExtensionsClient::Get()->ExtensionAPIEnabledInExtensionServiceWorkers()) { | 476 if (ExtensionsClient::Get()->ExtensionAPIEnabledInExtensionServiceWorkers()) { |
| 474 WorkerThreadDispatcher::Get()->AddWorkerData(service_worker_version_id, | 477 WorkerThreadDispatcher::Get()->AddWorkerData(service_worker_version_id, |
| 475 &source_map_); | 478 context, &source_map_); |
| 476 | 479 |
| 477 // TODO(lazyboy): Make sure accessing |source_map_| in worker thread is | 480 // TODO(lazyboy): Make sure accessing |source_map_| in worker thread is |
| 478 // safe. | 481 // safe. |
| 479 context->set_module_system( | 482 context->set_module_system( |
| 480 base::MakeUnique<ModuleSystem>(context, &source_map_)); | 483 base::MakeUnique<ModuleSystem>(context, &source_map_)); |
| 481 | 484 |
| 482 ModuleSystem* module_system = context->module_system(); | 485 ModuleSystem* module_system = context->module_system(); |
| 483 // Enable natives in startup. | 486 // Enable natives in startup. |
| 484 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system); | 487 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system); |
| 485 ExtensionBindingsSystem* worker_bindings_system = | 488 ExtensionBindingsSystem* worker_bindings_system = |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 std::unique_ptr<NativeHandler>(new IdGeneratorCustomBindings(context))); | 890 std::unique_ptr<NativeHandler>(new IdGeneratorCustomBindings(context))); |
| 888 module_system->RegisterNativeHandler( | 891 module_system->RegisterNativeHandler( |
| 889 "runtime", | 892 "runtime", |
| 890 std::unique_ptr<NativeHandler>(new RuntimeCustomBindings(context))); | 893 std::unique_ptr<NativeHandler>(new RuntimeCustomBindings(context))); |
| 891 module_system->RegisterNativeHandler( | 894 module_system->RegisterNativeHandler( |
| 892 "display_source", | 895 "display_source", |
| 893 base::MakeUnique<DisplaySourceCustomBindings>(context, bindings_system)); | 896 base::MakeUnique<DisplaySourceCustomBindings>(context, bindings_system)); |
| 894 } | 897 } |
| 895 | 898 |
| 896 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { | 899 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { |
| 900 if (WorkerThreadDispatcher::Get()->OnControlMessageReceived(message)) |
| 901 return true; |
| 902 |
| 897 bool handled = true; | 903 bool handled = true; |
| 898 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) | 904 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) |
| 899 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) | 905 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) |
| 900 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelSuspend, OnCancelSuspend) | 906 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelSuspend, OnCancelSuspend) |
| 901 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) | 907 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) |
| 902 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect) | 908 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect) |
| 903 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, OnDispatchOnDisconnect) | 909 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, OnDispatchOnDisconnect) |
| 904 IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnLoaded) | 910 IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnLoaded) |
| 905 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnMessageInvoke) | 911 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnMessageInvoke) |
| 906 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchEvent, OnDispatchEvent) | 912 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchEvent, OnDispatchEvent) |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1480 // The "guestViewDeny" module must always be loaded last. It registers | 1486 // The "guestViewDeny" module must always be loaded last. It registers |
| 1481 // error-providing custom elements for the GuestView types that are not | 1487 // error-providing custom elements for the GuestView types that are not |
| 1482 // available, and thus all of those types must have been checked and loaded | 1488 // available, and thus all of those types must have been checked and loaded |
| 1483 // (or not loaded) beforehand. | 1489 // (or not loaded) beforehand. |
| 1484 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { | 1490 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { |
| 1485 module_system->Require("guestViewDeny"); | 1491 module_system->Require("guestViewDeny"); |
| 1486 } | 1492 } |
| 1487 } | 1493 } |
| 1488 | 1494 |
| 1489 } // namespace extensions | 1495 } // namespace extensions |
| OLD | NEW |