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

Unified Diff: extensions/renderer/event_bindings.cc

Issue 2943583002: [extension SW] Support lazy events from extension service workers. (Closed)
Patch Set: sync @tott 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/renderer/dispatcher.cc ('k') | extensions/renderer/script_context.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/event_bindings.cc
diff --git a/extensions/renderer/event_bindings.cc b/extensions/renderer/event_bindings.cc
index 59cc404d8b7daa7499f336b9a86a0f5ee9058b12..7a5dee4d37519bed3120976e178c18147c22ec44 100644
--- a/extensions/renderer/event_bindings.cc
+++ b/extensions/renderer/event_bindings.cc
@@ -249,10 +249,15 @@ void EventBindings::AttachEvent(const std::string& event_name) {
const int worker_thread_id = content::WorkerThread::GetCurrentId();
const std::string& extension_id = context()->GetExtensionID();
+ const bool is_service_worker_context =
+ context()->context_type() == Feature::SERVICE_WORKER_CONTEXT;
IPC::Sender* sender = GetIPCSender();
if (IncrementEventListenerCount(context(), event_name) == 1) {
sender->Send(new ExtensionHostMsg_AddListener(
- extension_id, context()->url(), event_name, worker_thread_id));
+ extension_id,
+ is_service_worker_context ? context()->service_worker_scope()
+ : context()->url(),
+ event_name, worker_thread_id));
}
// This is called the first time the page has added a listener. Since
@@ -262,8 +267,13 @@ void EventBindings::AttachEvent(const std::string& event_name) {
ExtensionFrameHelper::IsContextForEventPage(context()) ||
context()->context_type() == Feature::SERVICE_WORKER_CONTEXT;
if (is_lazy_context) {
- sender->Send(new ExtensionHostMsg_AddLazyListener(extension_id, event_name,
- worker_thread_id));
+ if (is_service_worker_context) {
+ sender->Send(new ExtensionHostMsg_AddLazyServiceWorkerListener(
+ extension_id, event_name, context()->service_worker_scope()));
+ } else {
+ sender->Send(
+ new ExtensionHostMsg_AddLazyListener(extension_id, event_name));
+ }
}
}
@@ -280,12 +290,16 @@ void EventBindings::DetachEvent(const std::string& event_name, bool is_manual) {
attached_event_names_.erase(event_name);
int worker_thread_id = content::WorkerThread::GetCurrentId();
+ const bool is_service_worker_context = worker_thread_id != kNonWorkerThreadId;
IPC::Sender* sender = GetIPCSender();
const std::string& extension_id = context()->GetExtensionID();
if (DecrementEventListenerCount(context(), event_name) == 0) {
sender->Send(new ExtensionHostMsg_RemoveListener(
- extension_id, context()->url(), event_name, worker_thread_id));
+ extension_id,
+ is_service_worker_context ? context()->service_worker_scope()
+ : context()->url(),
+ event_name, worker_thread_id));
}
// DetachEvent is called when the last listener for the context is
@@ -297,8 +311,13 @@ void EventBindings::DetachEvent(const std::string& event_name, bool is_manual) {
ExtensionFrameHelper::IsContextForEventPage(context()) ||
context()->context_type() == Feature::SERVICE_WORKER_CONTEXT;
if (is_lazy_context) {
- sender->Send(new ExtensionHostMsg_RemoveLazyListener(
- extension_id, event_name, worker_thread_id));
+ if (is_service_worker_context) {
+ sender->Send(new ExtensionHostMsg_RemoveLazyServiceWorkerListener(
+ extension_id, event_name, context()->service_worker_scope()));
+ } else {
+ sender->Send(
+ new ExtensionHostMsg_RemoveLazyListener(extension_id, event_name));
+ }
}
}
}
« no previous file with comments | « extensions/renderer/dispatcher.cc ('k') | extensions/renderer/script_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698