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

Side by Side 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: Rename enum to a more understandable name 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "modules/push_messaging/PushManager.h" 6 #include "modules/push_messaging/PushManager.h"
7 7
8 #include "bindings/core/v8/CallbackPromiseAdapter.h" 8 #include "bindings/core/v8/CallbackPromiseAdapter.h"
9 #include "bindings/core/v8/ScriptPromise.h" 9 #include "bindings/core/v8/ScriptPromise.h"
10 #include "bindings/core/v8/ScriptPromiseResolver.h" 10 #include "bindings/core/v8/ScriptPromiseResolver.h"
11 #include "bindings/core/v8/ScriptState.h" 11 #include "bindings/core/v8/ScriptState.h"
12 #include "core/dom/DOMException.h" 12 #include "core/dom/DOMException.h"
13 #include "core/dom/Document.h" 13 #include "core/dom/Document.h"
14 #include "core/dom/ExceptionCode.h" 14 #include "core/dom/ExceptionCode.h"
15 #include "core/dom/ExecutionContext.h" 15 #include "core/dom/ExecutionContext.h"
16 #include "core/frame/LocalDOMWindow.h" 16 #include "core/frame/LocalDOMWindow.h"
17 #include "modules/push_messaging/PushController.h" 17 #include "modules/push_messaging/PushController.h"
18 #include "modules/push_messaging/PushError.h" 18 #include "modules/push_messaging/PushError.h"
19 #include "modules/push_messaging/PushPermissionCallback.h"
19 #include "modules/push_messaging/PushRegistration.h" 20 #include "modules/push_messaging/PushRegistration.h"
20 #include "modules/serviceworkers/NavigatorServiceWorker.h" 21 #include "modules/serviceworkers/NavigatorServiceWorker.h"
21 #include "modules/serviceworkers/ServiceWorkerContainer.h" 22 #include "modules/serviceworkers/ServiceWorkerContainer.h"
22 #include "public/platform/WebPushClient.h" 23 #include "public/platform/WebPushClient.h"
23 #include "wtf/RefPtr.h" 24 #include "wtf/RefPtr.h"
24 25
26
27 // Implementation of the Push Api.
28 // FIXME: These calls should be available from workers which will not have a Doc ument 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.
25 namespace blink { 29 namespace blink {
26 30
27 PushManager::PushManager() 31 PushManager::PushManager()
28 { 32 {
29 } 33 }
30 34
31 ScriptPromise PushManager::registerPushMessaging(ScriptState* scriptState, const String& senderId) 35 ScriptPromise PushManager::registerPushMessaging(ScriptState* scriptState, const String& senderId)
32 { 36 {
33 ASSERT(scriptState->executionContext()->isDocument()); 37 ASSERT(scriptState->executionContext()->isDocument());
34 38
35 Document* document = toDocument(scriptState->executionContext()); 39 Document* document = toDocument(scriptState->executionContext());
36 if (!document->domWindow() || !document->page()) 40 if (!document->domWindow() || !document->page())
37 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(AbortError, "Document is detached from window.")); 41 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(AbortError, "Document is detached from window."));
38 42
39 WebServiceWorkerProvider* serviceWorkerProvider = NavigatorServiceWorker::se rviceWorker(document->domWindow()->navigator())->provider(); 43 WebServiceWorkerProvider* serviceWorkerProvider = NavigatorServiceWorker::se rviceWorker(document->domWindow()->navigator())->provider();
40 if (!serviceWorkerProvider) 44 if (!serviceWorkerProvider)
41 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(AbortError, "No Service Worker installed for this document.")); 45 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(AbortError, "No Service Worker installed for this document."));
42 46
43 WebPushClient* client = PushController::clientFrom(document->page()); 47 WebPushClient* client = PushController::clientFrom(document->page());
44 ASSERT(client); 48 ASSERT(client);
45 49
46 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); 50 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState);
47 ScriptPromise promise = resolver->promise(); 51 ScriptPromise promise = resolver->promise();
48 client->registerPushMessaging(senderId, new CallbackPromiseAdapter<PushRegis tration, PushError>(resolver), serviceWorkerProvider); 52 client->registerPushMessaging(senderId, new CallbackPromiseAdapter<PushRegis tration, PushError>(resolver), serviceWorkerProvider);
49 return promise; 53 return promise;
50 } 54 }
51 55
56
57 ScriptPromise PushManager::permissionStatus(ScriptState* scriptState)
58 {
59 ASSERT(scriptState->executionContext()->isDocument());
60
61 Document* document = toDocument(scriptState->executionContext());
62 if (!document->domWindow() || !document->page())
63 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.
64 blink::WebPushClient* client = PushController::clientFrom(document->page());
65 ASSERT(client);
66
67 WebServiceWorkerProvider* serviceWorkerProvider = NavigatorServiceWorker::se rviceWorker(document->domWindow()->navigator())->provider();
mlamouri (slow - plz ping) 2014/10/17 09:22:00 The way to access ServiceWorkerContainer is confus
68 if (!serviceWorkerProvider)
69 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.
70
71 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState);
72
73 client->permissionStatus(new PushPermissionCallback(resolver), serviceWorker Provider);
74 return resolver->promise();
75 }
76
52 } // namespace blink 77 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698