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

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

Issue 2469863002: [RemotePlayback API] Resolve/reject prompt() properly when the element is 'connected'. (Closed)
Patch Set: Fixed comments Created 4 years, 1 month 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 "bindings/modules/v8/RemotePlaybackAvailabilityCallback.h" 8 #include "bindings/modules/v8/RemotePlaybackAvailabilityCallback.h"
9 #include "core/HTMLNames.h" 9 #include "core/HTMLNames.h"
10 #include "core/dom/DOMException.h" 10 #include "core/dom/DOMException.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 if (!UserGestureIndicator::utilizeUserGesture()) { 172 if (!UserGestureIndicator::utilizeUserGesture()) {
173 resolver->reject(DOMException::create( 173 resolver->reject(DOMException::create(
174 InvalidAccessError, "RemotePlayback::prompt() requires user gesture.")); 174 InvalidAccessError, "RemotePlayback::prompt() requires user gesture."));
175 return promise; 175 return promise;
176 } 176 }
177 177
178 if (m_state == WebRemotePlaybackState::Disconnected) { 178 if (m_state == WebRemotePlaybackState::Disconnected) {
179 m_promptPromiseResolver = resolver; 179 m_promptPromiseResolver = resolver;
180 m_mediaElement->requestRemotePlayback(); 180 m_mediaElement->requestRemotePlayback();
181 } else { 181 } else {
182 m_promptPromiseResolver = resolver;
182 m_mediaElement->requestRemotePlaybackControl(); 183 m_mediaElement->requestRemotePlaybackControl();
183 // TODO(avayvod): Need to keep the resolver until user chooses to stop
184 // the remote playback (resolve) or dismisses the UI (reject).
185 // Steps 11 and 12 of the prompt() algorithm.
186 // https://crbug.com/647441
187 resolver->resolve();
188 } 184 }
189 185
190 return promise; 186 return promise;
191 } 187 }
192 188
193 String RemotePlayback::state() const { 189 String RemotePlayback::state() const {
194 return remotePlaybackStateToString(m_state); 190 return remotePlaybackStateToString(m_state);
195 } 191 }
196 192
197 bool RemotePlayback::hasPendingActivity() const { 193 bool RemotePlayback::hasPendingActivity() const {
198 return hasEventListeners() || !m_availabilityCallbacks.isEmpty() || 194 return hasEventListeners() || !m_availabilityCallbacks.isEmpty() ||
199 m_promptPromiseResolver; 195 m_promptPromiseResolver;
200 } 196 }
201 197
202 void RemotePlayback::notifyInitialAvailability(int callbackId) { 198 void RemotePlayback::notifyInitialAvailability(int callbackId) {
203 // May not find the callback if the website cancels it fast enough. 199 // May not find the callback if the website cancels it fast enough.
204 auto iter = m_availabilityCallbacks.find(callbackId); 200 auto iter = m_availabilityCallbacks.find(callbackId);
205 if (iter == m_availabilityCallbacks.end()) 201 if (iter == m_availabilityCallbacks.end())
206 return; 202 return;
207 203
208 iter->value->call(this, m_availability); 204 iter->value->call(this, m_availability);
209 } 205 }
210 206
211 void RemotePlayback::stateChanged(WebRemotePlaybackState state) { 207 void RemotePlayback::stateChanged(WebRemotePlaybackState state) {
212 // We may get a "disconnected" state change while in the "disconnected" 208 // We may get a "disconnected" state change while in the "disconnected"
213 // state if initiated connection fails. So cleanup the promise resolvers 209 // state if initiated connection fails. So cleanup the promise resolvers
214 // before checking if anything changed. 210 // before checking if anything changed.
215 // TODO(avayvod): cleanup this logic when we implementing the "connecting" 211 // TODO(avayvod): cleanup this logic when implementing the "connecting"
216 // state. 212 // state.
217 if (m_promptPromiseResolver) { 213 if (m_promptPromiseResolver) {
218 if (state != WebRemotePlaybackState::Disconnected) 214 // Changing state to Disconnected from "disconnected" or "connecting" means
219 m_promptPromiseResolver->resolve(); 215 // that establishing connection with remote playback device failed.
220 else 216 // Changing state to anything else means the state change intended by
217 // prompt() succeeded.
218 if (m_state != WebRemotePlaybackState::Connected &&
219 state == WebRemotePlaybackState::Disconnected) {
221 m_promptPromiseResolver->reject(DOMException::create( 220 m_promptPromiseResolver->reject(DOMException::create(
222 AbortError, "Failed to connect to the remote device.")); 221 AbortError, "Failed to connect to the remote device."));
222 } else {
223 m_promptPromiseResolver->resolve();
224 }
223 m_promptPromiseResolver = nullptr; 225 m_promptPromiseResolver = nullptr;
224 } 226 }
225 227
226 if (m_state == state) 228 if (m_state == state)
227 return; 229 return;
228 230
229 m_state = state; 231 m_state = state;
230 switch (m_state) { 232 switch (m_state) {
231 case WebRemotePlaybackState::Connecting: 233 case WebRemotePlaybackState::Connecting:
232 dispatchEvent(Event::create(EventTypeNames::connecting)); 234 dispatchEvent(Event::create(EventTypeNames::connecting));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 } 287 }
286 288
287 DEFINE_TRACE_WRAPPERS(RemotePlayback) { 289 DEFINE_TRACE_WRAPPERS(RemotePlayback) {
288 for (auto callback : m_availabilityCallbacks.values()) { 290 for (auto callback : m_availabilityCallbacks.values()) {
289 visitor->traceWrappers(callback); 291 visitor->traceWrappers(callback);
290 } 292 }
291 EventTargetWithInlineData::traceWrappers(visitor); 293 EventTargetWithInlineData::traceWrappers(visitor);
292 } 294 }
293 295
294 } // namespace blink 296 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698