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

Unified Diff: third_party/WebKit/Source/web/ServiceWorkerGlobalScopeProxy.cpp

Issue 2748213003: Service Worker event dispatcher for Background Fetch (Closed)
Patch Set: Service Worker event dispatcher for Background Fetch Created 3 years, 9 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
Index: third_party/WebKit/Source/web/ServiceWorkerGlobalScopeProxy.cpp
diff --git a/third_party/WebKit/Source/web/ServiceWorkerGlobalScopeProxy.cpp b/third_party/WebKit/Source/web/ServiceWorkerGlobalScopeProxy.cpp
index a77aff9b4f36c1e91c23f56fd9de58844003a6af..4250443bda3a8f3eb83834f7bef7b2979bb60c9c 100644
--- a/third_party/WebKit/Source/web/ServiceWorkerGlobalScopeProxy.cpp
+++ b/third_party/WebKit/Source/web/ServiceWorkerGlobalScopeProxy.cpp
@@ -42,6 +42,10 @@
#include "core/workers/ParentFrameTaskRunners.h"
#include "core/workers/WorkerGlobalScope.h"
#include "core/workers/WorkerThread.h"
+#include "modules/background_fetch/BackgroundFetchClickEvent.h"
+#include "modules/background_fetch/BackgroundFetchClickEventInit.h"
+#include "modules/background_fetch/BackgroundFetchEvent.h"
+#include "modules/background_fetch/BackgroundFetchEventInit.h"
#include "modules/background_sync/SyncEvent.h"
#include "modules/fetch/Headers.h"
#include "modules/notifications/Notification.h"
@@ -98,6 +102,53 @@ void ServiceWorkerGlobalScopeProxy::setRegistration(
workerGlobalScope()->setRegistration(std::move(handle));
}
+void ServiceWorkerGlobalScopeProxy::dispatchBackgroundFetchAbortEvent(
+ int eventID,
+ const WebString& tag) {
+ WaitUntilObserver* observer = WaitUntilObserver::create(
+ workerGlobalScope(), WaitUntilObserver::BackgroundFetchAbort, eventID);
+
+ BackgroundFetchClickEventInit init;
+ init.setTag(tag);
+
+ BackgroundFetchEvent* event = BackgroundFetchEvent::create(
+ EventTypeNames::backgroundfetchabort, init, observer);
+
+ workerGlobalScope()->dispatchExtendableEvent(event, observer);
+}
+
+void ServiceWorkerGlobalScopeProxy::dispatchBackgroundFetchClickEvent(
+ int eventID,
+ const WebString& tag,
+ BackgroundFetchState status) {
+ DEFINE_STATIC_LOCAL(const AtomicString, pending, ("pending"));
horo 2017/03/16 07:08:22 We should not use DEFINE_STATIC_LOCAL for AtomicSt
Peter Beverloo 2017/03/16 16:05:58 Removed, thanks
+ DEFINE_STATIC_LOCAL(const AtomicString, succeeded, ("succeeded"));
+ DEFINE_STATIC_LOCAL(const AtomicString, failed, ("failed"));
+
+ WaitUntilObserver* observer = WaitUntilObserver::create(
+ workerGlobalScope(), WaitUntilObserver::BackgroundFetchClick, eventID);
+
+ BackgroundFetchClickEventInit init;
+ init.setTag(tag);
+
+ switch (status) {
+ case BackgroundFetchState::Pending:
+ init.setState(pending);
+ break;
+ case BackgroundFetchState::Succeeded:
+ init.setState(succeeded);
+ break;
+ case BackgroundFetchState::Failed:
+ init.setState(failed);
+ break;
+ }
+
+ BackgroundFetchClickEvent* event = BackgroundFetchClickEvent::create(
+ EventTypeNames::backgroundfetchclick, init, observer);
+
+ workerGlobalScope()->dispatchExtendableEvent(event, observer);
+}
+
void ServiceWorkerGlobalScopeProxy::dispatchActivateEvent(int eventID) {
WaitUntilObserver* observer = WaitUntilObserver::create(
workerGlobalScope(), WaitUntilObserver::Activate, eventID);

Powered by Google App Engine
This is Rietveld 408576698