Chromium Code Reviews| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 "the 'allow-presentation' flag.")); | 62 "the 'allow-presentation' flag.")); |
| 63 } | 63 } |
| 64 | 64 |
| 65 } // anonymous namespace | 65 } // anonymous namespace |
| 66 | 66 |
| 67 // static | 67 // static |
| 68 PresentationRequest* PresentationRequest::create( | 68 PresentationRequest* PresentationRequest::create( |
| 69 ExecutionContext* executionContext, | 69 ExecutionContext* executionContext, |
| 70 const String& url, | 70 const String& url, |
| 71 ExceptionState& exceptionState) { | 71 ExceptionState& exceptionState) { |
| 72 KURL parsedUrl = KURL(executionContext->url(), url); | 72 WTF::Vector<String> urls(1); |
| 73 if (!parsedUrl.isValid() || parsedUrl.protocolIsAbout()) { | 73 urls[0] = url; |
| 74 exceptionState.throwTypeError("'" + url + | 74 return create(executionContext, urls, exceptionState); |
| 75 "' can't be resolved to a valid URL."); | 75 } |
| 76 return nullptr; | 76 |
| 77 PresentationRequest* PresentationRequest::create( | |
| 78 ExecutionContext* executionContext, | |
| 79 const WTF::Vector<String>& urls, | |
| 80 ExceptionState& exceptionState) { | |
| 81 WTF::Vector<KURL> parsedUrls(urls.size()); | |
| 82 for (size_t i = 0; i < urls.size(); ++i) { | |
| 83 const KURL& parsedUrl = KURL(executionContext->url(), urls[i]); | |
| 84 if (!parsedUrl.isValid() || parsedUrl.protocolIsAbout()) { | |
| 85 exceptionState.throwTypeError("'" + urls[i] + | |
|
mark a. foltz
2016/12/09 05:38:03
This should be a SyntaxError according to the spec
zhaobin
2016/12/09 23:01:59
Done.
| |
| 86 "' can't be resolved to a valid URL."); | |
| 87 return nullptr; | |
| 88 } | |
| 89 parsedUrls[i] = parsedUrl; | |
| 77 } | 90 } |
| 78 | |
| 79 PresentationRequest* request = | 91 PresentationRequest* request = |
| 80 new PresentationRequest(executionContext, parsedUrl); | 92 new PresentationRequest(executionContext, parsedUrls); |
| 81 request->suspendIfNeeded(); | 93 request->suspendIfNeeded(); |
| 82 return request; | 94 return request; |
| 83 } | 95 } |
| 84 | 96 |
| 85 const AtomicString& PresentationRequest::interfaceName() const { | 97 const AtomicString& PresentationRequest::interfaceName() const { |
| 86 return EventTargetNames::PresentationRequest; | 98 return EventTargetNames::PresentationRequest; |
| 87 } | 99 } |
| 88 | 100 |
| 89 ExecutionContext* PresentationRequest::getExecutionContext() const { | 101 ExecutionContext* PresentationRequest::getExecutionContext() const { |
| 90 return ActiveDOMObject::getExecutionContext(); | 102 return ActiveDOMObject::getExecutionContext(); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 114 bool isUserGestureRequired = | 126 bool isUserGestureRequired = |
| 115 !contextSettings || contextSettings->presentationRequiresUserGesture(); | 127 !contextSettings || contextSettings->presentationRequiresUserGesture(); |
| 116 | 128 |
| 117 if (isUserGestureRequired && !UserGestureIndicator::utilizeUserGesture()) | 129 if (isUserGestureRequired && !UserGestureIndicator::utilizeUserGesture()) |
| 118 return ScriptPromise::rejectWithDOMException( | 130 return ScriptPromise::rejectWithDOMException( |
| 119 scriptState, | 131 scriptState, |
| 120 DOMException::create( | 132 DOMException::create( |
| 121 InvalidAccessError, | 133 InvalidAccessError, |
| 122 "PresentationRequest::start() requires user gesture.")); | 134 "PresentationRequest::start() requires user gesture.")); |
| 123 | 135 |
| 124 if (MixedContentChecker::isMixedContent( | 136 for (const auto& url : m_urls) { |
|
mark a. foltz
2016/12/09 05:38:03
In the spec, we moved this check to the ctor, so i
zhaobin
2016/12/09 23:02:00
Done.
| |
| 125 getExecutionContext()->getSecurityOrigin(), m_url)) { | 137 if (MixedContentChecker::isMixedContent( |
| 126 return rejectWithMixedContentException(scriptState, m_url.getString()); | 138 getExecutionContext()->getSecurityOrigin(), url)) { |
| 139 return rejectWithMixedContentException(scriptState, url.getString()); | |
| 140 } | |
| 127 } | 141 } |
| 128 | 142 |
| 129 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) | 143 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) |
| 130 return rejectWithSandBoxException(scriptState); | 144 return rejectWithSandBoxException(scriptState); |
| 131 | 145 |
| 132 WebPresentationClient* client = presentationClient(getExecutionContext()); | 146 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 133 if (!client) | 147 if (!client) |
| 134 return ScriptPromise::rejectWithDOMException( | 148 return ScriptPromise::rejectWithDOMException( |
| 135 scriptState, | 149 scriptState, |
| 136 DOMException::create( | 150 DOMException::create( |
| 137 InvalidStateError, | 151 InvalidStateError, |
| 138 "The PresentationRequest is no longer associated to a frame.")); | 152 "The PresentationRequest is no longer associated to a frame.")); |
| 139 | 153 |
| 140 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 154 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 141 // TODO(crbug.com/627655): Accept multiple URLs per PresentationRequest. | |
| 142 WebVector<WebURL> presentationUrls(static_cast<size_t>(1U)); | |
| 143 presentationUrls[0] = m_url; | |
| 144 client->startSession( | 155 client->startSession( |
| 145 presentationUrls, | 156 m_urls, WTF::makeUnique<PresentationConnectionCallbacks>(resolver, this)); |
| 146 WTF::makeUnique<PresentationConnectionCallbacks>(resolver, this)); | |
| 147 return resolver->promise(); | 157 return resolver->promise(); |
| 148 } | 158 } |
| 149 | 159 |
| 150 ScriptPromise PresentationRequest::reconnect(ScriptState* scriptState, | 160 ScriptPromise PresentationRequest::reconnect(ScriptState* scriptState, |
| 151 const String& id) { | 161 const String& id) { |
| 152 if (MixedContentChecker::isMixedContent( | 162 for (const auto& url : m_urls) { |
| 153 getExecutionContext()->getSecurityOrigin(), m_url)) { | 163 if (MixedContentChecker::isMixedContent( |
| 154 return rejectWithMixedContentException(scriptState, m_url.getString()); | 164 getExecutionContext()->getSecurityOrigin(), url)) { |
| 165 return rejectWithMixedContentException(scriptState, url.getString()); | |
| 166 } | |
| 155 } | 167 } |
| 156 | 168 |
| 157 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) | 169 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) |
| 158 return rejectWithSandBoxException(scriptState); | 170 return rejectWithSandBoxException(scriptState); |
| 159 | 171 |
| 160 WebPresentationClient* client = presentationClient(getExecutionContext()); | 172 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 161 if (!client) | 173 if (!client) |
| 162 return ScriptPromise::rejectWithDOMException( | 174 return ScriptPromise::rejectWithDOMException( |
| 163 scriptState, | 175 scriptState, |
| 164 DOMException::create( | 176 DOMException::create( |
| 165 InvalidStateError, | 177 InvalidStateError, |
| 166 "The PresentationRequest is no longer associated to a frame.")); | 178 "The PresentationRequest is no longer associated to a frame.")); |
| 167 | 179 |
| 168 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 180 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 169 // TODO(crbug.com/627655): Accept multiple URLs per PresentationRequest. | |
| 170 WebVector<WebURL> presentationUrls(static_cast<size_t>(1U)); | |
| 171 presentationUrls[0] = m_url; | |
| 172 client->joinSession( | 181 client->joinSession( |
| 173 presentationUrls, id, | 182 m_urls, id, |
| 174 WTF::makeUnique<PresentationConnectionCallbacks>(resolver, this)); | 183 WTF::makeUnique<PresentationConnectionCallbacks>(resolver, this)); |
| 175 return resolver->promise(); | 184 return resolver->promise(); |
| 176 } | 185 } |
| 177 | 186 |
| 178 ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) { | 187 ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) { |
| 179 if (MixedContentChecker::isMixedContent( | 188 for (const auto& url : m_urls) { |
| 180 getExecutionContext()->getSecurityOrigin(), m_url)) { | 189 if (MixedContentChecker::isMixedContent( |
| 181 return rejectWithMixedContentException(scriptState, m_url.getString()); | 190 getExecutionContext()->getSecurityOrigin(), url)) { |
| 191 return rejectWithMixedContentException(scriptState, url.getString()); | |
| 192 } | |
| 182 } | 193 } |
| 183 | 194 |
| 184 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) | 195 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) |
| 185 return rejectWithSandBoxException(scriptState); | 196 return rejectWithSandBoxException(scriptState); |
| 186 | 197 |
| 187 WebPresentationClient* client = presentationClient(getExecutionContext()); | 198 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 188 if (!client) | 199 if (!client) |
| 189 return ScriptPromise::rejectWithDOMException( | 200 return ScriptPromise::rejectWithDOMException( |
| 190 scriptState, | 201 scriptState, |
| 191 DOMException::create( | 202 DOMException::create( |
| 192 InvalidStateError, | 203 InvalidStateError, |
| 193 "The PresentationRequest is no longer associated to a frame.")); | 204 "The PresentationRequest is no longer associated to a frame.")); |
| 194 | 205 |
| 195 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 206 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 196 client->getAvailability( | 207 client->getAvailability( |
| 197 m_url, | 208 m_urls, |
| 198 WTF::makeUnique<PresentationAvailabilityCallbacks>(resolver, m_url)); | 209 WTF::makeUnique<PresentationAvailabilityCallbacks>(resolver, m_urls)); |
| 199 return resolver->promise(); | 210 return resolver->promise(); |
| 200 } | 211 } |
| 201 | 212 |
| 202 const KURL& PresentationRequest::url() const { | 213 const WTF::Vector<KURL>& PresentationRequest::urls() const { |
| 203 return m_url; | 214 return m_urls; |
| 204 } | 215 } |
| 205 | 216 |
| 206 DEFINE_TRACE(PresentationRequest) { | 217 DEFINE_TRACE(PresentationRequest) { |
| 207 EventTargetWithInlineData::trace(visitor); | 218 EventTargetWithInlineData::trace(visitor); |
| 208 ActiveDOMObject::trace(visitor); | 219 ActiveDOMObject::trace(visitor); |
| 209 } | 220 } |
| 210 | 221 |
| 211 PresentationRequest::PresentationRequest(ExecutionContext* executionContext, | 222 PresentationRequest::PresentationRequest(ExecutionContext* executionContext, |
| 212 const KURL& url) | 223 const WTF::Vector<KURL>& urls) |
| 213 : ActiveScriptWrappable(this), | 224 : ActiveScriptWrappable(this), |
| 214 ActiveDOMObject(executionContext), | 225 ActiveDOMObject(executionContext), |
| 215 m_url(url) {} | 226 m_urls(urls) {} |
| 216 | 227 |
| 217 } // namespace blink | 228 } // namespace blink |
| OLD | NEW |