LayoutTests/ChangeLog

 12011-05-18 Gavin Peters <gavinp@chromium.org>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 Add rel type prerender to distinguish prerender from prefetch
 6 https://bugs.webkit.org/show_bug.cgi?id=61079
 7
 8 Chrome right now uses <link rel=prefetch ...> for one of two things,
 9 to warm the cache in the same way as firefox, or to launch a speculative
 10 rendering of a web page, for faster "loading" when the user navigates to it.
 11
 12 This new rel type will let us distinguish the two cases; the rel type prerender
 13 isn't used on the web today, but the Google Web Search example prerendering application
 14 is ready to experiment with it.
 15
 16 * fast/dom/HTMLLinkElement/prerender-expected.txt: Added.
 17 * fast/dom/HTMLLinkElement/prerender.html: Added.
 18 * platform/gtk/Skipped:
 19 * platform/mac/Skipped:
 20 * platform/qt/Skipped:
 21 * platform/win/Skipped:
 22
1232011-05-17 Jeremy Noble <jer.noble@apple.com>
224
325 Reviewed by Darin Adler.

LayoutTests/fast/dom/HTMLLinkElement/prerender-expected.txt

 1prefetch.link has MIME type application/octet-stream
 2PASS onload called!
 3This test will only print "PASS" or "FAIL" if link prefetches are enabled, otherwise it will show nothing below.

LayoutTests/fast/dom/HTMLLinkElement/prerender.html

 1<body>
 2<div id="console"></div>
 3<script src="../../js/resources/js-test-pre.js"></script>
 4<script>
 5function prefetch_onload() {
 6 testPassed('onload called!');
 7 layoutTestController.notifyDone();
 8}
 9if (window.layoutTestController) {
 10 layoutTestController.waitUntilDone();
 11 layoutTestController.dumpAsText();
 12 layoutTestController.dumpResourceResponseMIMETypes();
 13}
 14</script>
 15<html>
 16<p>This test will only print "PASS" or "FAIL" if link prefetches are
 17enabled, otherwise it will show nothing below.</p>
 18<link href="prefetch.link" rel="prerender" onload="prefetch_onload()" onerror="testFailed('onerror')" />
 19</html>
 20

LayoutTests/platform/gtk/Skipped

@@fast/dom/HTMLLinkElement/prefetch.html
943943fast/dom/HTMLLinkElement/prefetch-onerror.html
944944fast/dom/HTMLLinkElement/prefetch-onload.html
945945fast/dom/HTMLLinkElement/prefetch-beforeload.html
 946fast/dom/HTMLLinkElement/prerender.html
946947fast/dom/HTMLLinkElement/subresource.html
947948
948949# Tests failing because the context menu is grabbing mouse events.

LayoutTests/platform/mac/Skipped

@@fast/dom/HTMLLinkElement/prefetch.html
186186fast/dom/HTMLLinkElement/prefetch-beforeload.html
187187fast/dom/HTMLLinkElement/prefetch-onerror.html
188188fast/dom/HTMLLinkElement/prefetch-onload.html
 189fast/dom/HTMLLinkElement/prerender.html
189190fast/dom/HTMLLinkElement/subresource.html
190191http/tests/misc/link-rel-prefetch-and-subresource.html
191192http/tests/misc/prefetch-purpose.html

LayoutTests/platform/qt/Skipped

@@fast/dom/HTMLLinkElement/prefetch.html
20152015fast/dom/HTMLLinkElement/prefetch-beforeload.html
20162016fast/dom/HTMLLinkElement/prefetch-onerror.html
20172017fast/dom/HTMLLinkElement/prefetch-onload.html
 2018fast/dom/HTMLLinkElement/prerender.html
20182019fast/dom/HTMLLinkElement/subresource.html
20192020http/tests/misc/link-rel-prefetch-and-subresource.html
20202021http/tests/misc/prefetch-purpose.html

LayoutTests/platform/win/Skipped

@@fast/dom/HTMLLinkElement/prefetch.html
10051005fast/dom/HTMLLinkElement/prefetch-beforeload.html
10061006fast/dom/HTMLLinkElement/prefetch-onerror.html
10071007fast/dom/HTMLLinkElement/prefetch-onload.html
1008 fast/dom/HTMLLinkElement/subresource.html
10091008http/tests/misc/link-rel-prefetch-and-subresource.html
 1009fast/dom/HTMLLinkElement/prerender.html
 1010fast/dom/HTMLLinkElement/subresource.html
