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

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

Issue 779563003: [POC-WIP] Link window focus tokens with ExecutionContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 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/ServiceWorkerClient.cpp
diff --git a/Source/modules/serviceworkers/ServiceWorkerClient.cpp b/Source/modules/serviceworkers/ServiceWorkerClient.cpp
index 794644b59e611b3ea604cb28a42867f1adedef12..9265ae9c494864566a8ac21954953dc61b97aeaf 100644
--- a/Source/modules/serviceworkers/ServiceWorkerClient.cpp
+++ b/Source/modules/serviceworkers/ServiceWorkerClient.cpp
@@ -5,8 +5,12 @@
#include "config.h"
#include "modules/serviceworkers/ServiceWorkerClient.h"
+#include "bindings/core/v8/CallbackPromiseAdapter.h"
#include "bindings/core/v8/ExceptionState.h"
+#include "bindings/core/v8/ScriptPromiseResolver.h"
#include "bindings/core/v8/SerializedScriptValue.h"
+#include "core/page/WindowFocusAllowedIndicator.h"
+#include "modules/serviceworkers/ServiceWorkerError.h"
#include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h"
#include "public/platform/WebString.h"
#include "wtf/RefPtr.h"
@@ -35,4 +39,19 @@ void ServiceWorkerClient::postMessage(ExecutionContext* context, PassRefPtr<Seri
ServiceWorkerGlobalScopeClient::from(context)->postMessageToClient(m_id, messageString, webChannels.release());
}
+ScriptPromise ServiceWorkerClient::focus(ScriptState* scriptState)
+{
+ RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
+ ScriptPromise promise = resolver->promise();
+
+ if (!scriptState->executionContext()->isWindowFocusAllowed()) {
+ resolver->resolve(false);
+ return promise;
+ }
+ scriptState->executionContext()->consumeWindowFocusToken();
+
+ ServiceWorkerGlobalScopeClient::from(scriptState->executionContext())->focus(m_id, new CallbackPromiseAdapter<bool, ServiceWorkerError>(resolver));
+ return promise;
+}
+
} // namespace blink
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorkerClient.h ('k') | Source/modules/serviceworkers/ServiceWorkerClient.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698