| 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 MediaSessionActionCallback; |
| 21 | 23 |
| 22 class MODULES_EXPORT MediaSession final | 24 class MODULES_EXPORT MediaSession final |
| 23 : public EventTargetWithInlineData, | 25 : public GarbageCollectedFinalized<MediaSession>, |
| 24 public ContextLifecycleObserver, | 26 public ContextLifecycleObserver, |
| 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 setActionCallback(const String& action, MediaSessionActionCallback*); |
| 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 |
| 61 explicit MediaSession(ExecutionContext*); | 57 explicit MediaSession(ExecutionContext*); |
| 62 | 58 |
| 63 // EventTarget overrides | |
| 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 | |
| 72 // blink::mojom::blink::MediaSessionClient implementation. | 59 // blink::mojom::blink::MediaSessionClient implementation. |
| 73 void DidReceiveAction(blink::mojom::blink::MediaSessionAction) override; | 60 void DidReceiveAction(blink::mojom::blink::MediaSessionAction) override; |
| 74 | 61 |
| 62 void setV8ReferencesForCallbacks(v8::Isolate*, |
| 63 const v8::Persistent<v8::Object>& wrapper); |
| 64 |
| 75 // Returns null when the ExecutionContext is not document. | 65 // Returns null when the ExecutionContext is not document. |
| 76 mojom::blink::MediaSessionService* getService(); | 66 mojom::blink::MediaSessionService* getService(); |
| 77 | 67 |
| 78 mojom::blink::MediaSessionPlaybackState m_playbackState; | 68 mojom::blink::MediaSessionPlaybackState m_playbackState; |
| 79 Member<MediaMetadata> m_metadata; | 69 Member<MediaMetadata> m_metadata; |
| 70 HeapHashMap<String, TraceWrapperMember<MediaSessionActionCallback>> |
| 71 m_actionCallbacks; |
| 80 mojom::blink::MediaSessionServicePtr m_service; | 72 mojom::blink::MediaSessionServicePtr m_service; |
| 81 mojo::Binding<blink::mojom::blink::MediaSessionClient> m_clientBinding; | 73 mojo::Binding<blink::mojom::blink::MediaSessionClient> m_clientBinding; |
| 82 }; | 74 }; |
| 83 | 75 |
| 84 } // namespace blink | 76 } // namespace blink |
| 85 | 77 |
| 86 #endif // MediaSession_h | 78 #endif // MediaSession_h |
| OLD | NEW |