| OLD | NEW |
| 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 |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #ifndef FontResource_h | 26 #ifndef FontResource_h |
| 27 #define FontResource_h | 27 #define FontResource_h |
| 28 | 28 |
| 29 #include "base/gtest_prod_util.h" |
| 29 #include "core/CoreExport.h" | 30 #include "core/CoreExport.h" |
| 30 #include "core/fetch/Resource.h" | 31 #include "core/fetch/Resource.h" |
| 31 #include "core/fetch/ResourceClient.h" | 32 #include "core/fetch/ResourceClient.h" |
| 32 #include "platform/Timer.h" | 33 #include "platform/Timer.h" |
| 33 #include "platform/fonts/FontOrientation.h" | 34 #include "platform/fonts/FontOrientation.h" |
| 34 #include "platform/heap/Handle.h" | 35 #include "platform/heap/Handle.h" |
| 35 #include <memory> | 36 #include <memory> |
| 36 | 37 |
| 37 namespace blink { | 38 namespace blink { |
| 38 | 39 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 65 float size, | 66 float size, |
| 66 bool bold, | 67 bool bold, |
| 67 bool italic, | 68 bool italic, |
| 68 FontOrientation = FontOrientation::Horizontal); | 69 FontOrientation = FontOrientation::Horizontal); |
| 69 | 70 |
| 70 // Returns true if the loading priority of the remote font resource can be | 71 // Returns true if the loading priority of the remote font resource can be |
| 71 // lowered. The loading priority of the font can be lowered only if the | 72 // lowered. The loading priority of the font can be lowered only if the |
| 72 // font is not needed for painting the text. | 73 // font is not needed for painting the text. |
| 73 bool isLowPriorityLoadingAllowedForRemoteFont() const; | 74 bool isLowPriorityLoadingAllowedForRemoteFont() const; |
| 74 | 75 |
| 76 void willReloadAfterDiskCacheMiss() override; |
| 77 |
| 75 private: | 78 private: |
| 76 class FontResourceFactory : public ResourceFactory { | 79 class FontResourceFactory : public ResourceFactory { |
| 77 public: | 80 public: |
| 78 FontResourceFactory() : ResourceFactory(Resource::Font) {} | 81 FontResourceFactory() : ResourceFactory(Resource::Font) {} |
| 79 | 82 |
| 80 Resource* create(const ResourceRequest& request, | 83 Resource* create(const ResourceRequest& request, |
| 81 const ResourceLoaderOptions& options, | 84 const ResourceLoaderOptions& options, |
| 82 const String& charset) const override { | 85 const String& charset) const override { |
| 83 return new FontResource(request, options); | 86 return new FontResource(request, options); |
| 84 } | 87 } |
| 85 }; | 88 }; |
| 86 FontResource(const ResourceRequest&, const ResourceLoaderOptions&); | 89 FontResource(const ResourceRequest&, const ResourceLoaderOptions&); |
| 87 | 90 |
| 88 void checkNotify() override; | 91 void checkNotify() override; |
| 89 void fontLoadShortLimitCallback(TimerBase*); | 92 void fontLoadShortLimitCallback(TimerBase*); |
| 90 void fontLoadLongLimitCallback(TimerBase*); | 93 void fontLoadLongLimitCallback(TimerBase*); |
| 94 void notifyClientsShortLimitExceeded(); |
| 95 void notifyClientsLongLimitExceeded(); |
| 91 | 96 |
| 97 // This is used in UMA histograms, should not change order. |
| 92 enum LoadLimitState { | 98 enum LoadLimitState { |
| 93 LoadNotStarted, | 99 LoadNotStarted, |
| 94 UnderLimit, | 100 UnderLimit, |
| 95 ShortLimitExceeded, | 101 ShortLimitExceeded, |
| 96 LongLimitExceeded | 102 LongLimitExceeded, |
| 103 LoadLimitStateEnumMax |
| 97 }; | 104 }; |
| 98 | 105 |
| 99 std::unique_ptr<FontCustomPlatformData> m_fontData; | 106 std::unique_ptr<FontCustomPlatformData> m_fontData; |
| 100 String m_otsParsingMessage; | 107 String m_otsParsingMessage; |
| 101 LoadLimitState m_loadLimitState; | 108 LoadLimitState m_loadLimitState; |
| 102 bool m_corsFailed; | 109 bool m_corsFailed; |
| 103 Timer<FontResource> m_fontLoadShortLimitTimer; | 110 Timer<FontResource> m_fontLoadShortLimitTimer; |
| 104 Timer<FontResource> m_fontLoadLongLimitTimer; | 111 Timer<FontResource> m_fontLoadLongLimitTimer; |
| 105 | 112 |
| 106 friend class MemoryCache; | 113 friend class MemoryCache; |
| 114 FRIEND_TEST_ALL_PREFIXES(ResourceFetcherTest, CacheAwareFontLoading); |
| 107 }; | 115 }; |
| 108 | 116 |
| 109 DEFINE_RESOURCE_TYPE_CASTS(Font); | 117 DEFINE_RESOURCE_TYPE_CASTS(Font); |
| 110 | 118 |
| 111 class FontResourceClient : public ResourceClient { | 119 class FontResourceClient : public ResourceClient { |
| 112 public: | 120 public: |
| 113 ~FontResourceClient() override {} | 121 ~FontResourceClient() override {} |
| 114 static bool isExpectedType(ResourceClient* client) { | 122 static bool isExpectedType(ResourceClient* client) { |
| 115 return client->getResourceClientType() == FontType; | 123 return client->getResourceClientType() == FontType; |
| 116 } | 124 } |
| 117 ResourceClientType getResourceClientType() const final { return FontType; } | 125 ResourceClientType getResourceClientType() const final { return FontType; } |
| 126 |
| 127 // If cache-aware loading is activated, both callbacks will be blocked until |
| 128 // disk cache miss. Calls to addClient() and removeClient() in both callbacks |
| 129 // are prohibited to prevent race issues regarding current loading state. |
| 118 virtual void fontLoadShortLimitExceeded(FontResource*) {} | 130 virtual void fontLoadShortLimitExceeded(FontResource*) {} |
| 119 virtual void fontLoadLongLimitExceeded(FontResource*) {} | 131 virtual void fontLoadLongLimitExceeded(FontResource*) {} |
| 120 | 132 |
| 121 // Returns true if loading priority of remote font resources can be lowered. | 133 // Returns true if loading priority of remote font resources can be lowered. |
| 122 virtual bool isLowPriorityLoadingAllowedForRemoteFont() const { | 134 virtual bool isLowPriorityLoadingAllowedForRemoteFont() const { |
| 123 // Only the RemoteFontFaceSources clients can prevent lowering of loading | 135 // Only the RemoteFontFaceSources clients can prevent lowering of loading |
| 124 // priority of the remote fonts. Set the default to true to prevent | 136 // priority of the remote fonts. Set the default to true to prevent |
| 125 // other clients from incorrectly returning false. | 137 // other clients from incorrectly returning false. |
| 126 return true; | 138 return true; |
| 127 } | 139 } |
| 128 }; | 140 }; |
| 129 | 141 |
| 130 } // namespace blink | 142 } // namespace blink |
| 131 | 143 |
| 132 #endif | 144 #endif |
| OLD | NEW |