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

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

Issue 1060863003: Add initial link preload support (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Review comments Created 5 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 unified diff | Download patch
« no previous file with comments | « Source/core/loader/LinkLoader.h ('k') | Source/core/testing/InternalSettings.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 static void preconnectIfNeeded(const LinkRelAttribute& relAttribute, const KURL& href, Document& document) 131 static void preconnectIfNeeded(const LinkRelAttribute& relAttribute, const KURL& href, Document& document)
132 { 132 {
133 if (relAttribute.isPreconnect() && href.isValid()) { 133 if (relAttribute.isPreconnect() && href.isValid()) {
134 ASSERT(RuntimeEnabledFeatures::linkPreconnectEnabled()); 134 ASSERT(RuntimeEnabledFeatures::linkPreconnectEnabled());
135 if (document.settings()->logDnsPrefetchAndPreconnect()) 135 if (document.settings()->logDnsPrefetchAndPreconnect())
136 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource , DebugMessageLevel, String("Preconnect triggered for " + href.host()))); 136 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource , DebugMessageLevel, String("Preconnect triggered for " + href.host())));
137 preconnect(href); 137 preconnect(href);
138 } 138 }
139 } 139 }
140 140
141 Resource::Type getTypeFromAsAttribute(const String& as)
142 {
143 // FIXME: Add actual types here and make sure priorities work accordingly.
Mike West 2015/04/07 19:56:18 Nit: We spell this `TODO(yoav):` now...
144 return Resource::Raw;
145 }
146
147 void LinkLoader::preloadIfNeeded(const LinkRelAttribute& relAttribute, const KUR L& href, Document& document, const String& as)
148 {
149 if (relAttribute.isLinkPreload() && href.isValid()) {
Mike West 2015/04/07 19:56:18 https://w3c.github.io/preload/#fetch-settings says
150 ASSERT(RuntimeEnabledFeatures::linkPreloadEnabled());
151 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe tchInitiatorTypeNames::link);
152 Resource::Type type = getTypeFromAsAttribute(as);
153 if (document.settings()->logPreload())
154 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource , DebugMessageLevel, String("Preload triggered for " + href.host() + href.path() )));
155 setResource(document.fetcher()->fetchLinkPreloadResource(type, linkReque st));
156 }
157 }
158
141 bool LinkLoader::loadLinkFromHeader(const String& headerValue, Document* documen t) 159 bool LinkLoader::loadLinkFromHeader(const String& headerValue, Document* documen t)
142 { 160 {
143 if (!document) 161 if (!document)
144 return false; 162 return false;
145 LinkHeaderSet headerSet(headerValue); 163 LinkHeaderSet headerSet(headerValue);
146 for (auto& header : headerSet) { 164 for (auto& header : headerSet) {
147 if (!header.valid() || header.url().isEmpty() || header.rel().isEmpty()) 165 if (!header.valid() || header.url().isEmpty() || header.rel().isEmpty())
148 return false; 166 return false;
149 LinkRelAttribute relAttribute(header.rel()); 167 LinkRelAttribute relAttribute(header.rel());
150 KURL url = document->completeURL(header.url()); 168 KURL url = document->completeURL(header.url());
151 if (RuntimeEnabledFeatures::linkHeaderEnabled()) 169 if (RuntimeEnabledFeatures::linkHeaderEnabled())
152 dnsPrefetchIfNeeded(relAttribute, url, *document); 170 dnsPrefetchIfNeeded(relAttribute, url, *document);
153 171
154 if (RuntimeEnabledFeatures::linkPreconnectEnabled()) 172 if (RuntimeEnabledFeatures::linkPreconnectEnabled())
155 preconnectIfNeeded(relAttribute, url, *document); 173 preconnectIfNeeded(relAttribute, url, *document);
156 174
157 // FIXME: Add more supported headers as needed. 175 // FIXME: Add more supported headers as needed.
158 } 176 }
159 return true; 177 return true;
160 } 178 }
161 179
162 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const AtomicStri ng& crossOriginMode, const String& type, const KURL& href, Document& document) 180 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const AtomicStri ng& crossOriginMode, const String& type, const String& as, const KURL& href, Doc ument& document)
163 { 181 {
182 // FIXME(crbug.com/463266): We're ignoring type here. Maybe we shouldn't.
164 dnsPrefetchIfNeeded(relAttribute, href, document); 183 dnsPrefetchIfNeeded(relAttribute, href, document);
165 184
166 preconnectIfNeeded(relAttribute, href, document); 185 preconnectIfNeeded(relAttribute, href, document);
167 186
187 preloadIfNeeded(relAttribute, href, document, as);
188
168 // FIXME(crbug.com/323096): Should take care of import. 189 // FIXME(crbug.com/323096): Should take care of import.
169 if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource() || re lAttribute.isTransitionExitingStylesheet()) && href.isValid() && document.frame( )) { 190 if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource() || re lAttribute.isTransitionExitingStylesheet()) && href.isValid() && document.frame( )) {
170 if (!m_client->shouldLoadLink()) 191 if (!m_client->shouldLoadLink())
171 return false; 192 return false;
172 Resource::Type type = relAttribute.isLinkSubresource() ? Resource::Link Subresource : Resource::LinkPrefetch; 193 Resource::Type type = relAttribute.isLinkSubresource() ? Resource::Link Subresource : Resource::LinkPrefetch;
173 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe tchInitiatorTypeNames::link); 194 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe tchInitiatorTypeNames::link);
174 if (!crossOriginMode.isNull()) 195 if (!crossOriginMode.isNull())
175 linkRequest.setCrossOriginAccessControl(document.securityOrigin(), c rossOriginMode); 196 linkRequest.setCrossOriginAccessControl(document.securityOrigin(), c rossOriginMode);
176 setResource(document.fetcher()->fetchLinkResource(type, linkRequest)); 197 setResource(document.fetcher()->fetchLinkResource(type, linkRequest));
177 } 198 }
(...skipping 22 matching lines...) Expand all
200 m_prerender.clear(); 221 m_prerender.clear();
201 } 222 }
202 } 223 }
203 224
204 DEFINE_TRACE(LinkLoader) 225 DEFINE_TRACE(LinkLoader)
205 { 226 {
206 visitor->trace(m_prerender); 227 visitor->trace(m_prerender);
207 } 228 }
208 229
209 } 230 }
OLDNEW
« no previous file with comments | « Source/core/loader/LinkLoader.h ('k') | Source/core/testing/InternalSettings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698