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" |
| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 bool isUserGestureRequired = | 99 bool isUserGestureRequired = |
| 99 !contextSettings || contextSettings->presentationRequiresUserGesture(); | 100 !contextSettings || contextSettings->presentationRequiresUserGesture(); |
| 100 | 101 |
| 101 if (isUserGestureRequired && !UserGestureIndicator::utilizeUserGesture()) | 102 if (isUserGestureRequired && !UserGestureIndicator::utilizeUserGesture()) |
| 102 return ScriptPromise::rejectWithDOMException( | 103 return ScriptPromise::rejectWithDOMException( |
| 103 scriptState, | 104 scriptState, |
| 104 DOMException::create( | 105 DOMException::create( |
| 105 InvalidAccessError, | 106 InvalidAccessError, |
| 106 "PresentationRequest::start() requires user gesture.")); | 107 "PresentationRequest::start() requires user gesture.")); |
| 107 | 108 |
| 109 if (MixedContentChecker::isMixedContent( | |
| 110 getExecutionContext()->getSecurityOrigin(), m_url)) | |
| 111 return rejectWithMixedContentException(scriptState); | |
| 112 | |
| 108 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) | 113 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) |
| 109 return ScriptPromise::rejectWithDOMException( | 114 return rejectWithSandBoxException(scriptState); |
| 110 scriptState, DOMException::create(SecurityError, | |
| 111 "The document is sandboxed and lacks " | |
| 112 "the 'allow-presentation' flag.")); | |
| 113 | 115 |
| 114 WebPresentationClient* client = presentationClient(getExecutionContext()); | 116 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 115 if (!client) | 117 if (!client) |
| 116 return ScriptPromise::rejectWithDOMException( | 118 return ScriptPromise::rejectWithDOMException( |
| 117 scriptState, | 119 scriptState, |
| 118 DOMException::create( | 120 DOMException::create( |
| 119 InvalidStateError, | 121 InvalidStateError, |
| 120 "The PresentationRequest is no longer associated to a frame.")); | 122 "The PresentationRequest is no longer associated to a frame.")); |
| 121 | 123 |
| 122 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 124 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 123 // TODO(crbug.com/627655): Accept multiple URLs per PresentationRequest. | 125 // TODO(crbug.com/627655): Accept multiple URLs per PresentationRequest. |
| 124 WebVector<WebURL> presentationUrls(static_cast<size_t>(1U)); | 126 WebVector<WebURL> presentationUrls(static_cast<size_t>(1U)); |
| 125 presentationUrls[0] = m_url; | 127 presentationUrls[0] = m_url; |
| 126 client->startSession(presentationUrls, | 128 client->startSession(presentationUrls, |
| 127 new PresentationConnectionCallbacks(resolver, this)); | 129 new PresentationConnectionCallbacks(resolver, this)); |
| 128 return resolver->promise(); | 130 return resolver->promise(); |
| 129 } | 131 } |
| 130 | 132 |
| 131 ScriptPromise PresentationRequest::reconnect(ScriptState* scriptState, | 133 ScriptPromise PresentationRequest::reconnect(ScriptState* scriptState, |
| 132 const String& id) { | 134 const String& id) { |
| 135 if (MixedContentChecker::isMixedContent( | |
| 136 getExecutionContext()->getSecurityOrigin(), m_url)) | |
| 137 return rejectWithMixedContentException(scriptState); | |
| 138 | |
| 133 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) | 139 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) |
| 134 return ScriptPromise::rejectWithDOMException( | 140 return rejectWithSandBoxException(scriptState); |
| 135 scriptState, DOMException::create(SecurityError, | |
| 136 "The document is sandboxed and lacks " | |
| 137 "the 'allow-presentation' flag.")); | |
| 138 | 141 |
| 139 WebPresentationClient* client = presentationClient(getExecutionContext()); | 142 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 140 if (!client) | 143 if (!client) |
| 141 return ScriptPromise::rejectWithDOMException( | 144 return ScriptPromise::rejectWithDOMException( |
| 142 scriptState, | 145 scriptState, |
| 143 DOMException::create( | 146 DOMException::create( |
| 144 InvalidStateError, | 147 InvalidStateError, |
| 145 "The PresentationRequest is no longer associated to a frame.")); | 148 "The PresentationRequest is no longer associated to a frame.")); |
| 146 | 149 |
| 147 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 150 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 148 // TODO(crbug.com/627655): Accept multiple URLs per PresentationRequest. | 151 // TODO(crbug.com/627655): Accept multiple URLs per PresentationRequest. |
| 149 WebVector<WebURL> presentationUrls(static_cast<size_t>(1U)); | 152 WebVector<WebURL> presentationUrls(static_cast<size_t>(1U)); |
| 150 presentationUrls[0] = m_url; | 153 presentationUrls[0] = m_url; |
| 151 client->joinSession(presentationUrls, id, | 154 client->joinSession(presentationUrls, id, |
| 152 new PresentationConnectionCallbacks(resolver, this)); | 155 new PresentationConnectionCallbacks(resolver, this)); |
| 153 return resolver->promise(); | 156 return resolver->promise(); |
| 154 } | 157 } |
| 155 | 158 |
| 156 ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) { | 159 ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) { |
| 160 if (MixedContentChecker::isMixedContent( | |
| 161 getExecutionContext()->getSecurityOrigin(), m_url)) | |
| 162 return rejectWithMixedContentException(scriptState); | |
| 163 | |
| 157 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) | 164 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) |
| 158 return ScriptPromise::rejectWithDOMException( | 165 return rejectWithSandBoxException(scriptState); |
| 159 scriptState, DOMException::create(SecurityError, | |
| 160 "The document is sandboxed and lacks " | |
| 161 "the 'allow-presentation' flag.")); | |
| 162 | 166 |
| 163 WebPresentationClient* client = presentationClient(getExecutionContext()); | 167 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 164 if (!client) | 168 if (!client) |
| 165 return ScriptPromise::rejectWithDOMException( | 169 return ScriptPromise::rejectWithDOMException( |
| 166 scriptState, | 170 scriptState, |
| 167 DOMException::create( | 171 DOMException::create( |
| 168 InvalidStateError, | 172 InvalidStateError, |
| 169 "The PresentationRequest is no longer associated to a frame.")); | 173 "The PresentationRequest is no longer associated to a frame.")); |
| 170 | 174 |
| 171 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 175 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 182 EventTargetWithInlineData::trace(visitor); | 186 EventTargetWithInlineData::trace(visitor); |
| 183 ActiveDOMObject::trace(visitor); | 187 ActiveDOMObject::trace(visitor); |
| 184 } | 188 } |
| 185 | 189 |
| 186 PresentationRequest::PresentationRequest(ExecutionContext* executionContext, | 190 PresentationRequest::PresentationRequest(ExecutionContext* executionContext, |
| 187 const KURL& url) | 191 const KURL& url) |
| 188 : ActiveScriptWrappable(this), | 192 : ActiveScriptWrappable(this), |
| 189 ActiveDOMObject(executionContext), | 193 ActiveDOMObject(executionContext), |
| 190 m_url(url) {} | 194 m_url(url) {} |
| 191 | 195 |
| 196 ScriptPromise PresentationRequest::rejectWithMixedContentException( | |
| 197 ScriptState* scriptState) { | |
| 198 return ScriptPromise::rejectWithDOMException( | |
| 199 scriptState, | |
| 200 DOMException::create(SecurityError, | |
| 201 "Settings prohibit mixed security contexts and " | |
| 202 "url is an a priori unauthenticated URL. Url: " + | |
|
mark a. foltz
2016/10/20 21:56:14
I would say: "Presentation of an insecure document
zhaobin
2016/10/21 03:39:02
Done.
| |
| 203 m_url.getString())); | |
| 204 } | |
| 205 | |
| 206 ScriptPromise PresentationRequest::rejectWithSandBoxException( | |
| 207 ScriptState* scriptState) { | |
| 208 return ScriptPromise::rejectWithDOMException( | |
| 209 scriptState, DOMException::create(SecurityError, | |
| 210 "The document is sandboxed and lacks " | |
| 211 "the 'allow-presentation' flag.")); | |
| 212 } | |
| 213 | |
| 192 } // namespace blink | 214 } // namespace blink |
| OLD | NEW |