Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 if (m_state != WebRemotePlaybackState::Connected && |
| 219 m_promptPromiseResolver->resolve(); | 215 state == WebRemotePlaybackState::Disconnected) { |
| 220 else | |
| 221 m_promptPromiseResolver->reject(DOMException::create( | 216 m_promptPromiseResolver->reject(DOMException::create( |
| 222 AbortError, "Failed to connect to the remote device.")); | 217 AbortError, "Failed to connect to the remote device.")); |
| 218 } else { | |
| 219 m_promptPromiseResolver->resolve(); | |
|
mlamouri (slow - plz ping)
2016/11/02 14:59:10
So if we go from not connected to connected or fro
whywhat
2016/11/02 21:05:00
Yes, if we go from not-connected to disconnected -
whywhat
2016/11/03 00:10:34
It becomes a bit easier to follow with the 'connec
| |
| 220 } | |
| 223 m_promptPromiseResolver = nullptr; | 221 m_promptPromiseResolver = nullptr; |
| 224 } | 222 } |
| 225 | 223 |
| 226 if (m_state == state) | 224 if (m_state == state) |
| 227 return; | 225 return; |
| 228 | 226 |
| 229 m_state = state; | 227 m_state = state; |
| 230 switch (m_state) { | 228 switch (m_state) { |
| 231 case WebRemotePlaybackState::Connecting: | 229 case WebRemotePlaybackState::Connecting: |
| 232 dispatchEvent(Event::create(EventTypeNames::connecting)); | 230 dispatchEvent(Event::create(EventTypeNames::connecting)); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 } | 283 } |
| 286 | 284 |
| 287 DEFINE_TRACE_WRAPPERS(RemotePlayback) { | 285 DEFINE_TRACE_WRAPPERS(RemotePlayback) { |
| 288 for (auto callback : m_availabilityCallbacks.values()) { | 286 for (auto callback : m_availabilityCallbacks.values()) { |
| 289 visitor->traceWrappers(callback); | 287 visitor->traceWrappers(callback); |
| 290 } | 288 } |
| 291 EventTargetWithInlineData::traceWrappers(visitor); | 289 EventTargetWithInlineData::traceWrappers(visitor); |
| 292 } | 290 } |
| 293 | 291 |
| 294 } // namespace blink | 292 } // namespace blink |
| OLD | NEW |