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 "modules/push_messaging/PushManager.h" | 5 #include "modules/push_messaging/PushManager.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptPromise.h" | 7 #include "bindings/core/v8/ScriptPromise.h" |
8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 // permission so that later calls in different contexts can succeed. | 64 // permission so that later calls in different contexts can succeed. |
65 if (scriptState->getExecutionContext()->isDocument()) { | 65 if (scriptState->getExecutionContext()->isDocument()) { |
66 Document* document = toDocument(scriptState->getExecutionContext()); | 66 Document* document = toDocument(scriptState->getExecutionContext()); |
67 if (!document->domWindow() || !document->frame()) | 67 if (!document->domWindow() || !document->frame()) |
68 return ScriptPromise::rejectWithDOMException( | 68 return ScriptPromise::rejectWithDOMException( |
69 scriptState, | 69 scriptState, |
70 DOMException::create(InvalidStateError, | 70 DOMException::create(InvalidStateError, |
71 "Document is detached from window.")); | 71 "Document is detached from window.")); |
72 PushController::clientFrom(document->frame()) | 72 PushController::clientFrom(document->frame()) |
73 .subscribe(m_registration->webRegistration(), webOptions, | 73 .subscribe(m_registration->webRegistration(), webOptions, |
74 new PushSubscriptionCallbacks(resolver, m_registration)); | 74 WTF::makeUnique<PushSubscriptionCallbacks>(resolver, |
| 75 m_registration)); |
75 } else { | 76 } else { |
76 pushProvider()->subscribe( | 77 pushProvider()->subscribe( |
77 m_registration->webRegistration(), webOptions, | 78 m_registration->webRegistration(), webOptions, |
78 new PushSubscriptionCallbacks(resolver, m_registration)); | 79 WTF::makeUnique<PushSubscriptionCallbacks>(resolver, m_registration)); |
79 } | 80 } |
80 | 81 |
81 return promise; | 82 return promise; |
82 } | 83 } |
83 | 84 |
84 ScriptPromise PushManager::getSubscription(ScriptState* scriptState) { | 85 ScriptPromise PushManager::getSubscription(ScriptState* scriptState) { |
85 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 86 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
86 ScriptPromise promise = resolver->promise(); | 87 ScriptPromise promise = resolver->promise(); |
87 | 88 |
88 pushProvider()->getSubscription( | 89 pushProvider()->getSubscription( |
89 m_registration->webRegistration(), | 90 m_registration->webRegistration(), |
90 new PushSubscriptionCallbacks(resolver, m_registration)); | 91 WTF::makeUnique<PushSubscriptionCallbacks>(resolver, m_registration)); |
91 return promise; | 92 return promise; |
92 } | 93 } |
93 | 94 |
94 ScriptPromise PushManager::permissionState( | 95 ScriptPromise PushManager::permissionState( |
95 ScriptState* scriptState, | 96 ScriptState* scriptState, |
96 const PushSubscriptionOptionsInit& options, | 97 const PushSubscriptionOptionsInit& options, |
97 ExceptionState& exceptionState) { | 98 ExceptionState& exceptionState) { |
98 if (scriptState->getExecutionContext()->isDocument()) { | 99 if (scriptState->getExecutionContext()->isDocument()) { |
99 Document* document = toDocument(scriptState->getExecutionContext()); | 100 Document* document = toDocument(scriptState->getExecutionContext()); |
100 if (!document->domWindow() || !document->frame()) | 101 if (!document->domWindow() || !document->frame()) |
101 return ScriptPromise::rejectWithDOMException( | 102 return ScriptPromise::rejectWithDOMException( |
102 scriptState, | 103 scriptState, |
103 DOMException::create(InvalidStateError, | 104 DOMException::create(InvalidStateError, |
104 "Document is detached from window.")); | 105 "Document is detached from window.")); |
105 } | 106 } |
106 | 107 |
107 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 108 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
108 ScriptPromise promise = resolver->promise(); | 109 ScriptPromise promise = resolver->promise(); |
109 | 110 |
110 pushProvider()->getPermissionStatus( | 111 pushProvider()->getPermissionStatus( |
111 m_registration->webRegistration(), | 112 m_registration->webRegistration(), |
112 PushSubscriptionOptions::toWeb(options, exceptionState), | 113 PushSubscriptionOptions::toWeb(options, exceptionState), |
113 new PushPermissionStatusCallbacks(resolver)); | 114 WTF::makeUnique<PushPermissionStatusCallbacks>(resolver)); |
114 return promise; | 115 return promise; |
115 } | 116 } |
116 | 117 |
117 DEFINE_TRACE(PushManager) { | 118 DEFINE_TRACE(PushManager) { |
118 visitor->trace(m_registration); | 119 visitor->trace(m_registration); |
119 } | 120 } |
120 | 121 |
121 } // namespace blink | 122 } // namespace blink |
OLD | NEW |