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