Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/WebKit/Source/modules/presentation/PresentationRequest.cpp

Issue 2602523002: [Presentation API] Resolve PresentationRequest::reconnect() with existing presentation connection i… (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 return ScriptPromise::rejectWithDOMException( 163 return ScriptPromise::rejectWithDOMException(
160 scriptState, 164 scriptState,
161 DOMException::create( 165 DOMException::create(
162 InvalidStateError, 166 InvalidStateError,
163 "The PresentationRequest is no longer associated to a frame.")); 167 "The PresentationRequest is no longer associated to a frame."));
164 168
165 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 169 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
166 // TODO(crbug.com/627655): Accept multiple URLs per PresentationRequest. 170 // TODO(crbug.com/627655): Accept multiple URLs per PresentationRequest.
167 WebVector<WebURL> presentationUrls(static_cast<size_t>(1U)); 171 WebVector<WebURL> presentationUrls(static_cast<size_t>(1U));
168 presentationUrls[0] = m_url; 172 presentationUrls[0] = m_url;
169 client->joinSession( 173
170 presentationUrls, id, 174 PresentationController* controller =
171 WTF::makeUnique<PresentationConnectionCallbacks>(resolver, this)); 175 presentationController(getExecutionContext());
haraken 2016/12/23 14:26:10 Not related to this CL, getExecutionContext() retu
zhaobin 2016/12/30 05:05:00 Done.
176 DCHECK(controller);
177
178 PresentationConnection* existingConnection =
179 controller->findExistingConnection(presentationUrls, id);
180 if (existingConnection) {
181 client->joinSession(
182 presentationUrls, id,
183 WTF::makeUnique<ExistingPresentationConnectionCallbacks>(
184 resolver, existingConnection));
185 } else {
186 client->joinSession(
187 presentationUrls, id,
188 WTF::makeUnique<PresentationConnectionCallbacks>(resolver, this));
189 }
172 return resolver->promise(); 190 return resolver->promise();
173 } 191 }
174 192
175 ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) { 193 ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) {
176 if (MixedContentChecker::isMixedContent( 194 if (MixedContentChecker::isMixedContent(
177 getExecutionContext()->getSecurityOrigin(), m_url)) { 195 getExecutionContext()->getSecurityOrigin(), m_url)) {
178 return rejectWithMixedContentException(scriptState, m_url.getString()); 196 return rejectWithMixedContentException(scriptState, m_url.getString());
179 } 197 }
180 198
181 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) 199 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation))
(...skipping 27 matching lines...) Expand all
209 visitor->trace(m_availabilityProperty); 227 visitor->trace(m_availabilityProperty);
210 EventTargetWithInlineData::trace(visitor); 228 EventTargetWithInlineData::trace(visitor);
211 SuspendableObject::trace(visitor); 229 SuspendableObject::trace(visitor);
212 } 230 }
213 231
214 PresentationRequest::PresentationRequest(ExecutionContext* executionContext, 232 PresentationRequest::PresentationRequest(ExecutionContext* executionContext,
215 const KURL& url) 233 const KURL& url)
216 : SuspendableObject(executionContext), m_url(url) {} 234 : SuspendableObject(executionContext), m_url(url) {}
217 235
218 } // namespace blink 236 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698