| 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 #include "platform/heap/Heap.h" |
| 17 | 18 |
| 18 namespace blink { | 19 namespace blink { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 const AtomicString& remotePlaybackStateToString(WebRemotePlaybackState state) { | 23 const AtomicString& remotePlaybackStateToString(WebRemotePlaybackState state) { |
| 23 DEFINE_STATIC_LOCAL(const AtomicString, connectingValue, ("connecting")); | 24 DEFINE_STATIC_LOCAL(const AtomicString, connectingValue, ("connecting")); |
| 24 DEFINE_STATIC_LOCAL(const AtomicString, connectedValue, ("connected")); | 25 DEFINE_STATIC_LOCAL(const AtomicString, connectedValue, ("connected")); |
| 25 DEFINE_STATIC_LOCAL(const AtomicString, disconnectedValue, ("disconnected")); | 26 DEFINE_STATIC_LOCAL(const AtomicString, disconnectedValue, ("disconnected")); |
| 26 | 27 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 52 } | 53 } |
| 53 | 54 |
| 54 RemotePlayback::RemotePlayback(ScriptState* scriptState, | 55 RemotePlayback::RemotePlayback(ScriptState* scriptState, |
| 55 HTMLMediaElement& element) | 56 HTMLMediaElement& element) |
| 56 : ActiveScriptWrappable(this), | 57 : ActiveScriptWrappable(this), |
| 57 m_scriptState(scriptState), | 58 m_scriptState(scriptState), |
| 58 m_state(element.isPlayingRemotely() | 59 m_state(element.isPlayingRemotely() |
| 59 ? WebRemotePlaybackState::Connected | 60 ? WebRemotePlaybackState::Connected |
| 60 : WebRemotePlaybackState::Disconnected), | 61 : WebRemotePlaybackState::Disconnected), |
| 61 m_availability(element.hasRemoteRoutes()), | 62 m_availability(element.hasRemoteRoutes()), |
| 62 m_mediaElement(&element) {} | 63 m_mediaElement(&element), |
| 64 m_isLowEndDevice(ProcessHeap::isLowEndDevice()) {} |
| 63 | 65 |
| 64 const AtomicString& RemotePlayback::interfaceName() const { | 66 const AtomicString& RemotePlayback::interfaceName() const { |
| 65 return EventTargetNames::RemotePlayback; | 67 return EventTargetNames::RemotePlayback; |
| 66 } | 68 } |
| 67 | 69 |
| 68 ExecutionContext* RemotePlayback::getExecutionContext() const { | 70 ExecutionContext* RemotePlayback::getExecutionContext() const { |
| 69 return &m_mediaElement->document(); | 71 return &m_mediaElement->document(); |
| 70 } | 72 } |
| 71 | 73 |
| 72 ScriptPromise RemotePlayback::watchAvailability( | 74 ScriptPromise RemotePlayback::watchAvailability( |
| 73 RemotePlaybackAvailabilityCallback* callback) { | 75 RemotePlaybackAvailabilityCallback* callback) { |
| 74 ScriptPromiseResolver* resolver = | 76 ScriptPromiseResolver* resolver = |
| 75 ScriptPromiseResolver::create(m_scriptState.get()); | 77 ScriptPromiseResolver::create(m_scriptState.get()); |
| 76 ScriptPromise promise = resolver->promise(); | 78 ScriptPromise promise = resolver->promise(); |
| 77 | 79 |
| 78 if (m_mediaElement->fastHasAttribute(HTMLNames::disableremoteplaybackAttr)) { | 80 if (m_mediaElement->fastHasAttribute(HTMLNames::disableremoteplaybackAttr)) { |
| 79 resolver->reject(DOMException::create( | 81 resolver->reject(DOMException::create( |
| 80 InvalidStateError, "disableRemotePlayback attribute is present.")); | 82 InvalidStateError, "disableRemotePlayback attribute is present.")); |
| 81 return promise; | 83 return promise; |
| 82 } | 84 } |
| 83 | 85 |
| 84 // TODO(avayvod): implement steps 4 and 5 of the algorithm. | 86 if (m_isLowEndDevice) { |
| 85 // https://crbug.com/655233 | 87 resolver->reject(DOMException::create( |
| 88 NotSupportedError, |
| 89 "Availability monitoring is not supported on this device.")); |
| 90 return promise; |
| 91 } |
| 92 |
| 86 int id; | 93 int id; |
| 87 do { | 94 do { |
| 88 id = getExecutionContext()->circularSequentialID(); | 95 id = getExecutionContext()->circularSequentialID(); |
| 89 } while (!m_availabilityCallbacks | 96 } while (!m_availabilityCallbacks |
| 90 .add(id, TraceWrapperMember<RemotePlaybackAvailabilityCallback>( | 97 .add(id, TraceWrapperMember<RemotePlaybackAvailabilityCallback>( |
| 91 this, callback)) | 98 this, callback)) |
| 92 .isNewEntry); | 99 .isNewEntry); |
| 93 | 100 |
| 94 // Report the current availability via the callback. | 101 // Report the current availability via the callback. |
| 95 getExecutionContext()->postTask( | 102 getExecutionContext()->postTask( |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 } | 294 } |
| 288 | 295 |
| 289 DEFINE_TRACE_WRAPPERS(RemotePlayback) { | 296 DEFINE_TRACE_WRAPPERS(RemotePlayback) { |
| 290 for (auto callback : m_availabilityCallbacks.values()) { | 297 for (auto callback : m_availabilityCallbacks.values()) { |
| 291 visitor->traceWrappers(callback); | 298 visitor->traceWrappers(callback); |
| 292 } | 299 } |
| 293 EventTargetWithInlineData::traceWrappers(visitor); | 300 EventTargetWithInlineData::traceWrappers(visitor); |
| 294 } | 301 } |
| 295 | 302 |
| 296 } // namespace blink | 303 } // namespace blink |
| OLD | NEW |