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

Unified Diff: third_party/WebKit/Source/core/loader/LinkLoader.cpp

Issue 2483713002: Add referrerpolicy support to link prefetch (Closed)
Patch Set: added tests for dns-prefetch and preconnct outside Document Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/loader/LinkLoader.cpp
diff --git a/third_party/WebKit/Source/core/loader/LinkLoader.cpp b/third_party/WebKit/Source/core/loader/LinkLoader.cpp
index ddea909a2986908fde64e5c7f90b99963bf2183d..8c91554684908de98142f7e9cc8241a711d55311 100644
--- a/third_party/WebKit/Source/core/loader/LinkLoader.cpp
+++ b/third_party/WebKit/Source/core/loader/LinkLoader.cpp
@@ -340,6 +340,29 @@ static Resource* preloadIfNeeded(const LinkRelAttribute& relAttribute,
return document.loader()->startPreload(resourceType, linkRequest);
}
+void LinkLoader::prefetchIfNeeded(Document& document,
+ const KURL& href,
+ const LinkRelAttribute& relAttribute,
+ CrossOriginAttributeValue crossOrigin,
+ ReferrerPolicy referrerPolicy) {
+ if (relAttribute.isLinkPrefetch() && href.isValid() && document.frame()) {
+ UseCounter::count(document, UseCounter::LinkRelPrefetch);
+
+ ResourceRequest resourceRequest(document.completeURL(href));
Mike West 2016/11/07 09:52:43 You could avoid creating this intermediate object
Yoav Weiss 2016/11/08 09:23:53 Yeah, slightly simpler I guess. Changed
+ if (referrerPolicy != ReferrerPolicyDefault) {
+ resourceRequest.setHTTPReferrer(SecurityPolicy::generateReferrer(
+ referrerPolicy, href, document.outgoingReferrer()));
+ }
+ FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link);
+ if (crossOrigin != CrossOriginAttributeNotSet) {
+ linkRequest.setCrossOriginAccessControl(document.getSecurityOrigin(),
+ crossOrigin);
+ }
+ setResource(LinkFetchResource::fetch(Resource::LinkPrefetch, linkRequest,
+ document.fetcher()));
+ }
+}
+
void LinkLoader::loadLinksFromHeader(
const String& headerValue,
const KURL& baseURL,
@@ -399,13 +422,9 @@ bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute,
const KURL& href,
Document& document,
const NetworkHintsInterface& networkHintsInterface) {
- // TODO(yoav): Do all links need to load only after they're in document???
+ if (!m_client->shouldLoadLink())
+ return false;
- // TODO(yoav): Convert all uses of the CrossOriginAttribute to
- // CrossOriginAttributeValue. crbug.com/486689
-
- // FIXME(crbug.com/463266): We're ignoring type here, for everything but
- // preload. Maybe we shouldn't.
dnsPrefetchIfNeeded(relAttribute, href, document, networkHintsInterface,
LinkCalledFromMarkup);
@@ -413,32 +432,16 @@ bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute,
networkHintsInterface, LinkCalledFromMarkup);
bool errorOccurred = false;
- if (m_client->shouldLoadLink()) {
- createLinkPreloadResourceClient(preloadIfNeeded(
- relAttribute, href, document, as, type, media, crossOrigin,
- LinkCalledFromMarkup, errorOccurred, nullptr, referrerPolicy));
- }
+ createLinkPreloadResourceClient(preloadIfNeeded(
+ relAttribute, href, document, as, type, media, crossOrigin,
+ LinkCalledFromMarkup, errorOccurred, nullptr, referrerPolicy));
if (errorOccurred)
m_linkLoadingErrorTimer.startOneShot(0, BLINK_FROM_HERE);
if (href.isEmpty() || !href.isValid())
released();
- // FIXME(crbug.com/323096): Should take care of import.
- if (relAttribute.isLinkPrefetch() && href.isValid() && document.frame()) {
- if (!m_client->shouldLoadLink())
- return false;
- UseCounter::count(document, UseCounter::LinkRelPrefetch);
-
- FetchRequest linkRequest(ResourceRequest(document.completeURL(href)),
- FetchInitiatorTypeNames::link);
- if (crossOrigin != CrossOriginAttributeNotSet) {
- linkRequest.setCrossOriginAccessControl(document.getSecurityOrigin(),
- crossOrigin);
- }
- setResource(LinkFetchResource::fetch(Resource::LinkPrefetch, linkRequest,
- document.fetcher()));
- }
+ prefetchIfNeeded(document, href, relAttribute, crossOrigin, referrerPolicy);
if (const unsigned prerenderRelTypes =
prerenderRelTypesFromRelAttribute(relAttribute, document)) {
« no previous file with comments | « third_party/WebKit/Source/core/loader/LinkLoader.h ('k') | third_party/WebKit/Source/core/loader/LinkLoaderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698