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

        Reviewed by Adam Barth.

        refactor HTMLLinkElement to allow Link header implementation
        https://bugs.webkit.org/show_bug.cgi?id=51941

        This change moves the LinkRelAttribute helper struct into its own
        file in html/, since the LinkRelAttribute is used by the LinkLoader,
        and leaving it in HTMLLinkElement would have been too circular for
        my tastes.

        The new LinkLoader class contains the loader code for icons, dns
        prefetching and prefetch/prerender/subresource into a common
        LinkLoader.  This is a step in getting the Link header working in
        WebKit, as discussed in webkit-dev For more information, see
        thread "beforeload & link
        (esp rel prefetch)".

        No new tests, since this is a refactoring.

        * CMakeLists.txt:
        * GNUmakefile.list.am:
        * WebCore.gypi:
        * WebCore.pro:
        * WebCore.vcproj/WebCore.vcproj:
        * WebCore.xcodeproj/project.pbxproj:
        * html/HTMLLinkElement.cpp:
        (WebCore::HTMLLinkElement::HTMLLinkElement):
        (WebCore::HTMLLinkElement::~HTMLLinkElement):
        (WebCore::HTMLLinkElement::parseMappedAttribute):
        (WebCore::HTMLLinkElement::shouldLoadLink):
        (WebCore::HTMLLinkElement::process):
        (WebCore::HTMLLinkElement::linkLoaded):
        (WebCore::HTMLLinkElement::linkLoadingErrored):
        * html/HTMLLinkElement.h:
        * html/LinkRelAttribute.cpp: Added.
        (WebCore::LinkRelAttribute::LinkRelAttribute):
        * html/LinkRelAttribute.h: Added.
        * html/parser/HTMLPreloadScanner.cpp:
        (WebCore::HTMLNames::PreloadTask::relAttributeIsStyleSheet):
        * loader/LinkLoader.cpp: Added.
        (WebCore::LinkLoader::LinkLoader):
        (WebCore::LinkLoader::~LinkLoader):
        (WebCore::LinkLoader::linkLoadedTimerFired):
        (WebCore::LinkLoader::notifyFinished):
        (WebCore::LinkLoader::loadLink):
        * loader/LinkLoader.h: Added.
        * loader/LinkLoaderClient.h: Added.
        (WebCore::LinkLoaderClient::~LinkLoaderClient):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@89146 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 92397f8c
