layout/style/nsFontFaceLoader.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/style/nsFontFaceLoader.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,140 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +// vim:cindent:ts=2:et:sw=2:
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +/* code for loading in @font-face defined font data */
    1.11 +
    1.12 +#ifndef nsFontFaceLoader_h_
    1.13 +#define nsFontFaceLoader_h_
    1.14 +
    1.15 +#include "mozilla/Attributes.h"
    1.16 +#include "nsCOMPtr.h"
    1.17 +#include "nsIStreamLoader.h"
    1.18 +#include "nsIChannel.h"
    1.19 +#include "gfxUserFontSet.h"
    1.20 +#include "nsHashKeys.h"
    1.21 +#include "nsTHashtable.h"
    1.22 +#include "nsCSSRules.h"
    1.23 +
    1.24 +class nsPresContext;
    1.25 +class nsIPrincipal;
    1.26 +
    1.27 +class nsFontFaceLoader;
    1.28 +
    1.29 +// nsUserFontSet - defines the loading mechanism for downloadable fonts
    1.30 +class nsUserFontSet : public gfxUserFontSet
    1.31 +{
    1.32 +public:
    1.33 +  nsUserFontSet(nsPresContext* aContext);
    1.34 +
    1.35 +  // Called when this font set is no longer associated with a presentation.
    1.36 +  void Destroy();
    1.37 +
    1.38 +  // starts loading process, creating and initializing a nsFontFaceLoader obj
    1.39 +  // returns whether load process successfully started or not
    1.40 +  nsresult StartLoad(gfxMixedFontFamily* aFamily,
    1.41 +                     gfxProxyFontEntry* aFontToLoad,
    1.42 +                     const gfxFontFaceSrc* aFontFaceSrc) MOZ_OVERRIDE;
    1.43 +
    1.44 +  // Called by nsFontFaceLoader when the loader has completed normally.
    1.45 +  // It's removed from the mLoaders set.
    1.46 +  void RemoveLoader(nsFontFaceLoader* aLoader);
    1.47 +
    1.48 +  bool UpdateRules(const nsTArray<nsFontFaceRuleContainer>& aRules);
    1.49 +
    1.50 +  virtual nsPresContext* GetPresContext() { return mPresContext; }
    1.51 +
    1.52 +  virtual void ReplaceFontEntry(gfxMixedFontFamily* aFamily,
    1.53 +                                gfxProxyFontEntry* aProxy,
    1.54 +                                gfxFontEntry* aFontEntry) MOZ_OVERRIDE;
    1.55 +
    1.56 +  nsCSSFontFaceRule* FindRuleForEntry(gfxFontEntry* aFontEntry);
    1.57 +
    1.58 +protected:
    1.59 +  // Protected destructor, to discourage deletion outside of Release()
    1.60 +  // (since we inherit from refcounted class gfxUserFontSet):
    1.61 +  ~nsUserFontSet();
    1.62 +
    1.63 +  // The font-set keeps track of the collection of rules, and their
    1.64 +  // corresponding font entries (whether proxies or real entries),
    1.65 +  // so that we can update the set without having to throw away
    1.66 +  // all the existing fonts.
    1.67 +  struct FontFaceRuleRecord {
    1.68 +    nsRefPtr<gfxFontEntry>       mFontEntry;
    1.69 +    nsFontFaceRuleContainer      mContainer;
    1.70 +  };
    1.71 +
    1.72 +  void InsertRule(nsCSSFontFaceRule* aRule, uint8_t aSheetType,
    1.73 +                  nsTArray<FontFaceRuleRecord>& oldRules,
    1.74 +                  bool& aFontSetModified);
    1.75 +
    1.76 +  virtual nsresult LogMessage(gfxMixedFontFamily* aFamily,
    1.77 +                              gfxProxyFontEntry* aProxy,
    1.78 +                              const char* aMessage,
    1.79 +                              uint32_t aFlags = nsIScriptError::errorFlag,
    1.80 +                              nsresult aStatus = NS_OK) MOZ_OVERRIDE;
    1.81 +
    1.82 +  virtual nsresult CheckFontLoad(const gfxFontFaceSrc* aFontFaceSrc,
    1.83 +                                 nsIPrincipal** aPrincipal,
    1.84 +                                 bool* aBypassCache) MOZ_OVERRIDE;
    1.85 +
    1.86 +  virtual nsresult SyncLoadFontData(gfxProxyFontEntry* aFontToLoad,
    1.87 +                                    const gfxFontFaceSrc* aFontFaceSrc,
    1.88 +                                    uint8_t*& aBuffer,
    1.89 +                                    uint32_t& aBufferLength) MOZ_OVERRIDE;
    1.90 +
    1.91 +  virtual bool GetPrivateBrowsing() MOZ_OVERRIDE;
    1.92 +
    1.93 +  virtual void DoRebuildUserFontSet() MOZ_OVERRIDE;
    1.94 +
    1.95 +  nsPresContext* mPresContext;  // weak reference
    1.96 +
    1.97 +  // Set of all loaders pointing to us. These are not strong pointers,
    1.98 +  // but that's OK because nsFontFaceLoader always calls RemoveLoader on
    1.99 +  // us before it dies (unless we die first).
   1.100 +  nsTHashtable< nsPtrHashKey<nsFontFaceLoader> > mLoaders;
   1.101 +
   1.102 +  nsTArray<FontFaceRuleRecord>   mRules;
   1.103 +};
   1.104 +
   1.105 +class nsFontFaceLoader : public nsIStreamLoaderObserver
   1.106 +{
   1.107 +public:
   1.108 +  nsFontFaceLoader(gfxMixedFontFamily* aFontFamily,
   1.109 +                   gfxProxyFontEntry* aFontToLoad, nsIURI* aFontURI, 
   1.110 +                   nsUserFontSet* aFontSet, nsIChannel* aChannel);
   1.111 +
   1.112 +  virtual ~nsFontFaceLoader();
   1.113 +
   1.114 +  NS_DECL_ISUPPORTS
   1.115 +  NS_DECL_NSISTREAMLOADEROBSERVER 
   1.116 +
   1.117 +  // initiate the load
   1.118 +  nsresult Init();
   1.119 +  // cancel the load and remove its reference to mFontSet
   1.120 +  void Cancel();
   1.121 +
   1.122 +  void DropChannel() { mChannel = nullptr; }
   1.123 +
   1.124 +  void StartedLoading(nsIStreamLoader* aStreamLoader);
   1.125 +
   1.126 +  static void LoadTimerCallback(nsITimer* aTimer, void* aClosure);
   1.127 +
   1.128 +  static nsresult CheckLoadAllowed(nsIPrincipal* aSourcePrincipal,
   1.129 +                                   nsIURI* aTargetURI,
   1.130 +                                   nsISupports* aContext);
   1.131 +
   1.132 +private:
   1.133 +  nsRefPtr<gfxMixedFontFamily> mFontFamily;
   1.134 +  nsRefPtr<gfxProxyFontEntry>  mFontEntry;
   1.135 +  nsCOMPtr<nsIURI>        mFontURI;
   1.136 +  nsRefPtr<nsUserFontSet> mFontSet;
   1.137 +  nsCOMPtr<nsIChannel>    mChannel;
   1.138 +  nsCOMPtr<nsITimer>      mLoadTimer;
   1.139 +
   1.140 +  nsIStreamLoader*        mStreamLoader;
   1.141 +};
   1.142 +
   1.143 +#endif /* !defined(nsFontFaceLoader_h_) */

mercurial