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

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

Issue 1131513004: Revert of Added <link rel=preconnect> crossorigin attribute (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 7 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/LinkHeaderTest.cpp ('k') | Source/platform/network/NetworkHints.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 19 matching lines...) Expand all
30 */ 30 */
31 31
32 #include "config.h" 32 #include "config.h"
33 #include "core/loader/LinkLoader.h" 33 #include "core/loader/LinkLoader.h"
34 34
35 #include "core/dom/Document.h" 35 #include "core/dom/Document.h"
36 #include "core/fetch/FetchInitiatorTypeNames.h" 36 #include "core/fetch/FetchInitiatorTypeNames.h"
37 #include "core/fetch/FetchRequest.h" 37 #include "core/fetch/FetchRequest.h"
38 #include "core/fetch/ResourceFetcher.h" 38 #include "core/fetch/ResourceFetcher.h"
39 #include "core/frame/Settings.h" 39 #include "core/frame/Settings.h"
40 #include "core/html/CrossOriginAttribute.h"
41 #include "core/html/LinkRelAttribute.h" 40 #include "core/html/LinkRelAttribute.h"
42 #include "core/inspector/ConsoleMessage.h" 41 #include "core/inspector/ConsoleMessage.h"
43 #include "core/loader/LinkHeader.h" 42 #include "core/loader/LinkHeader.h"
44 #include "core/loader/PrerenderHandle.h" 43 #include "core/loader/PrerenderHandle.h"
45 #include "platform/Prerender.h" 44 #include "platform/Prerender.h"
46 #include "platform/RuntimeEnabledFeatures.h" 45 #include "platform/RuntimeEnabledFeatures.h"
47 #include "platform/network/NetworkHints.h" 46 #include "platform/network/NetworkHints.h"
48 #include "public/platform/WebPrerender.h" 47 #include "public/platform/WebPrerender.h"
49 48
50 namespace blink { 49 namespace blink {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 // FIXME: The href attribute of the link element can be in "//hostname" form, and we shouldn't attempt 121 // FIXME: The href attribute of the link element can be in "//hostname" form, and we shouldn't attempt
123 // to complete that as URL <https://bugs.webkit.org/show_bug.cgi?id=4885 7>. 122 // to complete that as URL <https://bugs.webkit.org/show_bug.cgi?id=4885 7>.
124 if (settings && settings->dnsPrefetchingEnabled() && href.isValid() && ! href.isEmpty()) { 123 if (settings && settings->dnsPrefetchingEnabled() && href.isValid() && ! href.isEmpty()) {
125 if (settings->logDnsPrefetchAndPreconnect()) 124 if (settings->logDnsPrefetchAndPreconnect())
126 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSo urce, DebugMessageLevel, String("DNS prefetch triggered for " + href.host()))); 125 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSo urce, DebugMessageLevel, String("DNS prefetch triggered for " + href.host())));
127 prefetchDNS(href.host()); 126 prefetchDNS(href.host());
128 } 127 }
129 } 128 }
130 } 129 }
131 130
132 static void preconnectIfNeeded(const LinkRelAttribute& relAttribute, const KURL& href, Document& document, const CrossOriginAttributeValue crossOrigin) 131 static void preconnectIfNeeded(const LinkRelAttribute& relAttribute, const KURL& href, Document& document)
133 { 132 {
134 if (relAttribute.isPreconnect() && href.isValid()) { 133 if (relAttribute.isPreconnect() && href.isValid()) {
135 ASSERT(RuntimeEnabledFeatures::linkPreconnectEnabled()); 134 ASSERT(RuntimeEnabledFeatures::linkPreconnectEnabled());
136 Settings* settings = document.settings(); 135 Settings* settings = document.settings();
137 if (settings && settings->logDnsPrefetchAndPreconnect()) { 136 if (settings && settings->logDnsPrefetchAndPreconnect())
138 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource , DebugMessageLevel, String("Preconnect triggered for " + href.host()))); 137 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource , DebugMessageLevel, String("Preconnect triggered for " + href.host())));
139 if (crossOrigin != CrossOriginAttributeNotSet) { 138 preconnect(href);
140 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSo urce, DebugMessageLevel,
141 String("Preconnect CORS setting is ") + String((crossOrigin == CrossOriginAttributeAnonymous) ? "anonymous" : "use-credentials")));
142 }
143 }
144 preconnect(href, crossOrigin);
145 } 139 }
146 } 140 }
147 141
148 // TODO(yoav): Replace Resource:Type here with some way that conveys priority bu t not context. 142 // TODO(yoav): Replace Resource:Type here with some way that conveys priority bu t not context.
149 static bool getTypeFromAsAttribute(const String& as, Resource::Type& type) 143 static bool getTypeFromAsAttribute(const String& as, Resource::Type& type)
150 { 144 {
151 if (as.isEmpty()) 145 if (as.isEmpty())
152 return false; 146 return false;
153 // TODO(yoav): Return false also when the `as` value is not a valid one. 147 // TODO(yoav): Return false also when the `as` value is not a valid one.
154 // TODO(yoav): Add actual types here and make sure priorities work according ly. 148 // TODO(yoav): Add actual types here and make sure priorities work according ly.
(...skipping 29 matching lines...) Expand all
184 LinkHeaderSet headerSet(headerValue); 178 LinkHeaderSet headerSet(headerValue);
185 for (auto& header : headerSet) { 179 for (auto& header : headerSet) {
186 if (!header.valid() || header.url().isEmpty() || header.rel().isEmpty()) 180 if (!header.valid() || header.url().isEmpty() || header.rel().isEmpty())
187 return false; 181 return false;
188 LinkRelAttribute relAttribute(header.rel()); 182 LinkRelAttribute relAttribute(header.rel());
189 KURL url = document->completeURL(header.url()); 183 KURL url = document->completeURL(header.url());
190 if (RuntimeEnabledFeatures::linkHeaderEnabled()) 184 if (RuntimeEnabledFeatures::linkHeaderEnabled())
191 dnsPrefetchIfNeeded(relAttribute, url, *document); 185 dnsPrefetchIfNeeded(relAttribute, url, *document);
192 186
193 if (RuntimeEnabledFeatures::linkPreconnectEnabled()) 187 if (RuntimeEnabledFeatures::linkPreconnectEnabled())
194 preconnectIfNeeded(relAttribute, url, *document, header.crossOrigin( )); 188 preconnectIfNeeded(relAttribute, url, *document);
195 189
196 // FIXME: Add more supported headers as needed. 190 // FIXME: Add more supported headers as needed.
197 } 191 }
198 return true; 192 return true;
199 } 193 }
200 194
201 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const AtomicStri ng& crossOriginMode, const String& type, const String& as, const KURL& href, Doc ument& document) 195 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const AtomicStri ng& crossOriginMode, const String& type, const String& as, const KURL& href, Doc ument& document)
202 { 196 {
203 // TODO(yoav): Convert all uses of the CrossOriginAttribute to CrossOriginAt tributeValue. crbug.com/486689
204 // FIXME(crbug.com/463266): We're ignoring type here. Maybe we shouldn't. 197 // FIXME(crbug.com/463266): We're ignoring type here. Maybe we shouldn't.
205 dnsPrefetchIfNeeded(relAttribute, href, document); 198 dnsPrefetchIfNeeded(relAttribute, href, document);
206 199
207 preconnectIfNeeded(relAttribute, href, document, crossOriginAttributeValue(c rossOriginMode)); 200 preconnectIfNeeded(relAttribute, href, document);
208 201
209 preloadIfNeeded(relAttribute, href, document, as); 202 preloadIfNeeded(relAttribute, href, document, as);
210 203
211 // FIXME(crbug.com/323096): Should take care of import. 204 // FIXME(crbug.com/323096): Should take care of import.
212 if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource() || re lAttribute.isTransitionExitingStylesheet()) && href.isValid() && document.frame( )) { 205 if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource() || re lAttribute.isTransitionExitingStylesheet()) && href.isValid() && document.frame( )) {
213 if (!m_client->shouldLoadLink()) 206 if (!m_client->shouldLoadLink())
214 return false; 207 return false;
215 Resource::Type type = relAttribute.isLinkSubresource() ? Resource::Link Subresource : Resource::LinkPrefetch; 208 Resource::Type type = relAttribute.isLinkSubresource() ? Resource::Link Subresource : Resource::LinkPrefetch;
216 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe tchInitiatorTypeNames::link); 209 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe tchInitiatorTypeNames::link);
217 if (!crossOriginMode.isNull()) 210 if (!crossOriginMode.isNull())
(...skipping 25 matching lines...) Expand all
243 m_prerender.clear(); 236 m_prerender.clear();
244 } 237 }
245 } 238 }
246 239
247 DEFINE_TRACE(LinkLoader) 240 DEFINE_TRACE(LinkLoader)
248 { 241 {
249 visitor->trace(m_prerender); 242 visitor->trace(m_prerender);
250 } 243 }
251 244
252 } 245 }
OLDNEW
« no previous file with comments | « Source/core/loader/LinkHeaderTest.cpp ('k') | Source/platform/network/NetworkHints.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698