10101011http/tests/misc/prefetch-purpose.html
10111012
10121013# LayoutTestController::pageProperty is not implemented for WIN yet.

Source/WebCore/ChangeLog

 12011-05-18 Gavin Peters <gavinp@chromium.org>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 Add rel type prerender to distinguish prerender from prefetch
 6 https://bugs.webkit.org/show_bug.cgi?id=61079
 7
 8 Chrome right now uses <link rel=prefetch ...> for one of two things,
 9 to warm the cache in the same way as firefox, or to launch a speculative
 10 rendering of a web page, for faster "loading" when the user navigates to it.
 11
 12 This new rel type will let us distinguish the two cases; the rel type prerender
 13 isn't used on the web today, but the Google Web Search example prerendering application
 14 is ready to experiment with it.
 15
 16 Test: fast/dom/HTMLLinkElement/prerender.html
 17
 18 * html/HTMLLinkElement.cpp:
 19 (WebCore::HTMLLinkElement::tokenizeRelAttribute):
 20 (WebCore::HTMLLinkElement::process):
 21 * html/HTMLLinkElement.h:
 22 (WebCore::HTMLLinkElement::RelAttribute::RelAttribute):
 23 * loader/cache/CachedResource.cpp:
 24 (WebCore::defaultPriorityForResourceType):
 25 * loader/cache/CachedResource.h:
 26 (WebCore::CachedResource::isLinkResource):
 27 * loader/cache/CachedResourceLoader.cpp:
 28 (WebCore::createResource):
 29 (WebCore::CachedResourceLoader::requestLinkResource):
 30 (WebCore::CachedResourceLoader::canRequest):
 31 * loader/cache/CachedResourceLoader.h:
 32 * loader/cache/CachedResourceRequest.cpp:
 33 (WebCore::cachedResourceTypeToTargetType):
 34 (WebCore::CachedResourceRequest::load):
 35 * platform/network/ResourceRequestBase.h:
 36
1372011-05-17 Jeremy Noble <jer.noble@apple.com>
238
339 Reviewed by Darin Adler.

Source/WebCore/html/HTMLLinkElement.cpp

