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..389e5216359956adba6b4c46a4fd43f505c6f12a 100644 |
--- a/Source/modules/push_messaging/PushManager.cpp |
+++ b/Source/modules/push_messaging/PushManager.cpp |
@@ -16,12 +16,16 @@ |
#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" |
+ |
+// Implementation of the Push Api. |
+// FIXME: These calls should be available from workers which will not have a Document object available. |
mlamouri (slow - plz ping)
2014/10/17 09:22:01
I would move that FIXME in the two places where th
Miguel Garcia
2014/10/20 09:58:10
Done.
|
namespace blink { |
PushManager::PushManager() |
@@ -49,4 +53,25 @@ ScriptPromise PushManager::registerPushMessaging(ScriptState* scriptState, const |
return promise; |
} |
+ |
+ScriptPromise PushManager::permissionStatus(ScriptState* scriptState) |
+{ |
+ ASSERT(scriptState->executionContext()->isDocument()); |
+ |
+ Document* document = toDocument(scriptState->executionContext()); |
+ if (!document->domWindow() || !document->page()) |
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(AbortError, "Document is detached from window.")); |
mlamouri (slow - plz ping)
2014/10/17 09:22:00
I think rejecting with "InvalidStateError" would b
Miguel Garcia
2014/10/20 09:58:10
Done.
|
+ blink::WebPushClient* client = PushController::clientFrom(document->page()); |
+ ASSERT(client); |
+ |
+ WebServiceWorkerProvider* serviceWorkerProvider = NavigatorServiceWorker::serviceWorker(document->domWindow()->navigator())->provider(); |
mlamouri (slow - plz ping)
2014/10/17 09:22:00
The way to access ServiceWorkerContainer is confus
|
+ if (!serviceWorkerProvider) |
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(AbortError, "No Service Worker installed for this document.")); |
mlamouri (slow - plz ping)
2014/10/17 09:22:01
ditto: InvalidStateError is probably more appropri
Miguel Garcia
2014/10/20 09:58:10
Done.
|
+ |
+ RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState); |
+ |
+ client->permissionStatus(new PushPermissionCallback(resolver), serviceWorkerProvider); |
+ return resolver->promise(); |
+} |
+ |
} // namespace blink |