Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2009 Torch Mobile, Inc. | 3 * Copyright (C) 2009 Torch Mobile, Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 #include "core/fetch/ResourceClientWalker.h" | 31 #include "core/fetch/ResourceClientWalker.h" |
| 32 #include "core/fetch/ResourceFetcher.h" | 32 #include "core/fetch/ResourceFetcher.h" |
| 33 #include "platform/SharedBuffer.h" | 33 #include "platform/SharedBuffer.h" |
| 34 #include "platform/fonts/FontCustomPlatformData.h" | 34 #include "platform/fonts/FontCustomPlatformData.h" |
| 35 #include "platform/fonts/FontPlatformData.h" | 35 #include "platform/fonts/FontPlatformData.h" |
| 36 #include "public/platform/Platform.h" | 36 #include "public/platform/Platform.h" |
| 37 #include "wtf/CurrentTime.h" | 37 #include "wtf/CurrentTime.h" |
| 38 | 38 |
| 39 namespace blink { | 39 namespace blink { |
| 40 | 40 |
| 41 static const double fontLoadWaitLimitSec = 3.0; | 41 static const double fontLoadWaitShortLimitSec = 0.1; |
| 42 static const double fontLoadWaitLongLimitSec = 3.0; | |
|
kinuko
2015/11/01 16:32:04
I assume this corresponds to "'100ms' or less is r
Kunihiko Sakamoto
2015/11/02 05:30:16
Done.
| |
| 42 | 43 |
| 43 enum FontPackageFormat { | 44 enum FontPackageFormat { |
| 44 PackageFormatUnknown, | 45 PackageFormatUnknown, |
| 45 PackageFormatSFNT, | 46 PackageFormatSFNT, |
| 46 PackageFormatWOFF, | 47 PackageFormatWOFF, |
| 47 PackageFormatWOFF2, | 48 PackageFormatWOFF2, |
| 48 PackageFormatSVG, | 49 PackageFormatSVG, |
| 49 PackageFormatEnumMax | 50 PackageFormatEnumMax |
| 50 }; | 51 }; |
| 51 | 52 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 70 ResourcePtr<FontResource> FontResource::fetch(FetchRequest& request, ResourceFet cher* fetcher) | 71 ResourcePtr<FontResource> FontResource::fetch(FetchRequest& request, ResourceFet cher* fetcher) |
| 71 { | 72 { |
| 72 ASSERT(request.resourceRequest().frameType() == WebURLRequest::FrameTypeNone ); | 73 ASSERT(request.resourceRequest().frameType() == WebURLRequest::FrameTypeNone ); |
| 73 request.mutableResourceRequest().setRequestContext(WebURLRequest::RequestCon textFont); | 74 request.mutableResourceRequest().setRequestContext(WebURLRequest::RequestCon textFont); |
| 74 return toFontResource(fetcher->requestResource(request, FontResourceFactory( ))); | 75 return toFontResource(fetcher->requestResource(request, FontResourceFactory( ))); |
| 75 } | 76 } |
| 76 | 77 |
| 77 FontResource::FontResource(const ResourceRequest& resourceRequest) | 78 FontResource::FontResource(const ResourceRequest& resourceRequest) |
| 78 : Resource(resourceRequest, Font) | 79 : Resource(resourceRequest, Font) |
| 79 , m_state(Unloaded) | 80 , m_state(Unloaded) |
| 80 , m_exceedsFontLoadWaitLimit(false) | |
| 81 , m_corsFailed(false) | 81 , m_corsFailed(false) |
| 82 , m_fontLoadWaitLimitTimer(this, &FontResource::fontLoadWaitLimitCallback) | 82 , m_fontLoadShortLimitTimer(this, &FontResource::fontLoadShortLimitCallback) |
| 83 , m_fontLoadLongLimitTimer(this, &FontResource::fontLoadLongLimitCallback) | |
| 83 { | 84 { |
| 84 } | 85 } |
| 85 | 86 |
| 86 FontResource::~FontResource() | 87 FontResource::~FontResource() |
| 87 { | 88 { |
| 88 } | 89 } |
| 89 | 90 |
| 90 void FontResource::didScheduleLoad() | 91 void FontResource::didScheduleLoad() |
| 91 { | 92 { |
| 92 if (m_state == Unloaded) | 93 if (m_state == Unloaded) |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 114 Resource::didAddClient(c); | 115 Resource::didAddClient(c); |
| 115 if (!isLoading()) | 116 if (!isLoading()) |
| 116 static_cast<FontResourceClient*>(c)->fontLoaded(this); | 117 static_cast<FontResourceClient*>(c)->fontLoaded(this); |
| 117 } | 118 } |
| 118 | 119 |
| 119 void FontResource::beginLoadIfNeeded(ResourceFetcher* dl) | 120 void FontResource::beginLoadIfNeeded(ResourceFetcher* dl) |
| 120 { | 121 { |
| 121 if (m_state != LoadInitiated) { | 122 if (m_state != LoadInitiated) { |
| 122 m_state = LoadInitiated; | 123 m_state = LoadInitiated; |
| 123 Resource::load(dl, m_options); | 124 Resource::load(dl, m_options); |
| 124 m_fontLoadWaitLimitTimer.startOneShot(fontLoadWaitLimitSec, BLINK_FROM_H ERE); | 125 m_fontLoadShortLimitTimer.startOneShot(fontLoadWaitShortLimitSec, BLINK_ FROM_HERE); |
| 126 m_fontLoadLongLimitTimer.startOneShot(fontLoadWaitLongLimitSec, BLINK_FR OM_HERE); | |
| 125 | 127 |
| 126 ResourceClientWalker<FontResourceClient> walker(m_clients); | 128 ResourceClientWalker<FontResourceClient> walker(m_clients); |
| 127 while (FontResourceClient* client = walker.next()) | 129 while (FontResourceClient* client = walker.next()) |
| 128 client->didStartFontLoad(this); | 130 client->didStartFontLoad(this); |
| 129 } | 131 } |
| 130 } | 132 } |
| 131 | 133 |
| 132 bool FontResource::ensureCustomFontData() | 134 bool FontResource::ensureCustomFontData() |
| 133 { | 135 { |
| 134 if (!m_fontData && !errorOccurred() && !isLoading()) { | 136 if (!m_fontData && !errorOccurred() && !isLoading()) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 149 { | 151 { |
| 150 ASSERT(m_fontData); | 152 ASSERT(m_fontData); |
| 151 return m_fontData->fontPlatformData(size, bold, italic, orientation); | 153 return m_fontData->fontPlatformData(size, bold, italic, orientation); |
| 152 } | 154 } |
| 153 | 155 |
| 154 bool FontResource::isSafeToUnlock() const | 156 bool FontResource::isSafeToUnlock() const |
| 155 { | 157 { |
| 156 return m_data->hasOneRef(); | 158 return m_data->hasOneRef(); |
| 157 } | 159 } |
| 158 | 160 |
| 159 void FontResource::fontLoadWaitLimitCallback(Timer<FontResource>*) | 161 void FontResource::fontLoadShortLimitCallback(Timer<FontResource>*) |
| 160 { | 162 { |
| 161 if (!isLoading()) | 163 if (!isLoading()) |
| 162 return; | 164 return; |
| 163 m_exceedsFontLoadWaitLimit = true; | |
| 164 ResourceClientWalker<FontResourceClient> walker(m_clients); | 165 ResourceClientWalker<FontResourceClient> walker(m_clients); |
| 165 while (FontResourceClient* client = walker.next()) | 166 while (FontResourceClient* client = walker.next()) |
| 166 client->fontLoadWaitLimitExceeded(this); | 167 client->fontLoadShortLimitExceeded(this); |
| 168 } | |
| 169 | |
| 170 void FontResource::fontLoadLongLimitCallback(Timer<FontResource>*) | |
| 171 { | |
| 172 if (!isLoading()) | |
| 173 return; | |
| 174 ResourceClientWalker<FontResourceClient> walker(m_clients); | |
| 175 while (FontResourceClient* client = walker.next()) | |
| 176 client->fontLoadLongLimitExceeded(this); | |
| 167 } | 177 } |
| 168 | 178 |
| 169 void FontResource::allClientsRemoved() | 179 void FontResource::allClientsRemoved() |
| 170 { | 180 { |
| 171 m_fontData.clear(); | 181 m_fontData.clear(); |
| 172 Resource::allClientsRemoved(); | 182 Resource::allClientsRemoved(); |
| 173 } | 183 } |
| 174 | 184 |
| 175 void FontResource::checkNotify() | 185 void FontResource::checkNotify() |
| 176 { | 186 { |
| 177 m_fontLoadWaitLimitTimer.stop(); | 187 m_fontLoadShortLimitTimer.stop(); |
| 188 m_fontLoadLongLimitTimer.stop(); | |
| 178 ResourceClientWalker<FontResourceClient> w(m_clients); | 189 ResourceClientWalker<FontResourceClient> w(m_clients); |
| 179 while (FontResourceClient* c = w.next()) | 190 while (FontResourceClient* c = w.next()) |
| 180 c->fontLoaded(this); | 191 c->fontLoaded(this); |
| 181 } | 192 } |
| 182 | 193 |
| 183 } | 194 } |
| OLD | NEW |