2011-05-24 Nate Chapin <japhet@chromium.org>
authorjaphet@chromium.org <japhet@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 May 2011 00:24:38 +0000 (00:24 +0000)
committerjaphet@chromium.org <japhet@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 May 2011 00:24:38 +0000 (00:24 +0000)
        Reviewed by Adam Barth.

        Change CachedResources to take a ResourceRequest instead of
        a url in their constructors and provide a very minimal set of
        cases for avoiding reusing a CachedResource. The ResourceRequest
        part of this change requires pushing responsibility
        for calling Document::completeURL() to the caller, instead of
        CachedResourceLoader, since ResourceRequest ASSERTs if it
        is constructed with an invalid url.

        https://bugs.webkit.org/show_bug.cgi?id=61318

        Refactor, no new tests.

        * css/CSSFontSelector.cpp:
        (WebCore::CSSFontSelector::addFontFaceRule):
        * css/CSSImageValue.cpp:
        (WebCore::CSSImageValue::cachedImage):
        * css/CSSImportRule.cpp:
        (WebCore::CSSImportRule::insertedIntoParent):
        * dom/ProcessingInstruction.cpp:
        (WebCore::ProcessingInstruction::checkStyleSheet):
        * dom/ScriptElement.cpp:
        (WebCore::ScriptElement::requestScript):
        * html/HTMLLinkElement.cpp:
        (WebCore::HTMLLinkElement::process):
        * loader/ImageLoader.cpp:
        (WebCore::ImageLoader::updateFromElement):
        * loader/cache/CachedCSSStyleSheet.cpp:
        (WebCore::CachedCSSStyleSheet::CachedCSSStyleSheet):
        (WebCore::CachedCSSStyleSheet::didAddClient):
        (WebCore::CachedCSSStyleSheet::checkNotify):
        * loader/cache/CachedCSSStyleSheet.h:
        * loader/cache/CachedFont.cpp:
        (WebCore::CachedFont::CachedFont):
        * loader/cache/CachedFont.h:
        * loader/cache/CachedImage.cpp:
        (WebCore::CachedImage::CachedImage):
        (WebCore::CachedImage::checkShouldPaintBrokenImage):
        * loader/cache/CachedImage.h:
        * loader/cache/CachedResource.cpp:
        (WebCore::CachedResource::CachedResource):
        (WebCore::reuseRequest):
        (WebCore::CachedResource::allowReuseOfRequest):
        (WebCore::CachedResource::removeClient):
        (WebCore::CachedResource::canUseCacheValidator):
        * loader/cache/CachedResource.h:
        (WebCore::CachedResource::resourceRequest):
        (WebCore::CachedResource::url):
        * loader/cache/CachedResourceLoader.cpp:
        * loader/cache/CachedResourceLoader.h:
        * loader/cache/CachedResourceRequest.cpp:
        (WebCore::CachedResourceRequest::load):
        * loader/cache/CachedScript.cpp:
        (WebCore::CachedScript::CachedScript):
        * loader/cache/CachedScript.h:
        * loader/cache/CachedXSLStyleSheet.cpp:
        (WebCore::CachedXSLStyleSheet::CachedXSLStyleSheet):
        (WebCore::CachedXSLStyleSheet::didAddClient):
        (WebCore::CachedXSLStyleSheet::checkNotify):
        * loader/cache/CachedXSLStyleSheet.h:
        * svg/SVGFEImageElement.cpp:
        (WebCore::SVGFEImageElement::requestImageResource):
        * svg/SVGFontFaceUriElement.cpp:
        (WebCore::SVGFontFaceUriElement::loadFont):
        * xml/XSLImportRule.cpp:
        (WebCore::XSLImportRule::loadSheet):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@87239 268f45cc-cd09-0410-ab3c-d52691b4dbfc

29 files changed:
Source/WebCore/ChangeLog
Source/WebCore/css/CSSFontSelector.cpp
Source/WebCore/css/CSSImageValue.cpp
Source/WebCore/css/CSSImportRule.cpp
Source/WebCore/dom/ProcessingInstruction.cpp
Source/WebCore/dom/ScriptElement.cpp
Source/WebCore/html/HTMLLinkElement.cpp
Source/WebCore/html/parser/CSSPreloadScanner.cpp
Source/WebCore/html/parser/HTMLPreloadScanner.cpp
Source/WebCore/loader/ImageLoader.cpp
Source/WebCore/loader/cache/CachedCSSStyleSheet.cpp
Source/WebCore/loader/cache/CachedCSSStyleSheet.h
Source/WebCore/loader/cache/CachedFont.cpp
Source/WebCore/loader/cache/CachedFont.h
Source/WebCore/loader/cache/CachedImage.cpp
Source/WebCore/loader/cache/CachedImage.h
Source/WebCore/loader/cache/CachedResource.cpp
Source/WebCore/loader/cache/CachedResource.h
Source/WebCore/loader/cache/CachedResourceLoader.cpp
Source/WebCore/loader/cache/CachedResourceLoader.h
Source/WebCore/loader/cache/CachedResourceRequest.cpp
Source/WebCore/loader/cache/CachedScript.cpp
Source/WebCore/loader/cache/CachedScript.h
Source/WebCore/loader/cache/CachedXSLStyleSheet.cpp
Source/WebCore/loader/cache/CachedXSLStyleSheet.h
Source/WebCore/loader/cache/MemoryCache.cpp
Source/WebCore/svg/SVGFEImageElement.cpp
Source/WebCore/svg/SVGFontFaceUriElement.cpp
Source/WebCore/xml/XSLImportRule.cpp

