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

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

Issue 1660193007: [Presentation API] Adding a flag to disable gesture check for starting presentations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
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/Document.h" 11 #include "core/dom/Document.h"
12 #include "core/dom/ExecutionContext.h" 12 #include "core/dom/ExecutionContext.h"
13 #include "core/frame/Settings.h"
13 #include "core/frame/UseCounter.h" 14 #include "core/frame/UseCounter.h"
14 #include "modules/EventTargetModules.h" 15 #include "modules/EventTargetModules.h"
15 #include "modules/presentation/PresentationAvailability.h" 16 #include "modules/presentation/PresentationAvailability.h"
16 #include "modules/presentation/PresentationAvailabilityCallbacks.h" 17 #include "modules/presentation/PresentationAvailabilityCallbacks.h"
17 #include "modules/presentation/PresentationConnection.h" 18 #include "modules/presentation/PresentationConnection.h"
18 #include "modules/presentation/PresentationConnectionCallbacks.h" 19 #include "modules/presentation/PresentationConnectionCallbacks.h"
19 #include "modules/presentation/PresentationController.h" 20 #include "modules/presentation/PresentationController.h"
20 #include "modules/presentation/PresentationError.h" 21 #include "modules/presentation/PresentationError.h"
21 #include "platform/UserGestureIndicator.h" 22 #include "platform/UserGestureIndicator.h"
22 23
23 namespace blink { 24 namespace blink {
24 25
25 namespace { 26 namespace {
26 27
27 // TODO(mlamouri): refactor in one common place. 28 // TODO(mlamouri): refactor in one common place.
28 WebPresentationClient* presentationClient(ExecutionContext* executionContext) 29 WebPresentationClient* presentationClient(ExecutionContext* executionContext)
29 { 30 {
30 ASSERT(executionContext && executionContext->isDocument()); 31 ASSERT(executionContext && executionContext->isDocument());
31 32
32 Document* document = toDocument(executionContext); 33 Document* document = toDocument(executionContext);
33 if (!document->frame()) 34 if (!document->frame())
34 return nullptr; 35 return nullptr;
35 PresentationController* controller = PresentationController::from(*document- >frame()); 36 PresentationController* controller = PresentationController::from(*document- >frame());
36 return controller ? controller->client() : nullptr; 37 return controller ? controller->client() : nullptr;
37 } 38 }
38 39
40 Settings* getSettings(ExecutionContext* executionContext)
41 {
42 ASSERT(executionContext && executionContext->isDocument());
43
44 Document* document = toDocument(executionContext);
45 return document->settings();
46 }
47
39 } // anonymous namespace 48 } // anonymous namespace
40 49
41 // static 50 // static
42 PresentationRequest* PresentationRequest::create(ExecutionContext* executionCont ext, const String& url, ExceptionState& exceptionState) 51 PresentationRequest* PresentationRequest::create(ExecutionContext* executionCont ext, const String& url, ExceptionState& exceptionState)
43 { 52 {
44 KURL parsedUrl = KURL(executionContext->url(), url); 53 KURL parsedUrl = KURL(executionContext->url(), url);
45 if (!parsedUrl.isValid() || parsedUrl.protocolIsAbout()) { 54 if (!parsedUrl.isValid() || parsedUrl.protocolIsAbout()) {
46 exceptionState.throwTypeError("'" + url + "' can't be resolved to a vali d URL."); 55 exceptionState.throwTypeError("'" + url + "' can't be resolved to a vali d URL.");
47 return nullptr; 56 return nullptr;
48 } 57 }
(...skipping 29 matching lines...) Expand all
78 // Prevents garbage collecting of this object when not hold by another 87 // Prevents garbage collecting of this object when not hold by another
79 // object but still has listeners registered. 88 // object but still has listeners registered.
80 return hasEventListeners(); 89 return hasEventListeners();
81 } 90 }
82 91
83 ScriptPromise PresentationRequest::start(ScriptState* scriptState) 92 ScriptPromise PresentationRequest::start(ScriptState* scriptState)
84 { 93 {
85 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 94 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
86 ScriptPromise promise = resolver->promise(); 95 ScriptPromise promise = resolver->promise();
87 96
88 if (!UserGestureIndicator::processingUserGesture()) { 97 Settings* settings = getSettings(executionContext());
whywhat 2016/02/04 20:39:08 I wonder if this can be null? Does similar code ch
Zhiqiang Zhang (Slow) 2016/02/05 16:20:33 See here: https://code.google.com/p/chromium/codes
98 bool bypassGestureCheck = settings && settings->presentationRequiresUserGest ure();
whywhat 2016/02/04 20:39:08 I think the name of the variable means the opposit
Zhiqiang Zhang (Slow) 2016/02/05 16:20:33 Done.
99
100 if (!bypassGestureCheck && !UserGestureIndicator::processingUserGesture()) {
89 resolver->reject(DOMException::create(InvalidAccessError, "PresentationR equest::start() requires user gesture.")); 101 resolver->reject(DOMException::create(InvalidAccessError, "PresentationR equest::start() requires user gesture."));
90 return promise; 102 return promise;
91 } 103 }
92 104
93 WebPresentationClient* client = presentationClient(executionContext()); 105 WebPresentationClient* client = presentationClient(executionContext());
94 if (!client) { 106 if (!client) {
95 resolver->reject(DOMException::create(InvalidStateError, "The Presentati onRequest is no longer associated to a frame.")); 107 resolver->reject(DOMException::create(InvalidStateError, "The Presentati onRequest is no longer associated to a frame."));
96 return promise; 108 return promise;
97 } 109 }
98 client->startSession(m_url.string(), new PresentationConnectionCallbacks(res olver, this)); 110 client->startSession(m_url.string(), new PresentationConnectionCallbacks(res olver, this));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 ActiveDOMObject::trace(visitor); 152 ActiveDOMObject::trace(visitor);
141 } 153 }
142 154
143 PresentationRequest::PresentationRequest(ExecutionContext* executionContext, con st KURL& url) 155 PresentationRequest::PresentationRequest(ExecutionContext* executionContext, con st KURL& url)
144 : ActiveDOMObject(executionContext) 156 : ActiveDOMObject(executionContext)
145 , m_url(url) 157 , m_url(url)
146 { 158 {
147 } 159 }
148 160
149 } // namespace blink 161 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698