| 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 "core/dom/ContextLifecycleObserver.h" |
| 9 #include "core/events/EventTarget.h" | 10 #include "core/events/EventTarget.h" |
| 10 #include "modules/ModulesExport.h" | 11 #include "modules/ModulesExport.h" |
| 11 #include "mojo/public/cpp/bindings/binding.h" | 12 #include "mojo/public/cpp/bindings/binding.h" |
| 12 #include "platform/heap/Handle.h" | 13 #include "platform/heap/Handle.h" |
| 13 #include "public/platform/modules/mediasession/media_session.mojom-blink.h" | 14 #include "public/platform/modules/mediasession/media_session.mojom-blink.h" |
| 14 #include <memory> | 15 #include <memory> |
| 15 | 16 |
| 16 namespace blink { | 17 namespace blink { |
| 17 | 18 |
| 19 class ExecutionContext; |
| 18 class MediaMetadata; | 20 class MediaMetadata; |
| 19 class ScriptState; | |
| 20 | 21 |
| 21 class MODULES_EXPORT MediaSession final | 22 class MODULES_EXPORT MediaSession final |
| 22 : public EventTargetWithInlineData, | 23 : public EventTargetWithInlineData, |
| 24 public ContextLifecycleObserver, |
| 23 blink::mojom::blink::MediaSessionClient { | 25 blink::mojom::blink::MediaSessionClient { |
| 26 USING_GARBAGE_COLLECTED_MIXIN(MediaSession); |
| 24 DEFINE_WRAPPERTYPEINFO(); | 27 DEFINE_WRAPPERTYPEINFO(); |
| 25 USING_PRE_FINALIZER(MediaSession, dispose); | 28 USING_PRE_FINALIZER(MediaSession, dispose); |
| 26 | 29 |
| 27 public: | 30 public: |
| 28 static MediaSession* create(ScriptState*); | 31 static MediaSession* create(ExecutionContext*); |
| 29 | 32 |
| 30 void dispose(); | 33 void dispose(); |
| 31 | 34 |
| 32 void setMetadata(MediaMetadata*); | 35 void setMetadata(MediaMetadata*); |
| 33 MediaMetadata* metadata() const; | 36 MediaMetadata* metadata() const; |
| 34 | 37 |
| 35 // EventTarget implementation. | 38 // EventTarget implementation. |
| 36 const WTF::AtomicString& interfaceName() const override; | 39 const WTF::AtomicString& interfaceName() const override; |
| 37 ExecutionContext* getExecutionContext() const override; | 40 ExecutionContext* getExecutionContext() const override; |
| 38 | 41 |
| 39 DEFINE_ATTRIBUTE_EVENT_LISTENER(play); | 42 DEFINE_ATTRIBUTE_EVENT_LISTENER(play); |
| 40 DEFINE_ATTRIBUTE_EVENT_LISTENER(pause); | 43 DEFINE_ATTRIBUTE_EVENT_LISTENER(pause); |
| 41 DEFINE_ATTRIBUTE_EVENT_LISTENER(playpause); | 44 DEFINE_ATTRIBUTE_EVENT_LISTENER(playpause); |
| 42 DEFINE_ATTRIBUTE_EVENT_LISTENER(previoustrack); | 45 DEFINE_ATTRIBUTE_EVENT_LISTENER(previoustrack); |
| 43 DEFINE_ATTRIBUTE_EVENT_LISTENER(nexttrack); | 46 DEFINE_ATTRIBUTE_EVENT_LISTENER(nexttrack); |
| 44 DEFINE_ATTRIBUTE_EVENT_LISTENER(seekforward); | 47 DEFINE_ATTRIBUTE_EVENT_LISTENER(seekforward); |
| 45 DEFINE_ATTRIBUTE_EVENT_LISTENER(seekbackward); | 48 DEFINE_ATTRIBUTE_EVENT_LISTENER(seekbackward); |
| 46 | 49 |
| 47 DECLARE_VIRTUAL_TRACE(); | 50 DECLARE_VIRTUAL_TRACE(); |
| 48 | 51 |
| 49 private: | 52 private: |
| 50 friend class MediaSessionTest; | 53 friend class MediaSessionTest; |
| 51 | 54 |
| 52 MediaSession(ScriptState*); | 55 explicit MediaSession(ExecutionContext*); |
| 53 | 56 |
| 54 // EventTarget overrides | 57 // EventTarget overrides |
| 55 bool addEventListenerInternal( | 58 bool addEventListenerInternal( |
| 56 const AtomicString& eventType, | 59 const AtomicString& eventType, |
| 57 EventListener*, | 60 EventListener*, |
| 58 const AddEventListenerOptionsResolved&) override; | 61 const AddEventListenerOptionsResolved&) override; |
| 59 bool removeEventListenerInternal(const AtomicString& eventType, | 62 bool removeEventListenerInternal(const AtomicString& eventType, |
| 60 const EventListener*, | 63 const EventListener*, |
| 61 const EventListenerOptions&) override; | 64 const EventListenerOptions&) override; |
| 62 | 65 |
| 63 // blink::mojom::blink::MediaSessionClient implementation. | 66 // blink::mojom::blink::MediaSessionClient implementation. |
| 64 void DidReceiveAction(blink::mojom::blink::MediaSessionAction) override; | 67 void DidReceiveAction(blink::mojom::blink::MediaSessionAction) override; |
| 65 | 68 |
| 66 // Returns null when the ExecutionContext is not document. | 69 // Returns null when the ExecutionContext is not document. |
| 67 mojom::blink::MediaSessionService* getService(ScriptState*); | 70 mojom::blink::MediaSessionService* getService(); |
| 68 | 71 |
| 69 RefPtr<ScriptState> m_scriptState; | |
| 70 Member<MediaMetadata> m_metadata; | 72 Member<MediaMetadata> m_metadata; |
| 71 mojom::blink::MediaSessionServicePtr m_service; | 73 mojom::blink::MediaSessionServicePtr m_service; |
| 72 mojo::Binding<blink::mojom::blink::MediaSessionClient> m_clientBinding; | 74 mojo::Binding<blink::mojom::blink::MediaSessionClient> m_clientBinding; |
| 73 }; | 75 }; |
| 74 | 76 |
| 75 } // namespace blink | 77 } // namespace blink |
| 76 | 78 |
| 77 #endif // MediaSession_h | 79 #endif // MediaSession_h |
| OLD | NEW |