2011-06-17 Gavin Peters <gavinp@chromium.org>
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Jun 2011 18:11:00 +0000 (18:11 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Jun 2011 18:11:00 +0000 (18:11 +0000)
        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: https://svn.webkit.org/repository/webkit/trunk@89146 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.pro
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/html/HTMLLinkElement.cpp
Source/WebCore/html/HTMLLinkElement.h
Source/WebCore/html/LinkRelAttribute.cpp [new file with mode: 0644]
Source/WebCore/html/LinkRelAttribute.h [new file with mode: 0644]
Source/WebCore/html/parser/HTMLPreloadScanner.cpp
Source/WebCore/loader/LinkLoader.cpp [new file with mode: 0644]
Source/WebCore/loader/LinkLoader.h [new file with mode: 0644]
Source/WebCore/loader/LinkLoaderClient.h [new file with mode: 0644]

index c857992..f1fb362 100644 (file)
@@ -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
index 5198171..ff90952 100644 (file)
@@ -1,3 +1,54 @@
+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.
index 919364f..0136c89 100644 (file)
@@ -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 \
index 084d4fb..ccbf271 100644 (file)
             'html/IsIndexInputType.h',
             'html/LabelsNodeList.cpp',
             'html/LabelsNodeList.h',
+            'html/LinkRelAttribute.cpp',
+            'html/LinkRelAttribute.h',
             'html/MediaDocument.cpp',
             'html/MediaDocument.h',
             'html/MediaError.h',
             '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',
index 424705c..e05b75c 100644 (file)
@@ -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 \
index e762bcd..1dd7c3a 100755 (executable)
                                >
                        </File>
                        <File
+                               RelativePath="..\loader\LinkLoader.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\loader\LinkLoader.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\loader\LinkLoaderClient.h"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\loader\MainResourceLoader.cpp"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath="..\html\LinkRelAttribute.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\html\LinkRelAttribute.h"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\fileapi\LocalFileSystem.cpp"
                                >
                        </File>
index 502415c..3683df6 100644 (file)
                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 */; };
                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>"; };
                                F55B3D901251F12D003EF269 /* IsIndexInputType.h */,
                                A456FA2411AD4A830020B420 /* LabelsNodeList.cpp */,
                                A456FA2511AD4A830020B420 /* LabelsNodeList.h */,
+                               985BB96B13A94058007A0B69 /* LinkRelAttribute.cpp */,
+                               985BB96C13A94058007A0B69 /* LinkRelAttribute.h */,
                                97205AB31239291000B17380 /* MediaDocument.cpp */,
                                97205AB41239291000B17380 /* MediaDocument.h */,
                                E446139B0CD6331000FADA75 /* MediaError.h */,
                                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 */,
                                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 */,
                                E1BE512E0CF6C512002EA959 /* XSLTUnicodeSort.h in Headers */,
                                977E2E0F12F0FC9C00C13379 /* XSSAuditor.h in Headers */,
                                FD537353137B651800008DCE /* ZeroPole.h in Headers */,
+                               985BB96E13A94058007A0B69 /* LinkRelAttribute.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                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 */,
                                E1BE512D0CF6C512002EA959 /* XSLTUnicodeSort.cpp in Sources */,
                                977E2E0E12F0FC9C00C13379 /* XSSAuditor.cpp in Sources */,
                                FD537352137B651800008DCE /* ZeroPole.cpp in Sources */,
+                               985BB96D13A94058007A0B69 /* LinkRelAttribute.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 9539847..4335329 100644 (file)
@@ -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()
 {
index 5df68bc..ef3b0a6 100644 (file)
@@ -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;
diff --git a/Source/WebCore/html/LinkRelAttribute.cpp b/Source/WebCore/html/LinkRelAttribute.cpp
new file mode 100644 (file)
index 0000000..5261df2
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * 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;
+            else if (equalIgnoringCase(*it, "prerender"))
+              m_isLinkPrerender = true;
+            else if (equalIgnoringCase(*it, "subresource"))
+              m_isLinkSubresource = true;
+#endif
+        }
+    }
+}
+
+}
diff --git a/Source/WebCore/html/LinkRelAttribute.h b/Source/WebCore/html/LinkRelAttribute.h
new file mode 100644 (file)
index 0000000..3178194
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ *
+ */
+
+#ifndef LinkRelAttribute_h
+#define LinkRelAttribute_h
+
+#include "IconURL.h"
+
+namespace WebCore {
+
+struct LinkRelAttribute {
+public:
+    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
+
+    LinkRelAttribute();
+    explicit LinkRelAttribute(const String&);
+};
+    
+}
+
+#endif
+
index 6e05240..9c30ef9 100644 (file)
@@ -33,9 +33,9 @@
 #include "InputType.h"
 #include "HTMLDocumentParser.h"
 #include "HTMLTokenizer.h"
-#include "HTMLLinkElement.h"
 #include "HTMLNames.h"
 #include "HTMLParserIdioms.h"
+#include "LinkRelAttribute.h"
 #include "MediaList.h"
 #include "MediaQueryEvaluator.h"
 
@@ -93,8 +93,7 @@ public:
 
     static bool relAttributeIsStyleSheet(const String& attributeValue)
     {
-        HTMLLinkElement::RelAttribute rel;
-        HTMLLinkElement::tokenizeRelAttribute(attributeValue, rel);
+        LinkRelAttribute rel(attributeValue);
         return rel.m_isStyleSheet && !rel.m_isAlternate && rel.m_iconType == InvalidIcon && !rel.m_isDNSPrefetch;
     }
 
