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/TraceWrapperMember.h" | 10 #include "bindings/core/v8/TraceWrapperMember.h" |
11 #include "core/dom/ExecutionContext.h" | 11 #include "core/dom/ExecutionContext.h" |
12 #include "core/events/EventTarget.h" | 12 #include "core/events/EventTarget.h" |
13 #include "modules/ModulesExport.h" | 13 #include "modules/ModulesExport.h" |
14 #include "platform/heap/Handle.h" | 14 #include "platform/heap/Handle.h" |
15 #include "platform/wtf/Compiler.h" | 15 #include "platform/wtf/Compiler.h" |
| 16 #include "platform/wtf/Functional.h" |
16 #include "platform/wtf/text/AtomicString.h" | 17 #include "platform/wtf/text/AtomicString.h" |
17 #include "platform/wtf/text/WTFString.h" | 18 #include "platform/wtf/text/WTFString.h" |
18 #include "public/platform/modules/remoteplayback/WebRemotePlaybackAvailability.h
" | 19 #include "public/platform/modules/remoteplayback/WebRemotePlaybackAvailability.h
" |
19 #include "public/platform/modules/remoteplayback/WebRemotePlaybackClient.h" | 20 #include "public/platform/modules/remoteplayback/WebRemotePlaybackClient.h" |
20 #include "public/platform/modules/remoteplayback/WebRemotePlaybackState.h" | 21 #include "public/platform/modules/remoteplayback/WebRemotePlaybackState.h" |
21 | 22 |
22 namespace blink { | 23 namespace blink { |
23 | 24 |
24 class HTMLMediaElement; | 25 class HTMLMediaElement; |
25 class RemotePlaybackAvailabilityCallback; | 26 class RemotePlaybackAvailabilityCallback; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 String state() const; | 65 String state() const; |
65 | 66 |
66 // ScriptWrappable implementation. | 67 // ScriptWrappable implementation. |
67 bool HasPendingActivity() const final; | 68 bool HasPendingActivity() const final; |
68 | 69 |
69 DEFINE_ATTRIBUTE_EVENT_LISTENER(connecting); | 70 DEFINE_ATTRIBUTE_EVENT_LISTENER(connecting); |
70 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect); | 71 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect); |
71 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect); | 72 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect); |
72 | 73 |
73 DECLARE_VIRTUAL_TRACE(); | 74 DECLARE_VIRTUAL_TRACE(); |
74 DECLARE_VIRTUAL_TRACE_WRAPPERS(); | |
75 | 75 |
76 private: | 76 private: |
| 77 friend class MediaControlCastButtonElement; |
77 friend class V8RemotePlayback; | 78 friend class V8RemotePlayback; |
78 friend class RemotePlaybackTest; | 79 friend class RemotePlaybackTest; |
79 | 80 |
| 81 // Wraps either a WTF::Closure or RemotePlaybackAvailabilityCallback object |
| 82 // to be kept in the |availability_callbacks_| map. |
| 83 class AvailabilityCallback final |
| 84 : public GarbageCollectedFinalized<AvailabilityCallback> { |
| 85 WTF_MAKE_NONCOPYABLE(AvailabilityCallback); |
| 86 |
| 87 public: |
| 88 explicit AvailabilityCallback(RemotePlaybackAvailabilityCallback*); |
| 89 explicit AvailabilityCallback(std::unique_ptr<WTF::Closure>); |
| 90 ~AvailabilityCallback() = default; |
| 91 |
| 92 void Run(RemotePlayback*, bool new_availability); |
| 93 |
| 94 DECLARE_VIRTUAL_TRACE_WRAPPERS(); |
| 95 DEFINE_INLINE_VIRTUAL_TRACE() {} |
| 96 |
| 97 private: |
| 98 // Only one of these members must be set. |
| 99 TraceWrapperMember<RemotePlaybackAvailabilityCallback> bindings_cb_; |
| 100 std::unique_ptr<WTF::Closure> internal_cb_; |
| 101 }; |
| 102 |
80 explicit RemotePlayback(HTMLMediaElement&); | 103 explicit RemotePlayback(HTMLMediaElement&); |
81 | 104 |
| 105 // The implementation of prompt(). Used by the native remote playback button. |
| 106 void PromptInternal(); |
| 107 |
| 108 // The implementation of watchAvailability() and cancelWatchAvailability(). |
| 109 int WatchAvailabilityInternal(AvailabilityCallback*); |
| 110 bool CancelWatchAvailabilityInternal(int id); |
| 111 |
| 112 WebRemotePlaybackState GetState() const { return state_; } |
| 113 |
82 // Calls the specified availability callback with the current availability. | 114 // Calls the specified availability callback with the current availability. |
83 // Need a void() method to post it as a task. | 115 // Need a void() method to post it as a task. |
84 void NotifyInitialAvailability(int callback_id); | 116 void NotifyInitialAvailability(int callback_id); |
85 | 117 |
86 // WebRemotePlaybackClient implementation. | 118 // WebRemotePlaybackClient implementation. |
87 void StateChanged(WebRemotePlaybackState) override; | 119 void StateChanged(WebRemotePlaybackState) override; |
88 void AvailabilityChanged(WebRemotePlaybackAvailability) override; | 120 void AvailabilityChanged(WebRemotePlaybackAvailability) override; |
89 void PromptCancelled() override; | 121 void PromptCancelled() override; |
90 bool RemotePlaybackAvailable() const override; | 122 bool RemotePlaybackAvailable() const override; |
91 | 123 |
92 WebRemotePlaybackState state_; | 124 WebRemotePlaybackState state_; |
93 WebRemotePlaybackAvailability availability_; | 125 WebRemotePlaybackAvailability availability_; |
94 HeapHashMap<int, TraceWrapperMember<RemotePlaybackAvailabilityCallback>> | 126 HeapHashMap<int, Member<AvailabilityCallback>> availability_callbacks_; |
95 availability_callbacks_; | |
96 Member<HTMLMediaElement> media_element_; | 127 Member<HTMLMediaElement> media_element_; |
97 Member<ScriptPromiseResolver> prompt_promise_resolver_; | 128 Member<ScriptPromiseResolver> prompt_promise_resolver_; |
98 }; | 129 }; |
99 | 130 |
100 } // namespace blink | 131 } // namespace blink |
101 | 132 |
102 #endif // RemotePlayback_h | 133 #endif // RemotePlayback_h |
OLD | NEW |