OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 MediaSession_h | 5 #ifndef MediaSession_h |
6 #define MediaSession_h | 6 #define MediaSession_h |
7 | 7 |
8 #include "bindings/core/v8/ScriptWrappable.h" | 8 #include "bindings/core/v8/ScriptWrappable.h" |
| 9 #include "bindings/core/v8/TraceWrapperMember.h" |
9 #include "core/dom/ContextLifecycleObserver.h" | 10 #include "core/dom/ContextLifecycleObserver.h" |
10 #include "core/events/EventTarget.h" | |
11 #include "modules/ModulesExport.h" | 11 #include "modules/ModulesExport.h" |
12 #include "mojo/public/cpp/bindings/binding.h" | 12 #include "mojo/public/cpp/bindings/binding.h" |
13 #include "platform/heap/Handle.h" | 13 #include "platform/heap/Handle.h" |
14 #include "public/platform/modules/mediasession/media_session.mojom-blink.h" | 14 #include "public/platform/modules/mediasession/media_session.mojom-blink.h" |
| 15 #include "wtf/text/WTFString.h" |
15 #include <memory> | 16 #include <memory> |
16 | 17 |
17 namespace blink { | 18 namespace blink { |
18 | 19 |
19 class ExecutionContext; | 20 class ExecutionContext; |
20 class MediaMetadata; | 21 class MediaMetadata; |
| 22 class MediaSessionActionHandler; |
21 | 23 |
22 class MODULES_EXPORT MediaSession final | 24 class MODULES_EXPORT MediaSession final |
23 : public EventTargetWithInlineData, | 25 : public GarbageCollectedFinalized<MediaSession>, |
24 public ContextClient, | 26 public ContextClient, |
| 27 public ScriptWrappable, |
25 blink::mojom::blink::MediaSessionClient { | 28 blink::mojom::blink::MediaSessionClient { |
26 USING_GARBAGE_COLLECTED_MIXIN(MediaSession); | 29 USING_GARBAGE_COLLECTED_MIXIN(MediaSession); |
27 DEFINE_WRAPPERTYPEINFO(); | 30 DEFINE_WRAPPERTYPEINFO(); |
28 USING_PRE_FINALIZER(MediaSession, dispose); | 31 USING_PRE_FINALIZER(MediaSession, dispose); |
29 | 32 |
30 public: | 33 public: |
31 static MediaSession* create(ExecutionContext*); | 34 static MediaSession* create(ExecutionContext*); |
32 | 35 |
33 void dispose(); | 36 void dispose(); |
34 | 37 |
35 void setPlaybackState(const String&); | 38 void setPlaybackState(const String&); |
36 String playbackState(); | 39 String playbackState(); |
37 | 40 |
38 void setMetadata(MediaMetadata*); | 41 void setMetadata(MediaMetadata*); |
39 MediaMetadata* metadata() const; | 42 MediaMetadata* metadata() const; |
40 | 43 |
41 // EventTarget implementation. | 44 void setActionHandler(const String& action, MediaSessionActionHandler*); |
42 const WTF::AtomicString& interfaceName() const override; | |
43 ExecutionContext* getExecutionContext() const override; | |
44 | 45 |
45 // Called by the MediaMetadata owned by |this| when it has updates. Also used | 46 // Called by the MediaMetadata owned by |this| when it has updates. Also used |
46 // internally when a new MediaMetadata object is set. | 47 // internally when a new MediaMetadata object is set. |
47 void onMetadataChanged(); | 48 void onMetadataChanged(); |
48 | 49 |
49 DEFINE_ATTRIBUTE_EVENT_LISTENER(play); | |
50 DEFINE_ATTRIBUTE_EVENT_LISTENER(pause); | |
51 DEFINE_ATTRIBUTE_EVENT_LISTENER(previoustrack); | |
52 DEFINE_ATTRIBUTE_EVENT_LISTENER(nexttrack); | |
53 DEFINE_ATTRIBUTE_EVENT_LISTENER(seekforward); | |
54 DEFINE_ATTRIBUTE_EVENT_LISTENER(seekbackward); | |
55 | |
56 DECLARE_VIRTUAL_TRACE(); | 50 DECLARE_VIRTUAL_TRACE(); |
| 51 DECLARE_VIRTUAL_TRACE_WRAPPERS(); |
57 | 52 |
58 private: | 53 private: |
| 54 friend class V8MediaSession; |
59 friend class MediaSessionTest; | 55 friend class MediaSessionTest; |
60 | 56 |
| 57 enum class ActionChangeType { |
| 58 ActionEnabled, |
| 59 ActionDisabled, |
| 60 }; |
| 61 |
61 explicit MediaSession(ExecutionContext*); | 62 explicit MediaSession(ExecutionContext*); |
62 | 63 |
63 // EventTarget overrides | 64 void notifyActionChange(const String& action, ActionChangeType); |
64 bool addEventListenerInternal( | |
65 const AtomicString& eventType, | |
66 EventListener*, | |
67 const AddEventListenerOptionsResolved&) override; | |
68 bool removeEventListenerInternal(const AtomicString& eventType, | |
69 const EventListener*, | |
70 const EventListenerOptions&) override; | |
71 | 65 |
72 // blink::mojom::blink::MediaSessionClient implementation. | 66 // blink::mojom::blink::MediaSessionClient implementation. |
73 void DidReceiveAction(blink::mojom::blink::MediaSessionAction) override; | 67 void DidReceiveAction(blink::mojom::blink::MediaSessionAction) override; |
74 | 68 |
| 69 void setV8ReferencesForHandlers(v8::Isolate*, |
| 70 const v8::Persistent<v8::Object>& wrapper); |
| 71 |
75 // Returns null when the ExecutionContext is not document. | 72 // Returns null when the ExecutionContext is not document. |
76 mojom::blink::MediaSessionService* getService(); | 73 mojom::blink::MediaSessionService* getService(); |
77 | 74 |
78 mojom::blink::MediaSessionPlaybackState m_playbackState; | 75 mojom::blink::MediaSessionPlaybackState m_playbackState; |
79 Member<MediaMetadata> m_metadata; | 76 Member<MediaMetadata> m_metadata; |
| 77 HeapHashMap<String, TraceWrapperMember<MediaSessionActionHandler>> |
| 78 m_actionHandlers; |
80 mojom::blink::MediaSessionServicePtr m_service; | 79 mojom::blink::MediaSessionServicePtr m_service; |
81 mojo::Binding<blink::mojom::blink::MediaSessionClient> m_clientBinding; | 80 mojo::Binding<blink::mojom::blink::MediaSessionClient> m_clientBinding; |
82 }; | 81 }; |
83 | 82 |
84 } // namespace blink | 83 } // namespace blink |
85 | 84 |
86 #endif // MediaSession_h | 85 #endif // MediaSession_h |
OLD | NEW |