+++ /dev/null
-Test: http://www.w3.org/2001/DOM-Test-Suite/level2/html/HTMLLinkElement10
-Status: Success
+++ /dev/null
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<HTML>
-<HEAD>
-<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=utf-8">
-<TITLE>NIST DOM HTML Test - LINK</TITLE>
-<BODY>
-<P>
-This is the test link that's pre-fetched by the prefetch test.
-</P>
-</BODY>
-</HTML>
-
+++ /dev/null
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<HTML>
-<HEAD>
-<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=utf-8">
-<TITLE>NIST DOM HTML Test - LINK</TITLE>
-<script charset='UTF-8' type='text/javascript' src='selfhtml.js'></script>
-<script charset='UTF-8' type='text/javascript' src='HTMLLinkElement10.js'></script>
-<LINK CHARSET="Latin-1" HREF="HTMLLinkElement10-link.file" HREFLANG="en" MEDIA="screen" REL="prefetch" TYPE="text/html" onload="prefetchComplete()">
-<LINK CHARSET="Latin-1" HREF="./files/style1.css" HREFLANG="en" MEDIA="screen" REV="stylesheet" TYPE="text/css">
-<script type='text/javascript'>startTest10();
-</script></HEAD>
-<BODY onload="loadComplete()">
-<P>
-<BR>
-</P>
-</BODY>
-</HTML>
-
+++ /dev/null
-
-
- /**
- * Gets URI that identifies the test.
- * @return uri identifier of test
- */
-function getTargetURI() {
- return "http://www.w3.org/2001/DOM-Test-Suite/level2/html/HTMLLinkElement10";
- }
-
-var docsLoaded = 0;
-var mainLoaded = false;
-var prefetchLoaded = false;
-
-function finishTest() {
- if (mainLoaded && prefetchLoaded) {
- setResult(null, null);
- } else {
- if (!prefetchLoaded) {
- setResult("fail", "No prefetch onload fired");
- } else {
- setResult("fail", "Prefetch fired, but maybe the document onload didn't");
- }
- }
- if (window.layoutTestController) {
- layoutTestController.notifyDone();
- }
-}
-
-function loadComplete() {
- mainLoaded = true;
- if (++docsLoaded == 2) {
- finishTest();
- }
-}
-
-function prefetchComplete() {
- prefetchLoaded = true;
- if (++docsLoaded == 2) {
- finishTest();
- }
-}
-
-
-
-function startTest10() {
- if (window.layoutTestController) {
- layoutTestController.dumpAsText();
- layoutTestController.waitUntilDone();
- }
-}
+++ /dev/null
-Test: http://www.w3.org/2001/DOM-Test-Suite/level2/html/HTMLLinkElement11
-Status: Success
+++ /dev/null
-div { font-family: Arial, Helvetica, sans-serif; color: red; }
+++ /dev/null
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<HTML>
-<HEAD>
-<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=utf-8">
-<TITLE>NIST DOM HTML Test - LINK</TITLE>
-<script charset='UTF-8' type='text/javascript' src='selfhtml.js'></script>
-<script charset='UTF-8' type='text/javascript' src='HTMLLinkElement11.js'></script><script type='text/javascript'>startTest11();</script></HEAD>
-<LINK CHARSET="Latin-1" HREF="HTMLLinkElement11.css" HREFLANG="en" MEDIA="screen" REL="stylesheet" TYPE="text/css" onload="cssComplete()">
-<BODY onload="loadComplete()">
-<P>
-<BR>
-</P>
-</BODY>
-</HTML>
-
+++ /dev/null
-
-
- /**
- * Gets URI that identifies the test.
- * @return uri identifier of test
- */
-function getTargetURI() {
- return "http://www.w3.org/2001/DOM-Test-Suite/level2/html/HTMLLinkElement11";
- }
-
-var docsLoaded = 0;
-var mainLoaded = false;
-var cssLoaded = false;
-
-function finishTest() {
- if (mainLoaded && cssLoaded) {
- setResult(null, null);
- } else {
- if (!cssLoaded) {
- setResult("fail", "No css onload fired");
- } else {
- setResult("fail", "Css fired, but maybe the document onload didn't");
- }
- }
- if (window.layoutTestController) {
- layoutTestController.notifyDone();
- }
-}
-
-function loadComplete() {
- mainLoaded = true;
- if (++docsLoaded == 2) {
- finishTest();
- }
-}
-
-function cssComplete() {
- cssLoaded = true;
- if (++docsLoaded == 2) {
- finishTest();
- }
-}
-
-
-
-function startTest11() {
- if (window.layoutTestController) {
- layoutTestController.dumpAsText();
- layoutTestController.waitUntilDone();
- }
-}
#include "ScriptEventListener.h"
#include "Settings.h"
#include <wtf/StdLibExtras.h>
-#if PLATFORM(ANDROID) && ENABLE(LINK_PREFETCH)
-#include "CachedLinkPrefetch.h"
-#endif
namespace WebCore {
, m_loading(false)
, m_createdByParser(createdByParser)
, m_shouldProcessAfterAttach(false)
-#if PLATFORM(ANDROID) && ENABLE(LINK_PREFETCH)
- , m_timer(this, &HTMLLinkElement::timerFired)
-#endif
{
ASSERT(hasTagName(linkTag));
}
setDisabledState(!attr->isNull());
else if (attr->name() == onbeforeloadAttr)
setAttributeEventListener(eventNames().beforeloadEvent, createAttributeEventListener(this, attr));
-#if PLATFORM(ANDROID) && ENABLE(LINK_PREFETCH)
- else if (attr->name() == onloadAttr)
- setAttributeEventListener(eventNames().loadEvent, createAttributeEventListener(this, attr));
-#endif
else {
if (attr->name() == titleAttr && m_sheet)
m_sheet->setTitle(attr->value());
relAttribute.m_isIcon = false;
relAttribute.m_isAlternate = false;
relAttribute.m_isDNSPrefetch = false;
-#if PLATFORM(ANDROID) && ENABLE(LINK_PREFETCH)
+#if ENABLE(LINK_PREFETCH)
relAttribute.m_isLinkPrefetch = false;
#endif
#ifdef ANDROID_APPLE_TOUCH_ICON
#endif
else if (equalIgnoringCase(rel, "dns-prefetch"))
relAttribute.m_isDNSPrefetch = true;
-#if PLATFORM(ANDROID) && ENABLE(LINK_PREFETCH)
+#if ENABLE(LINK_PREFETCH)
else if (equalIgnoringCase(rel, "prefetch"))
relAttribute.m_isLinkPrefetch = true;
#endif
if (m_relAttribute.m_isDNSPrefetch && m_url.isValid() && !m_url.isEmpty())
ResourceHandle::prepareForURL(m_url);
-#if PLATFORM(ANDROID) && ENABLE(LINK_PREFETCH)
- if (m_relAttribute.m_isLinkPrefetch && m_url.isValid()) {
- m_cachedLinkPrefetch = document()->docLoader()->requestLinkPrefetch(m_url);
- m_loading = true;
-
- if (m_cachedLinkPrefetch)
- m_cachedLinkPrefetch->addClient(this);
- }
+#if ENABLE(LINK_PREFETCH)
+ if (m_relAttribute.m_isLinkPrefetch && m_url.isValid())
+ document()->docLoader()->requestLinkPrefetch(m_url);
#endif
bool acceptIfTypeContainsTextCSS = document()->page() && document()->page()->settings() && document()->page()->settings()->treatsAnyTextCSSLinkAsStylesheet();
return static_cast<CSSStyleSheet *>(m_sheet.get())->isLoading();
}
-#if PLATFORM(ANDROID) && ENABLE(LINK_PREFETCH)
-void HTMLLinkElement::notifyFinished(CachedResource*)
-{
- if (!m_timer.isActive())
- m_timer.startOneShot(0);
-}
-
-void HTMLLinkElement::timerFired(Timer<HTMLLinkElement>*)
-{
- dispatchEvent(Event::create(eventNames().loadEvent, false, false));
-}
-#endif
-
bool HTMLLinkElement::sheetLoaded()
{
if (!isLoading() && !isDisabled() && !isAlternate()) {
#include "CachedResourceClient.h"
#include "CachedResourceHandle.h"
#include "HTMLElement.h"
-#if PLATFORM(ANDROID) && ENABLE(LINK_PREFETCH)
-#include "Timer.h"
-#endif
namespace WebCore {
class CachedCSSStyleSheet;
-#if PLATFORM(ANDROID) && ENABLE(LINK_PREFETCH)
class CachedLinkPrefetch;
-#endif
class KURL;
class HTMLLinkElement : public HTMLElement, public CachedResourceClient {
bool m_isTouchIcon;
bool m_isPrecomposedTouchIcon;
#endif
-#if PLATFORM(ANDROID) && ENABLE(LINK_PREFETCH)
+#if ENABLE(LINK_PREFETCH)
bool m_isLinkPrefetch;
#endif
- RelAttribute() : m_isStyleSheet(false), m_isIcon(false), m_isAlternate(false), m_isDNSPrefetch(false)
-#ifdef ANDROID_APPLE_TOUCH_ICON
- , m_isTouchIcon(false), m_isPrecomposedTouchIcon(false)
-#endif
-#if PLATFORM(ANDROID) && ENABLE(LINK_PREFETCH)
+ RelAttribute()
+ : m_isStyleSheet(false)
+ , m_isIcon(false)
+ , m_isAlternate(false)
+ , m_isDNSPrefetch(false)
+#if ENABLE(LINK_PREFETCH)
, m_isLinkPrefetch(false)
#endif
{ };
// from CachedResourceClient
virtual void setCSSStyleSheet(const String& href, const KURL& baseURL, const String& charset, const CachedCSSStyleSheet* sheet);
-#if PLATFORM(ANDROID) && ENABLE(LINK_PREFETCH)
- virtual void notifyFinished(CachedResource*);
-#endif
-
virtual bool sheetLoaded();
bool isAlternate() const { return m_disabledState == Unset && m_relAttribute.m_isAlternate; }
#endif
private:
-#if PLATFORM(ANDROID) && ENABLE(LINK_PREFETCH)
- void timerFired(Timer<HTMLLinkElement>*);
-#endif
HTMLLinkElement(const QualifiedName&, Document*, bool createdByParser);
enum DisabledState {
CachedResourceHandle<CachedCSSStyleSheet> m_cachedSheet;
RefPtr<CSSStyleSheet> m_sheet;
-#if PLATFORM(ANDROID) && ENABLE(LINK_PREFETCH)
- CachedResourceHandle<CachedLinkPrefetch> m_cachedLinkPrefetch;
-#endif
KURL m_url;
String m_type;
String m_media;
bool m_loading;
bool m_createdByParser;
bool m_shouldProcessAfterAttach;
-#if PLATFORM(ANDROID) && ENABLE(LINK_PREFETCH)
- Timer<HTMLLinkElement> m_timer;
-#endif
};
} //namespace
#include "SecurityOrigin.h"
#include <stdio.h>
#include <wtf/CurrentTime.h>
-#if ENABLE(LINK_PREFETCH)
-#include "CachedLinkPrefetch.h"
-#endif
using namespace std;
#endif
#if ENABLE(LINK_PREFETCH)
case CachedResource::LinkPrefetch:
- return new CachedLinkPrefetch(url.string());
+ return new CachedResource(url.string(), CachedResource::LinkPrefetch);
#endif
default:
break;
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()
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()
+++ /dev/null
-/*
- * 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
#include "Cache.h"
#include "CachedMetadata.h"
+#include "CachedResourceClient.h"
+#include "CachedResourceClientWalker.h"
#include "CachedResourceHandle.h"
#include "DocLoader.h"
#include "Frame.h"
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;
didAddClient(client);
}
+void CachedResource::didAddClient(CachedResourceClient* c)
+{
+ if (!isLoading())
+ c->notifyFinished(this);
+}
+
void CachedResource::addClientToSet(CachedResourceClient* client)
{
ASSERT(!isPurgeable());
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; }
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(); }
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++; }
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/*".
{
}
-void CachedScript::didAddClient(CachedResourceClient* c)
-{
- if (!isLoading())
- c->notifyFinished(this);
-}
-
void CachedScript::allClientsRemoved()
{
m_decodedDataDeletionTimer.startOneShot(0);
const String& script();
- virtual void didAddClient(CachedResourceClient*);
virtual void allClientsRemoved();
virtual void setEncoding(const String&);
#include "Settings.h"
#include <wtf/text/CString.h>
-#if ENABLE(LINK_PREFETCH)
-#include "CachedLinkPrefetch.h"
-#endif
-
#define PRELOAD_DEBUG 0
namespace WebCore {
#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
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()) {
}
break;
}
+#if ENABLE(LINK_PREFETCH)
+ case CachedResource::LinkPrefetch:
+ // Prefetch cannot affect the current document.
+ break;
+#endif
default:
ASSERT_NOT_REACHED();
break;
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 {
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.
return ResourceRequest::TargetIsImage;
#if ENABLE(LINK_PREFETCH)
case CachedResource::LinkPrefetch:
- return ResourceRequest::TargetIsSubresource;
+ return ResourceRequest::TargetIsPrefetch;
#endif
}
ASSERT_NOT_REACHED();
}
}
-#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) {
TargetIsObject,
TargetIsMedia,
TargetIsWorker,
- TargetIsSharedWorker
+ TargetIsSharedWorker,
+ TargetIsPrefetch,
};
static PassOwnPtr<ResourceRequest> adopt(PassOwnPtr<CrossThreadResourceRequestData>);