OLD | NEW |
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/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
10 #include "bindings/core/v8/ScriptState.h" | 10 #include "bindings/core/v8/ScriptState.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Subscription failed - no active Service Worker")); | 56 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Subscription failed - no active Service Worker")); |
57 | 57 |
58 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 58 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
59 ScriptPromise promise = resolver->promise(); | 59 ScriptPromise promise = resolver->promise(); |
60 | 60 |
61 // The document context is the only reasonable context from which to ask the
user for permission | 61 // The document context is the only reasonable context from which to ask the
user for permission |
62 // to use the Push API. The embedder should persist the permission so that l
ater calls in | 62 // to use the Push API. The embedder should persist the permission so that l
ater calls in |
63 // different contexts can succeed. | 63 // different contexts can succeed. |
64 if (scriptState->executionContext()->isDocument()) { | 64 if (scriptState->executionContext()->isDocument()) { |
65 Document* document = toDocument(scriptState->executionContext()); | 65 Document* document = toDocument(scriptState->executionContext()); |
66 // FIXME: add test coverage for this condition - https://crbug.com/44043
1 | |
67 if (!document->domWindow() || !document->frame()) | 66 if (!document->domWindow() || !document->frame()) |
68 return ScriptPromise::rejectWithDOMException(scriptState, DOMExcepti
on::create(InvalidStateError, "Document is detached from window.")); | 67 return ScriptPromise::rejectWithDOMException(scriptState, DOMExcepti
on::create(InvalidStateError, "Document is detached from window.")); |
69 PushController::clientFrom(document->frame()).subscribe(m_registration->
webRegistration(), toWebPushSubscriptionOptions(options), new PushSubscriptionCa
llbacks(resolver, m_registration)); | 68 PushController::clientFrom(document->frame()).subscribe(m_registration->
webRegistration(), toWebPushSubscriptionOptions(options), new PushSubscriptionCa
llbacks(resolver, m_registration)); |
70 } else { | 69 } else { |
71 pushProvider()->subscribe(m_registration->webRegistration(), toWebPushSu
bscriptionOptions(options), new PushSubscriptionCallbacks(resolver, m_registrati
on)); | 70 pushProvider()->subscribe(m_registration->webRegistration(), toWebPushSu
bscriptionOptions(options), new PushSubscriptionCallbacks(resolver, m_registrati
on)); |
72 } | 71 } |
73 | 72 |
74 return promise; | 73 return promise; |
75 } | 74 } |
76 | 75 |
77 ScriptPromise PushManager::getSubscription(ScriptState* scriptState) | 76 ScriptPromise PushManager::getSubscription(ScriptState* scriptState) |
78 { | 77 { |
79 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 78 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
80 ScriptPromise promise = resolver->promise(); | 79 ScriptPromise promise = resolver->promise(); |
81 | 80 |
82 pushProvider()->getSubscription(m_registration->webRegistration(), new PushS
ubscriptionCallbacks(resolver, m_registration)); | 81 pushProvider()->getSubscription(m_registration->webRegistration(), new PushS
ubscriptionCallbacks(resolver, m_registration)); |
83 return promise; | 82 return promise; |
84 } | 83 } |
85 | 84 |
86 ScriptPromise PushManager::permissionState(ScriptState* scriptState, const PushS
ubscriptionOptions& options) | 85 ScriptPromise PushManager::permissionState(ScriptState* scriptState, const PushS
ubscriptionOptions& options) |
87 { | 86 { |
88 if (scriptState->executionContext()->isDocument()) { | 87 if (scriptState->executionContext()->isDocument()) { |
89 Document* document = toDocument(scriptState->executionContext()); | 88 Document* document = toDocument(scriptState->executionContext()); |
90 // FIXME: add test coverage for this condition - https://crbug.com/44043
1 | |
91 if (!document->domWindow() || !document->frame()) | 89 if (!document->domWindow() || !document->frame()) |
92 return ScriptPromise::rejectWithDOMException(scriptState, DOMExcepti
on::create(InvalidStateError, "Document is detached from window.")); | 90 return ScriptPromise::rejectWithDOMException(scriptState, DOMExcepti
on::create(InvalidStateError, "Document is detached from window.")); |
93 } | 91 } |
94 | 92 |
95 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 93 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
96 ScriptPromise promise = resolver->promise(); | 94 ScriptPromise promise = resolver->promise(); |
97 | 95 |
98 pushProvider()->getPermissionStatus(m_registration->webRegistration(), toWeb
PushSubscriptionOptions(options), new PushPermissionStatusCallbacks(resolver)); | 96 pushProvider()->getPermissionStatus(m_registration->webRegistration(), toWeb
PushSubscriptionOptions(options), new PushPermissionStatusCallbacks(resolver)); |
99 return promise; | 97 return promise; |
100 } | 98 } |
101 | 99 |
102 DEFINE_TRACE(PushManager) | 100 DEFINE_TRACE(PushManager) |
103 { | 101 { |
104 visitor->trace(m_registration); | 102 visitor->trace(m_registration); |
105 } | 103 } |
106 | 104 |
107 } // namespace blink | 105 } // namespace blink |
OLD | NEW |