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

Unified Diff: Source/modules/push_messaging/PushManager.cpp

Issue 658723003: Blink implementation of PushManager#hasPermission() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 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: Source/modules/push_messaging/PushManager.cpp
diff --git a/Source/modules/push_messaging/PushManager.cpp b/Source/modules/push_messaging/PushManager.cpp
index 1468d880d342ac3587df10d56c8d8d913a1c3329..acb9198ee3a45e8534575722aa67bf65848086b2 100644
--- a/Source/modules/push_messaging/PushManager.cpp
+++ b/Source/modules/push_messaging/PushManager.cpp
@@ -16,18 +16,21 @@
#include "core/frame/LocalDOMWindow.h"
#include "modules/push_messaging/PushController.h"
#include "modules/push_messaging/PushError.h"
+#include "modules/push_messaging/PushPermissionCallback.h"
#include "modules/push_messaging/PushRegistration.h"
#include "modules/serviceworkers/NavigatorServiceWorker.h"
#include "modules/serviceworkers/ServiceWorkerContainer.h"
#include "public/platform/WebPushClient.h"
#include "wtf/RefPtr.h"
+
Michael van Ouwerkerk 2014/10/20 11:25:42 nit: delete this extra empty line
Miguel Garcia 2014/10/22 12:58:43 Done.
namespace blink {
PushManager::PushManager()
{
}
+// FIXME: This calls should be available from workers which will not have a Document object available.
Michael van Ouwerkerk 2014/10/20 11:25:42 nit: s/This/These/
Michael van Ouwerkerk 2014/10/20 11:25:42 crbug.com/389194
Miguel Garcia 2014/10/22 12:58:43 Done.
ScriptPromise PushManager::registerPushMessaging(ScriptState* scriptState, const String& senderId)
{
ASSERT(scriptState->executionContext()->isDocument());
@@ -49,4 +52,25 @@ ScriptPromise PushManager::registerPushMessaging(ScriptState* scriptState, const
return promise;
}
+// FIXME: This calls should be available from workers which will not have a Document object available.
Michael van Ouwerkerk 2014/10/20 11:25:42 nit: same as above
Miguel Garcia 2014/10/22 12:58:43 Done.
+ScriptPromise PushManager::hasPermission(ScriptState* scriptState)
+{
+ ASSERT(scriptState->executionContext()->isDocument());
+
+ Document* document = toDocument(scriptState->executionContext());
+ if (!document->domWindow() || !document->page())
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "Document is detached from window."));
+ blink::WebPushClient* client = PushController::clientFrom(document->page());
+ ASSERT(client);
+
+ WebServiceWorkerProvider* serviceWorkerProvider = NavigatorServiceWorker::serviceWorker(document->domWindow()->navigator())->provider();
+ if (!serviceWorkerProvider)
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "No Service Worker installed for this document."));
Michael van Ouwerkerk 2014/10/20 11:25:42 The spec says to not provide any arguments when re
Peter Beverloo 2014/10/20 12:23:49 We don't care at all about whether there's a Servi
Miguel Garcia 2014/10/22 12:58:43 mm I don't know, we use the service worker stuff l
Michael van Ouwerkerk 2014/10/22 13:20:01 You could take the origin from the RenderFrameHost
Michael van Ouwerkerk 2014/10/22 15:52:45 Ok on further discussion... in future, when called
+
+ RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
+
+ client->permissionStatus(new PushPermissionCallback(resolver), serviceWorkerProvider);
Michael van Ouwerkerk 2014/10/20 11:25:42 It's not a simple getter is it? Then please name t
Miguel Garcia 2014/10/22 12:58:43 Done.
+ return resolver->promise();
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698