| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/presentation/PresentationRequest.h" | 6 #include "modules/presentation/PresentationRequest.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 9 #include "bindings/core/v8/ExceptionState.h" | 9 #include "bindings/core/v8/ExceptionState.h" |
| 10 #include "bindings/core/v8/ScriptPromise.h" | 10 #include "bindings/core/v8/ScriptPromise.h" |
| 11 #include "bindings/core/v8/ScriptPromiseResolver.h" | 11 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 12 #include "core/dom/Document.h" | 12 #include "core/dom/Document.h" |
| 13 #include "core/dom/ExecutionContext.h" | 13 #include "core/dom/ExecutionContext.h" |
| 14 #include "core/frame/UseCounter.h" | 14 #include "core/frame/UseCounter.h" |
| 15 #include "modules/EventTargetModules.h" | 15 #include "modules/EventTargetModules.h" |
| 16 #include "modules/presentation/PresentationAvailability.h" | 16 #include "modules/presentation/PresentationAvailability.h" |
| 17 #include "modules/presentation/PresentationAvailabilityCallbacks.h" | 17 #include "modules/presentation/PresentationAvailabilityCallbacks.h" |
| 18 #include "modules/presentation/PresentationController.h" | 18 #include "modules/presentation/PresentationController.h" |
| 19 #include "modules/presentation/PresentationError.h" | 19 #include "modules/presentation/PresentationError.h" |
| 20 #include "modules/presentation/PresentationSession.h" | 20 #include "modules/presentation/PresentationSession.h" |
| 21 #include "modules/presentation/PresentationSessionCallbacks.h" | 21 #include "modules/presentation/PresentationSessionCallbacks.h" |
| 22 #include "platform/UserGestureIndicator.h" |
| 22 | 23 |
| 23 namespace blink { | 24 namespace blink { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 // TODO(mlamouri): refactor in one common place. | 28 // TODO(mlamouri): refactor in one common place. |
| 28 WebPresentationClient* presentationClient(ExecutionContext* executionContext) | 29 WebPresentationClient* presentationClient(ExecutionContext* executionContext) |
| 29 { | 30 { |
| 30 ASSERT(executionContext && executionContext->isDocument()); | 31 ASSERT(executionContext && executionContext->isDocument()); |
| 31 | 32 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 // Prevents garbage collecting of this object when not hold by another | 76 // Prevents garbage collecting of this object when not hold by another |
| 76 // object but still has listeners registered. | 77 // object but still has listeners registered. |
| 77 return hasEventListeners(); | 78 return hasEventListeners(); |
| 78 } | 79 } |
| 79 | 80 |
| 80 ScriptPromise PresentationRequest::start(ScriptState* scriptState) | 81 ScriptPromise PresentationRequest::start(ScriptState* scriptState) |
| 81 { | 82 { |
| 82 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 83 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 83 ScriptPromise promise = resolver->promise(); | 84 ScriptPromise promise = resolver->promise(); |
| 84 | 85 |
| 86 if (!UserGestureIndicator::processingUserGesture()) { |
| 87 resolver->reject(DOMException::create(InvalidAccessError, "PresentationR
equest::start() requires user gesture.")); |
| 88 return promise; |
| 89 } |
| 90 |
| 85 WebPresentationClient* client = presentationClient(executionContext()); | 91 WebPresentationClient* client = presentationClient(executionContext()); |
| 86 if (!client) { | 92 if (!client) { |
| 87 resolver->reject(DOMException::create(InvalidStateError, "The Presentati
onRequest is no longer associated to a frame.")); | 93 resolver->reject(DOMException::create(InvalidStateError, "The Presentati
onRequest is no longer associated to a frame.")); |
| 88 return promise; | 94 return promise; |
| 89 } | 95 } |
| 90 client->startSession(m_url.string(), new PresentationSessionCallbacks(resolv
er, this)); | 96 client->startSession(m_url.string(), new PresentationSessionCallbacks(resolv
er, this)); |
| 91 | 97 |
| 92 return promise; | 98 return promise; |
| 93 } | 99 } |
| 94 | 100 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 ActiveDOMObject::trace(visitor); | 138 ActiveDOMObject::trace(visitor); |
| 133 } | 139 } |
| 134 | 140 |
| 135 PresentationRequest::PresentationRequest(ExecutionContext* executionContext, con
st KURL& url) | 141 PresentationRequest::PresentationRequest(ExecutionContext* executionContext, con
st KURL& url) |
| 136 : ActiveDOMObject(executionContext) | 142 : ActiveDOMObject(executionContext) |
| 137 , m_url(url) | 143 , m_url(url) |
| 138 { | 144 { |
| 139 } | 145 } |
| 140 | 146 |
| 141 } // namespace blink | 147 } // namespace blink |
| OLD | NEW |