Chromium Code Reviews| Index: third_party/WebKit/Source/modules/presentation/PresentationRequest.cpp |
| diff --git a/third_party/WebKit/Source/modules/presentation/PresentationRequest.cpp b/third_party/WebKit/Source/modules/presentation/PresentationRequest.cpp |
| index c5226b152dd05baaba5ee5986703f0d1dbfdcc0f..0adf4fbf3b81eb00ca35c9128c22899ae17a2415 100644 |
| --- a/third_party/WebKit/Source/modules/presentation/PresentationRequest.cpp |
| +++ b/third_party/WebKit/Source/modules/presentation/PresentationRequest.cpp |
| @@ -69,15 +69,27 @@ PresentationRequest* PresentationRequest::create( |
| ExecutionContext* executionContext, |
| const String& url, |
| ExceptionState& exceptionState) { |
| - KURL parsedUrl = KURL(executionContext->url(), url); |
| - if (!parsedUrl.isValid() || parsedUrl.protocolIsAbout()) { |
| - exceptionState.throwTypeError("'" + url + |
| - "' can't be resolved to a valid URL."); |
| - return nullptr; |
| - } |
| + WTF::Vector<String> urls(1); |
| + urls[0] = url; |
| + return create(executionContext, urls, exceptionState); |
| +} |
| +PresentationRequest* PresentationRequest::create( |
| + ExecutionContext* executionContext, |
| + const WTF::Vector<String>& urls, |
| + ExceptionState& exceptionState) { |
| + WTF::Vector<KURL> parsedUrls(urls.size()); |
| + for (size_t i = 0; i < urls.size(); ++i) { |
| + const KURL& parsedUrl = KURL(executionContext->url(), urls[i]); |
| + if (!parsedUrl.isValid() || parsedUrl.protocolIsAbout()) { |
| + 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.
|
| + "' can't be resolved to a valid URL."); |
| + return nullptr; |
| + } |
| + parsedUrls[i] = parsedUrl; |
| + } |
| PresentationRequest* request = |
| - new PresentationRequest(executionContext, parsedUrl); |
| + new PresentationRequest(executionContext, parsedUrls); |
| request->suspendIfNeeded(); |
| return request; |
| } |
| @@ -121,9 +133,11 @@ ScriptPromise PresentationRequest::start(ScriptState* scriptState) { |
| InvalidAccessError, |
| "PresentationRequest::start() requires user gesture.")); |
| - if (MixedContentChecker::isMixedContent( |
| - getExecutionContext()->getSecurityOrigin(), m_url)) { |
| - return rejectWithMixedContentException(scriptState, m_url.getString()); |
| + 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.
|
| + if (MixedContentChecker::isMixedContent( |
| + getExecutionContext()->getSecurityOrigin(), url)) { |
| + return rejectWithMixedContentException(scriptState, url.getString()); |
| + } |
| } |
| if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) |
| @@ -138,20 +152,18 @@ ScriptPromise PresentationRequest::start(ScriptState* scriptState) { |
| "The PresentationRequest is no longer associated to a frame.")); |
| ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| - // TODO(crbug.com/627655): Accept multiple URLs per PresentationRequest. |
| - WebVector<WebURL> presentationUrls(static_cast<size_t>(1U)); |
| - presentationUrls[0] = m_url; |
| client->startSession( |
| - presentationUrls, |
| - WTF::makeUnique<PresentationConnectionCallbacks>(resolver, this)); |
| + m_urls, WTF::makeUnique<PresentationConnectionCallbacks>(resolver, this)); |
| return resolver->promise(); |
| } |
| ScriptPromise PresentationRequest::reconnect(ScriptState* scriptState, |
| const String& id) { |
| - if (MixedContentChecker::isMixedContent( |
| - getExecutionContext()->getSecurityOrigin(), m_url)) { |
| - return rejectWithMixedContentException(scriptState, m_url.getString()); |
| + for (const auto& url : m_urls) { |
| + if (MixedContentChecker::isMixedContent( |
| + getExecutionContext()->getSecurityOrigin(), url)) { |
| + return rejectWithMixedContentException(scriptState, url.getString()); |
| + } |
| } |
| if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) |
| @@ -166,19 +178,18 @@ ScriptPromise PresentationRequest::reconnect(ScriptState* scriptState, |
| "The PresentationRequest is no longer associated to a frame.")); |
| ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| - // TODO(crbug.com/627655): Accept multiple URLs per PresentationRequest. |
| - WebVector<WebURL> presentationUrls(static_cast<size_t>(1U)); |
| - presentationUrls[0] = m_url; |
| client->joinSession( |
| - presentationUrls, id, |
| + m_urls, id, |
| WTF::makeUnique<PresentationConnectionCallbacks>(resolver, this)); |
| return resolver->promise(); |
| } |
| ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) { |
| - if (MixedContentChecker::isMixedContent( |
| - getExecutionContext()->getSecurityOrigin(), m_url)) { |
| - return rejectWithMixedContentException(scriptState, m_url.getString()); |
| + for (const auto& url : m_urls) { |
| + if (MixedContentChecker::isMixedContent( |
| + getExecutionContext()->getSecurityOrigin(), url)) { |
| + return rejectWithMixedContentException(scriptState, url.getString()); |
| + } |
| } |
| if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) |
| @@ -194,13 +205,13 @@ ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) { |
| ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| client->getAvailability( |
| - m_url, |
| - WTF::makeUnique<PresentationAvailabilityCallbacks>(resolver, m_url)); |
| + m_urls, |
| + WTF::makeUnique<PresentationAvailabilityCallbacks>(resolver, m_urls)); |
| return resolver->promise(); |
| } |
| -const KURL& PresentationRequest::url() const { |
| - return m_url; |
| +const WTF::Vector<KURL>& PresentationRequest::urls() const { |
| + return m_urls; |
| } |
| DEFINE_TRACE(PresentationRequest) { |
| @@ -209,9 +220,9 @@ DEFINE_TRACE(PresentationRequest) { |
| } |
| PresentationRequest::PresentationRequest(ExecutionContext* executionContext, |
| - const KURL& url) |
| + const WTF::Vector<KURL>& urls) |
| : ActiveScriptWrappable(this), |
| ActiveDOMObject(executionContext), |
| - m_url(url) {} |
| + m_urls(urls) {} |
| } // namespace blink |