......@@ -784,6 +784,7 @@ SET(WebCore_SOURCES
html/InputType.cpp
html/IsIndexInputType.cpp
html/LabelsNodeList.cpp
html/LinkRelAttribute.cpp
html/MediaDocument.cpp
html/MonthInputType.cpp
html/NumberInputType.cpp
......@@ -906,6 +907,7 @@ SET(WebCore_SOURCES
loader/FrameLoaderStateMachine.cpp
loader/HistoryController.cpp
loader/ImageLoader.cpp
loader/LinkLoader.cpp
loader/MainResourceLoader.cpp
loader/NavigationAction.cpp
loader/NetscapePlugInStreamLoader.cpp
......
2011-06-17 Gavin Peters <gavinp@chromium.org>
Reviewed by Adam Barth.
refactor HTMLLinkElement to allow Link header implementation
https://bugs.webkit.org/show_bug.cgi?id=51941
This change moves the LinkRelAttribute helper struct into its own
file in html/, since the LinkRelAttribute is used by the LinkLoader,
and leaving it in HTMLLinkElement would have been too circular for
my tastes.
The new LinkLoader class contains the loader code for icons, dns
prefetching and prefetch/prerender/subresource into a common
LinkLoader. This is a step in getting the Link header working in
WebKit, as discussed in webkit-dev For more information, see
thread "beforeload & link
(esp rel prefetch)".
No new tests, since this is a refactoring.
* CMakeLists.txt:
* GNUmakefile.list.am:
* WebCore.gypi:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* html/HTMLLinkElement.cpp:
(WebCore::HTMLLinkElement::HTMLLinkElement):
(WebCore::HTMLLinkElement::~HTMLLinkElement):
(WebCore::HTMLLinkElement::parseMappedAttribute):
(WebCore::HTMLLinkElement::shouldLoadLink):
(WebCore::HTMLLinkElement::process):
(WebCore::HTMLLinkElement::linkLoaded):
(WebCore::HTMLLinkElement::linkLoadingErrored):
* html/HTMLLinkElement.h:
* html/LinkRelAttribute.cpp: Added.
(WebCore::LinkRelAttribute::LinkRelAttribute):
* html/LinkRelAttribute.h: Added.
* html/parser/HTMLPreloadScanner.cpp:
(WebCore::HTMLNames::PreloadTask::relAttributeIsStyleSheet):
* loader/LinkLoader.cpp: Added.
(WebCore::LinkLoader::LinkLoader):
(WebCore::LinkLoader::~LinkLoader):
(WebCore::LinkLoader::linkLoadedTimerFired):
(WebCore::LinkLoader::notifyFinished):
(WebCore::LinkLoader::loadLink):
* loader/LinkLoader.h: Added.
* loader/LinkLoaderClient.h: Added.
(WebCore::LinkLoaderClient::~LinkLoaderClient):
2011-06-17 Annie Sullivan <sullivan@chromium.org>
Reviewed by Ryosuke Niwa.
......
......@@ -1802,6 +1802,8 @@ webcore_sources += \
Source/WebCore/html/IsIndexInputType.h \
Source/WebCore/html/LabelsNodeList.cpp \
Source/WebCore/html/LabelsNodeList.h \
Source/WebCore/html/LinkRelAttribute.cpp \
Source/WebCore/html/LinkRelAttribute.h \
Source/WebCore/html/MediaDocument.cpp \
Source/WebCore/html/MediaDocument.h \
Source/WebCore/html/MediaError.h \
......@@ -2118,6 +2120,9 @@ webcore_sources += \
Source/WebCore/loader/icon/PageURLRecord.h \
Source/WebCore/loader/ImageLoader.cpp \
Source/WebCore/loader/ImageLoader.h \
Source/WebCore/loader/LinkLoader.h \
Source/WebCore/loader/LinkLoader.cpp \
Source/WebCore/loader/LinkLoaderClient.h \
Source/WebCore/loader/MainResourceLoader.cpp \
Source/WebCore/loader/MainResourceLoader.h \
Source/WebCore/loader/NavigationAction.cpp \
......
......@@ -3038,6 +3038,8 @@
'html/IsIndexInputType.h',
'html/LabelsNodeList.cpp',
'html/LabelsNodeList.h',
'html/LinkRelAttribute.cpp',
'html/LinkRelAttribute.h',
'html/MediaDocument.cpp',
'html/MediaDocument.h',
'html/MediaError.h',
......@@ -3351,6 +3353,9 @@
'loader/HistoryController.cpp',
'loader/ImageLoader.cpp',
'loader/ImageLoader.h',
'loader/LinkLoader.cpp',
'loader/LinkLoader.h',
'loader/LinkLoaderClient.h',
'loader/MainResourceLoader.cpp',
'loader/MainResourceLoader.h',
'loader/NavigationAction.cpp',
......
......@@ -743,6 +743,7 @@ SOURCES += \
html/InputType.cpp \
html/IsIndexInputType.cpp \
html/LabelsNodeList.cpp \
html/LinkRelAttribute.cpp \
html/MediaDocument.cpp \
html/MonthInputType.cpp \
html/NumberInputType.cpp \
......@@ -875,6 +876,7 @@ SOURCES += \
loader/icon/IconDatabaseBase.cpp \
loader/icon/IconLoader.cpp \
loader/ImageLoader.cpp \
loader/LinkLoader.cpp \
loader/MainResourceLoader.cpp \
loader/NavigationAction.cpp \
loader/NetscapePlugInStreamLoader.cpp \
......@@ -1730,6 +1732,7 @@ HEADERS += \
html/ImageData.h \
html/ImageDocument.h \
html/LabelsNodeList.h \
html/LinkRelAttribute.h \
html/MediaDocument.h \
html/PluginDocument.h \
html/StepRange.h \
......@@ -1830,6 +1833,8 @@ HEADERS += \
loader/icon/IconRecord.h \
loader/icon/PageURLRecord.h \
loader/ImageLoader.h \
loader/LinkLoader.h \
loader/LinkLoaderClient.h \
loader/MainResourceLoader.h \
loader/NavigationAction.h \
loader/NetscapePlugInStreamLoader.h \
......
......@@ -25785,6 +25785,18 @@
RelativePath="..\loader\ImageLoader.h"
>
</File>
<File
RelativePath="..\loader\LinkLoader.cpp"
>
</File>
<File
RelativePath="..\loader\LinkLoader.h"
>
</File>
<File
RelativePath="..\loader\LinkLoaderClient.h"
>
</File>
<File
RelativePath="..\loader\MainResourceLoader.cpp"
>
......@@ -57109,6 +57121,14 @@
RelativePath="..\html\LabelsNodeList.h"
>
</File>
<File
RelativePath="..\html\LinkRelAttribute.cpp"
>
</File>
<File
RelativePath="..\html\LinkRelAttribute.h"
>
</File>
<File
RelativePath="..\fileapi\LocalFileSystem.cpp"
>
......@@ -3174,6 +3174,11 @@
97E4028F13A696ED00913D67 /* IconController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97E4028D13A696ED00913D67 /* IconController.cpp */; };
97E4029013A696ED00913D67 /* IconController.h in Headers */ = {isa = PBXBuildFile; fileRef = 97E4028E13A696ED00913D67 /* IconController.h */; settings = {ATTRIBUTES = (Private, ); }; };
97EF7DFE107E55B700D7C49C /* ScriptControllerBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97EF7DFD107E55B700D7C49C /* ScriptControllerBase.cpp */; };
984264F112D5280A000D88A4 /* LinkLoaderClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 984264EF12D5280A000D88A4 /* LinkLoaderClient.h */; };
985BB96D13A94058007A0B69 /* LinkRelAttribute.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 985BB96B13A94058007A0B69 /* LinkRelAttribute.cpp */; };
985BB96E13A94058007A0B69 /* LinkRelAttribute.h in Headers */ = {isa = PBXBuildFile; fileRef = 985BB96C13A94058007A0B69 /* LinkRelAttribute.h */; };
98CE4326129E00BD005821DC /* LinkLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 98CE4325129E00BD005821DC /* LinkLoader.cpp */; };
98CE432A129E00E5005821DC /* LinkLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 98CE4329129E00E5005821DC /* LinkLoader.h */; };
98EB1F951313FE0500D0E1EA /* NotImplemented.h in Headers */ = {isa = PBXBuildFile; fileRef = 98EB1F941313FE0500D0E1EA /* NotImplemented.h */; settings = {ATTRIBUTES = (Private, ); }; };
9B417064125662B3006B28FC /* ApplyBlockElementCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B417062125662B3006B28FC /* ApplyBlockElementCommand.h */; settings = {ATTRIBUTES = (Private, ); }; };
9B417065125662B3006B28FC /* ApplyBlockElementCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9B417063125662B3006B28FC /* ApplyBlockElementCommand.cpp */; };
......@@ -9631,6 +9636,11 @@
97E4028D13A696ED00913D67 /* IconController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IconController.cpp; sourceTree = "<group>"; };
97E4028E13A696ED00913D67 /* IconController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IconController.h; sourceTree = "<group>"; };
97EF7DFD107E55B700D7C49C /* ScriptControllerBase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptControllerBase.cpp; sourceTree = "<group>"; };
984264EF12D5280A000D88A4 /* LinkLoaderClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LinkLoaderClient.h; sourceTree = "<group>"; };
985BB96B13A94058007A0B69 /* LinkRelAttribute.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LinkRelAttribute.cpp; sourceTree = "<group>"; };
985BB96C13A94058007A0B69 /* LinkRelAttribute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LinkRelAttribute.h; sourceTree = "<group>"; };
98CE4325129E00BD005821DC /* LinkLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LinkLoader.cpp; sourceTree = "<group>"; };
98CE4329129E00E5005821DC /* LinkLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LinkLoader.h; sourceTree = "<group>"; };
98EB1F941313FE0500D0E1EA /* NotImplemented.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NotImplemented.h; sourceTree = "<group>"; };
9B417062125662B3006B28FC /* ApplyBlockElementCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ApplyBlockElementCommand.h; sourceTree = "<group>"; };
9B417063125662B3006B28FC /* ApplyBlockElementCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ApplyBlockElementCommand.cpp; sourceTree = "<group>"; };
......@@ -16082,6 +16092,8 @@
F55B3D901251F12D003EF269 /* IsIndexInputType.h */,
A456FA2411AD4A830020B420 /* LabelsNodeList.cpp */,
A456FA2511AD4A830020B420 /* LabelsNodeList.h */,
985BB96B13A94058007A0B69 /* LinkRelAttribute.cpp */,
985BB96C13A94058007A0B69 /* LinkRelAttribute.h */,
97205AB31239291000B17380 /* MediaDocument.cpp */,
97205AB41239291000B17380 /* MediaDocument.h */,
E446139B0CD6331000FADA75 /* MediaError.h */,
......@@ -18532,6 +18544,9 @@
97DCE20010807C750057D394 /* HistoryController.h */,
089582530E857A7E00F82C83 /* ImageLoader.cpp */,
089582540E857A7E00F82C83 /* ImageLoader.h */,
984264EF12D5280A000D88A4 /* LinkLoaderClient.h */,
98CE4325129E00BD005821DC /* LinkLoader.cpp */,
98CE4329129E00E5005821DC /* LinkLoader.h */,
93E227DC0AF589AD00D48324 /* MainResourceLoader.cpp */,
656D37290ADBA5DE00A4554D /* MainResourceLoader.h */,
93CCF05F0AF6CA7600018E89 /* NavigationAction.cpp */,
......@@ -21863,6 +21878,8 @@
AB31C91E10AE1B8E000C7B92 /* LineClampValue.h in Headers */,
89B5EAA211E8003D00F2367E /* LineEnding.h in Headers */,
A7AD2F880EC89D07008AB002 /* LinkHash.h in Headers */,
98CE432A129E00E5005821DC /* LinkLoader.h in Headers */,
984264F112D5280A000D88A4 /* LinkLoaderClient.h in Headers */,
656D37320ADBA5DE00A4554D /* LoaderNSURLExtras.h in Headers */,
7EE6846912D26E3800E79415 /* LoaderRunLoopCF.h in Headers */,
06E81ED70AB5D5E900C87837 /* LocalCurrentGraphicsContext.h in Headers */,
......@@ -22875,6 +22892,7 @@
E1BE512E0CF6C512002EA959 /* XSLTUnicodeSort.h in Headers */,
977E2E0F12F0FC9C00C13379 /* XSSAuditor.h in Headers */,
FD537353137B651800008DCE /* ZeroPole.h in Headers */,
985BB96E13A94058007A0B69 /* LinkRelAttribute.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -24826,6 +24844,7 @@
84730D901248F0B300D3A9C9 /* LightSource.cpp in Sources */,
89B5EAA111E8003D00F2367E /* LineEnding.cpp in Sources */,
A7AD2F870EC89D07008AB002 /* LinkHash.cpp in Sources */,
98CE4326129E00BD005821DC /* LinkLoader.cpp in Sources */,
656D37330ADBA5DE00A4554D /* LoaderNSURLExtras.mm in Sources */,
7EE6846812D26E3800E79415 /* LoaderRunLoopCF.cpp in Sources */,
06E81EEC0AB5DA9700C87837 /* LocalCurrentGraphicsContext.mm in Sources */,
......@@ -25612,6 +25631,7 @@
E1BE512D0CF6C512002EA959 /* XSLTUnicodeSort.cpp in Sources */,
977E2E0E12F0FC9C00C13379 /* XSSAuditor.cpp in Sources */,
FD537352137B651800008DCE /* ZeroPole.cpp in Sources */,
985BB96D13A94058007A0B69 /* LinkRelAttribute.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -52,9 +52,7 @@ using namespace HTMLNames;
inline HTMLLinkElement::HTMLLinkElement(const QualifiedName& tagName, Document* document, bool createdByParser)
: HTMLElement(tagName, document)
#if ENABLE(LINK_PREFETCH)
, m_onloadTimer(this, &HTMLLinkElement::onloadTimerFired)
#endif
, m_linkLoader(this)
, m_loading(false)
, m_isEnabledViaScript(false)
, m_createdByParser(createdByParser)
......@@ -78,11 +76,6 @@ HTMLLinkElement::~HTMLLinkElement()
m_cachedSheet->removeClient(this);
removePendingSheet();
}
#if ENABLE(LINK_PREFETCH)
if (m_cachedLinkResource)
m_cachedLinkResource->removeClient(this);
#endif
}
void HTMLLinkElement::setDisabled(bool disabled)
......@@ -132,7 +125,7 @@ StyleSheet* HTMLLinkElement::sheet() const
void HTMLLinkElement::parseMappedAttribute(Attribute* attr)
{
if (attr->name() == relAttr) {
tokenizeRelAttribute(attr->value(), m_relAttribute);
m_relAttribute = LinkRelAttribute(attr->value());
process();
} else if (attr->name() == hrefAttr) {
m_url = document()->completeURL(stripLeadingAndTrailingHTMLSpaces(attr->value()));
......@@ -158,65 +151,7 @@ void HTMLLinkElement::parseMappedAttribute(Attribute* attr)
}
}
void HTMLLinkElement::tokenizeRelAttribute(const AtomicString& rel, RelAttribute& relAttribute)
{
relAttribute.m_isStyleSheet = false;
relAttribute.m_iconType = InvalidIcon;
relAttribute.m_isAlternate = false;
relAttribute.m_isDNSPrefetch = false;
#if ENABLE(LINK_PREFETCH)
relAttribute.m_isLinkPrefetch = false;
relAttribute.m_isLinkPrerender = false;
relAttribute.m_isLinkSubresource = false;
#endif
if (equalIgnoringCase(rel, "stylesheet"))
relAttribute.m_isStyleSheet = true;
else if (equalIgnoringCase(rel, "icon") || equalIgnoringCase(rel, "shortcut icon"))
relAttribute.m_iconType = Favicon;
#if ENABLE(TOUCH_ICON_LOADING)
else if (equalIgnoringCase(rel, "apple-touch-icon"))
relAttribute.m_iconType = TouchIcon;
else if (equalIgnoringCase(rel, "apple-touch-icon-precomposed"))
relAttribute.m_iconType = TouchPrecomposedIcon;
#endif
else if (equalIgnoringCase(rel, "dns-prefetch"))
relAttribute.m_isDNSPrefetch = true;
else if (equalIgnoringCase(rel, "alternate stylesheet") || equalIgnoringCase(rel, "stylesheet alternate")) {
relAttribute.m_isStyleSheet = true;
relAttribute.m_isAlternate = true;
} else {
// Tokenize the rel attribute and set bits based on specific keywords that we find.
String relString = rel.string();
relString.replace('\n', ' ');
Vector<String> list;
relString.split(' ', list);
Vector<String>::const_iterator end = list.end();
for (Vector<String>::const_iterator it = list.begin(); it != end; ++it) {
if (equalIgnoringCase(*it, "stylesheet"))
relAttribute.m_isStyleSheet = true;
else if (equalIgnoringCase(*it, "alternate"))
relAttribute.m_isAlternate = true;
else if (equalIgnoringCase(*it, "icon"))
relAttribute.m_iconType = Favicon;
#if ENABLE(TOUCH_ICON_LOADING)
else if (equalIgnoringCase(*it, "apple-touch-icon"))
relAttribute.m_iconType = TouchIcon;
else if (equalIgnoringCase(*it, "apple-touch-icon-precomposed"))
relAttribute.m_iconType = TouchPrecomposedIcon;
#endif
#if ENABLE(LINK_PREFETCH)
else if (equalIgnoringCase(*it, "prefetch"))
relAttribute.m_isLinkPrefetch = true;
else if (equalIgnoringCase(*it, "prerender"))
relAttribute.m_isLinkPrerender = true;
else if (equalIgnoringCase(*it, "subresource"))
relAttribute.m_isLinkSubresource = true;
#endif
}
}
}
bool HTMLLinkElement::checkBeforeLoadEvent()
bool HTMLLinkElement::shouldLoadLink()
{
RefPtr<Document> originalDocument = document();
if (!dispatchBeforeLoadEvent(m_url))
......@@ -236,50 +171,11 @@ void HTMLLinkElement::process()
String type = m_type.lower();
// IE extension: location of small icon for locationbar / bookmarks
// We'll record this URL per document, even if we later only use it in top level frames
if (m_relAttribute.m_iconType != InvalidIcon && m_url.isValid() && !m_url.isEmpty()) {
if (!checkBeforeLoadEvent())
return;
document()->setIconURL(m_url.string(), type, m_relAttribute.m_iconType);
}
if (m_relAttribute.m_isDNSPrefetch) {
Settings* settings = document()->settings();
// FIXME: The href attribute of the link element can be in "//hostname" form, and we shouldn't attempt
// to complete that as URL <https://bugs.webkit.org/show_bug.cgi?id=48857>.
if (settings && settings->dnsPrefetchingEnabled() && m_url.isValid() && !m_url.isEmpty())
ResourceHandle::prepareForURL(m_url);
}
#if ENABLE(LINK_PREFETCH)
if ((m_relAttribute.m_isLinkPrefetch || m_relAttribute.m_isLinkPrerender || m_relAttribute.m_isLinkSubresource) && m_url.isValid() && document()->frame()) {
if (!checkBeforeLoadEvent())
return;
ResourceLoadPriority priority = ResourceLoadPriorityUnresolved;
CachedResource::Type type = CachedResource::LinkPrefetch;
// We only make one request to the cachedresourcelodaer if multiple rel types are
// specified,
if (m_relAttribute.m_isLinkSubresource) {
priority = ResourceLoadPriorityLow;
type = CachedResource::LinkSubresource;
} else if (m_relAttribute.m_isLinkPrerender)
type = CachedResource::LinkPrerender;
ResourceRequest linkRequest(document()->completeURL(m_url));
if (m_cachedLinkResource) {
m_cachedLinkResource->removeClient(this);
m_cachedLinkResource = 0;
}
m_cachedLinkResource = document()->cachedResourceLoader()->requestLinkResource(type, linkRequest, priority);
if (m_cachedLinkResource)
m_cachedLinkResource->addClient(this);
}
#endif
if (!m_linkLoader.loadLink(m_relAttribute, type, m_url, document()))
return;
bool acceptIfTypeContainsTextCSS = document()->page() && document()->page()->settings() && document()->page()->settings()->treatsAnyTextCSSLinkAsStylesheet();
if (!disabled() && (m_relAttribute.m_isStyleSheet || (acceptIfTypeContainsTextCSS && type.contains("text/css")))
&& document()->frame() && m_url.isValid()) {
......@@ -293,7 +189,7 @@ void HTMLLinkElement::process()
m_cachedSheet = 0;
}
if (!checkBeforeLoadEvent())
if (!shouldLoadLink())
return;
m_loading = true;
......@@ -443,26 +339,15 @@ bool HTMLLinkElement::isLoading() const
return static_cast<CSSStyleSheet *>(m_sheet.get())->isLoading();
}
#if ENABLE(LINK_PREFETCH)
void HTMLLinkElement::onloadTimerFired(Timer<HTMLLinkElement>* timer)
void HTMLLinkElement::linkLoaded()
{
ASSERT_UNUSED(timer, timer == &m_onloadTimer);
if (m_cachedLinkResource->errorOccurred())
dispatchEvent(Event::create(eventNames().errorEvent, false, false));
else if (!m_cachedLinkResource->wasCanceled())
dispatchEvent(Event::create(eventNames().loadEvent, false, false));
m_cachedLinkResource->removeClient(this);
m_cachedLinkResource = 0;
dispatchEvent(Event::create(eventNames().loadEvent, false, false));
}
void HTMLLinkElement::notifyFinished(CachedResource* resource)
void HTMLLinkElement::linkLoadingErrored()
{
ASSERT(m_cachedLinkResource.get() == resource || m_cachedSheet.get() == resource);
if (m_cachedLinkResource.get() == resource)
m_onloadTimer.startOneShot(0);
dispatchEvent(Event::create(eventNames().errorEvent, false, false));
}
#endif
bool HTMLLinkElement::sheetLoaded()
{
......
......@@ -28,6 +28,9 @@
#include "CachedResourceHandle.h"
#include "HTMLElement.h"
#include "IconURL.h"
#include "LinkLoader.h"
#include "LinkLoaderClient.h"
#include "LinkRelAttribute.h"
#include "Timer.h"
namespace WebCore {
......@@ -36,33 +39,8 @@ class CachedCSSStyleSheet;
class CachedResource;
class KURL;
class HTMLLinkElement : public HTMLElement, public CachedResourceClient {
class HTMLLinkElement : public HTMLElement, public CachedResourceClient, public LinkLoaderClient {
public:
struct RelAttribute {
bool m_isStyleSheet;
IconType m_iconType;
bool m_isAlternate;
bool m_isDNSPrefetch;
#if ENABLE(LINK_PREFETCH)
bool m_isLinkPrefetch;
bool m_isLinkPrerender;
bool m_isLinkSubresource;
#endif
RelAttribute()
: m_isStyleSheet(false)
, m_iconType(InvalidIcon)
, m_isAlternate(false)
, m_isDNSPrefetch(false)
#if ENABLE(LINK_PREFETCH)
, m_isLinkPrefetch(false)
, m_isLinkPrerender(false)
, m_isLinkSubresource(false)
#endif
{
}
};
static PassRefPtr<HTMLLinkElement> create(const QualifiedName&, Document*, bool createdByParser);
virtual ~HTMLLinkElement();
......@@ -84,10 +62,7 @@ public:
private:
virtual void parseMappedAttribute(Attribute*);
#if ENABLE(LINK_PREFETCH)
void onloadTimerFired(Timer<HTMLLinkElement>*);
#endif
bool checkBeforeLoadEvent();
virtual bool shouldLoadLink();
void process();
static void processCallback(Node*);
......@@ -96,19 +71,16 @@ private:
// from CachedResourceClient
virtual void setCSSStyleSheet(const String& href, const KURL& baseURL, const String& charset, const CachedCSSStyleSheet* sheet);
#if ENABLE(LINK_PREFETCH)
virtual void notifyFinished(CachedResource*);
#endif
virtual bool sheetLoaded();
virtual void startLoadingDynamicSheet();
virtual void linkLoaded();
virtual void linkLoadingErrored();
bool isAlternate() const { return m_relAttribute.m_isAlternate; }
virtual bool isURLAttribute(Attribute*) const;
public:
static void tokenizeRelAttribute(const AtomicString& value, RelAttribute&);
private:
virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
......@@ -121,16 +93,13 @@ private:
private:
HTMLLinkElement(const QualifiedName&, Document*, bool createdByParser);
LinkLoader m_linkLoader;
CachedResourceHandle<CachedCSSStyleSheet> m_cachedSheet;
RefPtr<CSSStyleSheet> m_sheet;
#if ENABLE(LINK_PREFETCH)
CachedResourceHandle<CachedResource> m_cachedLinkResource;
Timer<HTMLLinkElement> m_onloadTimer;
#endif
KURL m_url;
String m_type;
String m_media;
RelAttribute m_relAttribute;
LinkRelAttribute m_relAttribute;
bool m_loading;
bool m_isEnabledViaScript;
bool m_createdByParser;
......
/*
* Copyright (C) 2011 Google Inc. All rights reserved.
*
* 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.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "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.
*
*/
#include "config.h"
#include "LinkRelAttribute.h"
namespace WebCore {
LinkRelAttribute::LinkRelAttribute()
: m_isStyleSheet(false)
, m_iconType(InvalidIcon)
, m_isAlternate(false)
, m_isDNSPrefetch(false)
#if ENABLE(LINK_PREFETCH)
, m_isLinkPrefetch(false)
, m_isLinkPrerender(false)
, m_isLinkSubresource(false)
#endif
{
}
LinkRelAttribute::LinkRelAttribute(const String& rel)
: m_isStyleSheet(false)
, m_iconType(InvalidIcon)
, m_isAlternate(false)
, m_isDNSPrefetch(false)
#if ENABLE(LINK_PREFETCH)
, m_isLinkPrefetch(false)
, m_isLinkPrerender(false)
, m_isLinkSubresource(false)
#endif
{
if (equalIgnoringCase(rel, "stylesheet"))
m_isStyleSheet = true;
else if (equalIgnoringCase(rel, "icon") || equalIgnoringCase(rel, "shortcut icon"))
m_iconType = Favicon;
#if ENABLE(TOUCH_ICON_LOADING)
else if (equalIgnoringCase(rel, "apple-touch-icon"))
m_iconType = TouchIcon;
else if (equalIgnoringCase(rel, "apple-touch-icon-precomposed"))
m_iconType = TouchPrecomposedIcon;
#endif
else if (equalIgnoringCase(rel, "dns-prefetch"))
m_isDNSPrefetch = true;
else if (equalIgnoringCase(rel, "alternate stylesheet") || equalIgnoringCase(rel, "stylesheet alternate")) {
m_isStyleSheet = true;
m_isAlternate = true;
} else {
// Tokenize the rel attribute and set bits based on specific keywords that we find.
String relCopy = rel;
relCopy.replace('\n', ' ');
Vector<String> list;
relCopy.split(' ', list);
Vector<String>::const_iterator end = list.end();
for (Vector<String>::const_iterator it = list.begin(); it != end; ++it) {
if (equalIgnoringCase(*it, "stylesheet"))
m_isStyleSheet = true;
else if (equalIgnoringCase(*it, "alternate"))
m_isAlternate = true;
else if (equalIgnoringCase(*it, "icon"))
m_iconType = Favicon;
#if ENABLE(TOUCH_ICON_LOADING)
else if (equalIgnoringCase(*it, "apple-touch-icon"))
m_iconType = TouchIcon;
else if (equalIgnoringCase(*it, "apple-touch-icon-precomposed"))
m_iconType = TouchPrecomposedIcon;
#endif
#if ENABLE(LINK_PREFETCH)
else if (equalIgnoringCase(*it, "prefetch"))
m_isLinkPrefetch = true;