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

Side by Side Diff: extensions/renderer/dispatcher.cc

Issue 2886923002: [extension SW]: Support event listener registration and event dispatching. (Closed)
Patch Set: sync Created 3 years, 6 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
« no previous file with comments | « extensions/common/extension_messages.h ('k') | extensions/renderer/event_bindings.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 std::unique_ptr<NativeHandler>(new IdGeneratorCustomBindings(context))); 889 std::unique_ptr<NativeHandler>(new IdGeneratorCustomBindings(context)));
887 module_system->RegisterNativeHandler( 890 module_system->RegisterNativeHandler(
888 "runtime", 891 "runtime",
889 std::unique_ptr<NativeHandler>(new RuntimeCustomBindings(context))); 892 std::unique_ptr<NativeHandler>(new RuntimeCustomBindings(context)));
890 module_system->RegisterNativeHandler( 893 module_system->RegisterNativeHandler(
891 "display_source", 894 "display_source",
892 base::MakeUnique<DisplaySourceCustomBindings>(context, bindings_system)); 895 base::MakeUnique<DisplaySourceCustomBindings>(context, bindings_system));
893 } 896 }
894 897
895 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { 898 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) {
899 if (WorkerThreadDispatcher::Get()->OnControlMessageReceived(message))
900 return true;
901
896 bool handled = true; 902 bool handled = true;
897 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) 903 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message)
898 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) 904 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension)
899 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelSuspend, OnCancelSuspend) 905 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelSuspend, OnCancelSuspend)
900 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) 906 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage)
901 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect) 907 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect)
902 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, OnDispatchOnDisconnect) 908 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, OnDispatchOnDisconnect)
903 IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnLoaded) 909 IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnLoaded)
904 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnMessageInvoke) 910 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnMessageInvoke)
905 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchEvent, OnDispatchEvent) 911 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchEvent, OnDispatchEvent)
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 // The "guestViewDeny" module must always be loaded last. It registers 1485 // The "guestViewDeny" module must always be loaded last. It registers
1480 // error-providing custom elements for the GuestView types that are not 1486 // error-providing custom elements for the GuestView types that are not
1481 // available, and thus all of those types must have been checked and loaded 1487 // available, and thus all of those types must have been checked and loaded
1482 // (or not loaded) beforehand. 1488 // (or not loaded) beforehand.
1483 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { 1489 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) {
1484 module_system->Require("guestViewDeny"); 1490 module_system->Require("guestViewDeny");
1485 } 1491 }
1486 } 1492 }
1487 1493
1488 } // namespace extensions 1494 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/extension_messages.h ('k') | extensions/renderer/event_bindings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698