| 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 "modules/presentation/PresentationRequest.h" | 5 #include "modules/presentation/PresentationRequest.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 if (!getExecutionContext() || getExecutionContext()->activeDOMObjectsAreStop
ped()) | 84 if (!getExecutionContext() || getExecutionContext()->activeDOMObjectsAreStop
ped()) |
| 85 return false; | 85 return false; |
| 86 | 86 |
| 87 // Prevents garbage collecting of this object when not hold by another | 87 // Prevents garbage collecting of this object when not hold by another |
| 88 // object but still has listeners registered. | 88 // object but still has listeners registered. |
| 89 return hasEventListeners(); | 89 return hasEventListeners(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 ScriptPromise PresentationRequest::start(ScriptState* scriptState) | 92 ScriptPromise PresentationRequest::start(ScriptState* scriptState) |
| 93 { | 93 { |
| 94 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | |
| 95 ScriptPromise promise = resolver->promise(); | |
| 96 | |
| 97 Settings* contextSettings = settings(getExecutionContext()); | 94 Settings* contextSettings = settings(getExecutionContext()); |
| 98 bool isUserGestureRequired = !contextSettings || contextSettings->presentati
onRequiresUserGesture(); | 95 bool isUserGestureRequired = !contextSettings || contextSettings->presentati
onRequiresUserGesture(); |
| 99 | 96 |
| 100 if (isUserGestureRequired && !UserGestureIndicator::utilizeUserGesture()) { | 97 if (isUserGestureRequired && !UserGestureIndicator::utilizeUserGesture()) |
| 101 resolver->reject(DOMException::create(InvalidAccessError, "PresentationR
equest::start() requires user gesture.")); | 98 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidAccessError, "PresentationRequest::start() requires user gesture."
)); |
| 102 return promise; | |
| 103 } | |
| 104 | 99 |
| 105 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) { | 100 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) |
| 106 resolver->reject(DOMException::create(SecurityError, "The document is sa
ndboxed and lacks the 'allow-presentation' flag.")); | 101 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, "The document is sandboxed and lacks the 'allow-presentati
on' flag.")); |
| 107 return promise; | |
| 108 } | |
| 109 | 102 |
| 110 WebPresentationClient* client = presentationClient(getExecutionContext()); | 103 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 111 if (!client) { | 104 if (!client) |
| 112 resolver->reject(DOMException::create(InvalidStateError, "The Presentati
onRequest is no longer associated to a frame.")); | 105 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "The PresentationRequest is no longer associated to a
frame.")); |
| 113 return promise; | 106 |
| 114 } | 107 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 115 client->startSession(m_url.getString(), new PresentationConnectionCallbacks(
resolver, this)); | 108 client->startSession(m_url.getString(), new PresentationConnectionCallbacks(
resolver, this)); |
| 116 return promise; | 109 return resolver->promise(); |
| 117 } | 110 } |
| 118 | 111 |
| 119 ScriptPromise PresentationRequest::reconnect(ScriptState* scriptState, const Str
ing& id) | 112 ScriptPromise PresentationRequest::reconnect(ScriptState* scriptState, const Str
ing& id) |
| 120 { | 113 { |
| 121 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 114 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) |
| 122 ScriptPromise promise = resolver->promise(); | 115 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, "The document is sandboxed and lacks the 'allow-presentati
on' flag.")); |
| 123 | |
| 124 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) { | |
| 125 resolver->reject(DOMException::create(SecurityError, "The document is sa
ndboxed and lacks the 'allow-presentation' flag.")); | |
| 126 return promise; | |
| 127 } | |
| 128 | 116 |
| 129 WebPresentationClient* client = presentationClient(getExecutionContext()); | 117 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 130 if (!client) { | 118 if (!client) |
| 131 resolver->reject(DOMException::create(InvalidStateError, "The Presentati
onRequest is no longer associated to a frame.")); | 119 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "The PresentationRequest is no longer associated to a
frame.")); |
| 132 return promise; | 120 |
| 133 } | 121 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 134 client->joinSession(m_url.getString(), id, new PresentationConnectionCallbac
ks(resolver, this)); | 122 client->joinSession(m_url.getString(), id, new PresentationConnectionCallbac
ks(resolver, this)); |
| 135 return promise; | 123 return resolver->promise(); |
| 136 } | 124 } |
| 137 | 125 |
| 138 ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) | 126 ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) |
| 139 { | 127 { |
| 140 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 128 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) |
| 141 ScriptPromise promise = resolver->promise(); | 129 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, "The document is sandboxed and lacks the 'allow-presentati
on' flag.")); |
| 142 | |
| 143 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) { | |
| 144 resolver->reject(DOMException::create(SecurityError, "The document is sa
ndboxed and lacks the 'allow-presentation' flag.")); | |
| 145 return promise; | |
| 146 } | |
| 147 | 130 |
| 148 WebPresentationClient* client = presentationClient(getExecutionContext()); | 131 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 149 if (!client) { | 132 if (!client) |
| 150 resolver->reject(DOMException::create(InvalidStateError, "The object is
no longer associated to a frame.")); | 133 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "The PresentationRequest is no longer associated to a
frame.")); |
| 151 return promise; | 134 |
| 152 } | 135 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 153 client->getAvailability(m_url.getString(), new PresentationAvailabilityCallb
acks(resolver, m_url)); | 136 client->getAvailability(m_url.getString(), new PresentationAvailabilityCallb
acks(resolver, m_url)); |
| 154 return promise; | 137 return resolver->promise(); |
| 155 } | 138 } |
| 156 | 139 |
| 157 const KURL& PresentationRequest::url() const | 140 const KURL& PresentationRequest::url() const |
| 158 { | 141 { |
| 159 return m_url; | 142 return m_url; |
| 160 } | 143 } |
| 161 | 144 |
| 162 DEFINE_TRACE(PresentationRequest) | 145 DEFINE_TRACE(PresentationRequest) |
| 163 { | 146 { |
| 164 EventTargetWithInlineData::trace(visitor); | 147 EventTargetWithInlineData::trace(visitor); |
| 165 ActiveDOMObject::trace(visitor); | 148 ActiveDOMObject::trace(visitor); |
| 166 } | 149 } |
| 167 | 150 |
| 168 PresentationRequest::PresentationRequest(ExecutionContext* executionContext, con
st KURL& url) | 151 PresentationRequest::PresentationRequest(ExecutionContext* executionContext, con
st KURL& url) |
| 169 : ActiveScriptWrappable(this) | 152 : ActiveScriptWrappable(this) |
| 170 , ActiveDOMObject(executionContext) | 153 , ActiveDOMObject(executionContext) |
| 171 , m_url(url) | 154 , m_url(url) |
| 172 { | 155 { |
| 173 } | 156 } |
| 174 | 157 |
| 175 } // namespace blink | 158 } // namespace blink |
| OLD | NEW |