Changeset 84110 in webkit


Ignore:
Timestamp:
Apr 17, 2011 2:30:32 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2011-04-17 Gavin Peters <gavinp@chromium.org>

Reviewed by Adam Barth.

Add support for link rel type "subresource"
https://bugs.webkit.org/show_bug.cgi?id=57842

Link rel=prefetch is great for cache warming for resources on
subsequent pages, but it launches requests at too low a priority
to use for subresources of the current page.

During testing, I was dissapointed to see the results for the http
test below don't give the subresource priority ordering. This is
another instance of https://bugs.webkit.org/show_bug.cgi?id=49238
which I'll be working on next, and thus fix the test.

  • fast/dom/HTMLLinkElement/subresource-expected.txt: Added.
  • fast/dom/HTMLLinkElement/subresource.html: Added.
  • http/tests/misc/link-rel-prefetch-and-subresource-expected.txt: Added.
  • http/tests/misc/link-rel-prefetch-and-subresource.html: Added.
  • platform/gtk/Skipped:
  • platform/mac/Skipped:
  • platform/qt/Skipped:
  • platform/win/Skipped:

2011-04-17 Gavin Peters <gavinp@chromium.org>

Reviewed by Adam Barth.

Add support for link rel type "subresource"
https://bugs.webkit.org/show_bug.cgi?id=57842

Link rel=prefetch is great for cache warming for resources on
subsequent pages, but it launches requests at too low a priority
to use for subresources of the current page.

Particularly after https://bugs.webkit.org/show_bug.cgi?id=51940
is implemented, a rel type that launches requests at an higher
priority is going to be very useful. This rel type is in the
HTML5 spec at http://wiki.whatwg.org/wiki/RelExtensions . An
expected use case will be for servers to provide subresource hints
in link headers, which will allow servers to help make the web
faster.

This feature continues my implementation of the Link header, which
we've talked about in WebKit-dev in
https://lists.webkit.org/pipermail/webkit-dev/2011-February/016034.html.

Tests: fast/dom/HTMLLinkElement/subresource.html

http/tests/misc/link-rel-prefetch-and-subresource.html

  • html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::~HTMLLinkElement): (WebCore::HTMLLinkElement::tokenizeRelAttribute): (WebCore::HTMLLinkElement::process): (WebCore::HTMLLinkElement::onloadTimerFired): (WebCore::HTMLLinkElement::notifyFinished):
  • html/HTMLLinkElement.h: (WebCore::HTMLLinkElement::RelAttribute::RelAttribute):
  • loader/cache/CachedResource.cpp: (WebCore::defaultPriorityForResourceType):
  • loader/cache/CachedResource.h: (WebCore::CachedResource::isLinkResource):
  • loader/cache/CachedResourceLoader.cpp: (WebCore::createResource): (WebCore::CachedResourceLoader::requestLinkResource): (WebCore::CachedResourceLoader::canRequest): (WebCore::CachedResourceLoader::incrementRequestCount): (WebCore::CachedResourceLoader::decrementRequestCount):
  • loader/cache/CachedResourceLoader.h:
  • loader/cache/CachedResourceRequest.cpp: (WebCore::cachedResourceTypeToTargetType): (WebCore::CachedResourceRequest::load):
