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

Unified Diff: Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp

Issue 723923002: ServiceWorker: Add support for .skipWaiting and controllerchange event(1/3) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: split the CL Created 6 years 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: Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp
diff --git a/Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp b/Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp
index 037117e47973d3aa1c7fedfaa240333df1ff9915..d8489174f07adc3758ff72abf85ec603333995f0 100644
--- a/Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp
+++ b/Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp
@@ -50,11 +50,28 @@
#include "modules/serviceworkers/WaitUntilObserver.h"
#include "platform/network/ResourceRequest.h"
#include "platform/weborigin/KURL.h"
+#include "public/platform/WebServiceWorkerSkipWaitingCallbacks.h"
#include "public/platform/WebURL.h"
#include "wtf/CurrentTime.h"
namespace blink {
+class ServiceWorkerGlobalScope::SkipWaitingCallback final : public WebServiceWorkerSkipWaitingCallbacks {
+ WTF_MAKE_NONCOPYABLE(SkipWaitingCallback);
+public:
+ explicit SkipWaitingCallback(PassRefPtr<ScriptPromiseResolver> resolver)
+ : m_resolver(resolver) { }
+ ~SkipWaitingCallback() { }
+
+ void onSuccess() override
+ {
+ m_resolver->resolve();
+ }
+
+private:
+ RefPtr<ScriptPromiseResolver> m_resolver;
+};
+
PassRefPtrWillBeRawPtr<ServiceWorkerGlobalScope> ServiceWorkerGlobalScope::create(ServiceWorkerThread* thread, PassOwnPtrWillBeRawPtr<WorkerThreadStartupData> startupData)
{
RefPtrWillBeRawPtr<ServiceWorkerGlobalScope> context = adoptRefWillBeNoop(new ServiceWorkerGlobalScope(startupData->m_scriptURL, startupData->m_userAgent, thread, monotonicallyIncreasingTime(), startupData->m_starterOrigin, startupData->m_workerClients.release()));
@@ -127,6 +144,16 @@ void ServiceWorkerGlobalScope::close(ExceptionState& exceptionState)
exceptionState.throwDOMException(InvalidAccessError, "Not supported.");
}
+ScriptPromise ServiceWorkerGlobalScope::skipWaiting(ScriptState* scriptState)
+{
+ RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
+ ScriptPromise promise = resolver->promise();
+
+ ExecutionContext* executionContext = scriptState->executionContext();
+ ServiceWorkerGlobalScopeClient::from(executionContext)->skipWaiting(new SkipWaitingCallback(resolver));
+ return promise;
+}
+
bool ServiceWorkerGlobalScope::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener, bool useCapture)
{
if (m_didEvaluateScript) {

Powered by Google App Engine
This is Rietveld 408576698