| 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" |
| 11 #include "core/dom/DOMException.h" | 11 #include "core/dom/DOMException.h" |
| 12 #include "core/dom/Document.h" | 12 #include "core/dom/Document.h" |
| 13 #include "core/dom/ExecutionContext.h" | 13 #include "core/dom/ExecutionContext.h" |
| 14 #include "core/frame/Settings.h" | 14 #include "core/frame/Settings.h" |
| 15 #include "core/frame/UseCounter.h" | 15 #include "core/frame/UseCounter.h" |
| 16 #include "core/loader/MixedContentChecker.h" |
| 16 #include "modules/EventTargetModules.h" | 17 #include "modules/EventTargetModules.h" |
| 17 #include "modules/presentation/PresentationAvailability.h" | 18 #include "modules/presentation/PresentationAvailability.h" |
| 18 #include "modules/presentation/PresentationAvailabilityCallbacks.h" | 19 #include "modules/presentation/PresentationAvailabilityCallbacks.h" |
| 19 #include "modules/presentation/PresentationConnection.h" | 20 #include "modules/presentation/PresentationConnection.h" |
| 20 #include "modules/presentation/PresentationConnectionCallbacks.h" | 21 #include "modules/presentation/PresentationConnectionCallbacks.h" |
| 21 #include "modules/presentation/PresentationController.h" | 22 #include "modules/presentation/PresentationController.h" |
| 22 #include "modules/presentation/PresentationError.h" | 23 #include "modules/presentation/PresentationError.h" |
| 23 #include "platform/UserGestureIndicator.h" | 24 #include "platform/UserGestureIndicator.h" |
| 24 | 25 |
| 25 namespace blink { | 26 namespace blink { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 38 return controller ? controller->client() : nullptr; | 39 return controller ? controller->client() : nullptr; |
| 39 } | 40 } |
| 40 | 41 |
| 41 Settings* settings(ExecutionContext* executionContext) { | 42 Settings* settings(ExecutionContext* executionContext) { |
| 42 DCHECK(executionContext); | 43 DCHECK(executionContext); |
| 43 | 44 |
| 44 Document* document = toDocument(executionContext); | 45 Document* document = toDocument(executionContext); |
| 45 return document->settings(); | 46 return document->settings(); |
| 46 } | 47 } |
| 47 | 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) { |
| 59 return ScriptPromise::rejectWithDOMException( |
| 60 scriptState, DOMException::create(SecurityError, |
| 61 "The document is sandboxed and lacks " |
| 62 "the 'allow-presentation' flag.")); |
| 63 } |
| 64 |
| 48 } // anonymous namespace | 65 } // anonymous namespace |
| 49 | 66 |
| 50 // static | 67 // static |
| 51 PresentationRequest* PresentationRequest::create( | 68 PresentationRequest* PresentationRequest::create( |
| 52 ExecutionContext* executionContext, | 69 ExecutionContext* executionContext, |
| 53 const String& url, | 70 const String& url, |
| 54 ExceptionState& exceptionState) { | 71 ExceptionState& exceptionState) { |
| 55 KURL parsedUrl = KURL(executionContext->url(), url); | 72 KURL parsedUrl = KURL(executionContext->url(), url); |
| 56 if (!parsedUrl.isValid() || parsedUrl.protocolIsAbout()) { | 73 if (!parsedUrl.isValid() || parsedUrl.protocolIsAbout()) { |
| 57 exceptionState.throwTypeError("'" + url + | 74 exceptionState.throwTypeError("'" + url + |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 bool isUserGestureRequired = | 115 bool isUserGestureRequired = |
| 99 !contextSettings || contextSettings->presentationRequiresUserGesture(); | 116 !contextSettings || contextSettings->presentationRequiresUserGesture(); |
| 100 | 117 |
| 101 if (isUserGestureRequired && !UserGestureIndicator::utilizeUserGesture()) | 118 if (isUserGestureRequired && !UserGestureIndicator::utilizeUserGesture()) |
| 102 return ScriptPromise::rejectWithDOMException( | 119 return ScriptPromise::rejectWithDOMException( |
| 103 scriptState, | 120 scriptState, |
| 104 DOMException::create( | 121 DOMException::create( |
| 105 InvalidAccessError, | 122 InvalidAccessError, |
| 106 "PresentationRequest::start() requires user gesture.")); | 123 "PresentationRequest::start() requires user gesture.")); |
| 107 | 124 |
| 125 if (MixedContentChecker::isMixedContent( |
| 126 getExecutionContext()->getSecurityOrigin(), m_url)) { |
| 127 return rejectWithMixedContentException(scriptState, m_url.getString()); |
| 128 } |
| 129 |
| 108 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) | 130 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) |
| 109 return ScriptPromise::rejectWithDOMException( | 131 return rejectWithSandBoxException(scriptState); |
| 110 scriptState, DOMException::create(SecurityError, | |
| 111 "The document is sandboxed and lacks " | |
| 112 "the 'allow-presentation' flag.")); | |
| 113 | 132 |
| 114 WebPresentationClient* client = presentationClient(getExecutionContext()); | 133 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 115 if (!client) | 134 if (!client) |
| 116 return ScriptPromise::rejectWithDOMException( | 135 return ScriptPromise::rejectWithDOMException( |
| 117 scriptState, | 136 scriptState, |
| 118 DOMException::create( | 137 DOMException::create( |
| 119 InvalidStateError, | 138 InvalidStateError, |
| 120 "The PresentationRequest is no longer associated to a frame.")); | 139 "The PresentationRequest is no longer associated to a frame.")); |
| 121 | 140 |
| 122 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 141 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 123 // TODO(crbug.com/627655): Accept multiple URLs per PresentationRequest. | 142 // TODO(crbug.com/627655): Accept multiple URLs per PresentationRequest. |
| 124 WebVector<WebURL> presentationUrls(static_cast<size_t>(1U)); | 143 WebVector<WebURL> presentationUrls(static_cast<size_t>(1U)); |
| 125 presentationUrls[0] = m_url; | 144 presentationUrls[0] = m_url; |
| 126 client->startSession(presentationUrls, | 145 client->startSession(presentationUrls, |
| 127 new PresentationConnectionCallbacks(resolver, this)); | 146 new PresentationConnectionCallbacks(resolver, this)); |
| 128 return resolver->promise(); | 147 return resolver->promise(); |
| 129 } | 148 } |
| 130 | 149 |
| 131 ScriptPromise PresentationRequest::reconnect(ScriptState* scriptState, | 150 ScriptPromise PresentationRequest::reconnect(ScriptState* scriptState, |
| 132 const String& id) { | 151 const String& id) { |
| 152 if (MixedContentChecker::isMixedContent( |
| 153 getExecutionContext()->getSecurityOrigin(), m_url)) { |
| 154 return rejectWithMixedContentException(scriptState, m_url.getString()); |
| 155 } |
| 156 |
| 133 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) | 157 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) |
| 134 return ScriptPromise::rejectWithDOMException( | 158 return rejectWithSandBoxException(scriptState); |
| 135 scriptState, DOMException::create(SecurityError, | |
| 136 "The document is sandboxed and lacks " | |
| 137 "the 'allow-presentation' flag.")); | |
| 138 | 159 |
| 139 WebPresentationClient* client = presentationClient(getExecutionContext()); | 160 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 140 if (!client) | 161 if (!client) |
| 141 return ScriptPromise::rejectWithDOMException( | 162 return ScriptPromise::rejectWithDOMException( |
| 142 scriptState, | 163 scriptState, |
| 143 DOMException::create( | 164 DOMException::create( |
| 144 InvalidStateError, | 165 InvalidStateError, |
| 145 "The PresentationRequest is no longer associated to a frame.")); | 166 "The PresentationRequest is no longer associated to a frame.")); |
| 146 | 167 |
| 147 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 168 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 148 // TODO(crbug.com/627655): Accept multiple URLs per PresentationRequest. | 169 // TODO(crbug.com/627655): Accept multiple URLs per PresentationRequest. |
| 149 WebVector<WebURL> presentationUrls(static_cast<size_t>(1U)); | 170 WebVector<WebURL> presentationUrls(static_cast<size_t>(1U)); |
| 150 presentationUrls[0] = m_url; | 171 presentationUrls[0] = m_url; |
| 151 client->joinSession(presentationUrls, id, | 172 client->joinSession(presentationUrls, id, |
| 152 new PresentationConnectionCallbacks(resolver, this)); | 173 new PresentationConnectionCallbacks(resolver, this)); |
| 153 return resolver->promise(); | 174 return resolver->promise(); |
| 154 } | 175 } |
| 155 | 176 |
| 156 ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) { | 177 ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) { |
| 178 if (MixedContentChecker::isMixedContent( |
| 179 getExecutionContext()->getSecurityOrigin(), m_url)) { |
| 180 return rejectWithMixedContentException(scriptState, m_url.getString()); |
| 181 } |
| 182 |
| 157 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) | 183 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) |
| 158 return ScriptPromise::rejectWithDOMException( | 184 return rejectWithSandBoxException(scriptState); |
| 159 scriptState, DOMException::create(SecurityError, | |
| 160 "The document is sandboxed and lacks " | |
| 161 "the 'allow-presentation' flag.")); | |
| 162 | 185 |
| 163 WebPresentationClient* client = presentationClient(getExecutionContext()); | 186 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 164 if (!client) | 187 if (!client) |
| 165 return ScriptPromise::rejectWithDOMException( | 188 return ScriptPromise::rejectWithDOMException( |
| 166 scriptState, | 189 scriptState, |
| 167 DOMException::create( | 190 DOMException::create( |
| 168 InvalidStateError, | 191 InvalidStateError, |
| 169 "The PresentationRequest is no longer associated to a frame.")); | 192 "The PresentationRequest is no longer associated to a frame.")); |
| 170 | 193 |
| 171 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 194 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 183 ActiveDOMObject::trace(visitor); | 206 ActiveDOMObject::trace(visitor); |
| 184 } | 207 } |
| 185 | 208 |
| 186 PresentationRequest::PresentationRequest(ExecutionContext* executionContext, | 209 PresentationRequest::PresentationRequest(ExecutionContext* executionContext, |
| 187 const KURL& url) | 210 const KURL& url) |
| 188 : ActiveScriptWrappable(this), | 211 : ActiveScriptWrappable(this), |
| 189 ActiveDOMObject(executionContext), | 212 ActiveDOMObject(executionContext), |
| 190 m_url(url) {} | 213 m_url(url) {} |
| 191 | 214 |
| 192 } // namespace blink | 215 } // namespace blink |
| OLD | NEW |