tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MediaMetadata.h (3039B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_dom_MediaMetadata_h
      8 #define mozilla_dom_MediaMetadata_h
      9 
     10 #include "js/TypeDecls.h"
     11 #include "mozilla/dom/BindingDeclarations.h"
     12 #include "mozilla/dom/MediaSessionBinding.h"
     13 #include "nsCycleCollectionParticipant.h"
     14 #include "nsWrapperCache.h"
     15 
     16 class nsIGlobalObject;
     17 
     18 namespace mozilla {
     19 class ErrorResult;
     20 
     21 namespace dom {
     22 
     23 class MediaMetadataBase {
     24 public:
     25  MediaMetadataBase() = default;
     26  MediaMetadataBase(const nsString& aTitle, const nsString& aArtist,
     27                    const nsString& aAlbum)
     28      : mTitle(aTitle), mArtist(aArtist), mAlbum(aAlbum) {}
     29 
     30  static MediaMetadataBase EmptyData() { return MediaMetadataBase(); }
     31 
     32  nsString mTitle;
     33  nsString mArtist;
     34  nsString mAlbum;
     35  nsCString mUrl;
     36  CopyableTArray<MediaImage> mArtwork;
     37 };
     38 
     39 class MediaMetadata final : public nsISupports,
     40                            public nsWrapperCache,
     41                            private MediaMetadataBase {
     42 public:
     43  // Ref counting and cycle collection
     44  NS_DECL_CYCLE_COLLECTING_ISUPPORTS_FINAL
     45  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(MediaMetadata)
     46 
     47  // WebIDL methods
     48  nsIGlobalObject* GetParentObject() const;
     49 
     50  JSObject* WrapObject(JSContext* aCx,
     51                       JS::Handle<JSObject*> aGivenProto) override;
     52 
     53  static already_AddRefed<MediaMetadata> Constructor(
     54      const GlobalObject& aGlobal, const MediaMetadataInit& aInit,
     55      ErrorResult& aRv);
     56 
     57  void GetTitle(nsString& aRetVal) const;
     58 
     59  void SetTitle(const nsAString& aTitle);
     60 
     61  void GetArtist(nsString& aRetVal) const;
     62 
     63  void SetArtist(const nsAString& aArtist);
     64 
     65  void GetAlbum(nsString& aRetVal) const;
     66 
     67  void SetAlbum(const nsAString& aAlbum);
     68 
     69  void GetArtwork(JSContext* aCx, nsTArray<JSObject*>& aRetVal,
     70                  ErrorResult& aRv) const;
     71 
     72  void SetArtwork(JSContext* aCx, const Sequence<JSObject*>& aArtwork,
     73                  ErrorResult& aRv);
     74 
     75  // This would expose MediaMetadataBase's members as public, so use this method
     76  // carefully. Now we only use this when we want to update the metadata to the
     77  // media session controller in the chrome process.
     78  MediaMetadataBase* AsMetadataBase() { return this; }
     79 
     80 private:
     81  MediaMetadata(nsIGlobalObject* aParent, const nsString& aTitle,
     82                const nsString& aArtist, const nsString& aAlbum);
     83 
     84  ~MediaMetadata() = default;
     85 
     86  // Perform `convert artwork algorithm`. Set `mArtwork` to a converted
     87  // `aArtwork` if the conversion works, otherwise throw a type error in `aRv`.
     88  void SetArtworkInternal(const Sequence<MediaImage>& aArtwork,
     89                          ErrorResult& aRv);
     90 
     91  nsCOMPtr<nsIGlobalObject> mParent;
     92 };
     93 
     94 }  // namespace dom
     95 }  // namespace mozilla
     96 
     97 #endif  // mozilla_dom_MediaMetadata_h