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

Issue 2886923002: [extension SW]: Support event listener registration and event dispatching. (Closed)

Created:
3 years, 7 months ago by lazyboy
Modified:
3 years, 6 months ago
Reviewers:
Devlin, dcheng
CC:
chromium-reviews, michaeln, jsbell+serviceworker_chromium.org, tzik, extensions-reviews_chromium.org, serviceworker-reviews, jam, kinuko+serviceworker, nhiroki, darin-cc_chromium.org, chromium-apps-reviews_chromium.org, horo+watch_chromium.org, kinuko+watch, shimazu+serviceworker_chromium.org, blink-worker-reviews_chromium.org
Target Ref:
refs/heads/master
Project:
chromium
Visibility:
Public.

Description

[extension SW]: Support event listener registration and event dispatching. Initial implementation, will only send events to an already running extension Service Worker. Subsequent CLs will add dispatching events to potentially stopped workers. Ref count while dispatching an event is missing in the CL, so is ExtensionHostMsg_EventAck IPC. Event filters are completely left out in this CL. Currently EventListeners have an added field called "worker_thread_id", its value being 0 (kNonWorkerThreadId) means these are not SW event listeners. Otherwise similar to lazy and non-lazy events, we will have SW events with worker_thread_id filled in. EventRouter's event registration methods are a bit verbose, e.g. existing methods: Add/RemoveListener Add/RemoveLazyListener [1] have their service worker counterpart versions: Add/RemoveServiceWorkerListener Add/RemoveServiceWorkerLazyListener [2] The difference of these [2] with the previous ones [1] are just an added |worker_thread_id| param. Exposing only these and removing the previous ones would also work, but that would require non service worker events/listeners to explicitly specify kNonWorkerThreadId as the value of |worker_thread_id| param. Since the consumers are not just within extensions core code, it's better to leave the change out in this CL. Test fixture: 1. Open an extension SW that registers tabs.onUpdated listener. 2. Do something (page.js) to dispatch tabs.onUpdated event(s). 3. Expect extension SW to receive the event(s). Note that there's no guarantee that the service worker is running during step 2 and onwards. In worst case, the might become flaky, but it should be highly unlikely. BUG=721147 Review-Url: https://codereview.chromium.org/2886923002 Cr-Commit-Position: refs/heads/master@{#477787} Committed: https://chromium.googlesource.com/chromium/src/+/e784724ab7bdebd696a585003d28c835352ddc75

Patch Set 1 #

Patch Set 2 : compile fix #

Patch Set 3 : foo #

Patch Set 4 : cleaned up a bit more, with logs though #

Patch Set 5 : . + logs #

Patch Set 6 : removed debug logs #

Total comments: 16

Patch Set 7 : only sync #

Patch Set 8 : Fix tests + bug in DetachEvent + GetFilteredEvents #

Patch Set 9 : address comments #

Total comments: 17

Patch Set 10 : address comments #

Total comments: 6

Patch Set 11 : address comments #

Patch Set 12 : rebase @tott #

Patch Set 13 : fix DCHECK #

Total comments: 7

Patch Set 14 : address comments #

Patch Set 15 : sync + restore IPC CHECK #

Patch Set 16 : ipc comment #

Patch Set 17 : sync #

