tor-browser

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

ImageTrackList.h (2701B)


      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_ImageTrackList_h
      8 #define mozilla_dom_ImageTrackList_h
      9 
     10 #include "mozilla/dom/ImageDecoderBinding.h"
     11 #include "nsCycleCollectionParticipant.h"
     12 #include "nsWrapperCache.h"
     13 
     14 class nsIGlobalObject;
     15 
     16 namespace mozilla {
     17 class MediaResult;
     18 
     19 namespace image {
     20 struct DecodeFrameCountResult;
     21 struct DecodeMetadataResult;
     22 }  // namespace image
     23 
     24 namespace dom {
     25 
     26 class ImageTrack;
     27 class Promise;
     28 
     29 class ImageTrackList final : public nsISupports, public nsWrapperCache {
     30 public:
     31  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     32  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(ImageTrackList)
     33 
     34 public:
     35  ImageTrackList(nsIGlobalObject* aParent, ImageDecoder* aDecoder);
     36 
     37  void Initialize(ErrorResult& aRv);
     38  void MaybeRejectReady(const MediaResult& aResult);
     39  void Destroy();
     40  void OnMetadataSuccess(const image::DecodeMetadataResult& aMetadata);
     41  void OnFrameCountSuccess(const image::DecodeFrameCountResult& aResult);
     42  void SetSelectedIndex(int32_t aIndex, bool aSelected);
     43 
     44 protected:
     45  ~ImageTrackList();
     46 
     47 public:
     48  nsIGlobalObject* GetParentObject() const { return mParent; }
     49 
     50  JSObject* WrapObject(JSContext* aCx,
     51                       JS::Handle<JSObject*> aGivenProto) override;
     52 
     53  Promise* Ready() const { return mReadyPromise; }
     54 
     55  bool IsReady() const { return mIsReady; }
     56 
     57  uint32_t Length() const { return mTracks.Length(); }
     58 
     59  int32_t SelectedIndex() const { return mSelectedIndex; }
     60 
     61  ImageTrack* GetSelectedTrack() const {
     62    if (mSelectedIndex < 0) {
     63      return nullptr;
     64    }
     65    return mTracks[mSelectedIndex];
     66  }
     67 
     68  ImageTrack* GetDefaultTrack() const {
     69    if (mTracks.IsEmpty()) {
     70      return nullptr;
     71    }
     72    return mTracks[0];
     73  }
     74 
     75  ImageTrack* IndexedGetter(uint32_t aIndex, bool& aFound) const {
     76    if (aIndex >= mTracks.Length()) {
     77      aFound = false;
     78      return nullptr;
     79    }
     80 
     81    MOZ_ASSERT(mTracks[aIndex]);
     82    aFound = true;
     83    return mTracks[aIndex];
     84  }
     85 
     86 private:
     87  // ImageTrackList can run on either main thread or worker thread.
     88  void AssertIsOnOwningThread() const {
     89    NS_ASSERT_OWNINGTHREAD(ImageTrackList);
     90  }
     91 
     92  nsCOMPtr<nsIGlobalObject> mParent;
     93  RefPtr<ImageDecoder> mDecoder;
     94  AutoTArray<RefPtr<ImageTrack>, 1> mTracks;
     95  RefPtr<Promise> mReadyPromise;
     96  int32_t mSelectedIndex = -1;
     97  bool mIsReady = false;
     98 };
     99 
    100 }  // namespace dom
    101 }  // namespace mozilla
    102 
    103 #endif  // mozilla_dom_ImageTrackList_h