| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 return controller ? controller->client() : nullptr; | 44 return controller ? controller->client() : nullptr; |
| 45 } | 45 } |
| 46 | 46 |
| 47 Settings* settings(ExecutionContext* executionContext) { | 47 Settings* settings(ExecutionContext* executionContext) { |
| 48 DCHECK(executionContext); | 48 DCHECK(executionContext); |
| 49 | 49 |
| 50 Document* document = toDocument(executionContext); | 50 Document* document = toDocument(executionContext); |
| 51 return document->settings(); | 51 return document->settings(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 ScriptPromise rejectWithSandBoxException(ScriptState* scriptState) { | |
| 55 return ScriptPromise::rejectWithDOMException( | |
| 56 scriptState, DOMException::create(SecurityError, | |
| 57 "The document is sandboxed and lacks " | |
| 58 "the 'allow-presentation' flag.")); | |
| 59 } | |
| 60 | |
| 61 } // anonymous namespace | 54 } // anonymous namespace |
| 62 | 55 |
| 63 // static | 56 // static |
| 64 PresentationRequest* PresentationRequest::create( | 57 PresentationRequest* PresentationRequest::create( |
| 65 ExecutionContext* executionContext, | 58 ExecutionContext* executionContext, |
| 66 const String& url, | 59 const String& url, |
| 67 ExceptionState& exceptionState) { | 60 ExceptionState& exceptionState) { |
| 68 Vector<String> urls(1); | 61 Vector<String> urls(1); |
| 69 urls[0] = url; | 62 urls[0] = url; |
| 70 return create(executionContext, urls, exceptionState); | 63 return create(executionContext, urls, exceptionState); |
| 71 } | 64 } |
| 72 | 65 |
| 73 PresentationRequest* PresentationRequest::create( | 66 PresentationRequest* PresentationRequest::create( |
| 74 ExecutionContext* executionContext, | 67 ExecutionContext* executionContext, |
| 75 const Vector<String>& urls, | 68 const Vector<String>& urls, |
| 76 ExceptionState& exceptionState) { | 69 ExceptionState& exceptionState) { |
| 70 if (toDocument(executionContext)->isSandboxed(SandboxPresentation)) { |
| 71 exceptionState.throwSecurityError( |
| 72 "The document is sandboxed and lacks the 'allow-presentation' flag."); |
| 73 return nullptr; |
| 74 } |
| 75 |
| 77 if (urls.isEmpty()) { | 76 if (urls.isEmpty()) { |
| 78 exceptionState.throwDOMException(NotSupportedError, | 77 exceptionState.throwDOMException(NotSupportedError, |
| 79 "Do not support empty sequence of URLs."); | 78 "Do not support empty sequence of URLs."); |
| 80 return nullptr; | 79 return nullptr; |
| 81 } | 80 } |
| 82 | 81 |
| 83 Vector<KURL> parsedUrls(urls.size()); | 82 Vector<KURL> parsedUrls(urls.size()); |
| 84 for (size_t i = 0; i < urls.size(); ++i) { | 83 for (size_t i = 0; i < urls.size(); ++i) { |
| 85 const KURL& parsedUrl = KURL(executionContext->url(), urls[i]); | 84 const KURL& parsedUrl = KURL(executionContext->url(), urls[i]); |
| 86 | 85 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 bool isUserGestureRequired = | 132 bool isUserGestureRequired = |
| 134 !contextSettings || contextSettings->getPresentationRequiresUserGesture(); | 133 !contextSettings || contextSettings->getPresentationRequiresUserGesture(); |
| 135 | 134 |
| 136 if (isUserGestureRequired && !UserGestureIndicator::utilizeUserGesture()) | 135 if (isUserGestureRequired && !UserGestureIndicator::utilizeUserGesture()) |
| 137 return ScriptPromise::rejectWithDOMException( | 136 return ScriptPromise::rejectWithDOMException( |
| 138 scriptState, | 137 scriptState, |
| 139 DOMException::create( | 138 DOMException::create( |
| 140 InvalidAccessError, | 139 InvalidAccessError, |
| 141 "PresentationRequest::start() requires user gesture.")); | 140 "PresentationRequest::start() requires user gesture.")); |
| 142 | 141 |
| 143 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) | |
| 144 return rejectWithSandBoxException(scriptState); | |
| 145 | 142 |
| 146 WebPresentationClient* client = presentationClient(getExecutionContext()); | 143 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 147 if (!client) | 144 if (!client) |
| 148 return ScriptPromise::rejectWithDOMException( | 145 return ScriptPromise::rejectWithDOMException( |
| 149 scriptState, | 146 scriptState, |
| 150 DOMException::create( | 147 DOMException::create( |
| 151 InvalidStateError, | 148 InvalidStateError, |
| 152 "The PresentationRequest is no longer associated to a frame.")); | 149 "The PresentationRequest is no longer associated to a frame.")); |
| 153 | 150 |
| 154 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 151 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 155 client->startPresentation( | 152 client->startPresentation( |
| 156 m_urls, WTF::makeUnique<PresentationConnectionCallbacks>(resolver, this)); | 153 m_urls, WTF::makeUnique<PresentationConnectionCallbacks>(resolver, this)); |
| 157 return resolver->promise(); | 154 return resolver->promise(); |
| 158 } | 155 } |
| 159 | 156 |
| 160 ScriptPromise PresentationRequest::reconnect(ScriptState* scriptState, | 157 ScriptPromise PresentationRequest::reconnect(ScriptState* scriptState, |
| 161 const String& id) { | 158 const String& id) { |
| 162 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) | |
| 163 return rejectWithSandBoxException(scriptState); | |
| 164 | |
| 165 WebPresentationClient* client = presentationClient(getExecutionContext()); | 159 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 166 if (!client) | 160 if (!client) |
| 167 return ScriptPromise::rejectWithDOMException( | 161 return ScriptPromise::rejectWithDOMException( |
| 168 scriptState, | 162 scriptState, |
| 169 DOMException::create( | 163 DOMException::create( |
| 170 InvalidStateError, | 164 InvalidStateError, |
| 171 "The PresentationRequest is no longer associated to a frame.")); | 165 "The PresentationRequest is no longer associated to a frame.")); |
| 172 | 166 |
| 173 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 167 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 174 | 168 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 185 resolver, existingConnection)); | 179 resolver, existingConnection)); |
| 186 } else { | 180 } else { |
| 187 client->reconnectPresentation( | 181 client->reconnectPresentation( |
| 188 m_urls, id, | 182 m_urls, id, |
| 189 WTF::makeUnique<PresentationConnectionCallbacks>(resolver, this)); | 183 WTF::makeUnique<PresentationConnectionCallbacks>(resolver, this)); |
| 190 } | 184 } |
| 191 return resolver->promise(); | 185 return resolver->promise(); |
| 192 } | 186 } |
| 193 | 187 |
| 194 ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) { | 188 ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) { |
| 195 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) | |
| 196 return rejectWithSandBoxException(scriptState); | |
| 197 | |
| 198 WebPresentationClient* client = presentationClient(getExecutionContext()); | 189 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 199 if (!client) | 190 if (!client) |
| 200 return ScriptPromise::rejectWithDOMException( | 191 return ScriptPromise::rejectWithDOMException( |
| 201 scriptState, | 192 scriptState, |
| 202 DOMException::create( | 193 DOMException::create( |
| 203 InvalidStateError, | 194 InvalidStateError, |
| 204 "The PresentationRequest is no longer associated to a frame.")); | 195 "The PresentationRequest is no longer associated to a frame.")); |
| 205 | 196 |
| 206 if (!m_availabilityProperty) { | 197 if (!m_availabilityProperty) { |
| 207 m_availabilityProperty = new PresentationAvailabilityProperty( | 198 m_availabilityProperty = new PresentationAvailabilityProperty( |
| (...skipping 29 matching lines...) Expand all Loading... |
| 237 if (executionContext->isSecureContext()) { | 228 if (executionContext->isSecureContext()) { |
| 238 UseCounter::count(executionContext, | 229 UseCounter::count(executionContext, |
| 239 UseCounter::PresentationRequestSecureOrigin); | 230 UseCounter::PresentationRequestSecureOrigin); |
| 240 } else { | 231 } else { |
| 241 UseCounter::count(executionContext, | 232 UseCounter::count(executionContext, |
| 242 UseCounter::PresentationRequestInsecureOrigin); | 233 UseCounter::PresentationRequestInsecureOrigin); |
| 243 } | 234 } |
| 244 } | 235 } |
| 245 | 236 |
| 246 } // namespace blink | 237 } // namespace blink |
| OLD | NEW |