summaryrefslogtreecommitdiffstats
path: root/WebCore/loader
diff options
context:
space:
mode:
authorLeon Clarke <leonclarke@google.com>2010-07-12 16:00:49 +0100
committerLeon Clarke <leonclarke@google.com>2010-07-12 16:52:19 +0100
commit5d6f8ef31d11ee66598999b1b749ba9ff767e4d5 (patch)
treed6ade236b43a3dd8c80c6ffff695fbc5fea10d71 /WebCore/loader
parentf5a7037b5d31f66594af3428b1ffba88b4cc8d3b (diff)
downloadexternal_webkit-5d6f8ef31d11ee66598999b1b749ba9ff767e4d5.zip
external_webkit-5d6f8ef31d11ee66598999b1b749ba9ff767e4d5.tar.gz
external_webkit-5d6f8ef31d11ee66598999b1b749ba9ff767e4d5.tar.bz2
Copy back the upstreamed version of prefetch
https://bugs.webkit.org/show_bug.cgi?id=3652 Change-Id: Ibda522afed15e7581019a198e773785b7cad57ca
Diffstat (limited to 'WebCore/loader')
-rw-r--r--WebCore/loader/Cache.cpp5
-rw-r--r--WebCore/loader/CachedCSSStyleSheet.cpp8
-rw-r--r--WebCore/loader/CachedLinkPrefetch.h68
-rw-r--r--WebCore/loader/CachedResource.cpp18
-rw-r--r--WebCore/loader/CachedResource.h12
-rw-r--r--WebCore/loader/CachedScript.cpp6
-rw-r--r--WebCore/loader/CachedScript.h1
-rw-r--r--WebCore/loader/DocLoader.cpp16
-rw-r--r--WebCore/loader/DocLoader.h5
-rw-r--r--WebCore/loader/loader.cpp8
10 files changed, 37 insertions, 110 deletions
diff --git a/WebCore/loader/Cache.cpp b/WebCore/loader/Cache.cpp
index 5f4d0e7..521d075 100644
--- a/WebCore/loader/Cache.cpp
+++ b/WebCore/loader/Cache.cpp
@@ -38,9 +38,6 @@
#include "SecurityOrigin.h"
#include <stdio.h>
#include <wtf/CurrentTime.h>
-#if ENABLE(LINK_PREFETCH)
-#include "CachedLinkPrefetch.h"
-#endif
using namespace std;
@@ -91,7 +88,7 @@ static CachedResource* createResource(CachedResource::Type type, const KURL& url
#endif
#if ENABLE(LINK_PREFETCH)
case CachedResource::LinkPrefetch:
- return new CachedLinkPrefetch(url.string());
+ return new CachedResource(url.string(), CachedResource::LinkPrefetch);
#endif
default:
break;
diff --git a/WebCore/loader/CachedCSSStyleSheet.cpp b/WebCore/loader/CachedCSSStyleSheet.cpp
index 08f3712..7866efd 100644
--- a/WebCore/loader/CachedCSSStyleSheet.cpp
+++ b/WebCore/loader/CachedCSSStyleSheet.cpp
@@ -52,10 +52,8 @@ CachedCSSStyleSheet::~CachedCSSStyleSheet()
void CachedCSSStyleSheet::didAddClient(CachedResourceClient *c)
{
- if (!isLoading()) {
+ if (!isLoading())
c->setCSSStyleSheet(m_url, m_response.url(), m_decoder->encoding().name(), this);
- c->notifyFinished(this);
- }
}
void CachedCSSStyleSheet::allClientsRemoved()
@@ -106,10 +104,6 @@ void CachedCSSStyleSheet::data(PassRefPtr<SharedBuffer> data, bool allDataReceiv
checkNotify();
// Clear the decoded text as it is unlikely to be needed immediately again and is cheap to regenerate.
m_decodedSheetText = String();
-
- CachedResourceClientWalker w(m_clients);
- while (CachedResourceClient* c = w.next())
- c->notifyFinished(this);
}
void CachedCSSStyleSheet::checkNotify()
diff --git a/WebCore/loader/CachedLinkPrefetch.h b/WebCore/loader/CachedLinkPrefetch.h
deleted file mode 100644
index 1afed76..0000000
--- a/WebCore/loader/CachedLinkPrefetch.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright 2010, The Android Open Source Project
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-*/
-
-#ifndef CachedLinkPrefetch_h
-#define CachedLinkPrefetch_h
-
-#include "CachedResource.h"
-#include "CachedResourceClient.h"
-#include "CachedResourceClientWalker.h"
-#include "PassRefPtr.h"
-#include "SharedBuffer.h"
-
-namespace WebCore {
-
-class DocLoader;
-
-class CachedLinkPrefetch : public CachedResource {
-public:
- CachedLinkPrefetch(const String& URL) : CachedResource(URL, LinkPrefetch) { };
- virtual ~CachedLinkPrefetch() { };
-
- virtual void didAddClient(CachedResourceClient* c) {
- if (!isLoading())
- c->notifyFinished(this);
- };
-
- virtual void data(PassRefPtr<SharedBuffer> data, bool allDataReceived) {
- if (!allDataReceived)
- return;
-
- m_data = data;
-
- CachedResourceClientWalker w(m_clients);
- while (CachedResourceClient* c = w.next())
- c->notifyFinished(this);
- };
- virtual void error() { };
-
- virtual bool schedule() const { return true; }
-
- virtual bool isPrefetch() const { return true; }
-};
-}
-
-#endif
diff --git a/WebCore/loader/CachedResource.cpp b/WebCore/loader/CachedResource.cpp
index 67b5c9e..75037ba 100644
--- a/WebCore/loader/CachedResource.cpp
+++ b/WebCore/loader/CachedResource.cpp
@@ -26,6 +26,8 @@
#include "Cache.h"
#include "CachedMetadata.h"
+#include "CachedResourceClient.h"
+#include "CachedResourceClientWalker.h"
#include "CachedResourceHandle.h"
#include "DocLoader.h"
#include "Frame.h"
@@ -108,6 +110,16 @@ void CachedResource::load(DocLoader* docLoader, bool incremental, SecurityCheckP
m_loading = true;
}
+void CachedResource::data(PassRefPtr<SharedBuffer>, bool allDataReceived)
+{
+ if (!allDataReceived)
+ return;
+
+ CachedResourceClientWalker w(m_clients);
+ while (CachedResourceClient* c = w.next())
+ c->notifyFinished(this);
+}
+
void CachedResource::finish()
{
m_status = Cached;
@@ -204,6 +216,12 @@ void CachedResource::addClient(CachedResourceClient* client)
didAddClient(client);
}
+void CachedResource::didAddClient(CachedResourceClient* c)
+{
+ if (!isLoading())
+ c->notifyFinished(this);
+}
+
void CachedResource::addClientToSet(CachedResourceClient* client)
{
ASSERT(!isPurgeable());
diff --git a/WebCore/loader/CachedResource.h b/WebCore/loader/CachedResource.h
index 7e99da4..d5bb97e 100644
--- a/WebCore/loader/CachedResource.h
+++ b/WebCore/loader/CachedResource.h
@@ -85,8 +85,8 @@ public:
virtual void setEncoding(const String&) { }
virtual String encoding() const { return String(); }
- virtual void data(PassRefPtr<SharedBuffer> data, bool allDataReceived) = 0;
- virtual void error() = 0;
+ virtual void data(PassRefPtr<SharedBuffer> data, bool allDataReceived);
+ virtual void error() { }
virtual void httpStatusCodeError() { error(); } // Images keep loading in spite of HTTP errors (for legacy compat with <img>, etc.).
const String &url() const { return m_url; }
@@ -106,7 +106,7 @@ public:
PreloadResult preloadResult() const { return static_cast<PreloadResult>(m_preloadResult); }
void setRequestedFromNetworkingLayer() { m_requestedFromNetworkingLayer = true; }
- virtual void didAddClient(CachedResourceClient*) = 0;
+ virtual void didAddClient(CachedResourceClient*);
virtual void allClientsRemoved() { }
unsigned count() const { return m_clients.size(); }
@@ -125,7 +125,11 @@ public:
void setLoading(bool b) { m_loading = b; }
virtual bool isImage() const { return false; }
+#if ENABLE(LINK_PREFETCH)
+ virtual bool isPrefetch() const { return type() != LinkPrefetch; }
+#else
virtual bool isPrefetch() const { return false; }
+#endif
unsigned accessCount() const { return m_accessCount; }
void increaseAccessCount() { m_accessCount++; }
@@ -166,7 +170,7 @@ public:
bool isExpired() const;
- virtual bool schedule() const { return false; }
+ virtual bool schedule() const { return isPrefetch(); }
// List of acceptable MIME types separated by ",".
// A MIME type may contain a wildcard, e.g. "text/*".
diff --git a/WebCore/loader/CachedScript.cpp b/WebCore/loader/CachedScript.cpp
index c96427c..e3d618a 100644
--- a/WebCore/loader/CachedScript.cpp
+++ b/WebCore/loader/CachedScript.cpp
@@ -51,12 +51,6 @@ CachedScript::~CachedScript()
{
}
-void CachedScript::didAddClient(CachedResourceClient* c)
-{
- if (!isLoading())
- c->notifyFinished(this);
-}
-
void CachedScript::allClientsRemoved()
{
m_decodedDataDeletionTimer.startOneShot(0);
diff --git a/WebCore/loader/CachedScript.h b/WebCore/loader/CachedScript.h
index 2374409..dff49c3 100644
--- a/WebCore/loader/CachedScript.h
+++ b/WebCore/loader/CachedScript.h
@@ -41,7 +41,6 @@ namespace WebCore {
const String& script();
- virtual void didAddClient(CachedResourceClient*);
virtual void allClientsRemoved();
virtual void setEncoding(const String&);
diff --git a/WebCore/loader/DocLoader.cpp b/WebCore/loader/DocLoader.cpp
index c0ba2f3..f6588c7 100644
--- a/WebCore/loader/DocLoader.cpp
+++ b/WebCore/loader/DocLoader.cpp
@@ -45,10 +45,6 @@
#include "Settings.h"
#include <wtf/text/CString.h>
-#if ENABLE(LINK_PREFETCH)
-#include "CachedLinkPrefetch.h"
-#endif
-
#define PRELOAD_DEBUG 0
namespace WebCore {
@@ -181,9 +177,9 @@ CachedXBLDocument* DocLoader::requestXBLDocument(const String& url)
#endif
#if ENABLE(LINK_PREFETCH)
-CachedLinkPrefetch* DocLoader::requestLinkPrefetch(const String& url)
+CachedResource* DocLoader::requestLinkPrefetch(const String& url)
{
- return static_cast<CachedLinkPrefetch*>(requestResource(CachedResource::LinkPrefetch, url, String()));
+ return requestResource(CachedResource::LinkPrefetch, url, String());
}
#endif
@@ -242,9 +238,6 @@ bool DocLoader::canRequest(CachedResource::Type type, const KURL& url)
break;
case CachedResource::ImageResource:
case CachedResource::CSSStyleSheet:
-#if ENABLE(LINK_PREFETCH)
- case CachedResource::LinkPrefetch:
-#endif
case CachedResource::FontResource: {
// These resources can corrupt only the frame's pixels.
if (Frame* f = frame()) {
@@ -253,6 +246,11 @@ bool DocLoader::canRequest(CachedResource::Type type, const KURL& url)
}
break;
}
+#if ENABLE(LINK_PREFETCH)
+ case CachedResource::LinkPrefetch:
+ // Prefetch cannot affect the current document.
+ break;
+#endif
default:
ASSERT_NOT_REACHED();
break;
diff --git a/WebCore/loader/DocLoader.h b/WebCore/loader/DocLoader.h
index ec3e619..2b43bb3 100644
--- a/WebCore/loader/DocLoader.h
+++ b/WebCore/loader/DocLoader.h
@@ -45,9 +45,6 @@ class Document;
class Frame;
class ImageLoader;
class KURL;
-#if ENABLE(LINK_PREFETCH)
-class CachedLinkPrefetch;
-#endif
// The DocLoader manages the loading of scripts/images/stylesheets for a single document.
class DocLoader : public Noncopyable {
@@ -71,7 +68,7 @@ public:
CachedXBLDocument* requestXBLDocument(const String &url);
#endif
#if ENABLE(LINK_PREFETCH)
- CachedLinkPrefetch* requestLinkPrefetch(const String &url);
+ CachedResource* requestLinkPrefetch(const String &url);
#endif
// Logs an access denied message to the console for the specified URL.
diff --git a/WebCore/loader/loader.cpp b/WebCore/loader/loader.cpp
index 897130b..e137a5f 100644
--- a/WebCore/loader/loader.cpp
+++ b/WebCore/loader/loader.cpp
@@ -91,7 +91,7 @@ static ResourceRequest::TargetType cachedResourceTypeToTargetType(CachedResource
return ResourceRequest::TargetIsImage;
#if ENABLE(LINK_PREFETCH)
case CachedResource::LinkPrefetch:
- return ResourceRequest::TargetIsSubresource;
+ return ResourceRequest::TargetIsPrefetch;
#endif
}
ASSERT_NOT_REACHED();
@@ -370,12 +370,6 @@ void Loader::Host::servePendingRequests(RequestQueue& requestsPending, bool& ser
}
}
-#if ENABLE(LINK_PREFETCH)
- if (request->cachedResource()->type() == CachedResource::LinkPrefetch) {
- resourceRequest.setHTTPHeaderField("X-Moz", "prefetch");
- }
-#endif
-
RefPtr<SubresourceLoader> loader = SubresourceLoader::create(docLoader->doc()->frame(),
this, resourceRequest, request->shouldDoSecurityCheck(), request->sendResourceLoadCallbacks());
if (loader) {