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 10 matching lines...) Expand all Loading... | |
| 21 #include "modules/presentation/PresentationConnectionCallbacks.h" | 21 #include "modules/presentation/PresentationConnectionCallbacks.h" |
| 22 #include "modules/presentation/PresentationController.h" | 22 #include "modules/presentation/PresentationController.h" |
| 23 #include "modules/presentation/PresentationError.h" | 23 #include "modules/presentation/PresentationError.h" |
| 24 #include "platform/UserGestureIndicator.h" | 24 #include "platform/UserGestureIndicator.h" |
| 25 | 25 |
| 26 namespace blink { | 26 namespace blink { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // TODO(mlamouri): refactor in one common place. | 30 // TODO(mlamouri): refactor in one common place. |
| 31 WebPresentationClient* presentationClient(ExecutionContext* executionContext) { | 31 PresentationController* presentationController( |
| 32 ExecutionContext* executionContext) { | |
| 32 DCHECK(executionContext); | 33 DCHECK(executionContext); |
| 33 | 34 |
| 34 Document* document = toDocument(executionContext); | 35 Document* document = toDocument(executionContext); |
| 35 if (!document->frame()) | 36 if (!document->frame()) |
| 36 return nullptr; | 37 return nullptr; |
| 37 PresentationController* controller = | 38 return PresentationController::from(*document->frame()); |
| 38 PresentationController::from(*document->frame()); | 39 } |
| 40 | |
| 41 WebPresentationClient* presentationClient(ExecutionContext* executionContext) { | |
| 42 PresentationController* controller = presentationController(executionContext); | |
| 39 return controller ? controller->client() : nullptr; | 43 return controller ? controller->client() : nullptr; |
| 40 } | 44 } |
| 41 | 45 |
| 42 Settings* settings(ExecutionContext* executionContext) { | 46 Settings* settings(ExecutionContext* executionContext) { |
| 43 DCHECK(executionContext); | 47 DCHECK(executionContext); |
| 44 | 48 |
| 45 Document* document = toDocument(executionContext); | 49 Document* document = toDocument(executionContext); |
| 46 return document->settings(); | 50 return document->settings(); |
| 47 } | 51 } |
| 48 | 52 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 WebVector<WebURL> presentationUrls(static_cast<size_t>(1U)); | 143 WebVector<WebURL> presentationUrls(static_cast<size_t>(1U)); |
| 140 presentationUrls[0] = m_url; | 144 presentationUrls[0] = m_url; |
| 141 client->startSession( | 145 client->startSession( |
| 142 presentationUrls, | 146 presentationUrls, |
| 143 WTF::makeUnique<PresentationConnectionCallbacks>(resolver, this)); | 147 WTF::makeUnique<PresentationConnectionCallbacks>(resolver, this)); |
| 144 return resolver->promise(); | 148 return resolver->promise(); |
| 145 } | 149 } |
| 146 | 150 |
| 147 ScriptPromise PresentationRequest::reconnect(ScriptState* scriptState, | 151 ScriptPromise PresentationRequest::reconnect(ScriptState* scriptState, |
| 148 const String& id) { | 152 const String& id) { |
| 153 if (!getExecutionContext()) { | |
|
mlamouri (slow - plz ping)
2017/01/03 12:02:11
Why are you adding this check? can the ExecutionCo
zhaobin
2017/01/03 20:12:07
toDocument(getExecutionContext())->isSandboxed(...
| |
| 154 return ScriptPromise::rejectWithDOMException( | |
| 155 scriptState, | |
| 156 DOMException::create(InvalidStateError, | |
| 157 "The context is detached from the frame.")); | |
| 158 } | |
| 159 | |
| 149 if (MixedContentChecker::isMixedContent( | 160 if (MixedContentChecker::isMixedContent( |
| 150 getExecutionContext()->getSecurityOrigin(), m_url)) { | 161 getExecutionContext()->getSecurityOrigin(), m_url)) { |
| 151 return rejectWithMixedContentException(scriptState, m_url.getString()); | 162 return rejectWithMixedContentException(scriptState, m_url.getString()); |
| 152 } | 163 } |
| 153 | 164 |
| 154 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) | 165 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) |
| 155 return rejectWithSandBoxException(scriptState); | 166 return rejectWithSandBoxException(scriptState); |
| 156 | 167 |
| 157 WebPresentationClient* client = presentationClient(getExecutionContext()); | 168 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 158 if (!client) | 169 if (!client) |
| 159 return ScriptPromise::rejectWithDOMException( | 170 return ScriptPromise::rejectWithDOMException( |
| 160 scriptState, | 171 scriptState, |
| 161 DOMException::create( | 172 DOMException::create( |
| 162 InvalidStateError, | 173 InvalidStateError, |
| 163 "The PresentationRequest is no longer associated to a frame.")); | 174 "The PresentationRequest is no longer associated to a frame.")); |
| 164 | 175 |
| 165 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 176 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 166 // TODO(crbug.com/627655): Accept multiple URLs per PresentationRequest. | 177 // TODO(crbug.com/627655): Accept multiple URLs per PresentationRequest. |
| 167 WebVector<WebURL> presentationUrls(static_cast<size_t>(1U)); | 178 WebVector<WebURL> presentationUrls(static_cast<size_t>(1U)); |
| 168 presentationUrls[0] = m_url; | 179 presentationUrls[0] = m_url; |
| 169 client->joinSession( | 180 |
| 170 presentationUrls, id, | 181 PresentationController* controller = |
| 171 WTF::makeUnique<PresentationConnectionCallbacks>(resolver, this)); | 182 presentationController(getExecutionContext()); |
| 183 DCHECK(controller); | |
| 184 | |
| 185 PresentationConnection* existingConnection = | |
| 186 controller->findExistingConnection(presentationUrls, id); | |
| 187 if (existingConnection) { | |
| 188 client->joinSession( | |
| 189 presentationUrls, id, | |
| 190 WTF::makeUnique<ExistingPresentationConnectionCallbacks>( | |
| 191 resolver, existingConnection)); | |
| 192 } else { | |
| 193 client->joinSession( | |
| 194 presentationUrls, id, | |
| 195 WTF::makeUnique<PresentationConnectionCallbacks>(resolver, this)); | |
| 196 } | |
| 172 return resolver->promise(); | 197 return resolver->promise(); |
| 173 } | 198 } |
| 174 | 199 |
| 175 ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) { | 200 ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) { |
| 176 if (MixedContentChecker::isMixedContent( | 201 if (MixedContentChecker::isMixedContent( |
| 177 getExecutionContext()->getSecurityOrigin(), m_url)) { | 202 getExecutionContext()->getSecurityOrigin(), m_url)) { |
| 178 return rejectWithMixedContentException(scriptState, m_url.getString()); | 203 return rejectWithMixedContentException(scriptState, m_url.getString()); |
| 179 } | 204 } |
| 180 | 205 |
| 181 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) | 206 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 209 visitor->trace(m_availabilityProperty); | 234 visitor->trace(m_availabilityProperty); |
| 210 EventTargetWithInlineData::trace(visitor); | 235 EventTargetWithInlineData::trace(visitor); |
| 211 SuspendableObject::trace(visitor); | 236 SuspendableObject::trace(visitor); |
| 212 } | 237 } |
| 213 | 238 |
| 214 PresentationRequest::PresentationRequest(ExecutionContext* executionContext, | 239 PresentationRequest::PresentationRequest(ExecutionContext* executionContext, |
| 215 const KURL& url) | 240 const KURL& url) |
| 216 : SuspendableObject(executionContext), m_url(url) {} | 241 : SuspendableObject(executionContext), m_url(url) {} |
| 217 | 242 |
| 218 } // namespace blink | 243 } // namespace blink |
| OLD | NEW |