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 #Messages
Total messages: 53 (37 generated)
|