index eb88bed..f070286 100644 (file)
@@ -1,3 +1,73 @@
+2011-05-24  Nate Chapin  <japhet@chromium.org>
+
+        Reviewed by Adam Barth.
+
+        Change CachedResources to take a ResourceRequest instead of
+        a url in their constructors and provide a very minimal set of
+        cases for avoiding reusing a CachedResource. The ResourceRequest
+        part of this change requires pushing responsibility
+        for calling Document::completeURL() to the caller, instead of
+        CachedResourceLoader, since ResourceRequest ASSERTs if it
+        is constructed with an invalid url.
+
+        https://bugs.webkit.org/show_bug.cgi?id=61318
+
+        Refactor, no new tests.
+
+        * css/CSSFontSelector.cpp:
+        (WebCore::CSSFontSelector::addFontFaceRule):
+        * css/CSSImageValue.cpp:
+        (WebCore::CSSImageValue::cachedImage):
+        * css/CSSImportRule.cpp:
+        (WebCore::CSSImportRule::insertedIntoParent):
+        * dom/ProcessingInstruction.cpp:
+        (WebCore::ProcessingInstruction::checkStyleSheet):
+        * dom/ScriptElement.cpp:
+        (WebCore::ScriptElement::requestScript):
+        * html/HTMLLinkElement.cpp:
+        (WebCore::HTMLLinkElement::process):
+        * loader/ImageLoader.cpp:
+        (WebCore::ImageLoader::updateFromElement):
+        * loader/cache/CachedCSSStyleSheet.cpp:
+        (WebCore::CachedCSSStyleSheet::CachedCSSStyleSheet):
+        (WebCore::CachedCSSStyleSheet::didAddClient):
+        (WebCore::CachedCSSStyleSheet::checkNotify):
+        * loader/cache/CachedCSSStyleSheet.h:
+        * loader/cache/CachedFont.cpp:
+        (WebCore::CachedFont::CachedFont):
+        * loader/cache/CachedFont.h:
+        * loader/cache/CachedImage.cpp:
+        (WebCore::CachedImage::CachedImage):
+        (WebCore::CachedImage::checkShouldPaintBrokenImage):
+        * loader/cache/CachedImage.h:
+        * loader/cache/CachedResource.cpp:
+        (WebCore::CachedResource::CachedResource):
+        (WebCore::reuseRequest):
+        (WebCore::CachedResource::allowReuseOfRequest):
+        (WebCore::CachedResource::removeClient):
+        (WebCore::CachedResource::canUseCacheValidator):
+        * loader/cache/CachedResource.h:
+        (WebCore::CachedResource::resourceRequest):
+        (WebCore::CachedResource::url):
+        * loader/cache/CachedResourceLoader.cpp:
+        * loader/cache/CachedResourceLoader.h:
+        * loader/cache/CachedResourceRequest.cpp:
+        (WebCore::CachedResourceRequest::load):
+        * loader/cache/CachedScript.cpp:
+        (WebCore::CachedScript::CachedScript):
+        * loader/cache/CachedScript.h:
+        * loader/cache/CachedXSLStyleSheet.cpp:
+        (WebCore::CachedXSLStyleSheet::CachedXSLStyleSheet):
+        (WebCore::CachedXSLStyleSheet::didAddClient):
+        (WebCore::CachedXSLStyleSheet::checkNotify):
+        * loader/cache/CachedXSLStyleSheet.h:
+        * svg/SVGFEImageElement.cpp:
+        (WebCore::SVGFEImageElement::requestImageResource):
+        * svg/SVGFontFaceUriElement.cpp:
+        (WebCore::SVGFontFaceUriElement::loadFont):
+        * xml/XSLImportRule.cpp:
+        (WebCore::XSLImportRule::loadSheet):
+
 2011-05-24  Kent Tamura  <tkent@chromium.org>
 
         Reviewed by Dimitri Glazkov.
