tor-browser

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

nsFontFaceLoader.h (2371B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      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 /* code for loading in @font-face defined font data */
      8 
      9 #ifndef nsFontFaceLoader_h_
     10 #define nsFontFaceLoader_h_
     11 
     12 #include "gfxUserFontSet.h"
     13 #include "mozilla/Attributes.h"
     14 #include "mozilla/TimeStamp.h"
     15 #include "mozilla/dom/FontFaceSetImpl.h"
     16 #include "nsCOMPtr.h"
     17 #include "nsHashKeys.h"
     18 #include "nsIChannel.h"
     19 #include "nsIFontLoadCompleteCallback.h"
     20 #include "nsIRequestObserver.h"
     21 #include "nsIStreamLoader.h"
     22 #include "nsTHashtable.h"
     23 
     24 class nsIPrincipal;
     25 class nsITimer;
     26 
     27 class nsFontFaceLoader final : public nsIStreamLoaderObserver,
     28                               public nsIRequestObserver,
     29                               public nsIFontLoadCompleteCallback {
     30 public:
     31  nsFontFaceLoader(gfxUserFontEntry* aUserFontEntry, uint32_t aSrcIndex,
     32                   mozilla::dom::FontFaceSetImpl* aFontFaceSet,
     33                   nsIChannel* aChannel);
     34 
     35  NS_DECL_ISUPPORTS
     36  NS_DECL_NSISTREAMLOADEROBSERVER
     37  NS_DECL_NSIREQUESTOBSERVER
     38 
     39  // cancel the load and remove its reference to mFontFaceSet
     40  void Cancel();
     41 
     42  void DropChannel() { mChannel = nullptr; }
     43 
     44  void StartedLoading(nsIStreamLoader* aStreamLoader);
     45 
     46  static void LoadTimerCallback(nsITimer* aTimer, void* aClosure);
     47 
     48  gfxUserFontEntry* GetUserFontEntry() const { return mUserFontEntry; }
     49 
     50  // Called by the gfxUserFontEntry once it has finished the platform font
     51  // loading.
     52  NS_IMETHODIMP FontLoadComplete() final;
     53 
     54 protected:
     55  virtual ~nsFontFaceLoader();
     56 
     57  // helper method for determining the font-display value
     58  mozilla::StyleFontDisplay GetFontDisplay();
     59 
     60 private:
     61  RefPtr<gfxUserFontEntry> mUserFontEntry;
     62  nsCOMPtr<nsIURI> mFontURI;
     63  // Cleared in FontFaceSet::~FontFaceSet, and on cancelation and such too.
     64  mozilla::dom::FontFaceSetImpl* MOZ_NON_OWNING_REF mFontFaceSet;
     65  nsCOMPtr<nsIChannel> mChannel;
     66  nsCOMPtr<nsITimer> mLoadTimer;
     67  mozilla::TimeStamp mStartTime;
     68  nsIStreamLoader* mStreamLoader;
     69  uint32_t mSrcIndex;
     70  bool mInStreamComplete = false;
     71  bool mInLoadTimerCallback = false;
     72 };
     73 
     74 #endif /* !defined(nsFontFaceLoader_h_) */