Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(810)

Side by Side Diff: Source/core/fetch/FontResource.h

Issue 1170503003: Remove resource type-specific fetching logic from ResourceFetcher (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Null-check Document::loader() before calling startPreload() Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/fetch/FetchContext.h ('k') | Source/core/fetch/FontResource.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 16 matching lines...) Expand all
27 #define FontResource_h 27 #define FontResource_h
28 28
29 #include "core/fetch/ResourceClient.h" 29 #include "core/fetch/ResourceClient.h"
30 #include "core/fetch/ResourcePtr.h" 30 #include "core/fetch/ResourcePtr.h"
31 #include "platform/Timer.h" 31 #include "platform/Timer.h"
32 #include "platform/fonts/FontOrientation.h" 32 #include "platform/fonts/FontOrientation.h"
33 #include "wtf/OwnPtr.h" 33 #include "wtf/OwnPtr.h"
34 34
35 namespace blink { 35 namespace blink {
36 36
37 class FetchRequest;
37 class ResourceFetcher; 38 class ResourceFetcher;
38 class FontPlatformData; 39 class FontPlatformData;
39 class FontCustomPlatformData; 40 class FontCustomPlatformData;
40 41
41 class FontResource final : public Resource { 42 class FontResource final : public Resource {
42 public: 43 public:
43 typedef ResourceClient ClientType; 44 typedef ResourceClient ClientType;
44 45
45 FontResource(const ResourceRequest&); 46 static ResourcePtr<FontResource> fetch(FetchRequest&, ResourceFetcher*);
46 virtual ~FontResource(); 47 virtual ~FontResource();
47 48
48 virtual void load(ResourceFetcher*, const ResourceLoaderOptions&) override; 49 virtual void load(ResourceFetcher*, const ResourceLoaderOptions&) override;
49 50
50 virtual void didAddClient(ResourceClient*) override; 51 virtual void didAddClient(ResourceClient*) override;
51 52
52 virtual void allClientsRemoved() override; 53 virtual void allClientsRemoved() override;
53 void beginLoadIfNeeded(ResourceFetcher* dl); 54 void beginLoadIfNeeded(ResourceFetcher* dl);
54 virtual bool stillNeedsLoad() const override { return m_state != LoadInitiat ed; } 55 virtual bool stillNeedsLoad() const override { return m_state != LoadInitiat ed; }
55 bool exceedsFontLoadWaitLimit() const { return m_exceedsFontLoadWaitLimit; } 56 bool exceedsFontLoadWaitLimit() const { return m_exceedsFontLoadWaitLimit; }
56 57
57 bool loadScheduled() const { return m_state != Unloaded; } 58 bool loadScheduled() const { return m_state != Unloaded; }
58 void didScheduleLoad(); 59 void didScheduleLoad();
59 void didUnscheduleLoad(); 60 void didUnscheduleLoad();
60 61
61 void setCORSFailed() { m_corsFailed = true; } 62 void setCORSFailed() override { m_corsFailed = true; }
62 bool isCORSFailed() const { return m_corsFailed; } 63 bool isCORSFailed() const { return m_corsFailed; }
63 64
64 bool ensureCustomFontData(); 65 bool ensureCustomFontData();
65 FontPlatformData platformDataFromCustomData(float size, bool bold, bool ital ic, FontOrientation = FontOrientation::Horizontal); 66 FontPlatformData platformDataFromCustomData(float size, bool bold, bool ital ic, FontOrientation = FontOrientation::Horizontal);
66 67
67 protected: 68 protected:
68 virtual bool isSafeToUnlock() const override; 69 virtual bool isSafeToUnlock() const override;
69 70
70 private: 71 private:
72 class FontResourceFactory : public ResourceFactory {
73 public:
74 FontResourceFactory()
75 : ResourceFactory(Resource::Font) { }
76
77 Resource* create(const ResourceRequest& request, const String& charset) const override
78 {
79 return new FontResource(request);
80 }
81 };
82 FontResource(const ResourceRequest&);
83
71 virtual void checkNotify() override; 84 virtual void checkNotify() override;
72 void fontLoadWaitLimitCallback(Timer<FontResource>*); 85 void fontLoadWaitLimitCallback(Timer<FontResource>*);
73 86
74 enum State { Unloaded, LoadScheduled, LoadInitiated }; 87 enum State { Unloaded, LoadScheduled, LoadInitiated };
75 88
76 OwnPtr<FontCustomPlatformData> m_fontData; 89 OwnPtr<FontCustomPlatformData> m_fontData;
77 State m_state; 90 State m_state;
78 bool m_exceedsFontLoadWaitLimit; 91 bool m_exceedsFontLoadWaitLimit;
79 bool m_corsFailed; 92 bool m_corsFailed;
80 Timer<FontResource> m_fontLoadWaitLimitTimer; 93 Timer<FontResource> m_fontLoadWaitLimitTimer;
81 94
82 friend class MemoryCache; 95 friend class MemoryCache;
83 }; 96 };
84 97
85 DEFINE_RESOURCE_TYPE_CASTS(Font); 98 DEFINE_RESOURCE_TYPE_CASTS(Font);
86 99
87 class FontResourceClient : public ResourceClient { 100 class FontResourceClient : public ResourceClient {
88 public: 101 public:
89 virtual ~FontResourceClient() { } 102 virtual ~FontResourceClient() { }
90 static ResourceClientType expectedType() { return FontType; } 103 static ResourceClientType expectedType() { return FontType; }
91 virtual ResourceClientType resourceClientType() const override final { retur n expectedType(); } 104 virtual ResourceClientType resourceClientType() const override final { retur n expectedType(); }
92 virtual void fontLoaded(FontResource*) { } 105 virtual void fontLoaded(FontResource*) { }
93 virtual void didStartFontLoad(FontResource*) { } 106 virtual void didStartFontLoad(FontResource*) { }
94 virtual void fontLoadWaitLimitExceeded(FontResource*) { } 107 virtual void fontLoadWaitLimitExceeded(FontResource*) { }
95 }; 108 };
96 109
97 } 110 }
98 111
99 #endif 112 #endif
OLDNEW
« no previous file with comments | « Source/core/fetch/FetchContext.h ('k') | Source/core/fetch/FontResource.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698