| 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 "core/dom/DOMException.h" | 9 #include "core/dom/DOMException.h" |
| 10 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
| 11 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
| 12 #include "core/dom/ExecutionContext.h" | 12 #include "core/dom/ExecutionContext.h" |
| 13 #include "core/dom/UserGestureIndicator.h" |
| 13 #include "modules/push_messaging/PushController.h" | 14 #include "modules/push_messaging/PushController.h" |
| 14 #include "modules/push_messaging/PushError.h" | 15 #include "modules/push_messaging/PushError.h" |
| 15 #include "modules/push_messaging/PushPermissionStatusCallbacks.h" | 16 #include "modules/push_messaging/PushPermissionStatusCallbacks.h" |
| 16 #include "modules/push_messaging/PushSubscription.h" | 17 #include "modules/push_messaging/PushSubscription.h" |
| 17 #include "modules/push_messaging/PushSubscriptionCallbacks.h" | 18 #include "modules/push_messaging/PushSubscriptionCallbacks.h" |
| 18 #include "modules/push_messaging/PushSubscriptionOptions.h" | 19 #include "modules/push_messaging/PushSubscriptionOptions.h" |
| 19 #include "modules/push_messaging/PushSubscriptionOptionsInit.h" | 20 #include "modules/push_messaging/PushSubscriptionOptionsInit.h" |
| 20 #include "modules/serviceworkers/ServiceWorkerRegistration.h" | 21 #include "modules/serviceworkers/ServiceWorkerRegistration.h" |
| 21 #include "platform/bindings/ScriptState.h" | 22 #include "platform/bindings/ScriptState.h" |
| 22 #include "platform/wtf/Assertions.h" | 23 #include "platform/wtf/Assertions.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // permission so that later calls in different contexts can succeed. | 70 // permission so that later calls in different contexts can succeed. |
| 70 if (ExecutionContext::From(script_state)->IsDocument()) { | 71 if (ExecutionContext::From(script_state)->IsDocument()) { |
| 71 Document* document = ToDocument(ExecutionContext::From(script_state)); | 72 Document* document = ToDocument(ExecutionContext::From(script_state)); |
| 72 if (!document->domWindow() || !document->GetFrame()) | 73 if (!document->domWindow() || !document->GetFrame()) |
| 73 return ScriptPromise::RejectWithDOMException( | 74 return ScriptPromise::RejectWithDOMException( |
| 74 script_state, | 75 script_state, |
| 75 DOMException::Create(kInvalidStateError, | 76 DOMException::Create(kInvalidStateError, |
| 76 "Document is detached from window.")); | 77 "Document is detached from window.")); |
| 77 PushController::ClientFrom(document->GetFrame()) | 78 PushController::ClientFrom(document->GetFrame()) |
| 78 .Subscribe(registration_->WebRegistration(), web_options, | 79 .Subscribe(registration_->WebRegistration(), web_options, |
| 80 UserGestureIndicator::ProcessingUserGestureThreadSafe(), |
| 79 WTF::MakeUnique<PushSubscriptionCallbacks>(resolver, | 81 WTF::MakeUnique<PushSubscriptionCallbacks>(resolver, |
| 80 registration_)); | 82 registration_)); |
| 81 } else { | 83 } else { |
| 82 PushProvider()->Subscribe( | 84 PushProvider()->Subscribe( |
| 83 registration_->WebRegistration(), web_options, | 85 registration_->WebRegistration(), web_options, |
| 86 UserGestureIndicator::ProcessingUserGestureThreadSafe(), |
| 84 WTF::MakeUnique<PushSubscriptionCallbacks>(resolver, registration_)); | 87 WTF::MakeUnique<PushSubscriptionCallbacks>(resolver, registration_)); |
| 85 } | 88 } |
| 86 | 89 |
| 87 return promise; | 90 return promise; |
| 88 } | 91 } |
| 89 | 92 |
| 90 ScriptPromise PushManager::getSubscription(ScriptState* script_state) { | 93 ScriptPromise PushManager::getSubscription(ScriptState* script_state) { |
| 91 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 94 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
| 92 ScriptPromise promise = resolver->Promise(); | 95 ScriptPromise promise = resolver->Promise(); |
| 93 | 96 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 118 PushSubscriptionOptions::ToWeb(options, exception_state), | 121 PushSubscriptionOptions::ToWeb(options, exception_state), |
| 119 WTF::MakeUnique<PushPermissionStatusCallbacks>(resolver)); | 122 WTF::MakeUnique<PushPermissionStatusCallbacks>(resolver)); |
| 120 return promise; | 123 return promise; |
| 121 } | 124 } |
| 122 | 125 |
| 123 DEFINE_TRACE(PushManager) { | 126 DEFINE_TRACE(PushManager) { |
| 124 visitor->Trace(registration_); | 127 visitor->Trace(registration_); |
| 125 } | 128 } |
| 126 | 129 |
| 127 } // namespace blink | 130 } // namespace blink |
| OLD | NEW |