OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2007, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2010 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 21 matching lines...) Expand all Loading... | |
32 #include "core/dom/Node.h" | 32 #include "core/dom/Node.h" |
33 #include "core/fetch/FetchRequest.h" | 33 #include "core/fetch/FetchRequest.h" |
34 #include "core/fetch/FontResource.h" | 34 #include "core/fetch/FontResource.h" |
35 #include "core/fetch/ResourceFetcher.h" | 35 #include "core/fetch/ResourceFetcher.h" |
36 #include "core/svg/SVGFontFaceElement.h" | 36 #include "core/svg/SVGFontFaceElement.h" |
37 #include "platform/fonts/FontCustomPlatformData.h" | 37 #include "platform/fonts/FontCustomPlatformData.h" |
38 #include "wtf/text/StringBuilder.h" | 38 #include "wtf/text/StringBuilder.h" |
39 | 39 |
40 namespace WebCore { | 40 namespace WebCore { |
41 | 41 |
42 CSSFontFaceSrcValue::FontResourceInvalidator::FontResourceInvalidator(CSSFontFac eSrcValue& srcValue) | |
43 : m_srcValue(srcValue) | |
44 , m_resource(srcValue.m_fetched) | |
45 { | |
46 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.
| |
47 } | |
48 | |
49 CSSFontFaceSrcValue::FontResourceInvalidator::~FontResourceInvalidator() | |
50 { | |
51 m_resource->removeClient(this); | |
52 } | |
53 | |
54 void CSSFontFaceSrcValue::FontResourceInvalidator::fontLoaded(FontResource*) | |
55 { | |
56 m_srcValue.m_invalidator.clear(); | |
57 } | |
58 | |
59 void CSSFontFaceSrcValue::FontResourceInvalidator::corsFailed(FontResource*) | |
60 { | |
61 m_srcValue.m_fetched.clear(); | |
62 m_srcValue.m_corsEnabled = NotCORSEnabled; | |
63 m_srcValue.m_invalidator.clear(); | |
64 } | |
65 | |
42 #if ENABLE(SVG_FONTS) | 66 #if ENABLE(SVG_FONTS) |
43 bool CSSFontFaceSrcValue::isSVGFontFaceSrc() const | 67 bool CSSFontFaceSrcValue::isSVGFontFaceSrc() const |
44 { | 68 { |
45 return equalIgnoringCase(m_format, "svg"); | 69 return equalIgnoringCase(m_format, "svg"); |
46 } | 70 } |
47 #endif | 71 #endif |
48 | 72 |
49 bool CSSFontFaceSrcValue::isSupportedFormat() const | 73 bool CSSFontFaceSrcValue::isSupportedFormat() const |
50 { | 74 { |
51 // Normally we would just check the format, but in order to avoid conflicts with the old WinIE style of font-face, | 75 // Normally we would just check the format, but in order to avoid conflicts with the old WinIE style of font-face, |
(...skipping 29 matching lines...) Expand all Loading... | |
81 return result.toString(); | 105 return result.toString(); |
82 } | 106 } |
83 | 107 |
84 bool CSSFontFaceSrcValue::hasFailedOrCanceledSubresources() const | 108 bool CSSFontFaceSrcValue::hasFailedOrCanceledSubresources() const |
85 { | 109 { |
86 if (!m_fetched) | 110 if (!m_fetched) |
87 return false; | 111 return false; |
88 return m_fetched->loadFailedOrCanceled(); | 112 return m_fetched->loadFailedOrCanceled(); |
89 } | 113 } |
90 | 114 |
115 bool CSSFontFaceSrcValue::shouldSetCrossOriginAccessControl(const KURL& resource , SecurityOrigin* securityOrigin) | |
116 { | |
117 if (m_corsEnabled == NotCORSEnabled || resource.isLocalFile() || resource.pr otocolIsData()) | |
118 return false; | |
119 return !securityOrigin->canRequest(resource); | |
120 } | |
121 | |
91 FontResource* CSSFontFaceSrcValue::fetch(Document* document) | 122 FontResource* CSSFontFaceSrcValue::fetch(Document* document) |
92 { | 123 { |
93 if (!m_fetched) { | 124 if (!m_fetched) { |
94 FetchRequest request(ResourceRequest(document->completeURL(m_resource)), FetchInitiatorTypeNames::css); | 125 FetchRequest request(ResourceRequest(document->completeURL(m_resource)), FetchInitiatorTypeNames::css); |
126 SecurityOrigin* securityOrigin = document->securityOrigin(); | |
127 if (shouldSetCrossOriginAccessControl(request.url(), securityOrigin)) { | |
128 request.setCrossOriginAccessControl(securityOrigin, DoNotAllowStored Credentials); | |
129 } | |
95 m_fetched = document->fetcher()->fetchFont(request); | 130 m_fetched = document->fetcher()->fetchFont(request); |
131 m_invalidator = adoptPtr(new FontResourceInvalidator(*this)); | |
96 } | 132 } |
97 return m_fetched.get(); | 133 return m_fetched.get(); |
98 } | 134 } |
99 | 135 |
100 bool CSSFontFaceSrcValue::equals(const CSSFontFaceSrcValue& other) const | 136 bool CSSFontFaceSrcValue::equals(const CSSFontFaceSrcValue& other) const |
101 { | 137 { |
102 return m_isLocal == other.m_isLocal && m_format == other.m_format && m_resou rce == other.m_resource; | 138 return m_isLocal == other.m_isLocal && m_format == other.m_format && m_resou rce == other.m_resource; |
103 } | 139 } |
104 | 140 |
105 } | 141 } |
OLD | NEW |