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(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 |
43 // availability via the provided callback. May start the monitoring of remote | |
44 // playback devices if it isn't running yet. | |
45 ScriptPromise watchAvailability(ScriptState*, | |
46 RemotePlaybackAvailabilityCallback*); | |
47 | |
48 // Cancels updating the page via the callback specified by its id. | |
49 ScriptPromise cancelWatchAvailability(ScriptState*, int id); | |
50 | |
51 // Cancels all the callbacks watching remote playback availability changes | |
52 // registered with this element. | |
53 ScriptPromise cancelWatchAvailability(ScriptState*); | |
54 | |
55 // Shows the UI allowing user to change the remote playback state of the media | |
56 // element (by picking a remote playback device from the list, for example). | |
42 ScriptPromise prompt(ScriptState*); | 57 ScriptPromise prompt(ScriptState*); |
43 | 58 |
44 String state() const; | 59 String state() const; |
45 | 60 |
46 // ScriptWrappable implementation. | 61 // ScriptWrappable implementation. |
47 bool hasPendingActivity() const final; | 62 bool hasPendingActivity() const final; |
48 | 63 |
49 DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange); | 64 DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange); |
50 | 65 |
51 DECLARE_VIRTUAL_TRACE(); | 66 DECLARE_VIRTUAL_TRACE(); |
52 | 67 |
53 private: | 68 private: |
54 friend class RemotePlaybackTest; | 69 friend class RemotePlaybackTest; |
55 | 70 |
56 explicit RemotePlayback(HTMLMediaElement&); | 71 explicit RemotePlayback(HTMLMediaElement&); |
57 | 72 |
73 // Calls the specified availability callback with the current availability. | |
74 // Need a void() method to post it as a task. | |
Zhiqiang Zhang (Slow)
2016/10/13 15:23:11
s/Need a/Need to be a
| |
75 void notifyInitialAvailability(int callbackId); | |
76 | |
58 // WebRemotePlaybackClient implementation. | 77 // WebRemotePlaybackClient implementation. |
59 void stateChanged(WebRemotePlaybackState) override; | 78 void stateChanged(WebRemotePlaybackState) override; |
60 void availabilityChanged(bool available) override; | 79 void availabilityChanged(bool available) override; |
61 void promptCancelled() override; | 80 void promptCancelled() override; |
62 | 81 |
82 RefPtr<ScriptState> m_scriptState; | |
63 WebRemotePlaybackState m_state; | 83 WebRemotePlaybackState m_state; |
64 bool m_availability; | 84 bool m_availability; |
65 HeapVector<Member<RemotePlaybackAvailability>> m_availabilityObjects; | 85 HeapHashMap<int, Member<RemotePlaybackAvailabilityCallback>> |
86 m_availabilityCallbacks; | |
66 Member<HTMLMediaElement> m_mediaElement; | 87 Member<HTMLMediaElement> m_mediaElement; |
67 Member<ScriptPromiseResolver> m_promptPromiseResolver; | 88 Member<ScriptPromiseResolver> m_promptPromiseResolver; |
68 }; | 89 }; |
69 | 90 |
70 } // namespace blink | 91 } // namespace blink |
71 | 92 |
72 #endif // RemotePlayback_h | 93 #endif // RemotePlayback_h |
OLD | NEW |