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 28 matching lines...) Expand all Loading... | |
| 39 return controller ? controller->client() : nullptr; | 39 return controller ? controller->client() : nullptr; |
| 40 } | 40 } |
| 41 | 41 |
| 42 Settings* settings(ExecutionContext* executionContext) { | 42 Settings* settings(ExecutionContext* executionContext) { |
| 43 DCHECK(executionContext); | 43 DCHECK(executionContext); |
| 44 | 44 |
| 45 Document* document = toDocument(executionContext); | 45 Document* document = toDocument(executionContext); |
| 46 return document->settings(); | 46 return document->settings(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 ScriptPromise rejectWithMixedContentException(ScriptState* scriptState, | |
| 50 const String& url) { | |
| 51 return ScriptPromise::rejectWithDOMException( | |
| 52 scriptState, | |
| 53 DOMException::create(SecurityError, | |
| 54 "Presentation of an insecure document [" + url + | |
| 55 "] is prohibited from a secure context.")); | |
| 56 } | |
| 57 | |
| 58 ScriptPromise rejectWithSandBoxException(ScriptState* scriptState) { | 49 ScriptPromise rejectWithSandBoxException(ScriptState* scriptState) { |
| 59 return ScriptPromise::rejectWithDOMException( | 50 return ScriptPromise::rejectWithDOMException( |
| 60 scriptState, DOMException::create(SecurityError, | 51 scriptState, DOMException::create(SecurityError, |
| 61 "The document is sandboxed and lacks " | 52 "The document is sandboxed and lacks " |
| 62 "the 'allow-presentation' flag.")); | 53 "the 'allow-presentation' flag.")); |
| 63 } | 54 } |
| 64 | 55 |
| 65 } // anonymous namespace | 56 } // anonymous namespace |
| 66 | 57 |
| 67 // static | 58 // static |
| 68 PresentationRequest* PresentationRequest::create( | 59 PresentationRequest* PresentationRequest::create( |
| 69 ExecutionContext* executionContext, | 60 ExecutionContext* executionContext, |
| 70 const String& url, | 61 const String& url, |
| 71 ExceptionState& exceptionState) { | 62 ExceptionState& exceptionState) { |
| 72 KURL parsedUrl = KURL(executionContext->url(), url); | 63 WTF::Vector<String> urls(1); |
| 73 if (!parsedUrl.isValid() || parsedUrl.protocolIsAbout()) { | 64 urls[0] = url; |
| 74 exceptionState.throwTypeError("'" + url + | 65 return create(executionContext, urls, exceptionState); |
| 75 "' can't be resolved to a valid URL."); | 66 } |
| 76 return nullptr; | 67 |
| 68 PresentationRequest* PresentationRequest::create( | |
| 69 ExecutionContext* executionContext, | |
| 70 const WTF::Vector<String>& urls, | |
| 71 ExceptionState& exceptionState) { | |
| 72 WTF::Vector<KURL> parsedUrls(urls.size()); | |
| 73 for (size_t i = 0; i < urls.size(); ++i) { | |
| 74 const KURL& parsedUrl = KURL(executionContext->url(), urls[i]); | |
| 75 | |
| 76 if (!parsedUrl.isValid() || parsedUrl.protocolIsAbout()) { | |
| 77 exceptionState.throwDOMException( | |
| 78 SyntaxError, "'" + urls[i] + "' can't be resolved to a valid URL."); | |
| 79 return nullptr; | |
| 80 } | |
| 81 | |
| 82 if (MixedContentChecker::isMixedContent( | |
| 83 executionContext->getSecurityOrigin(), parsedUrl)) { | |
| 84 exceptionState.throwDOMException( | |
| 85 SecurityError, "Presentation of an insecure document [" + urls[i] + | |
| 86 "] is prohibited from a secure context."); | |
| 87 return nullptr; | |
| 88 } | |
| 89 | |
| 90 parsedUrls[i] = parsedUrl; | |
| 77 } | 91 } |
| 78 | |
| 79 PresentationRequest* request = | 92 PresentationRequest* request = |
| 80 new PresentationRequest(executionContext, parsedUrl); | 93 new PresentationRequest(executionContext, parsedUrls); |
| 81 request->suspendIfNeeded(); | 94 request->suspendIfNeeded(); |
| 82 return request; | 95 return request; |
| 83 } | 96 } |
| 84 | 97 |
| 85 const AtomicString& PresentationRequest::interfaceName() const { | 98 const AtomicString& PresentationRequest::interfaceName() const { |
| 86 return EventTargetNames::PresentationRequest; | 99 return EventTargetNames::PresentationRequest; |
| 87 } | 100 } |
| 88 | 101 |
| 89 ExecutionContext* PresentationRequest::getExecutionContext() const { | 102 ExecutionContext* PresentationRequest::getExecutionContext() const { |
| 90 return ActiveDOMObject::getExecutionContext(); | 103 return ActiveDOMObject::getExecutionContext(); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 114 bool isUserGestureRequired = | 127 bool isUserGestureRequired = |
| 115 !contextSettings || contextSettings->presentationRequiresUserGesture(); | 128 !contextSettings || contextSettings->presentationRequiresUserGesture(); |
| 116 | 129 |
| 117 if (isUserGestureRequired && !UserGestureIndicator::utilizeUserGesture()) | 130 if (isUserGestureRequired && !UserGestureIndicator::utilizeUserGesture()) |
| 118 return ScriptPromise::rejectWithDOMException( | 131 return ScriptPromise::rejectWithDOMException( |
| 119 scriptState, | 132 scriptState, |
| 120 DOMException::create( | 133 DOMException::create( |
| 121 InvalidAccessError, | 134 InvalidAccessError, |
| 122 "PresentationRequest::start() requires user gesture.")); | 135 "PresentationRequest::start() requires user gesture.")); |
| 123 | 136 |
| 124 if (MixedContentChecker::isMixedContent( | |
| 125 getExecutionContext()->getSecurityOrigin(), m_url)) { | |
| 126 return rejectWithMixedContentException(scriptState, m_url.getString()); | |
| 127 } | |
|
mlamouri (slow - plz ping)
2016/12/13 13:50:53
You are fixing another bug here, right? Should it
zhaobin
2016/12/14 01:51:54
Done.
| |
| 128 | |
| 129 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) | 137 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) |
| 130 return rejectWithSandBoxException(scriptState); | 138 return rejectWithSandBoxException(scriptState); |
| 131 | 139 |
| 132 WebPresentationClient* client = presentationClient(getExecutionContext()); | 140 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 133 if (!client) | 141 if (!client) |
| 134 return ScriptPromise::rejectWithDOMException( | 142 return ScriptPromise::rejectWithDOMException( |
| 135 scriptState, | 143 scriptState, |
| 136 DOMException::create( | 144 DOMException::create( |
| 137 InvalidStateError, | 145 InvalidStateError, |
| 138 "The PresentationRequest is no longer associated to a frame.")); | 146 "The PresentationRequest is no longer associated to a frame.")); |
| 139 | 147 |
| 140 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 148 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( | 149 client->startSession( |
| 145 presentationUrls, | 150 m_urls, WTF::makeUnique<PresentationConnectionCallbacks>(resolver, this)); |
| 146 WTF::makeUnique<PresentationConnectionCallbacks>(resolver, this)); | |
| 147 return resolver->promise(); | 151 return resolver->promise(); |
| 148 } | 152 } |
| 149 | 153 |
| 150 ScriptPromise PresentationRequest::reconnect(ScriptState* scriptState, | 154 ScriptPromise PresentationRequest::reconnect(ScriptState* scriptState, |
| 151 const String& id) { | 155 const String& id) { |
| 152 if (MixedContentChecker::isMixedContent( | |
| 153 getExecutionContext()->getSecurityOrigin(), m_url)) { | |
| 154 return rejectWithMixedContentException(scriptState, m_url.getString()); | |
| 155 } | |
| 156 | |
| 157 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) | 156 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) |
| 158 return rejectWithSandBoxException(scriptState); | 157 return rejectWithSandBoxException(scriptState); |
| 159 | 158 |
| 160 WebPresentationClient* client = presentationClient(getExecutionContext()); | 159 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 161 if (!client) | 160 if (!client) |
| 162 return ScriptPromise::rejectWithDOMException( | 161 return ScriptPromise::rejectWithDOMException( |
| 163 scriptState, | 162 scriptState, |
| 164 DOMException::create( | 163 DOMException::create( |
| 165 InvalidStateError, | 164 InvalidStateError, |
| 166 "The PresentationRequest is no longer associated to a frame.")); | 165 "The PresentationRequest is no longer associated to a frame.")); |
| 167 | 166 |
| 168 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 167 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( | 168 client->joinSession( |
| 173 presentationUrls, id, | 169 m_urls, id, |
| 174 WTF::makeUnique<PresentationConnectionCallbacks>(resolver, this)); | 170 WTF::makeUnique<PresentationConnectionCallbacks>(resolver, this)); |
| 175 return resolver->promise(); | 171 return resolver->promise(); |
| 176 } | 172 } |
| 177 | 173 |
| 178 ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) { | 174 ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) { |
| 179 if (MixedContentChecker::isMixedContent( | |
| 180 getExecutionContext()->getSecurityOrigin(), m_url)) { | |
| 181 return rejectWithMixedContentException(scriptState, m_url.getString()); | |
| 182 } | |
| 183 | |
| 184 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) | 175 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) |
| 185 return rejectWithSandBoxException(scriptState); | 176 return rejectWithSandBoxException(scriptState); |
| 186 | 177 |
| 187 WebPresentationClient* client = presentationClient(getExecutionContext()); | 178 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 188 if (!client) | 179 if (!client) |
| 189 return ScriptPromise::rejectWithDOMException( | 180 return ScriptPromise::rejectWithDOMException( |
| 190 scriptState, | 181 scriptState, |
| 191 DOMException::create( | 182 DOMException::create( |
| 192 InvalidStateError, | 183 InvalidStateError, |
| 193 "The PresentationRequest is no longer associated to a frame.")); | 184 "The PresentationRequest is no longer associated to a frame.")); |
| 194 | 185 |
| 195 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 186 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 196 client->getAvailability( | 187 client->getAvailability( |
| 197 m_url, | 188 m_urls, |
| 198 WTF::makeUnique<PresentationAvailabilityCallbacks>(resolver, m_url)); | 189 WTF::makeUnique<PresentationAvailabilityCallbacks>(resolver, m_urls)); |
| 199 return resolver->promise(); | 190 return resolver->promise(); |
| 200 } | 191 } |
| 201 | 192 |
| 202 const KURL& PresentationRequest::url() const { | 193 const WTF::Vector<KURL>& PresentationRequest::urls() const { |
| 203 return m_url; | 194 return m_urls; |
| 204 } | 195 } |
| 205 | 196 |
| 206 DEFINE_TRACE(PresentationRequest) { | 197 DEFINE_TRACE(PresentationRequest) { |
| 207 EventTargetWithInlineData::trace(visitor); | 198 EventTargetWithInlineData::trace(visitor); |
| 208 ActiveDOMObject::trace(visitor); | 199 ActiveDOMObject::trace(visitor); |
| 209 } | 200 } |
| 210 | 201 |
| 211 PresentationRequest::PresentationRequest(ExecutionContext* executionContext, | 202 PresentationRequest::PresentationRequest(ExecutionContext* executionContext, |
| 212 const KURL& url) | 203 const WTF::Vector<KURL>& urls) |
| 213 : ActiveScriptWrappable(this), | 204 : ActiveScriptWrappable(this), |
| 214 ActiveDOMObject(executionContext), | 205 ActiveDOMObject(executionContext), |
| 215 m_url(url) {} | 206 m_urls(urls) {} |
| 216 | 207 |
| 217 } // namespace blink | 208 } // namespace blink |
| OLD | NEW |