michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: // vim:cindent:ts=2:et:sw=2: michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* code for loading in @font-face defined font data */ michael@0: michael@0: #ifndef nsFontFaceLoader_h_ michael@0: #define nsFontFaceLoader_h_ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIStreamLoader.h" michael@0: #include "nsIChannel.h" michael@0: #include "gfxUserFontSet.h" michael@0: #include "nsHashKeys.h" michael@0: #include "nsTHashtable.h" michael@0: #include "nsCSSRules.h" michael@0: michael@0: class nsPresContext; michael@0: class nsIPrincipal; michael@0: michael@0: class nsFontFaceLoader; michael@0: michael@0: // nsUserFontSet - defines the loading mechanism for downloadable fonts michael@0: class nsUserFontSet : public gfxUserFontSet michael@0: { michael@0: public: michael@0: nsUserFontSet(nsPresContext* aContext); michael@0: michael@0: // Called when this font set is no longer associated with a presentation. michael@0: void Destroy(); michael@0: michael@0: // starts loading process, creating and initializing a nsFontFaceLoader obj michael@0: // returns whether load process successfully started or not michael@0: nsresult StartLoad(gfxMixedFontFamily* aFamily, michael@0: gfxProxyFontEntry* aFontToLoad, michael@0: const gfxFontFaceSrc* aFontFaceSrc) MOZ_OVERRIDE; michael@0: michael@0: // Called by nsFontFaceLoader when the loader has completed normally. michael@0: // It's removed from the mLoaders set. michael@0: void RemoveLoader(nsFontFaceLoader* aLoader); michael@0: michael@0: bool UpdateRules(const nsTArray& aRules); michael@0: michael@0: virtual nsPresContext* GetPresContext() { return mPresContext; } michael@0: michael@0: virtual void ReplaceFontEntry(gfxMixedFontFamily* aFamily, michael@0: gfxProxyFontEntry* aProxy, michael@0: gfxFontEntry* aFontEntry) MOZ_OVERRIDE; michael@0: michael@0: nsCSSFontFaceRule* FindRuleForEntry(gfxFontEntry* aFontEntry); michael@0: michael@0: protected: michael@0: // Protected destructor, to discourage deletion outside of Release() michael@0: // (since we inherit from refcounted class gfxUserFontSet): michael@0: ~nsUserFontSet(); michael@0: michael@0: // The font-set keeps track of the collection of rules, and their michael@0: // corresponding font entries (whether proxies or real entries), michael@0: // so that we can update the set without having to throw away michael@0: // all the existing fonts. michael@0: struct FontFaceRuleRecord { michael@0: nsRefPtr mFontEntry; michael@0: nsFontFaceRuleContainer mContainer; michael@0: }; michael@0: michael@0: void InsertRule(nsCSSFontFaceRule* aRule, uint8_t aSheetType, michael@0: nsTArray& oldRules, michael@0: bool& aFontSetModified); michael@0: michael@0: virtual nsresult LogMessage(gfxMixedFontFamily* aFamily, michael@0: gfxProxyFontEntry* aProxy, michael@0: const char* aMessage, michael@0: uint32_t aFlags = nsIScriptError::errorFlag, michael@0: nsresult aStatus = NS_OK) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult CheckFontLoad(const gfxFontFaceSrc* aFontFaceSrc, michael@0: nsIPrincipal** aPrincipal, michael@0: bool* aBypassCache) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult SyncLoadFontData(gfxProxyFontEntry* aFontToLoad, michael@0: const gfxFontFaceSrc* aFontFaceSrc, michael@0: uint8_t*& aBuffer, michael@0: uint32_t& aBufferLength) MOZ_OVERRIDE; michael@0: michael@0: virtual bool GetPrivateBrowsing() MOZ_OVERRIDE; michael@0: michael@0: virtual void DoRebuildUserFontSet() MOZ_OVERRIDE; michael@0: michael@0: nsPresContext* mPresContext; // weak reference michael@0: michael@0: // Set of all loaders pointing to us. These are not strong pointers, michael@0: // but that's OK because nsFontFaceLoader always calls RemoveLoader on michael@0: // us before it dies (unless we die first). michael@0: nsTHashtable< nsPtrHashKey > mLoaders; michael@0: michael@0: nsTArray mRules; michael@0: }; michael@0: michael@0: class nsFontFaceLoader : public nsIStreamLoaderObserver michael@0: { michael@0: public: michael@0: nsFontFaceLoader(gfxMixedFontFamily* aFontFamily, michael@0: gfxProxyFontEntry* aFontToLoad, nsIURI* aFontURI, michael@0: nsUserFontSet* aFontSet, nsIChannel* aChannel); michael@0: michael@0: virtual ~nsFontFaceLoader(); michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSISTREAMLOADEROBSERVER michael@0: michael@0: // initiate the load michael@0: nsresult Init(); michael@0: // cancel the load and remove its reference to mFontSet michael@0: void Cancel(); michael@0: michael@0: void DropChannel() { mChannel = nullptr; } michael@0: michael@0: void StartedLoading(nsIStreamLoader* aStreamLoader); michael@0: michael@0: static void LoadTimerCallback(nsITimer* aTimer, void* aClosure); michael@0: michael@0: static nsresult CheckLoadAllowed(nsIPrincipal* aSourcePrincipal, michael@0: nsIURI* aTargetURI, michael@0: nsISupports* aContext); michael@0: michael@0: private: michael@0: nsRefPtr mFontFamily; michael@0: nsRefPtr mFontEntry; michael@0: nsCOMPtr mFontURI; michael@0: nsRefPtr mFontSet; michael@0: nsCOMPtr mChannel; michael@0: nsCOMPtr mLoadTimer; michael@0: michael@0: nsIStreamLoader* mStreamLoader; michael@0: }; michael@0: michael@0: #endif /* !defined(nsFontFaceLoader_h_) */