static void dnsPrefetchIfNeeded( const LinkRelAttribute& relAttribute, const KURL& href, Document& document, const NetworkHintsInterface& networkHintsInterface, LinkCaller caller) { if (relAttribute.isDNSPrefetch()) { UseCounter::count(document, UseCounter::LinkRelDnsPrefetch); if (caller == LinkCalledFromHeader) UseCounter::count(document, UseCounter::LinkHeaderDnsPrefetch); Settings* settings = document.settings(); // FIXME: The href attribute of the link element can be in "//hostname" // form, and we shouldn't attempt to complete that as URL // <https://bugs.webkit.org/show_bug.cgi?id=48857>. if (settings && settings->dnsPrefetchingEnabled() && href.isValid() && !href.isEmpty()) { if (settings->logDnsPrefetchAndPreconnect()) { document.addConsoleMessage(ConsoleMessage::create( OtherMessageSource, DebugMessageLevel, String("DNS prefetch triggered for " + href.host()))); } networkHintsInterface.dnsPrefetchHost(href.host()); } } }
bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const AtomicString& crossOriginMode, const String& type, const KURL& href, Document& document) { if (relAttribute.isDNSPrefetch()) { Settings* settings = document.settings(); // FIXME: The href attribute of the link element can be in "//hostname" form, and we shouldn't attempt // to complete that as URL <https://bugs.webkit.org/show_bug.cgi?id=48857>. if (settings && settings->dnsPrefetchingEnabled() && href.isValid() && !href.isEmpty()) prefetchDNS(href.host()); } // FIXME(crbug.com/323096): Should take care of import. if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource()) && href.isValid() && document.frame()) { if (!m_client->shouldLoadLink()) return false; Resource::Type type = relAttribute.isLinkSubresource() ? Resource::LinkSubresource : Resource::LinkPrefetch; FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), FetchInitiatorTypeNames::link); if (!crossOriginMode.isNull()) linkRequest.setCrossOriginAccessControl(document.securityOrigin(), crossOriginMode); setResource(document.fetcher()->fetchLinkResource(type, linkRequest)); } if (const unsigned prerenderRelTypes = prerenderRelTypesFromRelAttribute(relAttribute)) { if (!m_prerender) { m_prerender = PrerenderHandle::create(document, this, href, prerenderRelTypes); } else if (m_prerender->url() != href) { m_prerender->cancel(); m_prerender = PrerenderHandle::create(document, this, href, prerenderRelTypes); } // TODO(gavinp): Handle changes to rel types of existing prerenders. } else if (m_prerender) { m_prerender->cancel(); m_prerender.clear(); } return true; }
static void dnsPrefetchIfNeeded(const LinkRelAttribute& relAttribute, const KURL& href, Document& document) { if (relAttribute.isDNSPrefetch()) { Settings* settings = document.settings(); // FIXME: The href attribute of the link element can be in "//hostname" form, and we shouldn't attempt // to complete that as URL <https://bugs.webkit.org/show_bug.cgi?id=48857>. if (settings && settings->dnsPrefetchingEnabled() && href.isValid() && !href.isEmpty()) { if (settings->logDnsPrefetchAndPreconnect()) document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, DebugMessageLevel, String("DNS prefetch triggered for " + href.host()))); prefetchDNS(href.host()); } } }