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

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

Issue 2483713002: Add referrerpolicy support to link prefetch (Closed)
Patch Set: -mReview nit & DCHECK 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..1c535034b50cdec01cd03c462d3da1c181234a90 100644
--- a/third_party/WebKit/Source/core/loader/LinkLoader.cpp
+++ b/third_party/WebKit/Source/core/loader/LinkLoader.cpp
@@ -75,7 +75,9 @@ static unsigned prerenderRelTypesFromRelAttribute(
LinkLoader::LinkLoader(LinkLoaderClient* client)
: m_client(client),
m_linkLoadTimer(this, &LinkLoader::linkLoadTimerFired),
- m_linkLoadingErrorTimer(this, &LinkLoader::linkLoadingErrorTimerFired) {}
+ m_linkLoadingErrorTimer(this, &LinkLoader::linkLoadingErrorTimerFired) {
+ DCHECK(m_client);
Yoav Weiss 2016/11/08 09:27:22 Added a DCHECK here that seemed missing...
+}
LinkLoader::~LinkLoader() {}
@@ -340,6 +342,30 @@ 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);
+
+ FetchRequest linkRequest(ResourceRequest(document.completeURL(href)),
+ FetchInitiatorTypeNames::link);
+ if (referrerPolicy != ReferrerPolicyDefault) {
+ linkRequest.mutableResourceRequest().setHTTPReferrer(
+ SecurityPolicy::generateReferrer(referrerPolicy, href,
+ document.outgoingReferrer()));
+ }
+ 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 +425,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 +435,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