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