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

Side by Side Diff: third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp

Issue 2345863002: [Blink, RemotePlayback] Rename connect() to prompt() (Closed)
Patch Set: Rebase Created 4 years, 2 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/remoteplayback/RemotePlayback.h" 5 #include "modules/remoteplayback/RemotePlayback.h"
6 6
7 #include "bindings/core/v8/ScriptPromiseResolver.h" 7 #include "bindings/core/v8/ScriptPromiseResolver.h"
8 #include "core/dom/DOMException.h" 8 #include "core/dom/DOMException.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/events/Event.h" 10 #include "core/events/Event.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // as soon as it's created, we probably want to limit that to when the page/ element 73 // as soon as it's created, we probably want to limit that to when the page/ element
74 // is visible (see https://crbug.com/597281) and has default controls. If th ere's 74 // is visible (see https://crbug.com/597281) and has default controls. If th ere's
75 // no default controls, we should also start tracking availability on demand 75 // no default controls, we should also start tracking availability on demand
76 // meaning the Promise returned by getAvailability() will be resolved asynch ronously. 76 // meaning the Promise returned by getAvailability() will be resolved asynch ronously.
77 RemotePlaybackAvailability* availability = RemotePlaybackAvailability::take( resolver, m_availability); 77 RemotePlaybackAvailability* availability = RemotePlaybackAvailability::take( resolver, m_availability);
78 m_availabilityObjects.append(availability); 78 m_availabilityObjects.append(availability);
79 resolver->resolve(availability); 79 resolver->resolve(availability);
80 return promise; 80 return promise;
81 } 81 }
82 82
83 ScriptPromise RemotePlayback::connect(ScriptState* scriptState) 83 ScriptPromise RemotePlayback::prompt(ScriptState* scriptState)
84 { 84 {
85 // TODO(avayvod): implement steps 3, 4, 5, 8, 9 of the algorithm.
86 // https://crbug.com/647441
85 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 87 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
86 ScriptPromise promise = resolver->promise(); 88 ScriptPromise promise = resolver->promise();
87 89
88 // TODO(avayvod): should we have a separate flag to disable the user gesture 90 // TODO(avayvod): should we have a separate flag to disable the user gesture
89 // requirement (for tests) or reuse the one for the PresentationRequest::sta rt()? 91 // requirement (for tests) or reuse the one for the PresentationRequest::sta rt()?
90 if (!UserGestureIndicator::utilizeUserGesture()) { 92 if (!UserGestureIndicator::utilizeUserGesture()) {
91 resolver->reject(DOMException::create(InvalidAccessError, "RemotePlaybac k::connect() requires user gesture.")); 93 resolver->reject(DOMException::create(InvalidAccessError, "RemotePlaybac k::prompt() requires user gesture."));
92 return promise; 94 return promise;
93 } 95 }
94 96
95 if (m_state == WebRemotePlaybackState::Disconnected) { 97 if (m_state == WebRemotePlaybackState::Disconnected) {
96 m_connectPromiseResolvers.append(resolver); 98 m_promptPromiseResolvers.append(resolver);
97 m_mediaElement->requestRemotePlayback(); 99 m_mediaElement->requestRemotePlayback();
98 } else { 100 } else {
99 m_mediaElement->requestRemotePlaybackControl(); 101 m_mediaElement->requestRemotePlaybackControl();
100 resolver->resolve(false); 102 // TODO(avayvod): Need to keep the resolver until user chooses to stop
103 // the remote playback (resolve) or dismisses the UI (reject).
104 // Steps 11 and 12 of the prompt() algorithm.
105 // https://crbug.com/647441
106 resolver->resolve();
101 } 107 }
102 108
103 return promise; 109 return promise;
104 } 110 }
105 111
106 String RemotePlayback::state() const 112 String RemotePlayback::state() const
107 { 113 {
108 return remotePlaybackStateToString(m_state); 114 return remotePlaybackStateToString(m_state);
109 } 115 }
110 116
111 bool RemotePlayback::hasPendingActivity() const 117 bool RemotePlayback::hasPendingActivity() const
112 { 118 {
113 return hasEventListeners() 119 return hasEventListeners()
114 || !m_availabilityObjects.isEmpty() 120 || !m_availabilityObjects.isEmpty()
115 || !m_connectPromiseResolvers.isEmpty(); 121 || !m_promptPromiseResolvers.isEmpty();
116 } 122 }
117 123
118 void RemotePlayback::stateChanged(WebRemotePlaybackState state) 124 void RemotePlayback::stateChanged(WebRemotePlaybackState state)
119 { 125 {
120 // We may get a "disconnected" state change while in the "disconnected" 126 // We may get a "disconnected" state change while in the "disconnected"
121 // state if initiated connection fails. So cleanup the promise resolvers 127 // state if initiated connection fails. So cleanup the promise resolvers
122 // before checking if anything changed. 128 // before checking if anything changed.
123 // TODO(avayvod): cleanup this logic when we implementing the "connecting" 129 // TODO(avayvod): cleanup this logic when we implementing the "connecting"
124 // state. 130 // state.
125 if (state != WebRemotePlaybackState::Disconnected) { 131 if (state != WebRemotePlaybackState::Disconnected) {
126 for (auto& resolver : m_connectPromiseResolvers) 132 for (auto& resolver : m_promptPromiseResolvers)
127 resolver->resolve(true); 133 resolver->resolve();
128 } else { 134 } else {
129 for (auto& resolver : m_connectPromiseResolvers) 135 for (auto& resolver : m_promptPromiseResolvers)
130 resolver->reject(DOMException::create(AbortError, "Failed to connect to the remote device.")); 136 resolver->reject(DOMException::create(AbortError, "Failed to connect to the remote device."));
131 } 137 }
132 m_connectPromiseResolvers.clear(); 138 m_promptPromiseResolvers.clear();
133 139
134 if (m_state == state) 140 if (m_state == state)
135 return; 141 return;
136 142
137 m_state = state; 143 m_state = state;
138 dispatchEvent(Event::create(EventTypeNames::statechange)); 144 dispatchEvent(Event::create(EventTypeNames::statechange));
139 } 145 }
140 146
141 void RemotePlayback::availabilityChanged(bool available) 147 void RemotePlayback::availabilityChanged(bool available)
142 { 148 {
143 if (m_availability == available) 149 if (m_availability == available)
144 return; 150 return;
145 151
146 m_availability = available; 152 m_availability = available;
147 for (auto& availabilityObject : m_availabilityObjects) 153 for (auto& availabilityObject : m_availabilityObjects)
148 availabilityObject->availabilityChanged(available); 154 availabilityObject->availabilityChanged(available);
149 } 155 }
150 156
151 void RemotePlayback::connectCancelled() 157 void RemotePlayback::promptCancelled()
152 { 158 {
153 for (auto& resolver : m_connectPromiseResolvers) 159 for (auto& resolver : m_promptPromiseResolvers)
154 resolver->resolve(false); 160 resolver->resolve();
155 m_connectPromiseResolvers.clear(); 161 m_promptPromiseResolvers.clear();
156 } 162 }
157 163
158 DEFINE_TRACE(RemotePlayback) 164 DEFINE_TRACE(RemotePlayback)
159 { 165 {
160 visitor->trace(m_availabilityObjects); 166 visitor->trace(m_availabilityObjects);
161 visitor->trace(m_connectPromiseResolvers); 167 visitor->trace(m_promptPromiseResolvers);
162 visitor->trace(m_mediaElement); 168 visitor->trace(m_mediaElement);
163 EventTargetWithInlineData::trace(visitor); 169 EventTargetWithInlineData::trace(visitor);
164 } 170 }
165 171
166 } // namespace blink 172 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698