Home | History | Annotate | Download | only in css
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef RemoteFontFaceSource_h
      6 #define RemoteFontFaceSource_h
      7 
      8 #include "core/css/CSSFontFaceSource.h"
      9 #include "core/fetch/FontResource.h"
     10 #include "core/fetch/ResourcePtr.h"
     11 
     12 namespace WebCore {
     13 
     14 class FontLoader;
     15 
     16 class RemoteFontFaceSource : public CSSFontFaceSource, public FontResourceClient {
     17 public:
     18     explicit RemoteFontFaceSource(FontResource*, PassRefPtrWillBeRawPtr<FontLoader>);
     19     virtual ~RemoteFontFaceSource();
     20 
     21     virtual FontResource* resource() OVERRIDE { return m_font.get(); }
     22     virtual bool isLoading() const OVERRIDE;
     23     virtual bool isLoaded() const OVERRIDE;
     24     virtual bool isValid() const OVERRIDE;
     25 
     26     void beginLoadIfNeeded() OVERRIDE;
     27     virtual bool ensureFontData();
     28 
     29 #if ENABLE(SVG_FONTS)
     30     virtual bool isSVGFontFaceSource() const { return false; }
     31 #endif
     32 
     33     virtual void didStartFontLoad(FontResource*) OVERRIDE;
     34     virtual void fontLoaded(FontResource*) OVERRIDE;
     35     virtual void fontLoadWaitLimitExceeded(FontResource*) OVERRIDE;
     36 
     37     // For UMA reporting
     38     virtual bool hadBlankText() OVERRIDE { return m_histograms.hadBlankText(); }
     39     void paintRequested() { m_histograms.fallbackFontPainted(); }
     40 
     41     virtual void trace(Visitor*) OVERRIDE;
     42 
     43 protected:
     44     virtual PassRefPtr<SimpleFontData> createFontData(const FontDescription&) OVERRIDE;
     45     PassRefPtr<SimpleFontData> createLoadingFallbackFontData(const FontDescription&);
     46     void pruneTable();
     47 
     48 private:
     49     class FontLoadHistograms {
     50     public:
     51         FontLoadHistograms() : m_loadStartTime(0), m_fallbackPaintTime(0) { }
     52         void loadStarted();
     53         void fallbackFontPainted();
     54         void recordRemoteFont(const FontResource*);
     55         void recordFallbackTime(const FontResource*);
     56         bool hadBlankText() { return m_fallbackPaintTime; }
     57     private:
     58         const char* histogramName(const FontResource*);
     59         double m_loadStartTime;
     60         double m_fallbackPaintTime;
     61     };
     62 
     63     ResourcePtr<FontResource> m_font;
     64     RefPtrWillBeMember<FontLoader> m_fontLoader;
     65     FontLoadHistograms m_histograms;
     66 };
     67 
     68 } // namespace WebCore
     69 
     70 #endif
     71