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