Location:
trunk
Files:
4 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r84098 r84110  
     12011-04-17  Gavin Peters  <gavinp@chromium.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Add support for link rel type "subresource"
     6        https://bugs.webkit.org/show_bug.cgi?id=57842
     7
     8        Link rel=prefetch is great for cache warming for resources on
     9        subsequent pages, but it launches requests at too low a priority
     10        to use for subresources of the current page.
     11
     12        During testing, I was dissapointed to see the results for the http
     13        test below don't give the subresource priority ordering.  This is
     14        another instance of https://bugs.webkit.org/show_bug.cgi?id=49238
     15        which I'll be working on next, and thus fix the test.
     16
     17        * fast/dom/HTMLLinkElement/subresource-expected.txt: Added.
     18        * fast/dom/HTMLLinkElement/subresource.html: Added.
     19        * http/tests/misc/link-rel-prefetch-and-subresource-expected.txt: Added.
     20        * http/tests/misc/link-rel-prefetch-and-subresource.html: Added.
     21        * platform/gtk/Skipped:
     22        * platform/mac/Skipped:
     23        * platform/qt/Skipped:
     24        * platform/win/Skipped:
     25
    1262011-04-16  Dan Bernstein  <mitz@apple.com>
    227
  • trunk/LayoutTests/platform/gtk/Skipped

    r84053 r84110  
    513513http/tests/mime/standard-mode-loads-stylesheet-with-text-css-and-invalid-type.html
    514514http/tests/misc/acid3.html
     515http/tests/misc/link-rel-prefetch-and-subresource.html
    515516http/tests/misc/policy-delegate-called-twice.html
    516517http/tests/misc/prefetch-purpose.html
     
    925926fast/dom/HTMLLinkElement/prefetch-onload.html
    926927fast/dom/HTMLLinkElement/prefetch-beforeload.html
     928fast/dom/HTMLLinkElement/subresource.html
    927929
    928930# Tests failing because the context menu is grabbing mouse events.
  • trunk/LayoutTests/platform/mac/Skipped

    r84053 r84110  
    187187fast/dom/HTMLLinkElement/prefetch-onerror.html
    188188fast/dom/HTMLLinkElement/prefetch-onload.html
     189fast/dom/HTMLLinkElement/subresource.html
     190http/tests/misc/link-rel-prefetch-and-subresource.html
    189191http/tests/misc/prefetch-purpose.html
    190192
  • trunk/LayoutTests/platform/qt/Skipped

    r84057 r84110  
    29592959fast/dom/HTMLLinkElement/prefetch-onerror.html
    29602960fast/dom/HTMLLinkElement/prefetch-onload.html
     2961fast/dom/HTMLLinkElement/subresource.html
     2962http/tests/misc/link-rel-prefetch-and-subresource.html
    29612963http/tests/misc/prefetch-purpose.html
    29622964
  • trunk/LayoutTests/platform/win/Skipped

    r84053 r84110  
    996996fast/dom/HTMLLinkElement/prefetch-onerror.html
    997997fast/dom/HTMLLinkElement/prefetch-onload.html
     998fast/dom/HTMLLinkElement/subresource.html
     999http/tests/misc/link-rel-prefetch-and-subresource.html
    9981000http/tests/misc/prefetch-purpose.html
    9991001
  • trunk/Source/WebCore/ChangeLog

    r84107 r84110  
     12011-04-17  Gavin Peters  <gavinp@chromium.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Add support for link rel type "subresource"
     6        https://bugs.webkit.org/show_bug.cgi?id=57842
     7
     8        Link rel=prefetch is great for cache warming for resources on
     9        subsequent pages, but it launches requests at too low a priority
     10        to use for subresources of the current page.
     11
     12        Particularly after https://bugs.webkit.org/show_bug.cgi?id=51940
     13        is implemented, a rel type that launches requests at an higher
     14        priority is going to be very useful.  This rel type is in the
     15        HTML5 spec at http://wiki.whatwg.org/wiki/RelExtensions .  An
     16        expected use case will be for servers to provide subresource hints
     17        in link headers, which will allow servers to help make the web
     18        faster.
     19
     20        This feature continues my implementation of the Link header, which
     21        we've talked about in WebKit-dev in
     22        https://lists.webkit.org/pipermail/webkit-dev/2011-February/016034.html.
     23
     24        Tests: fast/dom/HTMLLinkElement/subresource.html
     25               http/tests/misc/link-rel-prefetch-and-subresource.html
     26
     27        * html/HTMLLinkElement.cpp:
     28        (WebCore::HTMLLinkElement::~HTMLLinkElement):
     29        (WebCore::HTMLLinkElement::tokenizeRelAttribute):
     30        (WebCore::HTMLLinkElement::process):
     31        (WebCore::HTMLLinkElement::onloadTimerFired):
     32        (WebCore::HTMLLinkElement::notifyFinished):
     33        * html/HTMLLinkElement.h:
     34        (WebCore::HTMLLinkElement::RelAttribute::RelAttribute):
     35        * loader/cache/CachedResource.cpp:
     36        (WebCore::defaultPriorityForResourceType):
     37        * loader/cache/CachedResource.h:
     38        (WebCore::CachedResource::isLinkResource):
     39        * loader/cache/CachedResourceLoader.cpp:
     40        (WebCore::createResource):
     41        (WebCore::CachedResourceLoader::requestLinkResource):
     42        (WebCore::CachedResourceLoader::canRequest):
     43        (WebCore::CachedResourceLoader::incrementRequestCount):
     44        (WebCore::CachedResourceLoader::decrementRequestCount):
     45        * loader/cache/CachedResourceLoader.h:
     46        * loader/cache/CachedResourceRequest.cpp:
     47        (WebCore::cachedResourceTypeToTargetType):
     48        (WebCore::CachedResourceRequest::load):
     49
    1502011-04-17  Dan Bernstein  <mitz@apple.com>
    251
  • trunk/Source/WebCore/html/HTMLLinkElement.cpp

    r82342 r84110  
    2727#include "Attribute.h"
    2828#include "CachedCSSStyleSheet.h"
     29#include "CachedResource.h"
    2930#include "CachedResourceLoader.h"
    3031#include "CSSStyleSelector.h"
     
    7980   
    8081#if ENABLE(LINK_PREFETCH)
    81     if (m_cachedLinkPrefetch)
    82         m_cachedLinkPrefetch->removeClient(this);
     82    if (m_cachedLinkResource)
     83        m_cachedLinkResource->removeClient(this);
    8384#endif
    8485}
     
    164165#if ENABLE(LINK_PREFETCH)
    165166    relAttribute.m_isLinkPrefetch = false;
     167    relAttribute.m_isLinkSubresource = false;
    166168#endif
    167169    if (equalIgnoringCase(rel, "stylesheet"))
     
    171173    else if (equalIgnoringCase(rel, "dns-prefetch"))
    172174        relAttribute.m_isDNSPrefetch = true;
    173 #if ENABLE(LINK_PREFETCH)
    174     else if (equalIgnoringCase(rel, "prefetch"))
    175         relAttribute.m_isLinkPrefetch = true;
    176 #endif
    177175    else if (equalIgnoringCase(rel, "alternate stylesheet") || equalIgnoringCase(rel, "stylesheet alternate")) {
    178176        relAttribute.m_isStyleSheet = true;
     
    192190            else if (equalIgnoringCase(*it, "icon"))
    193191                relAttribute.m_isIcon = true;
     192#if ENABLE(LINK_PREFETCH)
     193            else if (equalIgnoringCase(*it, "prefetch"))
     194              relAttribute.m_isLinkPrefetch = true;
     195            else if (equalIgnoringCase(*it, "subresource"))
     196              relAttribute.m_isLinkSubresource = true;
     197#endif
    194198        }
    195199    }
     
    233237
    234238#if ENABLE(LINK_PREFETCH)
    235     if (m_relAttribute.m_isLinkPrefetch && m_url.isValid() && document()->frame()) {
     239    if ((m_relAttribute.m_isLinkPrefetch || m_relAttribute.m_isLinkSubresource) && m_url.isValid() && document()->frame()) {
    236240        if (!checkBeforeLoadEvent())
    237241            return;
    238         m_cachedLinkPrefetch = document()->cachedResourceLoader()->requestLinkPrefetch(m_url);
    239         if (m_cachedLinkPrefetch)
    240             m_cachedLinkPrefetch->addClient(this);
     242        ResourceLoadPriority priority = ResourceLoadPriorityUnresolved;
     243        if (m_relAttribute.m_isLinkSubresource)
     244            priority = ResourceLoadPriorityLow;
     245
     246        m_cachedLinkResource = document()->cachedResourceLoader()->requestLinkResource(m_url, priority);
     247        if (m_cachedLinkResource)
     248            m_cachedLinkResource->addClient(this);
    241249    }
    242250#endif
     
    410418{
    411419    ASSERT_UNUSED(timer, timer == &m_onloadTimer);
    412     if (m_cachedLinkPrefetch->errorOccurred())
     420    if (m_cachedLinkResource->errorOccurred())
    413421        dispatchEvent(Event::create(eventNames().errorEvent, false, false));
    414422    else
    415423        dispatchEvent(Event::create(eventNames().loadEvent, false, false));
    416424
    417     m_cachedLinkPrefetch->removeClient(this);
    418     m_cachedLinkPrefetch = 0;
     425    m_cachedLinkResource->removeClient(this);
     426    m_cachedLinkResource = 0;
    419427}
    420428
     
    422430{
    423431    m_onloadTimer.startOneShot(0);
    424     ASSERT(m_cachedLinkPrefetch.get() == resource);
     432    ASSERT(m_cachedLinkResource.get() == resource);
    425433}
    426434#endif
  • trunk/Source/WebCore/html/HTMLLinkElement.h

    r82342 r84110  
    4545#if ENABLE(LINK_PREFETCH)
    4646        bool m_isLinkPrefetch;
     47        bool m_isLinkSubresource;
    4748#endif
    4849
     
    5455#if ENABLE(LINK_PREFETCH)
    5556            , m_isLinkPrefetch(false)
     57            , m_isLinkSubresource(false)
    5658#endif
    5759            {
     
    127129    RefPtr<CSSStyleSheet> m_sheet;
    128130#if ENABLE(LINK_PREFETCH)
    129     CachedResourceHandle<CachedResource> m_cachedLinkPrefetch;
     131    CachedResourceHandle<CachedResource> m_cachedLinkResource;
    130132    Timer<HTMLLinkElement> m_onloadTimer;
    131133#endif
  • trunk/Source/WebCore/loader/cache/CachedResource.cpp

    r82764 r84110  
    6363            return ResourceLoadPriorityLow;
    6464#if ENABLE(LINK_PREFETCH)
    65         case CachedResource::LinkPrefetch:
     65        case CachedResource::LinkResource:
    6666            return ResourceLoadPriorityVeryLow;
    6767#endif
  • trunk/Source/WebCore/loader/cache/CachedResource.h

    r82217 r84110  
    6666#endif
    6767#if ENABLE(LINK_PREFETCH)
    68         , LinkPrefetch
     68        , LinkResource
    6969#endif
    7070    };
     
    130130
    131131    virtual bool isImage() const { return false; }
    132     bool isPrefetch() const
     132    bool isLinkResource() const
    133133    {
    134134#if ENABLE(LINK_PREFETCH)
    135         return type() == LinkPrefetch;
     135        return type() == LinkResource;
    136136#else
    137137        return false;
  • trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp

    r83235 r84110  
    7272#endif
    7373#if ENABLE(LINK_PREFETCH)
    74     case CachedResource::LinkPrefetch:
    75         return new CachedResource(url.string(), CachedResource::LinkPrefetch);
     74    case CachedResource::LinkResource:
     75        return new CachedResource(url.string(), CachedResource::LinkResource);
    7676#endif
    7777    }
     
    189189
    190190#if ENABLE(LINK_PREFETCH)
    191 CachedResource* CachedResourceLoader::requestLinkPrefetch(const String& url)
     191CachedResource* CachedResourceLoader::requestLinkResource(const String& url, ResourceLoadPriority priority)
    192192{
    193193    ASSERT(frame());
    194     return requestResource(CachedResource::LinkPrefetch, url, String());
     194    return requestResource(CachedResource::LinkResource, url, String(), priority);
    195195}
    196196#endif
     
    207207    case CachedResource::FontResource:
    208208#if ENABLE(LINK_PREFETCH)
    209     case CachedResource::LinkPrefetch:
     209    case CachedResource::LinkResource:
    210210#endif
    211211        // These types of resources can be loaded from any origin.
     
    249249    }
    250250#if ENABLE(LINK_PREFETCH)
    251     case CachedResource::LinkPrefetch:
     251    case CachedResource::LinkResource:
    252252        // Prefetch cannot affect the current document.
    253253        break;
     
    594594void CachedResourceLoader::incrementRequestCount(const CachedResource* res)
    595595{
    596     if (res->isPrefetch())
     596    if (res->isLinkResource())
    597597        return;
    598598
     
    602602void CachedResourceLoader::decrementRequestCount(const CachedResource* res)
    603603{
    604     if (res->isPrefetch())
     604    if (res->isLinkResource())
    605605        return;
    606606
  • trunk/Source/WebCore/loader/cache/CachedResourceLoader.h

    r80695 r84110  
    7070#endif
    7171#if ENABLE(LINK_PREFETCH)
    72     CachedResource* requestLinkPrefetch(const String &url);
     72    CachedResource* requestLinkResource(const String &url, ResourceLoadPriority priority = ResourceLoadPriorityUnresolved);
    7373#endif
    7474
  • trunk/Source/WebCore/loader/cache/CachedResourceRequest.cpp

    r78558 r84110  
    4343namespace WebCore {
    4444   
    45 static ResourceRequest::TargetType cachedResourceTypeToTargetType(CachedResource::Type type)
    46 {
     45static ResourceRequest::TargetType cachedResourceTypeToTargetType(CachedResource::Type type, ResourceLoadPriority priority)
     46{
     47#if !ENABLE(LINK_PREFETCH)
     48    UNUSED_PARAM(priority);
     49#endif
    4750    switch (type) {
    4851    case CachedResource::CSSStyleSheet:
     
    5861        return ResourceRequest::TargetIsImage;
    5962#if ENABLE(LINK_PREFETCH)
    60     case CachedResource::LinkPrefetch:
    61         return ResourceRequest::TargetIsPrefetch;
     63    case CachedResource::LinkResource:
     64        if (priority == ResourceLoadPriorityLowest)
     65            return ResourceRequest::TargetIsPrefetch;
     66        return ResourceRequest::TargetIsSubresource;
    6267#endif
    6368    }
     
    8691
    8792    ResourceRequest resourceRequest(resource->url());
    88     resourceRequest.setTargetType(cachedResourceTypeToTargetType(resource->type()));
     93    resourceRequest.setTargetType(cachedResourceTypeToTargetType(resource->type(), resource->loadPriority()));
    8994
    9095    if (!resource->accept().isEmpty())
     
    109114   
    110115#if ENABLE(LINK_PREFETCH)
    111     if (resource->type() == CachedResource::LinkPrefetch)
     116    if (resource->type() == CachedResource::LinkResource)
    112117        resourceRequest.setHTTPHeaderField("Purpose", "prefetch");
    113118#endif
Note: See TracChangeset for help on using the changeset viewer.