MediaControlKeyManager.h (2343B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef DOM_MEDIA_MEDIACONTROL_MEDIACONTROLKEYMANAGER_H_ 6 #define DOM_MEDIA_MEDIACONTROL_MEDIACONTROLKEYMANAGER_H_ 7 8 #include "MediaControlKeySource.h" 9 #include "MediaEventSource.h" 10 #include "nsIObserver.h" 11 12 namespace mozilla::dom { 13 14 /** 15 * MediaControlKeyManager is a wrapper of MediaControlKeySource, which 16 * is used to manage creating and destroying a real media keys event source. 17 * 18 * It monitors the amount of the media controller in MediaService, and would 19 * create the event source when there is any existing controller and destroy it 20 * when there is no controller. 21 */ 22 class MediaControlKeyManager final : public MediaControlKeySource, 23 public MediaControlKeyListener { 24 public: 25 NS_INLINE_DECL_REFCOUNTING(MediaControlKeyManager, override) 26 27 MediaControlKeyManager(); 28 29 // MediaControlKeySource methods 30 bool Open() override; 31 void Close() override; 32 bool IsOpened() const override; 33 34 void SetPlaybackState(MediaSessionPlaybackState aState) override; 35 MediaSessionPlaybackState GetPlaybackState() const override; 36 37 // MediaControlKeyListener methods 38 void OnActionPerformed(const MediaControlAction& aAction) override; 39 40 void SetMediaMetadata(const MediaMetadataBase& aMetadata) override; 41 void SetSupportedMediaKeys(const MediaKeysArray& aSupportedKeys) override; 42 void SetEnableFullScreen(bool aIsEnabled) override; 43 void SetEnablePictureInPictureMode(bool aIsEnabled) override; 44 void SetPositionState(const Maybe<PositionState>& aState) override; 45 46 private: 47 ~MediaControlKeyManager(); 48 void Shutdown(); 49 50 class Observer final : public nsIObserver { 51 public: 52 NS_DECL_ISUPPORTS 53 NS_DECL_NSIOBSERVER 54 explicit Observer(MediaControlKeyManager* aManager); 55 56 protected: 57 virtual ~Observer() = default; 58 59 MediaControlKeyManager* MOZ_OWNING_REF mManager; 60 }; 61 RefPtr<Observer> mObserver; 62 void OnPreferenceChange(); 63 64 bool StartMonitoringControlKeys(); 65 void StopMonitoringControlKeys(); 66 RefPtr<MediaControlKeySource> mEventSource; 67 MediaMetadataBase mMetadata; 68 nsTArray<MediaControlKey> mSupportedKeys; 69 }; 70 71 } // namespace mozilla::dom 72 73 #endif