Unified diffs Side-by-side diffs Delta from patch set Stats (+559 lines, -122 lines) Patch
M chrome/browser/extensions/service_worker_apitest.cc View 1 chunk +16 lines, -0 lines 0 comments Download
M chrome/common/extensions/api/_api_features.json View 1 2 3 4 5 6 1 chunk +1 line, -1 line 0 comments Download
A chrome/test/data/extensions/api_test/service_worker/events/manifest.json View 1 chunk +6 lines, -0 lines 0 comments Download
A chrome/test/data/extensions/api_test/service_worker/events/on_updated.html View 1 1 chunk +11 lines, -0 lines 0 comments Download
A chrome/test/data/extensions/api_test/service_worker/events/on_updated.js View 1 1 chunk +13 lines, -0 lines 0 comments Download
A chrome/test/data/extensions/api_test/service_worker/events/page.html View 1 1 chunk +7 lines, -0 lines 0 comments Download
A chrome/test/data/extensions/api_test/service_worker/events/page.js View 1 2 3 4 5 6 7 8 9 1 chunk +34 lines, -0 lines 0 comments Download
A chrome/test/data/extensions/api_test/service_worker/events/sw.js View 1 2 3 4 5 6 7 8 9 1 chunk +54 lines, -0 lines 0 comments Download
M extensions/browser/event_listener_map.h View 1 2 3 4 5 6 5 chunks +23 lines, -1 line 0 comments Download
M extensions/browser/event_listener_map.cc View 1 2 3 4 5 6 7 8 9 10 11 12 8 chunks +34 lines, -8 lines 0 comments Download
M extensions/browser/event_router.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 10 chunks +49 lines, -13 lines 0 comments Download
M extensions/browser/event_router.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 18 chunks +142 lines, -49 lines 0 comments Download
M extensions/browser/extension_message_filter.h View 1 chunk +8 lines, -4 lines 0 comments Download
M extensions/browser/extension_message_filter.cc View 1 2 3 4 5 6 7 8 9 5 chunks +36 lines, -9 lines 0 comments Download
M extensions/browser/extension_prefs.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 chunk +2 lines, -1 line 0 comments Download
M extensions/common/constants.h View 1 2 3 4 5 6 7 8 9 1 chunk +6 lines, -0 lines 0 comments Download
M extensions/common/constants.cc View 1 chunk +2 lines, -0 lines 0 comments Download
M extensions/common/extension_messages.h View 1 2 3 2 chunks +16 lines, -8 lines 0 comments Download
M extensions/renderer/dispatcher.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 4 chunks +13 lines, -7 lines 0 comments Download
M extensions/renderer/event_bindings.h View 1 2 3 4 5 6 7 8 9 10 2 chunks +6 lines, -0 lines 0 comments Download
M extensions/renderer/event_bindings.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 4 chunks +38 lines, -13 lines 0 comments Download
M extensions/renderer/service_worker_data.h View 2 chunks +3 lines, -0 lines 0 comments Download
M extensions/renderer/service_worker_data.cc View 1 chunk +2 lines, -0 lines 0 comments Download
M extensions/renderer/worker_thread_dispatcher.h View 1 2 3 4 5 6 7 8 9 5 chunks +16 lines, -5 lines 0 comments Download
M extensions/renderer/worker_thread_dispatcher.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 6 chunks +21 lines, -3 lines 0 comments Download

Messages

