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

Unified Diff: Source/core/css/CSSFontFaceSrcValue.cpp

Issue 230383003: Webfont CORS-enabled fetching with fallback (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add invalidator, retry only CORS failure Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/css/CSSFontFaceSrcValue.h ('k') | Source/core/css/RemoteFontFaceSource.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/CSSFontFaceSrcValue.cpp
diff --git a/Source/core/css/CSSFontFaceSrcValue.cpp b/Source/core/css/CSSFontFaceSrcValue.cpp
index 5ccf7547707efc0f79d2e69841d9ace072da92cb..f20a3428589a60e2bbc5004bef13c3d34c167c67 100644
--- a/Source/core/css/CSSFontFaceSrcValue.cpp
+++ b/Source/core/css/CSSFontFaceSrcValue.cpp
@@ -39,6 +39,30 @@
namespace WebCore {
+CSSFontFaceSrcValue::FontResourceInvalidator::FontResourceInvalidator(CSSFontFaceSrcValue& srcValue)
+ : m_srcValue(srcValue)
+ , m_resource(srcValue.m_fetched)
+{
+ m_resource->addClient(this);
Kunihiko Sakamoto 2014/04/10 05:49:24 Resource cancels in-flight request when all client
bashi 2014/04/10 07:05:51 Great suggestion! Done.
+}
+
+CSSFontFaceSrcValue::FontResourceInvalidator::~FontResourceInvalidator()
+{
+ m_resource->removeClient(this);
+}
+
+void CSSFontFaceSrcValue::FontResourceInvalidator::fontLoaded(FontResource*)
+{
+ m_srcValue.m_invalidator.clear();
+}
+
+void CSSFontFaceSrcValue::FontResourceInvalidator::corsFailed(FontResource*)
+{
+ m_srcValue.m_fetched.clear();
+ m_srcValue.m_corsEnabled = NotCORSEnabled;
+ m_srcValue.m_invalidator.clear();
+}
+
#if ENABLE(SVG_FONTS)
bool CSSFontFaceSrcValue::isSVGFontFaceSrc() const
{
@@ -88,11 +112,23 @@ bool CSSFontFaceSrcValue::hasFailedOrCanceledSubresources() const
return m_fetched->loadFailedOrCanceled();
}
+bool CSSFontFaceSrcValue::shouldSetCrossOriginAccessControl(const KURL& resource, SecurityOrigin* securityOrigin)
+{
+ if (m_corsEnabled == NotCORSEnabled || resource.isLocalFile() || resource.protocolIsData())
+ return false;
+ return !securityOrigin->canRequest(resource);
+}
+
FontResource* CSSFontFaceSrcValue::fetch(Document* document)
{
if (!m_fetched) {
FetchRequest request(ResourceRequest(document->completeURL(m_resource)), FetchInitiatorTypeNames::css);
+ SecurityOrigin* securityOrigin = document->securityOrigin();
+ if (shouldSetCrossOriginAccessControl(request.url(), securityOrigin)) {
+ request.setCrossOriginAccessControl(securityOrigin, DoNotAllowStoredCredentials);
+ }
m_fetched = document->fetcher()->fetchFont(request);
+ m_invalidator = adoptPtr(new FontResourceInvalidator(*this));
}
return m_fetched.get();
}
« no previous file with comments | « Source/core/css/CSSFontFaceSrcValue.h ('k') | Source/core/css/RemoteFontFaceSource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698