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

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: remove getExecutionContext() null check in PresentationRequest::reconnect() Created 3 years, 11 months 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
« no previous file with comments | « third_party/WebKit/Source/modules/presentation/PresentationController.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
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 "core/loader/MixedContentChecker.h"
17 #include "modules/EventTargetModules.h" 17 #include "modules/EventTargetModules.h"
18 #include "modules/presentation/ExistingPresentationConnectionCallbacks.h"
18 #include "modules/presentation/PresentationAvailability.h" 19 #include "modules/presentation/PresentationAvailability.h"
19 #include "modules/presentation/PresentationAvailabilityCallbacks.h" 20 #include "modules/presentation/PresentationAvailabilityCallbacks.h"
20 #include "modules/presentation/PresentationConnection.h" 21 #include "modules/presentation/PresentationConnection.h"
21 #include "modules/presentation/PresentationConnectionCallbacks.h" 22 #include "modules/presentation/PresentationConnectionCallbacks.h"
22 #include "modules/presentation/PresentationController.h" 23 #include "modules/presentation/PresentationController.h"
23 #include "modules/presentation/PresentationError.h" 24 #include "modules/presentation/PresentationError.h"
24 #include "platform/UserGestureIndicator.h" 25 #include "platform/UserGestureIndicator.h"
25 26
26 namespace blink { 27 namespace blink {
27 28
28 namespace { 29 namespace {
29 30
30 // TODO(mlamouri): refactor in one common place. 31 // TODO(mlamouri): refactor in one common place.
31 WebPresentationClient* presentationClient(ExecutionContext* executionContext) { 32 PresentationController* presentationController(
33 ExecutionContext* executionContext) {
32 DCHECK(executionContext); 34 DCHECK(executionContext);
33 35
34 Document* document = toDocument(executionContext); 36 Document* document = toDocument(executionContext);
35 if (!document->frame()) 37 if (!document->frame())
36 return nullptr; 38 return nullptr;
37 PresentationController* controller = 39 return PresentationController::from(*document->frame());
38 PresentationController::from(*document->frame()); 40 }
41
42 WebPresentationClient* presentationClient(ExecutionContext* executionContext) {
43 PresentationController* controller = presentationController(executionContext);
39 return controller ? controller->client() : nullptr; 44 return controller ? controller->client() : nullptr;
40 } 45 }
41 46
42 Settings* settings(ExecutionContext* executionContext) { 47 Settings* settings(ExecutionContext* executionContext) {
43 DCHECK(executionContext); 48 DCHECK(executionContext);
44 49
45 Document* document = toDocument(executionContext); 50 Document* document = toDocument(executionContext);
46 return document->settings(); 51 return document->settings();
47 } 52 }
48 53
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 return ScriptPromise::rejectWithDOMException( 161 return ScriptPromise::rejectWithDOMException(
157 scriptState, 162 scriptState,
158 DOMException::create( 163 DOMException::create(
159 InvalidStateError, 164 InvalidStateError,
160 "The PresentationRequest is no longer associated to a frame.")); 165 "The PresentationRequest is no longer associated to a frame."));
161 166
162 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 167 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
163 // TODO(crbug.com/627655): Accept multiple URLs per PresentationRequest. 168 // TODO(crbug.com/627655): Accept multiple URLs per PresentationRequest.
164 WebVector<WebURL> presentationUrls(static_cast<size_t>(1U)); 169 WebVector<WebURL> presentationUrls(static_cast<size_t>(1U));
165 presentationUrls[0] = m_url; 170 presentationUrls[0] = m_url;
166 client->joinSession( 171
167 presentationUrls, id, 172 PresentationController* controller =
168 WTF::makeUnique<PresentationConnectionCallbacks>(resolver, this)); 173 presentationController(getExecutionContext());
174 DCHECK(controller);
175
176 PresentationConnection* existingConnection =
177 controller->findExistingConnection(presentationUrls, id);
178 if (existingConnection) {
179 client->joinSession(
180 presentationUrls, id,
181 WTF::makeUnique<ExistingPresentationConnectionCallbacks>(
182 resolver, existingConnection));
183 } else {
184 client->joinSession(
185 presentationUrls, id,
186 WTF::makeUnique<PresentationConnectionCallbacks>(resolver, this));
187 }
169 return resolver->promise(); 188 return resolver->promise();
170 } 189 }
171 190
172 ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) { 191 ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) {
173 if (MixedContentChecker::isMixedContent( 192 if (MixedContentChecker::isMixedContent(
174 getExecutionContext()->getSecurityOrigin(), m_url)) { 193 getExecutionContext()->getSecurityOrigin(), m_url)) {
175 return rejectWithMixedContentException(scriptState, m_url.getString()); 194 return rejectWithMixedContentException(scriptState, m_url.getString());
176 } 195 }
177 196
178 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation)) 197 if (toDocument(getExecutionContext())->isSandboxed(SandboxPresentation))
(...skipping 27 matching lines...) Expand all
206 visitor->trace(m_availabilityProperty); 225 visitor->trace(m_availabilityProperty);
207 EventTargetWithInlineData::trace(visitor); 226 EventTargetWithInlineData::trace(visitor);
208 ContextClient::trace(visitor); 227 ContextClient::trace(visitor);
209 } 228 }
210 229
211 PresentationRequest::PresentationRequest(ExecutionContext* executionContext, 230 PresentationRequest::PresentationRequest(ExecutionContext* executionContext,
212 const KURL& url) 231 const KURL& url)
213 : ContextClient(executionContext), m_url(url) {} 232 : ContextClient(executionContext), m_url(url) {}
214 233
215 } // namespace blink 234 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/presentation/PresentationController.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698