1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 // vim:cindent:ts=2:et:sw=2:
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 "mozilla/Attributes.h"
13 #include "mozilla/TimeStamp.h"
14 #include "nsCOMPtr.h"
15 #include "nsIStreamLoader.h"
16 #include "nsIChannel.h"
17 #include "gfxUserFontSet.h"
18 #include "nsHashKeys.h"
19 #include "nsTHashtable.h"
20 #include "nsCSSRules.h"
21 
22 class nsIPrincipal;
23 
24 class nsFontFaceLoader : public nsIStreamLoaderObserver
25 {
26 public:
27   nsFontFaceLoader(gfxUserFontEntry* aFontToLoad, nsIURI* aFontURI,
28                    mozilla::dom::FontFaceSet* aFontFaceSet,
29                    nsIChannel* aChannel);
30 
31   NS_DECL_ISUPPORTS
32   NS_DECL_NSISTREAMLOADEROBSERVER
33 
34   // initiate the load
35   nsresult Init();
36   // cancel the load and remove its reference to mFontFaceSet
37   void Cancel();
38 
DropChannel()39   void DropChannel() { mChannel = nullptr; }
40 
41   void StartedLoading(nsIStreamLoader* aStreamLoader);
42 
43   static void LoadTimerCallback(nsITimer* aTimer, void* aClosure);
44 
GetUserFontEntry()45   gfxUserFontEntry* GetUserFontEntry() const { return mUserFontEntry; }
46 
47 protected:
48   virtual ~nsFontFaceLoader();
49 
50   // helper method for determining the font-display value
51   uint8_t GetFontDisplay();
52 
53 private:
54   RefPtr<gfxUserFontEntry>  mUserFontEntry;
55   nsCOMPtr<nsIURI>        mFontURI;
56   RefPtr<mozilla::dom::FontFaceSet> mFontFaceSet;
57   nsCOMPtr<nsIChannel>    mChannel;
58   nsCOMPtr<nsITimer>      mLoadTimer;
59   mozilla::TimeStamp      mStartTime;
60   nsIStreamLoader*        mStreamLoader;
61 };
62 
63 #endif /* !defined(nsFontFaceLoader_h_) */
64