index 8024afa..1bf4fca 100644 (file)
@@ -245,7 +245,8 @@ void CSSFontSelector::addFontFaceRule(const CSSFontFaceRule* fontFaceRule)
             Settings* settings = m_document ? m_document->frame() ? m_document->frame()->settings() : 0 : 0;
             bool allowDownloading = foundSVGFont || (settings && settings->downloadableBinaryFontsEnabled());
             if (allowDownloading && item->isSupportedFormat() && m_document) {
-                CachedFont* cachedFont = m_document->cachedResourceLoader()->requestFont(item->resource());
+                ResourceRequest request(m_document->completeURL(item->resource()));
+                CachedFont* cachedFont = m_document->cachedResourceLoader()->requestFont(request);
                 if (cachedFont) {
                     source = new CSSFontFaceSource(item->resource(), cachedFont);
 #if ENABLE(SVG_FONTS)
index a9038b9..ffc6763 100644 (file)
@@ -22,6 +22,7 @@
 #include "CSSImageValue.h"
 
 #include "CSSValueKeywords.h"
+#include "Document.h"
 #include "MemoryCache.h"
 #include "CachedImage.h"
 #include "CachedResourceLoader.h"
@@ -71,7 +72,8 @@ StyleCachedImage* CSSImageValue::cachedImage(CachedResourceLoader* loader, const
     if (!m_accessedImage) {
         m_accessedImage = true;
 
-        if (CachedImage* cachedImage = loader->requestImage(url)) {
+        ResourceRequest request(loader->document()->completeURL(url));
+        if (CachedImage* cachedImage = loader->requestImage(request)) {
             cachedImage->addClient(this);
             m_image = StyleCachedImage::create(cachedImage);
         }
index 5c53ebd..5a08c0b 100644 (file)
@@ -134,10 +134,11 @@ void CSSImportRule::insertedIntoParent()
         root = curr;
     }
 
+    ResourceRequest request(parentSheet->document()->completeURL(absHref));
     if (parentSheet->isUserStyleSheet())
-        m_cachedSheet = cachedResourceLoader->requestUserCSSStyleSheet(absHref, parentSheet->charset());
+        m_cachedSheet = cachedResourceLoader->requestUserCSSStyleSheet(request, parentSheet->charset());
     else
-        m_cachedSheet = cachedResourceLoader->requestCSSStyleSheet(absHref, parentSheet->charset());
+        m_cachedSheet = cachedResourceLoader->requestCSSStyleSheet(request, parentSheet->charset());
     if (m_cachedSheet) {
         // if the import rule is issued dynamically, the sheet may be
         // removed from the pending sheet count, so let the doc know
index 30111d8..3feb0ab 100644 (file)
@@ -161,9 +161,10 @@ void ProcessingInstruction::checkStyleSheet()
             m_loading = true;
             document()->addPendingSheet();
             
+            ResourceRequest request(document()->completeURL(href));
 #if ENABLE(XSLT)
             if (m_isXSL)
-                m_cachedSheet = document()->cachedResourceLoader()->requestXSLStyleSheet(url);
+                m_cachedSheet = document()->cachedResourceLoader()->requestXSLStyleSheet(request);
             else
 #endif
             {
@@ -171,7 +172,7 @@ void ProcessingInstruction::checkStyleSheet()
                 if (charset.isEmpty())
                     charset = document()->charset();
 
-                m_cachedSheet = document()->cachedResourceLoader()->requestCSSStyleSheet(url, charset);
+                m_cachedSheet = document()->cachedResourceLoader()->requestCSSStyleSheet(request, charset);
             }
             if (m_cachedSheet)
                 m_cachedSheet->addClient(this);
index 185bb75..bdaca77 100644 (file)
@@ -245,7 +245,8 @@ bool ScriptElement::requestScript(const String& sourceUrl)
 
     ASSERT(!m_cachedScript);
     // FIXME: If sourceUrl is empty, we should dispatchErrorEvent().
-    m_cachedScript = m_element->document()->cachedResourceLoader()->requestScript(sourceUrl, scriptCharset());
+    ResourceRequest request(m_element->document()->completeURL(sourceUrl));
+    m_cachedScript = m_element->document()->cachedResourceLoader()->requestScript(request, scriptCharset());
     m_isExternalScript = true;
 
     if (m_cachedScript)
index a77f275..e607997 100644 (file)
@@ -265,7 +265,8 @@ void HTMLLinkElement::process()
         } else if (m_relAttribute.m_isLinkPrerender)
             type = CachedResource::LinkPrerender;
 
-        m_cachedLinkResource = document()->cachedResourceLoader()->requestLinkResource(type, m_url, priority);
+        ResourceRequest linkRequest(document()->completeURL(m_url));
+        m_cachedLinkResource = document()->cachedResourceLoader()->requestLinkResource(type, linkRequest, priority);
         if (m_cachedLinkResource)
             m_cachedLinkResource->addClient(this);
     }
@@ -306,7 +307,8 @@ void HTMLLinkElement::process()
 
         // Load stylesheets that are not needed for the rendering immediately with low priority.
         ResourceLoadPriority priority = blocking ? ResourceLoadPriorityUnresolved : ResourceLoadPriorityVeryLow;
-        m_cachedSheet = document()->cachedResourceLoader()->requestCSSStyleSheet(m_url, charset, priority);
+        ResourceRequest request(document()->completeURL(m_url));
+        m_cachedSheet = document()->cachedResourceLoader()->requestCSSStyleSheet(request, charset, priority);
         
         if (m_cachedSheet)
             m_cachedSheet->addClient(this);
index 3c23b9f..18c28c5 100644 (file)
@@ -194,8 +194,10 @@ void CSSPreloadScanner::emitRule()
 {
     if (equalIgnoringCase("import", m_rule.data(), m_rule.size())) {
         String value = parseCSSStringOrURL(m_ruleValue.data(), m_ruleValue.size());
-        if (!value.isEmpty())
-            m_document->cachedResourceLoader()->preload(CachedResource::CSSStyleSheet, value, String(), m_scanningBody);
+        if (!value.isEmpty()) {
+            ResourceRequest request(m_document->completeURL(value));
+            m_document->cachedResourceLoader()->preload(CachedResource::CSSStyleSheet, request, String(), m_scanningBody);
+        }
         m_state = Initial;
     } else if (equalIgnoringCase("charset", m_rule.data(), m_rule.size()))
         m_state = Initial;
index d1d29ac..6e05240 100644 (file)
@@ -126,12 +126,13 @@ public:
             return;
 
         CachedResourceLoader* cachedResourceLoader = document->cachedResourceLoader();
+        ResourceRequest request = document->completeURL(m_urlToLoad);
         if (m_tagName == scriptTag)
-            cachedResourceLoader->preload(CachedResource::Script, m_urlToLoad, m_charset, scanningBody);
+            cachedResourceLoader->preload(CachedResource::Script, request, m_charset, scanningBody);
         else if (m_tagName == imgTag || (m_tagName == inputTag && m_inputIsImage))
-            cachedResourceLoader->preload(CachedResource::ImageResource, m_urlToLoad, String(), scanningBody);
+            cachedResourceLoader->preload(CachedResource::ImageResource, request, String(), scanningBody);
         else if (m_tagName == linkTag && m_linkIsStyleSheet && m_linkMediaAttributeIsScreen) 
-            cachedResourceLoader->preload(CachedResource::CSSStyleSheet, m_urlToLoad, m_charset, scanningBody);
+            cachedResourceLoader->preload(CachedResource::CSSStyleSheet, request, m_charset, scanningBody);
     }
 
     const AtomicString& tagName() const { return m_tagName; }
index ea956ee..d523c5f 100644 (file)
@@ -161,13 +161,16 @@ void ImageLoader::updateFromElement()
         if (m_loadManually) {
             bool autoLoadOtherImages = document->cachedResourceLoader()->autoLoadImages();
             document->cachedResourceLoader()->setAutoLoadImages(false);
-            newImage = new CachedImage(sourceURI(attr));
+            ResourceRequest request = ResourceRequest(document->completeURL(sourceURI(attr)));
+            newImage = new CachedImage(request);
             newImage->setLoading(true);
             newImage->setOwningCachedResourceLoader(document->cachedResourceLoader());
             document->cachedResourceLoader()->m_documentResources.set(newImage->url(), newImage);
             document->cachedResourceLoader()->setAutoLoadImages(autoLoadOtherImages);
-        } else
-            newImage = document->cachedResourceLoader()->requestImage(sourceURI(attr));
+        } else {
+            ResourceRequest request(document->completeURL(sourceURI(attr)));
+            newImage = document->cachedResourceLoader()->requestImage(request);
+        }
 
         // If we do not have an image here, it means that a cross-site
         // violation occurred.
index ae7a03c..53a04fb 100644 (file)
@@ -37,8 +37,8 @@
 
 namespace WebCore {
 
-CachedCSSStyleSheet::CachedCSSStyleSheet(const String& url, const String& charset)
-    : CachedResource(url, CSSStyleSheet)
+CachedCSSStyleSheet::CachedCSSStyleSheet(const ResourceRequest& resourceRequest, const String& charset)
+    : CachedResource(resourceRequest, CSSStyleSheet)
     , m_decoder(TextResourceDecoder::create("text/css", charset))
 {
     // Prefer text/css but accept any type (dell.com serves a stylesheet
@@ -53,7 +53,7 @@ CachedCSSStyleSheet::~CachedCSSStyleSheet()
 void CachedCSSStyleSheet::didAddClient(CachedResourceClient *c)
 {
     if (!isLoading())
-        c->setCSSStyleSheet(m_url, m_response.url(), m_decoder->encoding().name(), this);
+        c->setCSSStyleSheet(m_resourceRequest.url(), m_response.url(), m_decoder->encoding().name(), this);
 }
 
 void CachedCSSStyleSheet::allClientsRemoved()
@@ -113,7 +113,7 @@ void CachedCSSStyleSheet::checkNotify()
 
     CachedResourceClientWalker w(m_clients);
     while (CachedResourceClient *c = w.next())
-        c->setCSSStyleSheet(m_url, m_response.url(), m_decoder->encoding().name(), this);
+        c->setCSSStyleSheet(m_resourceRequest.url(), m_response.url(), m_decoder->encoding().name(), this);
 }
 
 void CachedCSSStyleSheet::error(CachedResource::Status status)
index 7a24a4f..1c0ae78 100644 (file)
@@ -37,7 +37,7 @@ namespace WebCore {
 
     class CachedCSSStyleSheet : public CachedResource {
     public:
-        CachedCSSStyleSheet(const String& URL, const String& charset);
+        CachedCSSStyleSheet(const ResourceRequest&, const String& charset);
         virtual ~CachedCSSStyleSheet();
 
         const String sheetText(bool enforceMIMEType = true, bool* hasValidMIMEType = 0) const;
index c88f9a7..bdae984 100644 (file)
@@ -56,8 +56,8 @@
 
 namespace WebCore {
 
-CachedFont::CachedFont(const String &url)
-    : CachedResource(url, FontResource)
+CachedFont::CachedFont(const ResourceRequest& resourceRequest)
+    : CachedResource(resourceRequest, FontResource)
     , m_fontData(0)
     , m_loadInitiated(false)
 {
index e234204..734388a 100644 (file)
@@ -46,7 +46,7 @@ struct FontCustomPlatformData;
 
 class CachedFont : public CachedResource {
 public:
-    CachedFont(const String& url);
+    CachedFont(const ResourceRequest&);
     virtual ~CachedFont();
     
     virtual void load(CachedResourceLoader* cachedResourceLoader);
index 683e402..bbdd6f0 100644 (file)
@@ -52,8 +52,8 @@ using std::max;
 
 namespace WebCore {
 
-CachedImage::CachedImage(const String& url)
-    : CachedResource(url, ImageResource)
+CachedImage::CachedImage(const ResourceRequest& resourceRequest)
+    : CachedResource(resourceRequest, ImageResource)
     , m_image(0)
     , m_decodedDataDeletionTimer(this, &CachedImage::decodedDataDeletionTimerFired)
     , m_shouldPaintBrokenImage(true)
@@ -62,7 +62,7 @@ CachedImage::CachedImage(const String& url)
 }
 
 CachedImage::CachedImage(Image* image)
-    : CachedResource(String(), ImageResource)
+    : CachedResource(ResourceRequest(), ImageResource)
     , m_image(image)
     , m_decodedDataDeletionTimer(this, &CachedImage::decodedDataDeletionTimerFired)
     , m_shouldPaintBrokenImage(true)
@@ -225,7 +225,7 @@ void CachedImage::checkShouldPaintBrokenImage()
     if (!frame)
         return;
 
-    m_shouldPaintBrokenImage = frame->loader()->client()->shouldPaintBrokenImage(KURL(ParsedURLString, m_url));
+    m_shouldPaintBrokenImage = frame->loader()->client()->shouldPaintBrokenImage(m_resourceRequest.url());
 }
 
 void CachedImage::clear()
index 42c7814..291c24e 100644 (file)
@@ -38,7 +38,7 @@ class CachedImage : public CachedResource, public ImageObserver {
     friend class MemoryCache;
 
 public:
-    CachedImage(const String& url);
+    CachedImage(const ResourceRequest&);
     CachedImage(Image*);
     virtual ~CachedImage();
     
index 9528e5a..7f8091f 100644 (file)
@@ -78,8 +78,8 @@ static ResourceLoadPriority defaultPriorityForResourceType(CachedResource::Type
 static RefCountedLeakCounter cachedResourceLeakCounter("CachedResource");
 #endif
 
-CachedResource::CachedResource(const String& url, Type type)
-    : m_url(url)
+CachedResource::CachedResource(const ResourceRequest& request, Type type)
+    : m_resourceRequest(request)
     , m_request(0)
     , m_loadPriority(defaultPriorityForResourceType(type))
     , m_responseTimestamp(currentTime())
index 09b5c03..71b25dc 100644 (file)
@@ -28,6 +28,7 @@
 #include "PlatformString.h"
 #include "PurgePriority.h"
 #include "ResourceLoadPriority.h"
+#include "ResourceRequest.h"
 #include "ResourceResponse.h"
 #include <wtf/HashCountedSet.h>
 #include <wtf/HashSet.h>
@@ -79,7 +80,7 @@ public:
         DecodeError
     };
 
-    CachedResource(const String& url, Type);
+    CachedResource(const ResourceRequest&, Type);
     virtual ~CachedResource();
     
     virtual void load(CachedResourceLoader* cachedResourceLoader)  { load(cachedResourceLoader, false, DoSecurityCheck, true); }
@@ -92,7 +93,8 @@ public:
 
     virtual bool shouldIgnoreHTTPStatusCodeErrors() const { return false; }
 
-    const String &url() const { return m_url; }
+    ResourceRequest& resourceRequest() { return m_resourceRequest; }
+    const KURL& url() const { return m_resourceRequest.url();}
     Type type() const { return static_cast<Type>(m_type); }
     
     ResourceLoadPriority loadPriority() const { return m_loadPriority; }
@@ -229,7 +231,7 @@ protected:
     
     HashCountedSet<CachedResourceClient*> m_clients;
 
-    String m_url;
+    ResourceRequest m_resourceRequest;
     String m_accept;
     CachedResourceRequest* m_request;
     ResourceLoadPriority m_loadPriority;
index 73d72e0..fc8c358 100644 (file)
 
 namespace WebCore {
 
-static CachedResource* createResource(CachedResource::Type type, const KURL& url, const String& charset)
+static CachedResource* createResource(CachedResource::Type type, ResourceRequest& request, const String& charset)
 {
     switch (type) {
     case CachedResource::ImageResource:
-        return new CachedImage(url.string());
+        return new CachedImage(request);
     case CachedResource::CSSStyleSheet:
-        return new CachedCSSStyleSheet(url.string(), charset);
+        return new CachedCSSStyleSheet(request, charset);
     case CachedResource::Script:
-        return new CachedScript(url.string(), charset);
+        return new CachedScript(request, charset);
     case CachedResource::FontResource:
-        return new CachedFont(url.string());
+        return new CachedFont(request);
 #if ENABLE(XSLT)
     case CachedResource::XSLStyleSheet:
-        return new CachedXSLStyleSheet(url.string());
+        return new CachedXSLStyleSheet(request);
 #endif
 #if ENABLE(LINK_PREFETCH)
     case CachedResource::LinkPrefetch:
-        return new CachedResource(url.string(), CachedResource::LinkPrefetch);
+        return new CachedResource(request, CachedResource::LinkPrefetch);
     case CachedResource::LinkPrerender:
-        return new CachedResource(url.string(), CachedResource::LinkPrerender);
+        return new CachedResource(request, CachedResource::LinkPrerender);
     case CachedResource::LinkSubresource:
-        return new CachedResource(url.string(), CachedResource::LinkSubresource);
+        return new CachedResource(request, CachedResource::LinkSubresource);
 #endif
     }
     ASSERT_NOT_REACHED();
@@ -124,7 +124,7 @@ Frame* CachedResourceLoader::frame() const
     return m_document ? m_document->frame() : 0;
 }
 
-CachedImage* CachedResourceLoader::requestImage(const String& url)
+CachedImage* CachedResourceLoader::requestImage(ResourceRequest& request)
 {
     if (Frame* f = frame()) {
         Settings* settings = f->settings();
@@ -132,13 +132,13 @@ CachedImage* CachedResourceLoader::requestImage(const String& url)
             return 0;
 
         if (f->loader()->pageDismissalEventBeingDispatched()) {
-            KURL completeURL = m_document->completeURL(url);
-            if (completeURL.isValid() && canRequest(CachedResource::ImageResource, completeURL))
-                PingLoader::loadImage(f, completeURL);
+            KURL requestURL = request.url();
+            if (requestURL.isValid() && canRequest(CachedResource::ImageResource, requestURL))
+                PingLoader::loadImage(f, requestURL);
             return 0;
         }
     }
-    CachedImage* resource = static_cast<CachedImage*>(requestResource(CachedResource::ImageResource, url, String()));
+    CachedImage* resource = static_cast<CachedImage*>(requestResource(CachedResource::ImageResource, request, String()));
     if (autoLoadImages() && resource && resource->stillNeedsLoad()) {
         resource->setLoading(true);
         load(resource, true);
@@ -146,26 +146,29 @@ CachedImage* CachedResourceLoader::requestImage(const String& url)
     return resource;
 }
 
-CachedFont* CachedResourceLoader::requestFont(const String& url)
+CachedFont* CachedResourceLoader::requestFont(ResourceRequest& request)
 {
-    return static_cast<CachedFont*>(requestResource(CachedResource::FontResource, url, String()));
+    return static_cast<CachedFont*>(requestResource(CachedResource::FontResource, request, String()));
 }
 
-CachedCSSStyleSheet* CachedResourceLoader::requestCSSStyleSheet(const String& url, const String& charset, ResourceLoadPriority priority)
+CachedCSSStyleSheet* CachedResourceLoader::requestCSSStyleSheet(ResourceRequest& request, const String& charset, ResourceLoadPriority priority)
 {
-    return static_cast<CachedCSSStyleSheet*>(requestResource(CachedResource::CSSStyleSheet, url, charset, priority));
+    return static_cast<CachedCSSStyleSheet*>(requestResource(CachedResource::CSSStyleSheet, request, charset, priority));
 }
 
-CachedCSSStyleSheet* CachedResourceLoader::requestUserCSSStyleSheet(const String& requestURL, const String& charset)
+CachedCSSStyleSheet* CachedResourceLoader::requestUserCSSStyleSheet(ResourceRequest& request, const String& charset)
 {
-    KURL url = MemoryCache::removeFragmentIdentifierIfNeeded(KURL(KURL(), requestURL));
+    KURL url = MemoryCache::removeFragmentIdentifierIfNeeded(request.url());
 
     if (CachedResource* existing = memoryCache()->resourceForURL(url)) {
         if (existing->type() == CachedResource::CSSStyleSheet)
             return static_cast<CachedCSSStyleSheet*>(existing);
         memoryCache()->remove(existing);
     }
-    CachedCSSStyleSheet* userSheet = new CachedCSSStyleSheet(url, charset);
+    if (url.string() != request.url())
+        request.setURL(url);
+
+    CachedCSSStyleSheet* userSheet = new CachedCSSStyleSheet(request, charset);
     
     bool inCache = memoryCache()->add(userSheet);
     if (!inCache)
@@ -179,24 +182,24 @@ CachedCSSStyleSheet* CachedResourceLoader::requestUserCSSStyleSheet(const String
     return userSheet;
 }
 
-CachedScript* CachedResourceLoader::requestScript(const String& url, const String& charset)
+CachedScript* CachedResourceLoader::requestScript(ResourceRequest& request, const String& charset)
 {
-    return static_cast<CachedScript*>(requestResource(CachedResource::Script, url, charset));
+    return static_cast<CachedScript*>(requestResource(CachedResource::Script, request, charset));
 }
 
 #if ENABLE(XSLT)
-CachedXSLStyleSheet* CachedResourceLoader::requestXSLStyleSheet(const String& url)
+CachedXSLStyleSheet* CachedResourceLoader::requestXSLStyleSheet(ResourceRequest& request)
 {
-    return static_cast<CachedXSLStyleSheet*>(requestResource(CachedResource::XSLStyleSheet, url, String()));
+    return static_cast<CachedXSLStyleSheet*>(requestResource(CachedResource::XSLStyleSheet, request, String()));
 }
 #endif
 
 #if ENABLE(LINK_PREFETCH)
-CachedResource* CachedResourceLoader::requestLinkResource(CachedResource::Type type, const String& url, ResourceLoadPriority priority)
+CachedResource* CachedResourceLoader::requestLinkResource(CachedResource::Type type, ResourceRequest& request, ResourceLoadPriority priority)
 {
     ASSERT(frame());
     ASSERT(type == CachedResource::LinkPrefetch || type == CachedResource::LinkPrerender || type == CachedResource::LinkSubresource);
-    return requestResource(type, url, String(), priority);
+    return requestResource(type, request, String(), priority);
 }
 #endif
 
@@ -308,9 +311,9 @@ bool CachedResourceLoader::canRequest(CachedResource::Type type, const KURL& url
     return true;
 }
 
-CachedResource* CachedResourceLoader::requestResource(CachedResource::Type type, const String& resourceURL, const String& charset, ResourceLoadPriority priority, bool forPreload)
+CachedResource* CachedResourceLoader::requestResource(CachedResource::Type type, ResourceRequest& request, const String& charset, ResourceLoadPriority priority, bool forPreload)
 {
-    KURL url = m_document->completeURL(resourceURL);
+    KURL url = request.url();
     
     LOG(ResourceLoading, "CachedResourceLoader::requestResource '%s', charset '%s', priority=%d, forPreload=%u", url.string().latin1().data(), charset.latin1().data(), priority, forPreload);
     
@@ -334,13 +337,16 @@ CachedResource* CachedResourceLoader::requestResource(CachedResource::Type type,
     // See if we can use an existing resource from the cache.
     CachedResource* resource = memoryCache()->resourceForURL(url);
 
+    if (request.url() != url)
+        request.setURL(url);
+
     switch (determineRevalidationPolicy(type, forPreload, resource)) {
     case Load:
-        resource = loadResource(type, url, charset, priority);
+        resource = loadResource(type, request, charset, priority);
         break;
     case Reload:
         memoryCache()->remove(resource);
-        resource = loadResource(type, url, charset, priority);
+        resource = loadResource(type, request, charset, priority);
         break;
     case Revalidate:
         resource = revalidateResource(resource, priority);
@@ -370,7 +376,7 @@ CachedResource* CachedResourceLoader::revalidateResource(CachedResource* resourc
     
     // Copy the URL out of the resource to be revalidated in case it gets deleted by the remove() call below.
     String url = resource->url();
-    CachedResource* newResource = createResource(resource->type(), KURL(ParsedURLString, url), resource->encoding());
+    CachedResource* newResource = createResource(resource->type(), resource->resourceRequest(), resource->encoding());
     
     LOG(ResourceLoading, "Resource %p created to revalidate %p", newResource, resource);
     newResource->setResourceToRevalidate(resource);
@@ -385,13 +391,13 @@ CachedResource* CachedResourceLoader::revalidateResource(CachedResource* resourc
     return newResource;
 }
 
-CachedResource* CachedResourceLoader::loadResource(CachedResource::Type type, const KURL& url, const String& charset, ResourceLoadPriority priority)
+CachedResource* CachedResourceLoader::loadResource(CachedResource::Type type, ResourceRequest& request, const String& charset, ResourceLoadPriority priority)
 {
-    ASSERT(!memoryCache()->resourceForURL(url));
+    ASSERT(!memoryCache()->resourceForURL(request.url()));
     
-    LOG(ResourceLoading, "Loading CachedResource for '%s'.", url.string().latin1().data());
+    LOG(ResourceLoading, "Loading CachedResource for '%s'.", request.url().string().latin1().data());
     
-    CachedResource* resource = createResource(type, url, charset);
+    CachedResource* resource = createResource(type, request, charset);
     
     bool inCache = memoryCache()->add(resource);
     
@@ -417,7 +423,7 @@ CachedResource* CachedResourceLoader::loadResource(CachedResource::Type type, co
         return 0;
     }
 
-    m_validatedURLs.add(url.string());
+    m_validatedURLs.add(request.url());
     return resource;
 }
 
@@ -632,7 +638,7 @@ int CachedResourceLoader::requestCount()
     return m_requestCount;
 }
     
-void CachedResourceLoader::preload(CachedResource::Type type, const String& url, const String& charset, bool referencedFromBody)
+void CachedResourceLoader::preload(CachedResource::Type type, ResourceRequest& request, const String& charset, bool referencedFromBody)
 {
     // FIXME: Rip this out when we are sure it is no longer necessary (even for mobile).
     UNUSED_PARAM(referencedFromBody);
@@ -642,11 +648,11 @@ void CachedResourceLoader::preload(CachedResource::Type type, const String& url,
     if (!hasRendering && !canBlockParser) {
         // Don't preload subresources that can't block the parser before we have something to draw.
         // This helps prevent preloads from delaying first display when bandwidth is limited.
-        PendingPreload pendingPreload = { type, url, charset };
+        PendingPreload pendingPreload = { type, request, charset };
         m_pendingPreloads.append(pendingPreload);
         return;
     }
-    requestPreload(type, url, charset);
+    requestPreload(type, request, charset);
 }
 
 void CachedResourceLoader::checkForPendingPreloads() 
@@ -656,19 +662,19 @@ void CachedResourceLoader::checkForPendingPreloads()
     while (!m_pendingPreloads.isEmpty()) {
         PendingPreload preload = m_pendingPreloads.takeFirst();
         // Don't request preload if the resource already loaded normally (this will result in double load if the page is being reloaded with cached results ignored).
-        if (!cachedResource(m_document->completeURL(preload.m_url)))
-            requestPreload(preload.m_type, preload.m_url, preload.m_charset);
+        if (!cachedResource(preload.m_request.url()))
+            requestPreload(preload.m_type, preload.m_request, preload.m_charset);
     }
     m_pendingPreloads.clear();
 }
 
-void CachedResourceLoader::requestPreload(CachedResource::Type type, const String& url, const String& charset)
+void CachedResourceLoader::requestPreload(CachedResource::Type type, ResourceRequest& request, const String& charset)
 {
     String encoding;
     if (type == CachedResource::Script || type == CachedResource::CSSStyleSheet)
         encoding = charset.isEmpty() ? m_document->charset() : charset;
 
-    CachedResource* resource = requestResource(type, url, encoding, ResourceLoadPriorityUnresolved, true);
+    CachedResource* resource = requestResource(type, request, encoding, ResourceLoadPriorityUnresolved, true);
     if (!resource || (m_preloads && m_preloads->contains(resource)))
         return;
     resource->increasePreloadCount();
index 7441db1..cb9100f 100644 (file)
@@ -60,17 +60,17 @@ public:
     CachedResourceLoader(Document*);
     ~CachedResourceLoader();
 
-    CachedImage* requestImage(const String& url);
-    CachedCSSStyleSheet* requestCSSStyleSheet(const String& url, const String& charset, ResourceLoadPriority priority = ResourceLoadPriorityUnresolved);
-    CachedCSSStyleSheet* requestUserCSSStyleSheet(const String& url, const String& charset);
-    CachedScript* requestScript(const String& url, const String& charset);
-    CachedFont* requestFont(const String& url);
+    CachedImage* requestImage(ResourceRequest&);
+    CachedCSSStyleSheet* requestCSSStyleSheet(ResourceRequest&, const String& charset, ResourceLoadPriority = ResourceLoadPriorityUnresolved);
+    CachedCSSStyleSheet* requestUserCSSStyleSheet(ResourceRequest&, const String& charset);
+    CachedScript* requestScript(ResourceRequest&, const String& charset);
+    CachedFont* requestFont(ResourceRequest&);
 
 #if ENABLE(XSLT)
-    CachedXSLStyleSheet* requestXSLStyleSheet(const String& url);
+    CachedXSLStyleSheet* requestXSLStyleSheet(ResourceRequest&);
 #endif
 #if ENABLE(LINK_PREFETCH)
-    CachedResource* requestLinkResource(CachedResource::Type, const String &url, ResourceLoadPriority priority = ResourceLoadPriorityUnresolved);
+    CachedResource* requestLinkResource(CachedResource::Type, ResourceRequest&, ResourceLoadPriority = ResourceLoadPriorityUnresolved);
 #endif
 
     // Logs an access denied message to the console for the specified URL.
@@ -103,15 +103,15 @@ public:
     
     void clearPreloads();
     void clearPendingPreloads();
-    void preload(CachedResource::Type, const String& url, const String& charset, bool referencedFromBody);
+    void preload(CachedResource::Type, ResourceRequest&, const String& charset, bool referencedFromBody);
     void checkForPendingPreloads();
     void printPreloadStats();
     
 private:
-    CachedResource* requestResource(CachedResource::Type, const String& url, const String& charset, ResourceLoadPriority priority = ResourceLoadPriorityUnresolved, bool isPreload = false);
+    CachedResource* requestResource(CachedResource::Type, ResourceRequest&, const String& charset, ResourceLoadPriority = ResourceLoadPriorityUnresolved, bool isPreload = false);
     CachedResource* revalidateResource(CachedResource*, ResourceLoadPriority priority);
-    CachedResource* loadResource(CachedResource::Type, const KURL&, const String& charset, ResourceLoadPriority priority);
-    void requestPreload(CachedResource::Type, const String& url, const String& charset);
+    CachedResource* loadResource(CachedResource::Type, ResourceRequest&, const String& charset, ResourceLoadPriority);
+    void requestPreload(CachedResource::Type, ResourceRequest& url, const String& charset);
 
     enum RevalidationPolicy { Use, Revalidate, Reload, Load };
     RevalidationPolicy determineRevalidationPolicy(CachedResource::Type, bool forPreload, CachedResource* existingResource) const;
@@ -135,7 +135,7 @@ private:
     OwnPtr<ListHashSet<CachedResource*> > m_preloads;
     struct PendingPreload {
         CachedResource::Type m_type;
-        String m_url;
+        ResourceRequest m_request;
         String m_charset;
     };
     Deque<PendingPreload> m_pendingPreloads;
index b3e3f7b..6b7aa58 100644 (file)
@@ -91,7 +91,7 @@ PassRefPtr<CachedResourceRequest> CachedResourceRequest::load(CachedResourceLoad
 {
     RefPtr<CachedResourceRequest> request = adoptRef(new CachedResourceRequest(cachedResourceLoader, resource, incremental));
 
-    ResourceRequest resourceRequest(resource->url());
+    ResourceRequest resourceRequest = resource->resourceRequest();
     resourceRequest.setTargetType(cachedResourceTypeToTargetType(resource->type()));
 
     if (!resource->accept().isEmpty())
@@ -126,7 +126,7 @@ PassRefPtr<CachedResourceRequest> CachedResourceRequest::load(CachedResourceLoad
         request.get(), resourceRequest, priority, securityCheck, sendResourceLoadCallbacks);
     if (!loader || loader->reachedTerminalState()) {
         // FIXME: What if resources in other frames were waiting for this revalidation?
-        LOG(ResourceLoading, "Cannot start loading '%s'", resource->url().latin1().data());
+        LOG(ResourceLoading, "Cannot start loading '%s'", resource->url().string().latin1().data());
         cachedResourceLoader->decrementRequestCount(resource);
         cachedResourceLoader->loadFinishing();
         if (resource->resourceToRevalidate()) 
@@ -151,7 +151,7 @@ void CachedResourceRequest::didFinishLoading(SubresourceLoader* loader, double)
 
     ASSERT(loader == m_loader.get());
     ASSERT(!m_resource->resourceToRevalidate());
-    LOG(ResourceLoading, "Received '%s'.", m_resource->url().latin1().data());
+    LOG(ResourceLoading, "Received '%s'.", m_resource->url().string().latin1().data());
 
     // Prevent the document from being destroyed before we are done with
     // the cachedResourceLoader that it will delete when the document gets deleted.
@@ -183,7 +183,7 @@ void CachedResourceRequest::didFail(bool cancelled)
     if (m_finishing)
         return;
 
-    LOG(ResourceLoading, "Failed to load '%s' (cancelled=%d).\n", m_resource->url().latin1().data(), cancelled);
+    LOG(ResourceLoading, "Failed to load '%s' (cancelled=%d).\n", m_resource->url().string().latin1().data(), cancelled);
 
     // Prevent the document from being destroyed before we are done with
     // the cachedResourceLoader that it will delete when the document gets deleted.
index e1a8a32..8c83bca 100644 (file)
@@ -40,8 +40,8 @@
 
 namespace WebCore {
 
-CachedScript::CachedScript(const String& url, const String& charset)
-    : CachedResource(url, Script)
+CachedScript::CachedScript(const ResourceRequest& resourceRequest, const String& charset)
+    : CachedResource(resourceRequest, Script)
     , m_decoder(TextResourceDecoder::create("application/javascript", charset))
     , m_decodedDataDeletionTimer(this, &CachedScript::decodedDataDeletionTimerFired)
 {
index a4ea453..1a76c18 100644 (file)
@@ -42,7 +42,7 @@ namespace WebCore {
 
     class CachedScript : public CachedResource {
     public:
-        CachedScript(const String& url, const String& charset);
+        CachedScript(const ResourceRequest&, const String& charset);
         virtual ~CachedScript();
 
         const String& script();
index ca7bf13..62e5048 100644 (file)
@@ -37,8 +37,8 @@ namespace WebCore {
 
 #if ENABLE(XSLT)
 
-CachedXSLStyleSheet::CachedXSLStyleSheet(const String &url)
-    : CachedResource(url, XSLStyleSheet)
+CachedXSLStyleSheet::CachedXSLStyleSheet(const ResourceRequest& resourceRequest)
+    : CachedResource(resourceRequest, XSLStyleSheet)
     , m_decoder(TextResourceDecoder::create("text/xsl"))
 {
     // It's XML we want.
@@ -49,7 +49,7 @@ CachedXSLStyleSheet::CachedXSLStyleSheet(const String &url)
 void CachedXSLStyleSheet::didAddClient(CachedResourceClient* c)
 {  
     if (!isLoading())
-        c->setXSLStyleSheet(m_url, m_response.url(), m_sheet);
+        c->setXSLStyleSheet(m_resourceRequest.url(), m_response.url(), m_sheet);
 }
 
 void CachedXSLStyleSheet::setEncoding(const String& chs)
@@ -84,7 +84,7 @@ void CachedXSLStyleSheet::checkNotify()
     
     CachedResourceClientWalker w(m_clients);
     while (CachedResourceClient *c = w.next())
-        c->setXSLStyleSheet(m_url, m_response.url(), m_sheet);
+        c->setXSLStyleSheet(m_resourceRequest.url(), m_response.url(), m_sheet);
 }
 
 void CachedXSLStyleSheet::error(CachedResource::Status status)
index 8b29792..b8f7283 100644 (file)
@@ -37,7 +37,7 @@ namespace WebCore {
 #if ENABLE(XSLT)
     class CachedXSLStyleSheet : public CachedResource {
     public:
-        CachedXSLStyleSheet(const String& url);
+        CachedXSLStyleSheet(const ResourceRequest&);
 
         const String& sheet() const { return m_sheet; }
         
index 93be453..103fac1 100644 (file)
@@ -94,7 +94,7 @@ bool MemoryCache::add(CachedResource* resource)
     
     resourceAccessed(resource);
     
-    LOG(ResourceLoading, "MemoryCache::add Added '%s', resource %p\n", resource->url().latin1().data(), resource);
+    LOG(ResourceLoading, "MemoryCache::add Added '%s', resource %p\n", resource->url().string().latin1().data(), resource);
     return true;
 }
 
@@ -363,7 +363,7 @@ bool MemoryCache::makeResourcePurgeable(CachedResource* resource)
 
 void MemoryCache::evict(CachedResource* resource)
 {
-    LOG(ResourceLoading, "Evicting resource %p for '%s' from cache", resource, resource->url().latin1().data());
+    LOG(ResourceLoading, "Evicting resource %p for '%s' from cache", resource, resource->url().string().latin1().data());
     // The resource may have already been removed by someone other than our caller,
     // who needed a fresh copy for a reload. See <http://bugs.webkit.org/show_bug.cgi?id=12479#c6>.
     if (resource->inCache()) {
index 25a4699..39dbbdb 100644 (file)
@@ -72,7 +72,8 @@ void SVGFEImageElement::requestImageResource()
     if (hrefElement && hrefElement->isSVGElement() && hrefElement->renderer())
         return;
 
-    m_cachedImage = ownerDocument()->cachedResourceLoader()->requestImage(href());
+    ResourceRequest request(ownerDocument()->completeURL(href()));
+    m_cachedImage = ownerDocument()->cachedResourceLoader()->requestImage(request);
 
     if (m_cachedImage)
         m_cachedImage->addClient(this);
index f33e42a..454ccdb 100644 (file)
@@ -96,7 +96,8 @@ void SVGFontFaceUriElement::loadFont()
     String href = getAttribute(XLinkNames::hrefAttr);
     if (!href.isNull()) {        
         CachedResourceLoader* cachedResourceLoader = document()->cachedResourceLoader();
-        m_cachedFont = cachedResourceLoader->requestFont(href);
+        ResourceRequest request(document()->completeURL(href));
+        m_cachedFont = cachedResourceLoader->requestFont(request);
         if (m_cachedFont) {
             m_cachedFont->addClient(this);
             m_cachedFont->beginLoadIfNeeded(cachedResourceLoader);
index c32da4e..d23f182 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "CachedXSLStyleSheet.h"
 #include "CachedResourceLoader.h"
+#include "Document.h"
 #include "XSLStyleSheet.h"
 
 namespace WebCore {
@@ -98,7 +99,8 @@ void XSLImportRule::loadSheet()
             return;
     }
     
-    m_cachedSheet = cachedResourceLoader->requestXSLStyleSheet(absHref);
+    ResourceRequest request(cachedResourceLoader->document()->completeURL(absHref));
+    m_cachedSheet = cachedResourceLoader->requestXSLStyleSheet(request);
     
     if (m_cachedSheet) {
         m_cachedSheet->addClient(this);