@@void HTMLLinkElement::tokenizeRelAttribute(const AtomicString& rel, RelAttribute
165165 relAttribute.m_isDNSPrefetch = false;
166166#if ENABLE(LINK_PREFETCH)
167167 relAttribute.m_isLinkPrefetch = false;
 168 relAttribute.m_isLinkPrerender = false;
168169 relAttribute.m_isLinkSubresource = false;
169170#endif
170171 if (equalIgnoringCase(rel, "stylesheet"))

@@void HTMLLinkElement::tokenizeRelAttribute(const AtomicString& rel, RelAttribute
205206#if ENABLE(LINK_PREFETCH)
206207 else if (equalIgnoringCase(*it, "prefetch"))
207208 relAttribute.m_isLinkPrefetch = true;
 209 else if (equalIgnoringCase(*it, "prerender"))
 210 relAttribute.m_isLinkPrerender = true;
208211 else if (equalIgnoringCase(*it, "subresource"))
209212 relAttribute.m_isLinkSubresource = true;
210213#endif

@@void HTMLLinkElement::process()
249252 }
250253
251254#if ENABLE(LINK_PREFETCH)
252  if ((m_relAttribute.m_isLinkPrefetch || m_relAttribute.m_isLinkSubresource) && m_url.isValid() && document()->frame()) {
 255 if ((m_relAttribute.m_isLinkPrefetch || m_relAttribute.m_isLinkPrerender || m_relAttribute.m_isLinkSubresource) && m_url.isValid() && document()->frame()) {
253256 if (!checkBeforeLoadEvent())
254257 return;
255258 ResourceLoadPriority priority = ResourceLoadPriorityUnresolved;
256  if (m_relAttribute.m_isLinkSubresource)
 259 CachedResource::Type type = CachedResource::LinkPrefetch;
 260 // We only make one request to the cachedresourcelodaer if multiple rel types are
 261 // specified,
 262 if (m_relAttribute.m_isLinkSubresource) {
257263 priority = ResourceLoadPriorityLow;
 264 type = CachedResource::LinkSubresource;
 265 } else if (m_relAttribute.m_isLinkPrerender)
 266 type = CachedResource::LinkPrerender;
258267
259  m_cachedLinkResource = document()->cachedResourceLoader()->requestLinkResource(m_url, priority);
 268 m_cachedLinkResource = document()->cachedResourceLoader()->requestLinkResource(type, m_url, priority);
260269 if (m_cachedLinkResource)
261270 m_cachedLinkResource->addClient(this);
262271 }

Source/WebCore/html/HTMLLinkElement.h

@@public:
4545 bool m_isDNSPrefetch;
4646#if ENABLE(LINK_PREFETCH)
4747 bool m_isLinkPrefetch;
 48 bool m_isLinkPrerender;
4849 bool m_isLinkSubresource;
4950#endif
5051

@@public:
5556 , m_isDNSPrefetch(false)
5657#if ENABLE(LINK_PREFETCH)
5758 , m_isLinkPrefetch(false)
 59 , m_isLinkPrerender(false)
5860 , m_isLinkSubresource(false)
5961#endif
6062 {

Source/WebCore/loader/cache/CachedResource.cpp

@@static ResourceLoadPriority defaultPriorityForResourceType(CachedResource::Type
6262 case CachedResource::ImageResource:
6363 return ResourceLoadPriorityLow;
6464#if ENABLE(LINK_PREFETCH)
65  case CachedResource::LinkResource:
 65 case CachedResource::LinkPrefetch:
 66 return ResourceLoadPriorityVeryLow;
 67 case CachedResource::LinkPrerender:
 68 return ResourceLoadPriorityVeryLow;
 69 case CachedResource::LinkSubresource:
6670 return ResourceLoadPriorityVeryLow;
6771#endif
6872 }

Source/WebCore/loader/cache/CachedResource.h

@@public:
6565 , XSLStyleSheet
6666#endif
6767#if ENABLE(LINK_PREFETCH)
68  , LinkResource
 68 , LinkPrefetch
 69 , LinkPrerender
 70 , LinkSubresource
6971#endif
7072 };
7173

@@public:
132134 bool isLinkResource() const
133135 {
134136#if ENABLE(LINK_PREFETCH)
135  return type() == LinkResource;
 137 return type() == LinkPrefetch || type() == LinkPrerender || type() == LinkSubresource;
136138#else
137139 return false;
138140#endif

Source/WebCore/loader/cache/CachedResourceLoader.cpp

@@static CachedResource* createResource(CachedResource::Type type, const KURL& url
7171 return new CachedXSLStyleSheet(url.string());
7272#endif
7373#if ENABLE(LINK_PREFETCH)
74  case CachedResource::LinkResource:
75  return new CachedResource(url.string(), CachedResource::LinkResource);
 74 case CachedResource::LinkPrefetch:
 75 return new CachedResource(url.string(), CachedResource::LinkPrefetch);
 76 case CachedResource::LinkPrerender:
 77 return new CachedResource(url.string(), CachedResource::LinkPrerender);
 78 case CachedResource::LinkSubresource:
 79 return new CachedResource(url.string(), CachedResource::LinkSubresource);
7680#endif
7781 }
7882 ASSERT_NOT_REACHED();

@@CachedXSLStyleSheet* CachedResourceLoader::requestXSLStyleSheet(const String& ur
188192#endif
189193
190194#if ENABLE(LINK_PREFETCH)
191 CachedResource* CachedResourceLoader::requestLinkResource(const String& url, ResourceLoadPriority priority)
 195CachedResource* CachedResourceLoader::requestLinkResource(CachedResource::Type type, const String& url, ResourceLoadPriority priority)
192196{
193197 ASSERT(frame());
194  return requestResource(CachedResource::LinkResource, url, String(), priority);
 198 ASSERT(type == CachedResource::LinkPrefetch || type == CachedResource::LinkPrerender || type == CachedResource::LinkSubresource);
 199 return requestResource(type, url, String(), priority);
195200}
196201#endif
197202

@@bool CachedResourceLoader::canRequest(CachedResource::Type type, const KURL& url
213218 case CachedResource::Script:
214219 case CachedResource::FontResource:
215220#if ENABLE(LINK_PREFETCH)
216  case CachedResource::LinkResource:
 221 case CachedResource::LinkPrefetch:
 222 case CachedResource::LinkPrerender:
 223 case CachedResource::LinkSubresource:
217224#endif
218225 // These types of resources can be loaded from any origin.
219226 // FIXME: Are we sure about CachedResource::FontResource?

@@bool CachedResourceLoader::canRequest(CachedResource::Type type, const KURL& url
260267 break;
261268 }
262269#if ENABLE(LINK_PREFETCH)
263  case CachedResource::LinkResource:
 270 case CachedResource::LinkPrefetch:
 271 case CachedResource::LinkPrerender:
 272 case CachedResource::LinkSubresource:
264273 // Prefetch cannot affect the current document.
265274 break;
266275#endif

@@bool CachedResourceLoader::canRequest(CachedResource::Type type, const KURL& url
289298 break;
290299 }
291300#if ENABLE(LINK_PREFETCH)
292  case CachedResource::LinkResource:
 301 case CachedResource::LinkPrefetch:
 302 case CachedResource::LinkPrerender:
 303 case CachedResource::LinkSubresource:
293304 break;
294305#endif
295306 }

Source/WebCore/loader/cache/CachedResourceLoader.h

@@public:
7070 CachedXSLStyleSheet* requestXSLStyleSheet(const String& url);
7171#endif
7272#if ENABLE(LINK_PREFETCH)
73  CachedResource* requestLinkResource(const String &url, ResourceLoadPriority priority = ResourceLoadPriorityUnresolved);
 73 CachedResource* requestLinkResource(CachedResource::Type, const String &url, ResourceLoadPriority priority = ResourceLoadPriorityUnresolved);
7474#endif
7575
7676 // Logs an access denied message to the console for the specified URL.

Source/WebCore/loader/cache/CachedResourceRequest.cpp

4444
4545namespace WebCore {
4646
47 static ResourceRequest::TargetType cachedResourceTypeToTargetType(CachedResource::Type type, ResourceLoadPriority priority)
 47static ResourceRequest::TargetType cachedResourceTypeToTargetType(CachedResource::Type type)
4848{
4949#if !ENABLE(LINK_PREFETCH)
5050 UNUSED_PARAM(priority);

@@static ResourceRequest::TargetType cachedResourceTypeToTargetType(CachedResource
6262 case CachedResource::ImageResource:
6363 return ResourceRequest::TargetIsImage;
6464#if ENABLE(LINK_PREFETCH)
65  case CachedResource::LinkResource:
66  if (priority == ResourceLoadPriorityLowest)
67  return ResourceRequest::TargetIsPrefetch;
 65 case CachedResource::LinkPrefetch:
 66 return ResourceRequest::TargetIsPrefetch;
 67 case CachedResource::LinkPrerender:
 68 return ResourceRequest::TargetIsSubresource;
 69 case CachedResource::LinkSubresource:
6870 return ResourceRequest::TargetIsSubresource;
6971#endif
7072 }

@@PassRefPtr<CachedResourceRequest> CachedResourceRequest::load(CachedResourceLoad
9294 RefPtr<CachedResourceRequest> request = adoptRef(new CachedResourceRequest(cachedResourceLoader, resource, incremental));
9395
9496 ResourceRequest resourceRequest(resource->url());
95  resourceRequest.setTargetType(cachedResourceTypeToTargetType(resource->type(), resource->loadPriority()));
 97 resourceRequest.setTargetType(cachedResourceTypeToTargetType(resource->type()));
9698
9799 if (!resource->accept().isEmpty())
98100 resourceRequest.setHTTPAccept(resource->accept());

@@PassRefPtr<CachedResourceRequest> CachedResourceRequest::load(CachedResourceLoad
115117 }
116118
117119#if ENABLE(LINK_PREFETCH)
118  if (resource->type() == CachedResource::LinkResource)
 120 if (resource->type() == CachedResource::LinkPrefetch || resource->type() == CachedResource::LinkPrerender || resource->type() == CachedResource::LinkSubresource)
119121 resourceRequest.setHTTPHeaderField("Purpose", "prefetch");
120122#endif
121123

Source/WebCore/platform/network/ResourceRequestBase.h

@@namespace WebCore {
6565 TargetIsWorker,
6666 TargetIsSharedWorker,
6767 TargetIsPrefetch,
 68 TargetIsPrerender,
6869 TargetIsFavicon,
6970 };
7071