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