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

Side by Side Diff: third_party/WebKit/Source/core/loader/LinkLoader.cpp

Issue 2035263002: Extract SourceLocation for ConsoleMessages on call sites. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2037593004
Patch Set: Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * 29 *
30 */ 30 */
31 31
32 #include "core/loader/LinkLoader.h" 32 #include "core/loader/LinkLoader.h"
33 33
34 #include "bindings/core/v8/SourceLocation.h"
34 #include "core/css/MediaList.h" 35 #include "core/css/MediaList.h"
35 #include "core/css/MediaQueryEvaluator.h" 36 #include "core/css/MediaQueryEvaluator.h"
36 #include "core/dom/Document.h" 37 #include "core/dom/Document.h"
37 #include "core/fetch/FetchInitiatorTypeNames.h" 38 #include "core/fetch/FetchInitiatorTypeNames.h"
38 #include "core/fetch/FetchRequest.h" 39 #include "core/fetch/FetchRequest.h"
39 #include "core/fetch/LinkFetchResource.h" 40 #include "core/fetch/LinkFetchResource.h"
40 #include "core/fetch/ResourceFetcher.h" 41 #include "core/fetch/ResourceFetcher.h"
41 #include "core/frame/Settings.h" 42 #include "core/frame/Settings.h"
42 #include "core/frame/UseCounter.h" 43 #include "core/frame/UseCounter.h"
43 #include "core/html/CrossOriginAttribute.h" 44 #include "core/html/CrossOriginAttribute.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 { 141 {
141 if (relAttribute.isDNSPrefetch()) { 142 if (relAttribute.isDNSPrefetch()) {
142 UseCounter::count(document, UseCounter::LinkRelDnsPrefetch); 143 UseCounter::count(document, UseCounter::LinkRelDnsPrefetch);
143 if (caller == LinkCalledFromHeader) 144 if (caller == LinkCalledFromHeader)
144 UseCounter::count(document, UseCounter::LinkHeaderDnsPrefetch); 145 UseCounter::count(document, UseCounter::LinkHeaderDnsPrefetch);
145 Settings* settings = document.settings(); 146 Settings* settings = document.settings();
146 // FIXME: The href attribute of the link element can be in "//hostname" form, and we shouldn't attempt 147 // FIXME: The href attribute of the link element can be in "//hostname" form, and we shouldn't attempt
147 // to complete that as URL <https://bugs.webkit.org/show_bug.cgi?id=4885 7>. 148 // to complete that as URL <https://bugs.webkit.org/show_bug.cgi?id=4885 7>.
148 if (settings && settings->dnsPrefetchingEnabled() && href.isValid() && ! href.isEmpty()) { 149 if (settings && settings->dnsPrefetchingEnabled() && href.isValid() && ! href.isEmpty()) {
149 if (settings->logDnsPrefetchAndPreconnect()) 150 if (settings->logDnsPrefetchAndPreconnect())
150 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSo urce, DebugMessageLevel, String("DNS prefetch triggered for " + href.host()))); 151 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSo urce, DebugMessageLevel, String("DNS prefetch triggered for " + href.host()), So urceLocation::capture(&document)));
151 networkHintsInterface.dnsPrefetchHost(href.host()); 152 networkHintsInterface.dnsPrefetchHost(href.host());
152 } 153 }
153 } 154 }
154 } 155 }
155 156
156 static void preconnectIfNeeded(const LinkRelAttribute& relAttribute, const KURL& href, Document& document, const CrossOriginAttributeValue crossOrigin, const Ne tworkHintsInterface& networkHintsInterface, LinkCaller caller) 157 static void preconnectIfNeeded(const LinkRelAttribute& relAttribute, const KURL& href, Document& document, const CrossOriginAttributeValue crossOrigin, const Ne tworkHintsInterface& networkHintsInterface, LinkCaller caller)
157 { 158 {
158 if (relAttribute.isPreconnect() && href.isValid() && href.protocolIsInHTTPFa mily()) { 159 if (relAttribute.isPreconnect() && href.isValid() && href.protocolIsInHTTPFa mily()) {
159 UseCounter::count(document, UseCounter::LinkRelPreconnect); 160 UseCounter::count(document, UseCounter::LinkRelPreconnect);
160 if (caller == LinkCalledFromHeader) 161 if (caller == LinkCalledFromHeader)
161 UseCounter::count(document, UseCounter::LinkHeaderPreconnect); 162 UseCounter::count(document, UseCounter::LinkHeaderPreconnect);
162 ASSERT(RuntimeEnabledFeatures::linkPreconnectEnabled()); 163 ASSERT(RuntimeEnabledFeatures::linkPreconnectEnabled());
163 Settings* settings = document.settings(); 164 Settings* settings = document.settings();
164 if (settings && settings->logDnsPrefetchAndPreconnect()) { 165 if (settings && settings->logDnsPrefetchAndPreconnect()) {
165 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource , DebugMessageLevel, String("Preconnect triggered for ") + href.getString())); 166 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource , DebugMessageLevel, String("Preconnect triggered for ") + href.getString(), Sou rceLocation::capture(&document)));
166 if (crossOrigin != CrossOriginAttributeNotSet) { 167 if (crossOrigin != CrossOriginAttributeNotSet) {
167 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSo urce, DebugMessageLevel, 168 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSo urce, DebugMessageLevel,
168 String("Preconnect CORS setting is ") + String((crossOrigin == CrossOriginAttributeAnonymous) ? "anonymous" : "use-credentials"))); 169 String("Preconnect CORS setting is ") + String((crossOrigin == CrossOriginAttributeAnonymous) ? "anonymous" : "use-credentials"),
170 SourceLocation::capture(&document)));
169 } 171 }
170 } 172 }
171 networkHintsInterface.preconnectHost(href, crossOrigin); 173 networkHintsInterface.preconnectHost(href, crossOrigin);
172 } 174 }
173 } 175 }
174 176
175 bool LinkLoader::getResourceTypeFromAsAttribute(const String& as, Resource::Type & type) 177 bool LinkLoader::getResourceTypeFromAsAttribute(const String& as, Resource::Type & type)
176 { 178 {
177 ASSERT(as.lower() == as); 179 ASSERT(as.lower() == as);
178 if (as == "image") { 180 if (as == "image") {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 253
252 static Resource* preloadIfNeeded(const LinkRelAttribute& relAttribute, const KUR L& href, Document& document, const String& as, const String& mimeType, 254 static Resource* preloadIfNeeded(const LinkRelAttribute& relAttribute, const KUR L& href, Document& document, const String& as, const String& mimeType,
253 const String& media, CrossOriginAttributeValue crossOrigin, LinkCaller calle r, bool& errorOccurred, ViewportDescription* viewportDescription) 255 const String& media, CrossOriginAttributeValue crossOrigin, LinkCaller calle r, bool& errorOccurred, ViewportDescription* viewportDescription)
254 { 256 {
255 if (!document.loader() || !relAttribute.isLinkPreload()) 257 if (!document.loader() || !relAttribute.isLinkPreload())
256 return nullptr; 258 return nullptr;
257 259
258 UseCounter::count(document, UseCounter::LinkRelPreload); 260 UseCounter::count(document, UseCounter::LinkRelPreload);
259 ASSERT(RuntimeEnabledFeatures::linkPreloadEnabled()); 261 ASSERT(RuntimeEnabledFeatures::linkPreloadEnabled());
260 if (!href.isValid() || href.isEmpty()) { 262 if (!href.isValid() || href.isEmpty()) {
261 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, Wa rningMessageLevel, String("<link rel=preload> has an invalid `href` value"))); 263 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, Wa rningMessageLevel, String("<link rel=preload> has an invalid `href` value"), Sou rceLocation::capture(&document)));
262 return nullptr; 264 return nullptr;
263 } 265 }
264 266
265 if (!media.isEmpty()) { 267 if (!media.isEmpty()) {
266 MediaValues* mediaValues = MediaValues::createDynamicIfFrameExists(docum ent.frame()); 268 MediaValues* mediaValues = MediaValues::createDynamicIfFrameExists(docum ent.frame());
267 if (viewportDescription) 269 if (viewportDescription)
268 mediaValues->overrideViewportDimensions(viewportDescription->maxWidt h.getFloatValue(), viewportDescription->maxHeight.getFloatValue()); 270 mediaValues->overrideViewportDimensions(viewportDescription->maxWidt h.getFloatValue(), viewportDescription->maxHeight.getFloatValue());
269 271
270 // Preload only if media matches 272 // Preload only if media matches
271 MediaQuerySet* mediaQueries = MediaQuerySet::create(media); 273 MediaQuerySet* mediaQueries = MediaQuerySet::create(media);
272 MediaQueryEvaluator evaluator(*mediaValues); 274 MediaQueryEvaluator evaluator(*mediaValues);
273 if (!evaluator.eval(mediaQueries)) 275 if (!evaluator.eval(mediaQueries))
274 return nullptr; 276 return nullptr;
275 } 277 }
276 if (caller == LinkCalledFromHeader) 278 if (caller == LinkCalledFromHeader)
277 UseCounter::count(document, UseCounter::LinkHeaderPreload); 279 UseCounter::count(document, UseCounter::LinkHeaderPreload);
278 Resource::Type resourceType; 280 Resource::Type resourceType;
279 if (!LinkLoader::getResourceTypeFromAsAttribute(as, resourceType)) { 281 if (!LinkLoader::getResourceTypeFromAsAttribute(as, resourceType)) {
280 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, Wa rningMessageLevel, String("<link rel=preload> must have a valid `as` value"))); 282 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, Wa rningMessageLevel, String("<link rel=preload> must have a valid `as` value"), So urceLocation::capture(&document)));
281 errorOccurred = true; 283 errorOccurred = true;
282 return nullptr; 284 return nullptr;
283 } 285 }
284 286
285 if (!isSupportedType(resourceType, mimeType)) { 287 if (!isSupportedType(resourceType, mimeType)) {
286 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, Wa rningMessageLevel, String("<link rel=preload> has an unsupported `type` value")) ); 288 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, Wa rningMessageLevel, String("<link rel=preload> has an unsupported `type` value"), SourceLocation::capture(&document)));
287 return nullptr; 289 return nullptr;
288 } 290 }
289 ResourceRequest resourceRequest(document.completeURL(href)); 291 ResourceRequest resourceRequest(document.completeURL(href));
290 ResourceFetcher::determineRequestContext(resourceRequest, resourceType, fals e); 292 ResourceFetcher::determineRequestContext(resourceRequest, resourceType, fals e);
291 FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link, doc ument.encodingName()); 293 FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link, doc ument.encodingName());
292 294
293 if (crossOrigin != CrossOriginAttributeNotSet) 295 if (crossOrigin != CrossOriginAttributeNotSet)
294 linkRequest.setCrossOriginAccessControl(document.getSecurityOrigin(), cr ossOrigin); 296 linkRequest.setCrossOriginAccessControl(document.getSecurityOrigin(), cr ossOrigin);
295 Settings* settings = document.settings(); 297 Settings* settings = document.settings();
296 if (settings && settings->logPreload()) 298 if (settings && settings->logPreload())
297 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, De bugMessageLevel, String("Preload triggered for " + href.host() + href.path()))); 299 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, De bugMessageLevel, String("Preload triggered for " + href.host() + href.path()), S ourceLocation::capture(&document)));
298 linkRequest.setForPreload(true, monotonicallyIncreasingTime()); 300 linkRequest.setForPreload(true, monotonicallyIncreasingTime());
299 linkRequest.setLinkPreload(true); 301 linkRequest.setLinkPreload(true);
300 linkRequest.setPriority(document.fetcher()->loadPriority(resourceType, linkR equest)); 302 linkRequest.setPriority(document.fetcher()->loadPriority(resourceType, linkR equest));
301 return document.loader()->startPreload(resourceType, linkRequest); 303 return document.loader()->startPreload(resourceType, linkRequest);
302 } 304 }
303 305
304 void LinkLoader::loadLinksFromHeader(const String& headerValue, const KURL& base URL, Document* document, const NetworkHintsInterface& networkHintsInterface, 306 void LinkLoader::loadLinksFromHeader(const String& headerValue, const KURL& base URL, Document* document, const NetworkHintsInterface& networkHintsInterface,
305 CanLoadResources canLoadResources, ViewportDescriptionWrapper* viewportDescr iptionWrapper) 307 CanLoadResources canLoadResources, ViewportDescriptionWrapper* viewportDescr iptionWrapper)
306 { 308 {
307 if (!document || headerValue.isEmpty()) 309 if (!document || headerValue.isEmpty())
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 DEFINE_TRACE(LinkLoader) 395 DEFINE_TRACE(LinkLoader)
394 { 396 {
395 visitor->trace(m_client); 397 visitor->trace(m_client);
396 visitor->trace(m_prerender); 398 visitor->trace(m_prerender);
397 visitor->trace(m_linkPreloadResourceClient); 399 visitor->trace(m_linkPreloadResourceClient);
398 ResourceOwner<Resource, ResourceClient>::trace(visitor); 400 ResourceOwner<Resource, ResourceClient>::trace(visitor);
399 PrerenderClient::trace(visitor); 401 PrerenderClient::trace(visitor);
400 } 402 }
401 403
402 } // namespace blink 404 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/HttpEquiv.cpp ('k') | third_party/WebKit/Source/core/loader/MixedContentChecker.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698