Total messages: 53 (37 generated)
lazyboy
Hi Devlin, This is the CL to register events from workers and dispatch events to ...
3 years, 7 months ago (2017-05-17 00:40:15 UTC) #6
lazyboy
Hi Devlin, This is the CL to register events from workers and dispatch events to ...
3 years, 7 months ago (2017-05-17 00:41:14 UTC) #8
Devlin
https://codereview.chromium.org/2886923002/diff/100001/extensions/browser/event_listener_map.cc File extensions/browser/event_listener_map.cc (right): https://codereview.chromium.org/2886923002/diff/100001/extensions/browser/event_listener_map.cc#newcode95 extensions/browser/event_listener_map.cc:95: DCHECK(worker_thread_id_ == kNonWorkerThreadId); nit: DCHECK_EQ https://codereview.chromium.org/2886923002/diff/100001/extensions/browser/event_router.cc File extensions/browser/event_router.cc (right): ...
3 years, 6 months ago (2017-05-24 17:58:25 UTC) #13
lazyboy
https://codereview.chromium.org/2886923002/diff/100001/extensions/browser/event_listener_map.cc File extensions/browser/event_listener_map.cc (right): https://codereview.chromium.org/2886923002/diff/100001/extensions/browser/event_listener_map.cc#newcode95 extensions/browser/event_listener_map.cc:95: DCHECK(worker_thread_id_ == kNonWorkerThreadId); On 2017/05/24 17:58:25, Devlin (catching up) ...
3 years, 6 months ago (2017-05-25 01:33:43 UTC) #16
Devlin
https://codereview.chromium.org/2886923002/diff/160001/chrome/test/data/extensions/api_test/service_worker/events/page.js File chrome/test/data/extensions/api_test/service_worker/events/page.js (right): https://codereview.chromium.org/2886923002/diff/160001/chrome/test/data/extensions/api_test/service_worker/events/page.js#newcode13 chrome/test/data/extensions/api_test/service_worker/events/page.js:13: console.error('data: ' + data); probably remove this or replace ...
3 years, 6 months ago (2017-06-01 04:54:50 UTC) #17
lazyboy
https://codereview.chromium.org/2886923002/diff/160001/chrome/test/data/extensions/api_test/service_worker/events/page.js File chrome/test/data/extensions/api_test/service_worker/events/page.js (right): https://codereview.chromium.org/2886923002/diff/160001/chrome/test/data/extensions/api_test/service_worker/events/page.js#newcode13 chrome/test/data/extensions/api_test/service_worker/events/page.js:13: console.error('data: ' + data); On 2017/06/01 04:54:49, Devlin wrote: ...
3 years, 6 months ago (2017-06-01 23:33:29 UTC) #18
Devlin
lgtm https://codereview.chromium.org/2886923002/diff/180001/extensions/renderer/dispatcher.cc File extensions/renderer/dispatcher.cc (right): https://codereview.chromium.org/2886923002/diff/180001/extensions/renderer/dispatcher.cc#newcode220 extensions/renderer/dispatcher.cc:220: const int worker_thread_id = content::WorkerThread::GetCurrentId(); hmm... this alone ...
3 years, 6 months ago (2017-06-02 14:53:08 UTC) #19
lazyboy
+dcheng for extensions/common/extension_messages.h https://codereview.chromium.org/2886923002/diff/160001/extensions/browser/event_router.cc File extensions/browser/event_router.cc (right): https://codereview.chromium.org/2886923002/diff/160001/extensions/browser/event_router.cc#newcode273 extensions/browser/event_router.cc:273: void EventRouter::AddLazyEventListenerImpl(const std::string& event_name, On 2017/06/01 ...
3 years, 6 months ago (2017-06-02 17:59:00 UTC) #21
dcheng
One other request (maybe not for this CL) is more documentation/comments on this whole event ...
3 years, 6 months ago (2017-06-05 20:23:15 UTC) #30
lazyboy
re: documentation, added note in event_router.h https://codereview.chromium.org/2886923002/diff/240001/extensions/renderer/event_bindings.cc File extensions/renderer/event_bindings.cc (right): https://codereview.chromium.org/2886923002/diff/240001/extensions/renderer/event_bindings.cc#newcode218 extensions/renderer/event_bindings.cc:218: event_name, worker_thread_id)); On ...
3 years, 6 months ago (2017-06-05 21:12:06 UTC) #31
dcheng
https://codereview.chromium.org/2886923002/diff/240001/extensions/renderer/worker_thread_dispatcher.cc File extensions/renderer/worker_thread_dispatcher.cc (right): https://codereview.chromium.org/2886923002/diff/240001/extensions/renderer/worker_thread_dispatcher.cc#newcode105 extensions/renderer/worker_thread_dispatcher.cc:105: bool found = base::PickleIterator(message).ReadInt(&worker_thread_id); Btw this seems pretty hard ...
3 years, 6 months ago (2017-06-06 04:55:07 UTC) #36
lazyboy
https://codereview.chromium.org/2886923002/diff/240001/extensions/renderer/worker_thread_dispatcher.cc File extensions/renderer/worker_thread_dispatcher.cc (right): https://codereview.chromium.org/2886923002/diff/240001/extensions/renderer/worker_thread_dispatcher.cc#newcode105 extensions/renderer/worker_thread_dispatcher.cc:105: bool found = base::PickleIterator(message).ReadInt(&worker_thread_id); On 2017/06/06 04:55:07, dcheng wrote: ...
3 years, 6 months ago (2017-06-06 19:12:00 UTC) #37
dcheng
ipc lgtm https://codereview.chromium.org/2886923002/diff/240001/extensions/renderer/worker_thread_dispatcher.cc File extensions/renderer/worker_thread_dispatcher.cc (right): https://codereview.chromium.org/2886923002/diff/240001/extensions/renderer/worker_thread_dispatcher.cc#newcode105 extensions/renderer/worker_thread_dispatcher.cc:105: bool found = base::PickleIterator(message).ReadInt(&worker_thread_id); On 2017/06/06 19:12:00, ...
3 years, 6 months ago (2017-06-06 20:59:55 UTC) #38
lazyboy
On 2017/06/06 20:59:55, dcheng wrote: > ipc lgtm > > https://codereview.chromium.org/2886923002/diff/240001/extensions/renderer/worker_thread_dispatcher.cc > File extensions/renderer/worker_thread_dispatcher.cc (right): ...
3 years, 6 months ago (2017-06-07 00:25:28 UTC) #39
commit-bot: I haz the power
CQ is trying da patch. Follow status at: https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2886923002/320001
3 years, 6 months ago (2017-06-07 21:30:13 UTC) #50
commit-bot: I haz the power
3 years, 6 months ago (2017-06-07 23:29:37 UTC) #53
Message was sent while issue was closed.
Committed patchset #17 (id:320001) as
https://chromium.googlesource.com/chromium/src/+/e784724ab7bdebd696a585003d28...

Powered by Google App Engine
This is Rietveld 408576698