| 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 #ifndef RemotePlayback_h | 5 #ifndef RemotePlayback_h |
| 6 #define RemotePlayback_h | 6 #define RemotePlayback_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/ActiveScriptWrappable.h" | 8 #include "bindings/core/v8/ActiveScriptWrappable.h" |
| 9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
| 10 #include "bindings/core/v8/ScriptState.h" | |
| 11 #include "bindings/core/v8/TraceWrapperMember.h" | 10 #include "bindings/core/v8/TraceWrapperMember.h" |
| 12 #include "core/events/EventTarget.h" | 11 #include "core/events/EventTarget.h" |
| 13 #include "modules/ModulesExport.h" | 12 #include "modules/ModulesExport.h" |
| 14 #include "platform/heap/Handle.h" | 13 #include "platform/heap/Handle.h" |
| 15 #include "public/platform/modules/remoteplayback/WebRemotePlaybackClient.h" | 14 #include "public/platform/modules/remoteplayback/WebRemotePlaybackClient.h" |
| 16 #include "public/platform/modules/remoteplayback/WebRemotePlaybackState.h" | 15 #include "public/platform/modules/remoteplayback/WebRemotePlaybackState.h" |
| 17 #include "wtf/Compiler.h" | 16 #include "wtf/Compiler.h" |
| 18 #include "wtf/text/AtomicString.h" | 17 #include "wtf/text/AtomicString.h" |
| 19 #include "wtf/text/WTFString.h" | 18 #include "wtf/text/WTFString.h" |
| 20 | 19 |
| 21 namespace blink { | 20 namespace blink { |
| 22 | 21 |
| 23 class ExecutionContext; | 22 class ExecutionContext; |
| 24 class HTMLMediaElement; | 23 class HTMLMediaElement; |
| 25 class RemotePlaybackAvailabilityCallback; | 24 class RemotePlaybackAvailabilityCallback; |
| 26 class ScriptPromiseResolver; | 25 class ScriptPromiseResolver; |
| 26 class ScriptState; |
| 27 | 27 |
| 28 class MODULES_EXPORT RemotePlayback final | 28 class MODULES_EXPORT RemotePlayback final |
| 29 : public EventTargetWithInlineData, | 29 : public EventTargetWithInlineData, |
| 30 public ActiveScriptWrappable, | 30 public ActiveScriptWrappable, |
| 31 WTF_NON_EXPORTED_BASE(private WebRemotePlaybackClient) { | 31 WTF_NON_EXPORTED_BASE(public WebRemotePlaybackClient) { |
| 32 DEFINE_WRAPPERTYPEINFO(); | 32 DEFINE_WRAPPERTYPEINFO(); |
| 33 USING_GARBAGE_COLLECTED_MIXIN(RemotePlayback); | 33 USING_GARBAGE_COLLECTED_MIXIN(RemotePlayback); |
| 34 | 34 |
| 35 public: | 35 public: |
| 36 static RemotePlayback* create(ScriptState*, HTMLMediaElement&); | 36 static RemotePlayback* create(HTMLMediaElement&); |
| 37 | 37 |
| 38 // Notifies this object that disableRemotePlayback attribute was set on the | 38 // Notifies this object that disableRemotePlayback attribute was set on the |
| 39 // corresponding media element. | 39 // corresponding media element. |
| 40 void remotePlaybackDisabled(); | 40 void remotePlaybackDisabled(); |
| 41 | 41 |
| 42 // EventTarget implementation. | 42 // EventTarget implementation. |
| 43 const WTF::AtomicString& interfaceName() const override; | 43 const WTF::AtomicString& interfaceName() const override; |
| 44 ExecutionContext* getExecutionContext() const override; | 44 ExecutionContext* getExecutionContext() const override; |
| 45 | 45 |
| 46 // Starts notifying the page about the changes to the remote playback devices | 46 // Starts notifying the page about the changes to the remote playback devices |
| 47 // availability via the provided callback. May start the monitoring of remote | 47 // availability via the provided callback. May start the monitoring of remote |
| 48 // playback devices if it isn't running yet. | 48 // playback devices if it isn't running yet. |
| 49 ScriptPromise watchAvailability(RemotePlaybackAvailabilityCallback*); | 49 ScriptPromise watchAvailability(ScriptState*, |
| 50 RemotePlaybackAvailabilityCallback*); |
| 50 | 51 |
| 51 // Cancels updating the page via the callback specified by its id. | 52 // Cancels updating the page via the callback specified by its id. |
| 52 ScriptPromise cancelWatchAvailability(int id); | 53 ScriptPromise cancelWatchAvailability(ScriptState*, int id); |
| 53 | 54 |
| 54 // Cancels all the callbacks watching remote playback availability changes | 55 // Cancels all the callbacks watching remote playback availability changes |
| 55 // registered with this element. | 56 // registered with this element. |
| 56 ScriptPromise cancelWatchAvailability(); | 57 ScriptPromise cancelWatchAvailability(ScriptState*); |
| 57 | 58 |
| 58 // Shows the UI allowing user to change the remote playback state of the media | 59 // Shows the UI allowing user to change the remote playback state of the media |
| 59 // element (by picking a remote playback device from the list, for example). | 60 // element (by picking a remote playback device from the list, for example). |
| 60 ScriptPromise prompt(); | 61 ScriptPromise prompt(ScriptState*); |
| 61 | 62 |
| 62 String state() const; | 63 String state() const; |
| 63 | 64 |
| 64 // ScriptWrappable implementation. | 65 // ScriptWrappable implementation. |
| 65 bool hasPendingActivity() const final; | 66 bool hasPendingActivity() const final; |
| 66 | 67 |
| 67 DEFINE_ATTRIBUTE_EVENT_LISTENER(connecting); | 68 DEFINE_ATTRIBUTE_EVENT_LISTENER(connecting); |
| 68 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect); | 69 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect); |
| 69 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect); | 70 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect); |
| 70 | 71 |
| 71 DECLARE_VIRTUAL_TRACE(); | 72 DECLARE_VIRTUAL_TRACE(); |
| 72 DECLARE_VIRTUAL_TRACE_WRAPPERS(); | 73 DECLARE_VIRTUAL_TRACE_WRAPPERS(); |
| 73 | 74 |
| 74 private: | 75 private: |
| 75 friend class V8RemotePlayback; | 76 friend class V8RemotePlayback; |
| 76 friend class RemotePlaybackTest; | 77 friend class RemotePlaybackTest; |
| 77 | 78 |
| 78 explicit RemotePlayback(ScriptState*, HTMLMediaElement&); | 79 explicit RemotePlayback(HTMLMediaElement&); |
| 79 | 80 |
| 80 // Calls the specified availability callback with the current availability. | 81 // Calls the specified availability callback with the current availability. |
| 81 // Need a void() method to post it as a task. | 82 // Need a void() method to post it as a task. |
| 82 void notifyInitialAvailability(int callbackId); | 83 void notifyInitialAvailability(int callbackId); |
| 83 | 84 |
| 84 // WebRemotePlaybackClient implementation. | 85 // WebRemotePlaybackClient implementation. |
| 85 void stateChanged(WebRemotePlaybackState) override; | 86 void stateChanged(WebRemotePlaybackState) override; |
| 86 void availabilityChanged(bool available) override; | 87 void availabilityChanged(bool available) override; |
| 87 void promptCancelled() override; | 88 void promptCancelled() override; |
| 88 | 89 |
| 89 // Prevent v8 from garbage collecting the availability callbacks. | 90 // Prevent v8 from garbage collecting the availability callbacks. |
| 90 // TODO(avayvod): remove when crbug.com/468240 is fixed and the references | 91 // TODO(avayvod): remove when crbug.com/468240 is fixed and the references |
| 91 // are maintained automatically. | 92 // are maintained automatically. |
| 92 void setV8ReferencesForCallbacks(v8::Isolate*, | 93 void setV8ReferencesForCallbacks(v8::Isolate*, |
| 93 const v8::Persistent<v8::Object>& wrapper); | 94 const v8::Persistent<v8::Object>& wrapper); |
| 94 | 95 |
| 95 RefPtr<ScriptState> m_scriptState; | |
| 96 WebRemotePlaybackState m_state; | 96 WebRemotePlaybackState m_state; |
| 97 bool m_availability; | 97 bool m_availability; |
| 98 HeapHashMap<int, TraceWrapperMember<RemotePlaybackAvailabilityCallback>> | 98 HeapHashMap<int, TraceWrapperMember<RemotePlaybackAvailabilityCallback>> |
| 99 m_availabilityCallbacks; | 99 m_availabilityCallbacks; |
| 100 Member<HTMLMediaElement> m_mediaElement; | 100 Member<HTMLMediaElement> m_mediaElement; |
| 101 Member<ScriptPromiseResolver> m_promptPromiseResolver; | 101 Member<ScriptPromiseResolver> m_promptPromiseResolver; |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 } // namespace blink | 104 } // namespace blink |
| 105 | 105 |
| 106 #endif // RemotePlayback_h | 106 #endif // RemotePlayback_h |
| OLD | NEW |