layout/style/nsFontFaceLoader.h

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 // vim:cindent:ts=2:et:sw=2:
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 /* code for loading in @font-face defined font data */
michael@0 8
michael@0 9 #ifndef nsFontFaceLoader_h_
michael@0 10 #define nsFontFaceLoader_h_
michael@0 11
michael@0 12 #include "mozilla/Attributes.h"
michael@0 13 #include "nsCOMPtr.h"
michael@0 14 #include "nsIStreamLoader.h"
michael@0 15 #include "nsIChannel.h"
michael@0 16 #include "gfxUserFontSet.h"
michael@0 17 #include "nsHashKeys.h"
michael@0 18 #include "nsTHashtable.h"
michael@0 19 #include "nsCSSRules.h"
michael@0 20
michael@0 21 class nsPresContext;
michael@0 22 class nsIPrincipal;
michael@0 23
michael@0 24 class nsFontFaceLoader;
michael@0 25
michael@0 26 // nsUserFontSet - defines the loading mechanism for downloadable fonts
michael@0 27 class nsUserFontSet : public gfxUserFontSet
michael@0 28 {
michael@0 29 public:
michael@0 30 nsUserFontSet(nsPresContext* aContext);
michael@0 31
michael@0 32 // Called when this font set is no longer associated with a presentation.
michael@0 33 void Destroy();
michael@0 34
michael@0 35 // starts loading process, creating and initializing a nsFontFaceLoader obj
michael@0 36 // returns whether load process successfully started or not
michael@0 37 nsresult StartLoad(gfxMixedFontFamily* aFamily,
michael@0 38 gfxProxyFontEntry* aFontToLoad,
michael@0 39 const gfxFontFaceSrc* aFontFaceSrc) MOZ_OVERRIDE;
michael@0 40
michael@0 41 // Called by nsFontFaceLoader when the loader has completed normally.
michael@0 42 // It's removed from the mLoaders set.
michael@0 43 void RemoveLoader(nsFontFaceLoader* aLoader);
michael@0 44
michael@0 45 bool UpdateRules(const nsTArray<nsFontFaceRuleContainer>& aRules);
michael@0 46
michael@0 47 virtual nsPresContext* GetPresContext() { return mPresContext; }
michael@0 48
michael@0 49 virtual void ReplaceFontEntry(gfxMixedFontFamily* aFamily,
michael@0 50 gfxProxyFontEntry* aProxy,
michael@0 51 gfxFontEntry* aFontEntry) MOZ_OVERRIDE;
michael@0 52
michael@0 53 nsCSSFontFaceRule* FindRuleForEntry(gfxFontEntry* aFontEntry);
michael@0 54
michael@0 55 protected:
michael@0 56 // Protected destructor, to discourage deletion outside of Release()
michael@0 57 // (since we inherit from refcounted class gfxUserFontSet):
michael@0 58 ~nsUserFontSet();
michael@0 59
michael@0 60 // The font-set keeps track of the collection of rules, and their
michael@0 61 // corresponding font entries (whether proxies or real entries),
michael@0 62 // so that we can update the set without having to throw away
michael@0 63 // all the existing fonts.
michael@0 64 struct FontFaceRuleRecord {
michael@0 65 nsRefPtr<gfxFontEntry> mFontEntry;
michael@0 66 nsFontFaceRuleContainer mContainer;
michael@0 67 };
michael@0 68
michael@0 69 void InsertRule(nsCSSFontFaceRule* aRule, uint8_t aSheetType,
michael@0 70 nsTArray<FontFaceRuleRecord>& oldRules,
michael@0 71 bool& aFontSetModified);
michael@0 72
michael@0 73 virtual nsresult LogMessage(gfxMixedFontFamily* aFamily,
michael@0 74 gfxProxyFontEntry* aProxy,
michael@0 75 const char* aMessage,
michael@0 76 uint32_t aFlags = nsIScriptError::errorFlag,
michael@0 77 nsresult aStatus = NS_OK) MOZ_OVERRIDE;
michael@0 78
michael@0 79 virtual nsresult CheckFontLoad(const gfxFontFaceSrc* aFontFaceSrc,
michael@0 80 nsIPrincipal** aPrincipal,
michael@0 81 bool* aBypassCache) MOZ_OVERRIDE;
michael@0 82
michael@0 83 virtual nsresult SyncLoadFontData(gfxProxyFontEntry* aFontToLoad,
michael@0 84 const gfxFontFaceSrc* aFontFaceSrc,
michael@0 85 uint8_t*& aBuffer,
michael@0 86 uint32_t& aBufferLength) MOZ_OVERRIDE;
michael@0 87
michael@0 88 virtual bool GetPrivateBrowsing() MOZ_OVERRIDE;
michael@0 89
michael@0 90 virtual void DoRebuildUserFontSet() MOZ_OVERRIDE;
michael@0 91
michael@0 92 nsPresContext* mPresContext; // weak reference
michael@0 93
michael@0 94 // Set of all loaders pointing to us. These are not strong pointers,
michael@0 95 // but that's OK because nsFontFaceLoader always calls RemoveLoader on
michael@0 96 // us before it dies (unless we die first).
michael@0 97 nsTHashtable< nsPtrHashKey<nsFontFaceLoader> > mLoaders;
michael@0 98
michael@0 99 nsTArray<FontFaceRuleRecord> mRules;
michael@0 100 };
michael@0 101
michael@0 102 class nsFontFaceLoader : public nsIStreamLoaderObserver
michael@0 103 {
michael@0 104 public:
michael@0 105 nsFontFaceLoader(gfxMixedFontFamily* aFontFamily,
michael@0 106 gfxProxyFontEntry* aFontToLoad, nsIURI* aFontURI,
michael@0 107 nsUserFontSet* aFontSet, nsIChannel* aChannel);
michael@0 108
michael@0 109 virtual ~nsFontFaceLoader();
michael@0 110
michael@0 111 NS_DECL_ISUPPORTS
michael@0 112 NS_DECL_NSISTREAMLOADEROBSERVER
michael@0 113
michael@0 114 // initiate the load
michael@0 115 nsresult Init();
michael@0 116 // cancel the load and remove its reference to mFontSet
michael@0 117 void Cancel();
michael@0 118
michael@0 119 void DropChannel() { mChannel = nullptr; }
michael@0 120
michael@0 121 void StartedLoading(nsIStreamLoader* aStreamLoader);
michael@0 122
michael@0 123 static void LoadTimerCallback(nsITimer* aTimer, void* aClosure);
michael@0 124
michael@0 125 static nsresult CheckLoadAllowed(nsIPrincipal* aSourcePrincipal,
michael@0 126 nsIURI* aTargetURI,
michael@0 127 nsISupports* aContext);
michael@0 128
michael@0 129 private:
michael@0 130 nsRefPtr<gfxMixedFontFamily> mFontFamily;
michael@0 131 nsRefPtr<gfxProxyFontEntry> mFontEntry;
michael@0 132 nsCOMPtr<nsIURI> mFontURI;
michael@0 133 nsRefPtr<nsUserFontSet> mFontSet;
michael@0 134 nsCOMPtr<nsIChannel> mChannel;
michael@0 135 nsCOMPtr<nsITimer> mLoadTimer;
michael@0 136
michael@0 137 nsIStreamLoader* mStreamLoader;
michael@0 138 };
michael@0 139
michael@0 140 #endif /* !defined(nsFontFaceLoader_h_) */

mercurial