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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 99 |
100 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) | 100 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) |
101 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, "The document is sandboxed and lacks the 'allow-presentati
on' flag.")); | 101 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, "The document is sandboxed and lacks the 'allow-presentati
on' flag.")); |
102 | 102 |
103 WebPresentationClient* client = presentationClient(getExecutionContext()); | 103 WebPresentationClient* client = presentationClient(getExecutionContext()); |
104 if (!client) | 104 if (!client) |
105 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "The PresentationRequest is no longer associated to a
frame.")); | 105 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "The PresentationRequest is no longer associated to a
frame.")); |
106 | 106 |
107 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 107 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
108 // TODO(crbug.com/627655): Accept multiple URLs per PresentationRequest. | 108 // TODO(crbug.com/627655): Accept multiple URLs per PresentationRequest. |
109 WebVector<WebString> presentationUrls(static_cast<size_t>(1U)); | 109 WebVector<WebURL> presentationUrls(static_cast<size_t>(1U)); |
110 presentationUrls[0] = m_url.getString(); | 110 presentationUrls[0] = m_url; |
111 client->startSession(presentationUrls, new PresentationConnectionCallbacks(r
esolver, this)); | 111 client->startSession(presentationUrls, new PresentationConnectionCallbacks(r
esolver, this)); |
112 return resolver->promise(); | 112 return resolver->promise(); |
113 } | 113 } |
114 | 114 |
115 ScriptPromise PresentationRequest::reconnect(ScriptState* scriptState, const Str
ing& id) | 115 ScriptPromise PresentationRequest::reconnect(ScriptState* scriptState, const Str
ing& id) |
116 { | 116 { |
117 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) | 117 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) |
118 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, "The document is sandboxed and lacks the 'allow-presentati
on' flag.")); | 118 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, "The document is sandboxed and lacks the 'allow-presentati
on' flag.")); |
119 | 119 |
120 WebPresentationClient* client = presentationClient(getExecutionContext()); | 120 WebPresentationClient* client = presentationClient(getExecutionContext()); |
121 if (!client) | 121 if (!client) |
122 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "The PresentationRequest is no longer associated to a
frame.")); | 122 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "The PresentationRequest is no longer associated to a
frame.")); |
123 | 123 |
124 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 124 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
125 // TODO(crbug.com/627655): Accept multiple URLs per PresentationRequest. | 125 // TODO(crbug.com/627655): Accept multiple URLs per PresentationRequest. |
126 WebVector<WebString> presentationUrls(static_cast<size_t>(1U)); | 126 WebVector<WebURL> presentationUrls(static_cast<size_t>(1U)); |
127 presentationUrls[0] = m_url.getString(); | 127 presentationUrls[0] = m_url; |
128 client->joinSession(presentationUrls, id, new PresentationConnectionCallback
s(resolver, this)); | 128 client->joinSession(presentationUrls, id, new PresentationConnectionCallback
s(resolver, this)); |
129 return resolver->promise(); | 129 return resolver->promise(); |
130 } | 130 } |
131 | 131 |
132 ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) | 132 ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) |
133 { | 133 { |
134 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) | 134 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) |
135 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, "The document is sandboxed and lacks the 'allow-presentati
on' flag.")); | 135 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, "The document is sandboxed and lacks the 'allow-presentati
on' flag.")); |
136 | 136 |
137 WebPresentationClient* client = presentationClient(getExecutionContext()); | 137 WebPresentationClient* client = presentationClient(getExecutionContext()); |
138 if (!client) | 138 if (!client) |
139 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "The PresentationRequest is no longer associated to a
frame.")); | 139 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "The PresentationRequest is no longer associated to a
frame.")); |
140 | 140 |
141 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 141 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
142 client->getAvailability(m_url.getString(), new PresentationAvailabilityCallb
acks(resolver, m_url)); | 142 client->getAvailability(m_url, new PresentationAvailabilityCallbacks(resolve
r, m_url)); |
143 return resolver->promise(); | 143 return resolver->promise(); |
144 } | 144 } |
145 | 145 |
146 const KURL& PresentationRequest::url() const | 146 const KURL& PresentationRequest::url() const |
147 { | 147 { |
148 return m_url; | 148 return m_url; |
149 } | 149 } |
150 | 150 |
151 DEFINE_TRACE(PresentationRequest) | 151 DEFINE_TRACE(PresentationRequest) |
152 { | 152 { |
153 EventTargetWithInlineData::trace(visitor); | 153 EventTargetWithInlineData::trace(visitor); |
154 ActiveDOMObject::trace(visitor); | 154 ActiveDOMObject::trace(visitor); |
155 } | 155 } |
156 | 156 |
157 PresentationRequest::PresentationRequest(ExecutionContext* executionContext, con
st KURL& url) | 157 PresentationRequest::PresentationRequest(ExecutionContext* executionContext, con
st KURL& url) |
158 : ActiveScriptWrappable(this) | 158 : ActiveScriptWrappable(this) |
159 , ActiveDOMObject(executionContext) | 159 , ActiveDOMObject(executionContext) |
160 , m_url(url) | 160 , m_url(url) |
161 { | 161 { |
162 } | 162 } |
163 | 163 |
164 } // namespace blink | 164 } // namespace blink |
OLD | NEW |