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

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

Issue 2415373002: Loading: bulk style errors fix in core/loader (Closed)
Patch Set: Created 4 years, 2 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 if (relAttribute.isDNSPrefetch()) { 133 if (relAttribute.isDNSPrefetch()) {
134 UseCounter::count(document, UseCounter::LinkRelDnsPrefetch); 134 UseCounter::count(document, UseCounter::LinkRelDnsPrefetch);
135 if (caller == LinkCalledFromHeader) 135 if (caller == LinkCalledFromHeader)
136 UseCounter::count(document, UseCounter::LinkHeaderDnsPrefetch); 136 UseCounter::count(document, UseCounter::LinkHeaderDnsPrefetch);
137 Settings* settings = document.settings(); 137 Settings* settings = document.settings();
138 // FIXME: The href attribute of the link element can be in "//hostname" 138 // FIXME: The href attribute of the link element can be in "//hostname"
139 // form, and we shouldn't attempt to complete that as URL 139 // form, and we shouldn't attempt to complete that as URL
140 // <https://bugs.webkit.org/show_bug.cgi?id=48857>. 140 // <https://bugs.webkit.org/show_bug.cgi?id=48857>.
141 if (settings && settings->dnsPrefetchingEnabled() && href.isValid() && 141 if (settings && settings->dnsPrefetchingEnabled() && href.isValid() &&
142 !href.isEmpty()) { 142 !href.isEmpty()) {
143 if (settings->logDnsPrefetchAndPreconnect()) 143 if (settings->logDnsPrefetchAndPreconnect()) {
144 document.addConsoleMessage(ConsoleMessage::create( 144 document.addConsoleMessage(ConsoleMessage::create(
145 OtherMessageSource, DebugMessageLevel, 145 OtherMessageSource, DebugMessageLevel,
146 String("DNS prefetch triggered for " + href.host()))); 146 String("DNS prefetch triggered for " + href.host())));
147 }
147 networkHintsInterface.dnsPrefetchHost(href.host()); 148 networkHintsInterface.dnsPrefetchHost(href.host());
148 } 149 }
149 } 150 }
150 } 151 }
151 152
152 static void preconnectIfNeeded( 153 static void preconnectIfNeeded(
153 const LinkRelAttribute& relAttribute, 154 const LinkRelAttribute& relAttribute,
154 const KURL& href, 155 const KURL& href,
155 Document& document, 156 Document& document,
156 const CrossOriginAttributeValue crossOrigin, 157 const CrossOriginAttributeValue crossOrigin,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 if (!href.isValid() || href.isEmpty()) { 277 if (!href.isValid() || href.isEmpty()) {
277 document.addConsoleMessage(ConsoleMessage::create( 278 document.addConsoleMessage(ConsoleMessage::create(
278 OtherMessageSource, WarningMessageLevel, 279 OtherMessageSource, WarningMessageLevel,
279 String("<link rel=preload> has an invalid `href` value"))); 280 String("<link rel=preload> has an invalid `href` value")));
280 return nullptr; 281 return nullptr;
281 } 282 }
282 283
283 if (!media.isEmpty()) { 284 if (!media.isEmpty()) {
284 MediaValues* mediaValues = 285 MediaValues* mediaValues =
285 MediaValues::createDynamicIfFrameExists(document.frame()); 286 MediaValues::createDynamicIfFrameExists(document.frame());
286 if (viewportDescription) 287 if (viewportDescription) {
287 mediaValues->overrideViewportDimensions( 288 mediaValues->overrideViewportDimensions(
288 viewportDescription->maxWidth.getFloatValue(), 289 viewportDescription->maxWidth.getFloatValue(),
289 viewportDescription->maxHeight.getFloatValue()); 290 viewportDescription->maxHeight.getFloatValue());
291 }
290 292
291 // Preload only if media matches 293 // Preload only if media matches
292 MediaQuerySet* mediaQueries = MediaQuerySet::create(media); 294 MediaQuerySet* mediaQueries = MediaQuerySet::create(media);
293 MediaQueryEvaluator evaluator(*mediaValues); 295 MediaQueryEvaluator evaluator(*mediaValues);
294 if (!evaluator.eval(mediaQueries)) 296 if (!evaluator.eval(mediaQueries))
295 return nullptr; 297 return nullptr;
296 } 298 }
297 if (caller == LinkCalledFromHeader) 299 if (caller == LinkCalledFromHeader)
298 UseCounter::count(document, UseCounter::LinkHeaderPreload); 300 UseCounter::count(document, UseCounter::LinkHeaderPreload);
299 Resource::Type resourceType; 301 Resource::Type resourceType;
(...skipping 10 matching lines...) Expand all
310 OtherMessageSource, WarningMessageLevel, 312 OtherMessageSource, WarningMessageLevel,
311 String("<link rel=preload> has an unsupported `type` value"))); 313 String("<link rel=preload> has an unsupported `type` value")));
312 return nullptr; 314 return nullptr;
313 } 315 }
314 ResourceRequest resourceRequest(document.completeURL(href)); 316 ResourceRequest resourceRequest(document.completeURL(href));
315 ResourceFetcher::determineRequestContext(resourceRequest, resourceType, 317 ResourceFetcher::determineRequestContext(resourceRequest, resourceType,
316 false); 318 false);
317 FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link, 319 FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link,
318 document.encodingName()); 320 document.encodingName());
319 321
320 if (crossOrigin != CrossOriginAttributeNotSet) 322 if (crossOrigin != CrossOriginAttributeNotSet) {
321 linkRequest.setCrossOriginAccessControl(document.getSecurityOrigin(), 323 linkRequest.setCrossOriginAccessControl(document.getSecurityOrigin(),
322 crossOrigin); 324 crossOrigin);
325 }
323 Settings* settings = document.settings(); 326 Settings* settings = document.settings();
324 if (settings && settings->logPreload()) 327 if (settings && settings->logPreload()) {
325 document.addConsoleMessage(ConsoleMessage::create( 328 document.addConsoleMessage(ConsoleMessage::create(
326 OtherMessageSource, DebugMessageLevel, 329 OtherMessageSource, DebugMessageLevel,
327 String("Preload triggered for " + href.host() + href.path()))); 330 String("Preload triggered for " + href.host() + href.path())));
331 }
328 linkRequest.setForPreload(true, monotonicallyIncreasingTime()); 332 linkRequest.setForPreload(true, monotonicallyIncreasingTime());
329 linkRequest.setLinkPreload(true); 333 linkRequest.setLinkPreload(true);
330 return document.loader()->startPreload(resourceType, linkRequest); 334 return document.loader()->startPreload(resourceType, linkRequest);
331 } 335 }
332 336
333 void LinkLoader::loadLinksFromHeader( 337 void LinkLoader::loadLinksFromHeader(
334 const String& headerValue, 338 const String& headerValue,
335 const KURL& baseURL, 339 const KURL& baseURL,
336 Document* document, 340 Document* document,
337 const NetworkHintsInterface& networkHintsInterface, 341 const NetworkHintsInterface& networkHintsInterface,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 397
394 // FIXME(crbug.com/463266): We're ignoring type here, for everything but 398 // FIXME(crbug.com/463266): We're ignoring type here, for everything but
395 // preload. Maybe we shouldn't. 399 // preload. Maybe we shouldn't.
396 dnsPrefetchIfNeeded(relAttribute, href, document, networkHintsInterface, 400 dnsPrefetchIfNeeded(relAttribute, href, document, networkHintsInterface,
397 LinkCalledFromMarkup); 401 LinkCalledFromMarkup);
398 402
399 preconnectIfNeeded(relAttribute, href, document, crossOrigin, 403 preconnectIfNeeded(relAttribute, href, document, crossOrigin,
400 networkHintsInterface, LinkCalledFromMarkup); 404 networkHintsInterface, LinkCalledFromMarkup);
401 405
402 bool errorOccurred = false; 406 bool errorOccurred = false;
403 if (m_client->shouldLoadLink()) 407 if (m_client->shouldLoadLink()) {
404 createLinkPreloadResourceClient(preloadIfNeeded( 408 createLinkPreloadResourceClient(preloadIfNeeded(
405 relAttribute, href, document, as, type, media, crossOrigin, 409 relAttribute, href, document, as, type, media, crossOrigin,
406 LinkCalledFromMarkup, errorOccurred, nullptr)); 410 LinkCalledFromMarkup, errorOccurred, nullptr));
411 }
407 if (errorOccurred) 412 if (errorOccurred)
408 m_linkLoadingErrorTimer.startOneShot(0, BLINK_FROM_HERE); 413 m_linkLoadingErrorTimer.startOneShot(0, BLINK_FROM_HERE);
409 414
410 if (href.isEmpty() || !href.isValid()) 415 if (href.isEmpty() || !href.isValid())
411 released(); 416 released();
412 417
413 // FIXME(crbug.com/323096): Should take care of import. 418 // FIXME(crbug.com/323096): Should take care of import.
414 if (relAttribute.isLinkPrefetch() && href.isValid() && document.frame()) { 419 if (relAttribute.isLinkPrefetch() && href.isValid() && document.frame()) {
415 if (!m_client->shouldLoadLink()) 420 if (!m_client->shouldLoadLink())
416 return false; 421 return false;
417 UseCounter::count(document, UseCounter::LinkRelPrefetch); 422 UseCounter::count(document, UseCounter::LinkRelPrefetch);
418 423
419 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), 424 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)),
420 FetchInitiatorTypeNames::link); 425 FetchInitiatorTypeNames::link);
421 if (crossOrigin != CrossOriginAttributeNotSet) 426 if (crossOrigin != CrossOriginAttributeNotSet) {
422 linkRequest.setCrossOriginAccessControl(document.getSecurityOrigin(), 427 linkRequest.setCrossOriginAccessControl(document.getSecurityOrigin(),
423 crossOrigin); 428 crossOrigin);
429 }
424 setResource(LinkFetchResource::fetch(Resource::LinkPrefetch, linkRequest, 430 setResource(LinkFetchResource::fetch(Resource::LinkPrefetch, linkRequest,
425 document.fetcher())); 431 document.fetcher()));
426 } 432 }
427 433
428 if (const unsigned prerenderRelTypes = 434 if (const unsigned prerenderRelTypes =
429 prerenderRelTypesFromRelAttribute(relAttribute, document)) { 435 prerenderRelTypesFromRelAttribute(relAttribute, document)) {
430 if (!m_prerender) { 436 if (!m_prerender) {
431 m_prerender = 437 m_prerender =
432 PrerenderHandle::create(document, this, href, prerenderRelTypes); 438 PrerenderHandle::create(document, this, href, prerenderRelTypes);
433 } else if (m_prerender->url() != href) { 439 } else if (m_prerender->url() != href) {
(...skipping 22 matching lines...) Expand all
456 462
457 DEFINE_TRACE(LinkLoader) { 463 DEFINE_TRACE(LinkLoader) {
458 visitor->trace(m_client); 464 visitor->trace(m_client);
459 visitor->trace(m_prerender); 465 visitor->trace(m_prerender);
460 visitor->trace(m_linkPreloadResourceClient); 466 visitor->trace(m_linkPreloadResourceClient);
461 ResourceOwner<Resource, ResourceClient>::trace(visitor); 467 ResourceOwner<Resource, ResourceClient>::trace(visitor);
462 PrerenderClient::trace(visitor); 468 PrerenderClient::trace(visitor);
463 } 469 }
464 470
465 } // namespace blink 471 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/ImageLoader.cpp ('k') | third_party/WebKit/Source/core/loader/LinkLoaderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698