| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } | 65 } |
| 66 | 66 |
| 67 static void recordPackageFormatHistogram(FontPackageFormat format) | 67 static void recordPackageFormatHistogram(FontPackageFormat format) |
| 68 { | 68 { |
| 69 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, packageFormatHistogram
, new EnumerationHistogram("WebFont.PackageFormat", PackageFormatEnumMax)); | 69 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, packageFormatHistogram
, new EnumerationHistogram("WebFont.PackageFormat", PackageFormatEnumMax)); |
| 70 packageFormatHistogram.count(format); | 70 packageFormatHistogram.count(format); |
| 71 } | 71 } |
| 72 | 72 |
| 73 FontResource* FontResource::fetch(FetchRequest& request, ResourceFetcher* fetche
r) | 73 FontResource* FontResource::fetch(FetchRequest& request, ResourceFetcher* fetche
r) |
| 74 { | 74 { |
| 75 ASSERT(request.resourceRequest().frameType() == WebURLRequest::FrameTypeNone
); | 75 DCHECK_EQ(request.resourceRequest().frameType(), WebURLRequest::FrameTypeNon
e); |
| 76 request.mutableResourceRequest().setRequestContext(WebURLRequest::RequestCon
textFont); | 76 request.mutableResourceRequest().setRequestContext(WebURLRequest::RequestCon
textFont); |
| 77 return toFontResource(fetcher->requestResource(request, FontResourceFactory(
))); | 77 return toFontResource(fetcher->requestResource(request, FontResourceFactory(
))); |
| 78 } | 78 } |
| 79 | 79 |
| 80 FontResource::FontResource(const ResourceRequest& resourceRequest, const Resourc
eLoaderOptions& options) | 80 FontResource::FontResource(const ResourceRequest& resourceRequest, const Resourc
eLoaderOptions& options) |
| 81 : Resource(resourceRequest, Font, options) | 81 : Resource(resourceRequest, Font, options) |
| 82 , m_loadLimitState(UnderLimit) | 82 , m_loadLimitState(UnderLimit) |
| 83 , m_corsFailed(false) | 83 , m_corsFailed(false) |
| 84 , m_fontLoadShortLimitTimer(this, &FontResource::fontLoadShortLimitCallback) | 84 , m_fontLoadShortLimitTimer(this, &FontResource::fontLoadShortLimitCallback) |
| 85 , m_fontLoadLongLimitTimer(this, &FontResource::fontLoadLongLimitCallback) | 85 , m_fontLoadLongLimitTimer(this, &FontResource::fontLoadLongLimitCallback) |
| 86 { | 86 { |
| 87 } | 87 } |
| 88 | 88 |
| 89 FontResource::~FontResource() | 89 FontResource::~FontResource() |
| 90 { | 90 { |
| 91 } | 91 } |
| 92 | 92 |
| 93 void FontResource::didAddClient(ResourceClient* c) | 93 void FontResource::didAddClient(ResourceClient* c) |
| 94 { | 94 { |
| 95 ASSERT(FontResourceClient::isExpectedType(c)); | 95 DCHECK(FontResourceClient::isExpectedType(c)); |
| 96 Resource::didAddClient(c); | 96 Resource::didAddClient(c); |
| 97 if (m_loadLimitState == ShortLimitExceeded || m_loadLimitState == LongLimitE
xceeded) | 97 if (m_loadLimitState == ShortLimitExceeded || m_loadLimitState == LongLimitE
xceeded) |
| 98 static_cast<FontResourceClient*>(c)->fontLoadShortLimitExceeded(this); | 98 static_cast<FontResourceClient*>(c)->fontLoadShortLimitExceeded(this); |
| 99 if (m_loadLimitState == LongLimitExceeded) | 99 if (m_loadLimitState == LongLimitExceeded) |
| 100 static_cast<FontResourceClient*>(c)->fontLoadLongLimitExceeded(this); | 100 static_cast<FontResourceClient*>(c)->fontLoadLongLimitExceeded(this); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void FontResource::setRevalidatingRequest(const ResourceRequest& request) | 103 void FontResource::setRevalidatingRequest(const ResourceRequest& request) |
| 104 { | 104 { |
| 105 // Reload will use the same object, and needs to reset |m_loadLimitState| | 105 // Reload will use the same object, and needs to reset |m_loadLimitState| |
| 106 // before any didAddClient() is called again. | 106 // before any didAddClient() is called again. |
| 107 m_loadLimitState = UnderLimit; | 107 m_loadLimitState = UnderLimit; |
| 108 Resource::setRevalidatingRequest(request); | 108 Resource::setRevalidatingRequest(request); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void FontResource::startLoadLimitTimersIfNeeded() | 111 void FontResource::startLoadLimitTimersIfNeeded() |
| 112 { | 112 { |
| 113 ASSERT(!stillNeedsLoad()); | 113 DCHECK(!stillNeedsLoad()); |
| 114 if (isLoaded() || m_fontLoadLongLimitTimer.isActive()) | 114 if (isLoaded() || m_fontLoadLongLimitTimer.isActive()) |
| 115 return; | 115 return; |
| 116 ASSERT(m_loadLimitState == UnderLimit); | 116 DCHECK_EQ(m_loadLimitState, UnderLimit); |
| 117 m_fontLoadShortLimitTimer.startOneShot(fontLoadWaitShortLimitSec, BLINK_FROM
_HERE); | 117 m_fontLoadShortLimitTimer.startOneShot(fontLoadWaitShortLimitSec, BLINK_FROM
_HERE); |
| 118 m_fontLoadLongLimitTimer.startOneShot(fontLoadWaitLongLimitSec, BLINK_FROM_H
ERE); | 118 m_fontLoadLongLimitTimer.startOneShot(fontLoadWaitLongLimitSec, BLINK_FROM_H
ERE); |
| 119 } | 119 } |
| 120 | 120 |
| 121 bool FontResource::ensureCustomFontData() | 121 bool FontResource::ensureCustomFontData() |
| 122 { | 122 { |
| 123 if (!m_fontData && !errorOccurred() && !isLoading()) { | 123 if (!m_fontData && !errorOccurred() && !isLoading()) { |
| 124 if (data()) | 124 if (data()) |
| 125 m_fontData = FontCustomPlatformData::create(data(), m_otsParsingMess
age); | 125 m_fontData = FontCustomPlatformData::create(data(), m_otsParsingMess
age); |
| 126 | 126 |
| 127 if (m_fontData) { | 127 if (m_fontData) { |
| 128 recordPackageFormatHistogram(packageFormatOf(data())); | 128 recordPackageFormatHistogram(packageFormatOf(data())); |
| 129 } else { | 129 } else { |
| 130 setStatus(DecodeError); | 130 setStatus(DecodeError); |
| 131 recordPackageFormatHistogram(PackageFormatUnknown); | 131 recordPackageFormatHistogram(PackageFormatUnknown); |
| 132 } | 132 } |
| 133 } | 133 } |
| 134 return m_fontData.get(); | 134 return m_fontData.get(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 FontPlatformData FontResource::platformDataFromCustomData(float size, bool bold,
bool italic, FontOrientation orientation) | 137 FontPlatformData FontResource::platformDataFromCustomData(float size, bool bold,
bool italic, FontOrientation orientation) |
| 138 { | 138 { |
| 139 ASSERT(m_fontData); | 139 DCHECK(m_fontData); |
| 140 return m_fontData->fontPlatformData(size, bold, italic, orientation); | 140 return m_fontData->fontPlatformData(size, bold, italic, orientation); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void FontResource::fontLoadShortLimitCallback(TimerBase*) | 143 void FontResource::fontLoadShortLimitCallback(TimerBase*) |
| 144 { | 144 { |
| 145 if (!isLoading()) | 145 if (!isLoading()) |
| 146 return; | 146 return; |
| 147 ASSERT(m_loadLimitState == UnderLimit); | 147 DCHECK_EQ(m_loadLimitState, UnderLimit); |
| 148 m_loadLimitState = ShortLimitExceeded; | 148 m_loadLimitState = ShortLimitExceeded; |
| 149 ResourceClientWalker<FontResourceClient> walker(clients()); | 149 ResourceClientWalker<FontResourceClient> walker(clients()); |
| 150 while (FontResourceClient* client = walker.next()) | 150 while (FontResourceClient* client = walker.next()) |
| 151 client->fontLoadShortLimitExceeded(this); | 151 client->fontLoadShortLimitExceeded(this); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void FontResource::fontLoadLongLimitCallback(TimerBase*) | 154 void FontResource::fontLoadLongLimitCallback(TimerBase*) |
| 155 { | 155 { |
| 156 if (!isLoading()) | 156 if (!isLoading()) |
| 157 return; | 157 return; |
| 158 ASSERT(m_loadLimitState == ShortLimitExceeded); | 158 DCHECK_EQ(m_loadLimitState, ShortLimitExceeded); |
| 159 m_loadLimitState = LongLimitExceeded; | 159 m_loadLimitState = LongLimitExceeded; |
| 160 ResourceClientWalker<FontResourceClient> walker(clients()); | 160 ResourceClientWalker<FontResourceClient> walker(clients()); |
| 161 while (FontResourceClient* client = walker.next()) | 161 while (FontResourceClient* client = walker.next()) |
| 162 client->fontLoadLongLimitExceeded(this); | 162 client->fontLoadLongLimitExceeded(this); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void FontResource::allClientsAndObserversRemoved() | 165 void FontResource::allClientsAndObserversRemoved() |
| 166 { | 166 { |
| 167 m_fontData.reset(); | 167 m_fontData.reset(); |
| 168 Resource::allClientsAndObserversRemoved(); | 168 Resource::allClientsAndObserversRemoved(); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void FontResource::checkNotify() | 171 void FontResource::checkNotify() |
| 172 { | 172 { |
| 173 m_fontLoadShortLimitTimer.stop(); | 173 m_fontLoadShortLimitTimer.stop(); |
| 174 m_fontLoadLongLimitTimer.stop(); | 174 m_fontLoadLongLimitTimer.stop(); |
| 175 | 175 |
| 176 Resource::checkNotify(); | 176 Resource::checkNotify(); |
| 177 } | 177 } |
| 178 | 178 |
| 179 } // namespace blink | 179 } // namespace blink |
| OLD | NEW |