| 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" |
| 11 #include "core/dom/Document.h" | 11 #include "core/dom/Document.h" |
| 12 #include "core/dom/ExecutionContextTask.h" | 12 #include "core/dom/ExecutionContextTask.h" |
| 13 #include "core/events/Event.h" | 13 #include "core/events/Event.h" |
| 14 #include "core/html/HTMLMediaElement.h" | 14 #include "core/html/HTMLMediaElement.h" |
| 15 #include "modules/EventTargetModules.h" | 15 #include "modules/EventTargetModules.h" |
| 16 #include "platform/UserGestureIndicator.h" | 16 #include "platform/UserGestureIndicator.h" |
| 17 | 17 |
| 18 namespace blink { | 18 namespace blink { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 const AtomicString& remotePlaybackStateToString(WebRemotePlaybackState state) { | 22 const AtomicString& remotePlaybackStateToString(WebRemotePlaybackState state) { |
| 23 DEFINE_STATIC_LOCAL(const AtomicString, connectingValue, ("connecting")); |
| 23 DEFINE_STATIC_LOCAL(const AtomicString, connectedValue, ("connected")); | 24 DEFINE_STATIC_LOCAL(const AtomicString, connectedValue, ("connected")); |
| 24 DEFINE_STATIC_LOCAL(const AtomicString, disconnectedValue, ("disconnected")); | 25 DEFINE_STATIC_LOCAL(const AtomicString, disconnectedValue, ("disconnected")); |
| 25 | 26 |
| 26 switch (state) { | 27 switch (state) { |
| 28 case WebRemotePlaybackState::Connecting: |
| 29 return connectingValue; |
| 27 case WebRemotePlaybackState::Connected: | 30 case WebRemotePlaybackState::Connected: |
| 28 return connectedValue; | 31 return connectedValue; |
| 29 case WebRemotePlaybackState::Disconnected: | 32 case WebRemotePlaybackState::Disconnected: |
| 30 return disconnectedValue; | 33 return disconnectedValue; |
| 31 } | 34 } |
| 32 | 35 |
| 33 ASSERT_NOT_REACHED(); | 36 ASSERT_NOT_REACHED(); |
| 34 return disconnectedValue; | 37 return disconnectedValue; |
| 35 } | 38 } |
| 36 | 39 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 else | 214 else |
| 212 m_promptPromiseResolver->reject(DOMException::create( | 215 m_promptPromiseResolver->reject(DOMException::create( |
| 213 AbortError, "Failed to connect to the remote device.")); | 216 AbortError, "Failed to connect to the remote device.")); |
| 214 m_promptPromiseResolver = nullptr; | 217 m_promptPromiseResolver = nullptr; |
| 215 } | 218 } |
| 216 | 219 |
| 217 if (m_state == state) | 220 if (m_state == state) |
| 218 return; | 221 return; |
| 219 | 222 |
| 220 m_state = state; | 223 m_state = state; |
| 221 dispatchEvent(Event::create(EventTypeNames::statechange)); | 224 switch (m_state) { |
| 225 case WebRemotePlaybackState::Connecting: |
| 226 dispatchEvent(Event::create(EventTypeNames::connecting)); |
| 227 break; |
| 228 case WebRemotePlaybackState::Connected: |
| 229 dispatchEvent(Event::create(EventTypeNames::connect)); |
| 230 break; |
| 231 case WebRemotePlaybackState::Disconnected: |
| 232 dispatchEvent(Event::create(EventTypeNames::disconnect)); |
| 233 break; |
| 234 } |
| 222 } | 235 } |
| 223 | 236 |
| 224 void RemotePlayback::availabilityChanged(bool available) { | 237 void RemotePlayback::availabilityChanged(bool available) { |
| 225 if (m_availability == available) | 238 if (m_availability == available) |
| 226 return; | 239 return; |
| 227 | 240 |
| 228 m_availability = available; | 241 m_availability = available; |
| 229 for (auto& callback : m_availabilityCallbacks.values()) | 242 for (auto& callback : m_availabilityCallbacks.values()) |
| 230 callback->call(m_scriptState.get(), this, m_availability); | 243 callback->call(m_scriptState.get(), this, m_availability); |
| 231 } | 244 } |
| 232 | 245 |
| 233 void RemotePlayback::promptCancelled() { | 246 void RemotePlayback::promptCancelled() { |
| 234 if (!m_promptPromiseResolver) | 247 if (!m_promptPromiseResolver) |
| 235 return; | 248 return; |
| 236 | 249 |
| 237 m_promptPromiseResolver->reject( | 250 m_promptPromiseResolver->reject( |
| 238 DOMException::create(NotAllowedError, "The prompt was dismissed.")); | 251 DOMException::create(NotAllowedError, "The prompt was dismissed.")); |
| 239 m_promptPromiseResolver = nullptr; | 252 m_promptPromiseResolver = nullptr; |
| 240 } | 253 } |
| 241 | 254 |
| 242 DEFINE_TRACE(RemotePlayback) { | 255 DEFINE_TRACE(RemotePlayback) { |
| 243 visitor->trace(m_availabilityCallbacks); | 256 visitor->trace(m_availabilityCallbacks); |
| 244 visitor->trace(m_promptPromiseResolver); | 257 visitor->trace(m_promptPromiseResolver); |
| 245 visitor->trace(m_mediaElement); | 258 visitor->trace(m_mediaElement); |
| 246 EventTargetWithInlineData::trace(visitor); | 259 EventTargetWithInlineData::trace(visitor); |
| 247 } | 260 } |
| 248 | 261 |
| 249 } // namespace blink | 262 } // namespace blink |
| OLD | NEW |