diff --git a/Source/WebCore/loader/LinkLoader.cpp b/Source/WebCore/loader/LinkLoader.cpp
new file mode 100644 (file)
index 0000000..63c9e91
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+ * 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 "LinkLoader.h"
+
+#include "CSSStyleSelector.h"
+#include "CSSStyleSheet.h"
+#include "CachedCSSStyleSheet.h"
+#include "CachedResourceLoader.h"
+#include "ContainerNode.h"
+#include "Document.h"
+#include "Frame.h"
+#include "FrameView.h"
+#include "LinkRelAttribute.h"
+#include "ResourceHandle.h"
+#include "Settings.h"
+
+namespace WebCore {
+
+LinkLoader::LinkLoader(LinkLoaderClient* client)
+    : m_client(client)
+    , m_linkLoadedTimer(this, &LinkLoader::linkLoadedTimerFired)
+{
+}
+
+LinkLoader::~LinkLoader()
+{
+    if (m_cachedLinkResource)
+        m_cachedLinkResource->removeClient(this);
+}
+
+void LinkLoader::linkLoadedTimerFired(Timer<LinkLoader>* timer)
+{
+    ASSERT_UNUSED(timer, timer == &m_linkLoadedTimer);
+    if (m_cachedLinkResource->errorOccurred())
+        m_client->linkLoadingErrored();
+    else if (!m_cachedLinkResource->wasCanceled())
+        m_client->linkLoaded();
+    m_cachedLinkResource->removeClient(this);
+    m_cachedLinkResource = 0;
+}
+
+void LinkLoader::notifyFinished(CachedResource* resource)
+{
+    ASSERT_UNUSED(resource, m_cachedLinkResource.get() == resource);
+    m_linkLoadedTimer.startOneShot(0);
+}
+
+bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const String& type,
+                          const KURL& href, Document* document)
+{
+    // We'll record this URL per document, even if we later only use it in top level frames
+    if (relAttribute.m_iconType != InvalidIcon && href.isValid() && !href.isEmpty()) {
+        if (!m_client->shouldLoadLink()) 
+            return false;
+        document->setIconURL(href.string(), type, relAttribute.m_iconType);
+    }
+
+    if (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() && href.isValid() && !href.isEmpty())
+            ResourceHandle::prepareForURL(href);
+    }
+
+#if ENABLE(LINK_PREFETCH)
+    if ((relAttribute.m_isLinkPrefetch || relAttribute.m_isLinkPrerender || relAttribute.m_isLinkSubresource) && href.isValid() && document->frame()) {
+        if (!m_client->shouldLoadLink())
+            return false;
+        ResourceLoadPriority priority = ResourceLoadPriorityUnresolved;
+        CachedResource::Type type = CachedResource::LinkPrefetch;
+        // We only make one request to the cachedresourcelodaer if multiple rel types are
+        // specified, 
+        if (relAttribute.m_isLinkSubresource) {
+            priority = ResourceLoadPriorityLow;
+            type = CachedResource::LinkSubresource;
+        } else if (relAttribute.m_isLinkPrerender)
+            type = CachedResource::LinkPrerender;
+
+        ResourceRequest linkRequest(document->completeURL(href));
+        
+        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
+    return true;
+}
+
+
+}
diff --git a/Source/WebCore/loader/LinkLoader.h b/Source/WebCore/loader/LinkLoader.h
new file mode 100644 (file)
index 0000000..6596618
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ *
+ */
+
+#ifndef LinkLoader_h
+#define LinkLoader_h
+
+#include "CachedResourceClient.h"
+#include "CachedResourceHandle.h"
+#include "LinkLoaderClient.h"
+#include "Timer.h"
+
+namespace WebCore {
+
+class LinkRelAttribute;
+
+// The LinkLoader can load link rel types icon, dns-prefetch, subresource, prefetch and prerender.
+class LinkLoader : public CachedResourceClient {
+public:
+    LinkLoader(LinkLoaderClient*);
+    virtual ~LinkLoader();
+
+    // from CachedResourceClient
+    virtual void notifyFinished(CachedResource*);
+    
+    bool loadLink(const LinkRelAttribute&, const String& type, const KURL&, Document*);
+
+private:
+    void linkLoadedTimerFired(Timer<LinkLoader>*);
+
+    LinkLoaderClient* m_client;
+
+    CachedResourceHandle<CachedResource> m_cachedLinkResource;
+    Timer<LinkLoader> m_linkLoadedTimer;
+};
+    
+}
+
+#endif
diff --git a/Source/WebCore/loader/LinkLoaderClient.h b/Source/WebCore/loader/LinkLoaderClient.h
new file mode 100644 (file)
index 0000000..4350ee7
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ *
+ */
+#ifndef LinkLoaderClient_h
+#define LinkLoaderClient_h
+
+namespace WebCore {
+
+class LinkLoaderClient {
+public:
+    virtual ~LinkLoaderClient() { }
+
+    virtual bool shouldLoadLink() = 0;
+
+    virtual void linkLoaded() = 0;
+    virtual void linkLoadingErrored() = 0;
+    // There is no notification for cancellation.
+};
+
+}
+
+#endif