WebCore:
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Apr 2008 05:56:21 +0000 (05:56 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Apr 2008 05:56:21 +0000 (05:56 +0000)
2008-04-02  Brady Eidson  <beidson@apple.com>

        Reviewed by Mitz Pettel

        <rdar://problem/5838347> and http://bugs.webkit.org/show_bug.cgi?id=11839
        Webarchive fails to save CSS files in @import statements

        * css/CSSStyleSheet.cpp:
        (WebCore::CSSStyleSheet::addSubresourceURLStrings): Recursively add the URL each @import rule under the current style sheet.
        * css/CSSStyleSheet.h:
        * css/StyleSheet.h:
        (WebCore::StyleSheet::addSubresourceURLStrings):

        * html/HTMLLinkElement.cpp:
        (WebCore::HTMLLinkElement::getSubresourceAttributeStrings): Add the linked URL as well as all @import
          rules rooted at the linked stylesheet.

        * html/HTMLStyleElement.cpp:
        (WebCore::HTMLStyleElement::getSubresourceAttributeStrings): Walk all @import rules rooted at this
          stylesheet to add to the list.
        * html/HTMLStyleElement.h:

LayoutTests:

2008-04-02  Brady Eidson  <beidson@apple.com>

        Written by David Kilzer, tweaked by Brady, Reviewed by Mitz Pettel

        - test for http://bugs.webkit.org/show_bug.cgi?id=11839
          Webarchive fails to save CSS files in @import statements

        The idea is to <link> to a CSS file which @imports another CSS file,
        and also @import a CSS file inside a <style> element, which also @imports another CSS file

        Then make sure all 4 of the css files are in the resulting webarchive

        * webarchive/resources/test-css-import-recurse.css: Added.
        * webarchive/resources/test-css-import.css: Added.
        * webarchive/resources/test-css-link-recurse.css: Added.
        * webarchive/resources/test-css-link.css: Added.
        * webarchive/test-css-import-expected.txt: Added.
        * webarchive/test-css-import.html: Added.

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

14 files changed:
LayoutTests/ChangeLog
LayoutTests/webarchive/resources/test-css-import-recurse.css [new file with mode: 0644]
LayoutTests/webarchive/resources/test-css-import.css [new file with mode: 0644]
LayoutTests/webarchive/resources/test-css-link-recurse.css [new file with mode: 0644]
LayoutTests/webarchive/resources/test-css-link.css [new file with mode: 0644]
LayoutTests/webarchive/test-css-import-expected.txt [new file with mode: 0644]
LayoutTests/webarchive/test-css-import.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/css/CSSStyleSheet.cpp
WebCore/css/CSSStyleSheet.h
WebCore/css/StyleSheet.h
WebCore/html/HTMLLinkElement.cpp
WebCore/html/HTMLStyleElement.cpp
WebCore/html/HTMLStyleElement.h

index 0e29ffc..4e48ff9 100644 (file)
@@ -1,3 +1,22 @@
+2008-04-02  Brady Eidson  <beidson@apple.com>
+
+        Written by David Kilzer, tweaked by Brady, Reviewed by Mitz Pettel
+
+        - test for http://bugs.webkit.org/show_bug.cgi?id=11839
+          Webarchive fails to save CSS files in @import statements
+
+        The idea is to <link> to a CSS file which @imports another CSS file,
+        and also @import a CSS file inside a <style> element, which also @imports another CSS file
+
+        Then make sure all 4 of the css files are in the resulting webarchive
+
+        * webarchive/resources/test-css-import-recurse.css: Added.
+        * webarchive/resources/test-css-import.css: Added.
+        * webarchive/resources/test-css-link-recurse.css: Added.
+        * webarchive/resources/test-css-link.css: Added.
+        * webarchive/test-css-import-expected.txt: Added.
+        * webarchive/test-css-import.html: Added.
+
 2008-04-02  Nikolas Zimmermann  <zimmermann@kde.org>
 
         Reviewed by Oliver.
diff --git a/LayoutTests/webarchive/resources/test-css-import-recurse.css b/LayoutTests/webarchive/resources/test-css-import-recurse.css
new file mode 100644 (file)
index 0000000..225a5e0
--- /dev/null
@@ -0,0 +1,2 @@
+@import url('test-css-import.css');
+.green { color: green; }
diff --git a/LayoutTests/webarchive/resources/test-css-import.css b/LayoutTests/webarchive/resources/test-css-import.css
new file mode 100644 (file)
index 0000000..b469d00
--- /dev/null
@@ -0,0 +1,2 @@
+@import url('test-css-import-recurse.css');
+.blue { color: blue; }
diff --git a/LayoutTests/webarchive/resources/test-css-link-recurse.css b/LayoutTests/webarchive/resources/test-css-link-recurse.css
new file mode 100644 (file)
index 0000000..72d2d58
--- /dev/null
@@ -0,0 +1,2 @@
+@import url('test-css-link-recurse.css');
+.purple { color: purple; }
diff --git a/LayoutTests/webarchive/resources/test-css-link.css b/LayoutTests/webarchive/resources/test-css-link.css
new file mode 100644 (file)
index 0000000..6110c50
--- /dev/null
@@ -0,0 +1,2 @@
+@import url('test-css-link-recurse.css');
+.red { color: red; }
diff --git a/LayoutTests/webarchive/test-css-import-expected.txt b/LayoutTests/webarchive/test-css-import-expected.txt
new file mode 100644 (file)
index 0000000..d2b4604
--- /dev/null
@@ -0,0 +1,114 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+       <key>WebMainResource</key>
+       <dict>
+               <key>WebResourceData</key>
+               <string>&lt;html&gt;&lt;head&gt;
+&lt;script&gt;
+    if (window.layoutTestController)
+        layoutTestController.dumpDOMAsWebArchive();
+&lt;/script&gt;
+&lt;link rel="stylesheet" href="resources/test-css-link.css" type="text/css"&gt;
+&lt;style type="text/css"&gt;
+       @import url('resources/test-css-import.css');
+&lt;/style&gt;
+&lt;/head&gt;&lt;body&gt;
+&lt;div class="blue"&gt;This text should be blue.&lt;/div&gt;
+&lt;div class="red"&gt;This text should be red.&lt;/div&gt;
+&lt;div class="green"&gt;This text should be green.&lt;/div&gt;
+&lt;div class="purple"&gt;This text should be purple.&lt;/div&gt;
+
+
+&lt;/body&gt;&lt;/html&gt;</string>
+               <key>WebResourceFrameName</key>
+               <string></string>
+               <key>WebResourceMIMEType</key>
+               <string>text/html</string>
+               <key>WebResourceTextEncodingName</key>
+               <string>UTF-8</string>
+               <key>WebResourceURL</key>
+               <string>file:///LayoutTests/webarchive/test-css-import.html</string>
+       </dict>
+       <key>WebSubresources</key>
+       <array>
+               <dict>
+                       <key>WebResourceData</key>
+                       <string>@import url('test-css-link-recurse.css');
+.red { color: red; }
+</string>
+                       <key>WebResourceMIMEType</key>
+                       <string>text/css</string>
+                       <key>WebResourceResponse</key>
+                       <dict>
+                               <key>MIMEType</key>
+                               <string>text/css</string>
+                               <key>URL</key>
+                               <string>file:///LayoutTests/webarchive/resources/test-css-link.css</string>
+                               <key>expectedContentLength</key>
+                               <integer>63</integer>
+                       </dict>
+                       <key>WebResourceURL</key>
+                       <string>file:///LayoutTests/webarchive/resources/test-css-link.css</string>
+               </dict>
+               <dict>
+                       <key>WebResourceData</key>
+                       <string>@import url('test-css-link-recurse.css');
+.purple { color: purple; }
+</string>
+                       <key>WebResourceMIMEType</key>
+                       <string>text/css</string>
+                       <key>WebResourceResponse</key>
+                       <dict>
+                               <key>MIMEType</key>
+                               <string>text/css</string>
+                               <key>URL</key>
+                               <string>file:///LayoutTests/webarchive/resources/test-css-link-recurse.css</string>
+                               <key>expectedContentLength</key>
+                               <integer>69</integer>
+                       </dict>
+                       <key>WebResourceURL</key>
+                       <string>file:///LayoutTests/webarchive/resources/test-css-link-recurse.css</string>
+               </dict>
+               <dict>
+                       <key>WebResourceData</key>
+                       <string>@import url('test-css-import.css');
+.green { color: green; }
+</string>
+                       <key>WebResourceMIMEType</key>
+                       <string>text/css</string>
+                       <key>WebResourceResponse</key>
+                       <dict>
+                               <key>MIMEType</key>
+                               <string>text/css</string>
+                               <key>URL</key>
+                               <string>file:///LayoutTests/webarchive/resources/test-css-import-recurse.css</string>
+                               <key>expectedContentLength</key>
+                               <integer>61</integer>
+                       </dict>
+                       <key>WebResourceURL</key>
+                       <string>file:///LayoutTests/webarchive/resources/test-css-import-recurse.css</string>
+               </dict>
+               <dict>
+                       <key>WebResourceData</key>
+                       <string>@import url('test-css-import-recurse.css');
+.blue { color: blue; }
+</string>
+                       <key>WebResourceMIMEType</key>
+                       <string>text/css</string>
+                       <key>WebResourceResponse</key>
+                       <dict>
+                               <key>MIMEType</key>
+                               <string>text/css</string>
+                               <key>URL</key>
+                               <string>file:///LayoutTests/webarchive/resources/test-css-import.css</string>
+                               <key>expectedContentLength</key>
+                               <integer>67</integer>
+                       </dict>
+                       <key>WebResourceURL</key>
+                       <string>file:///LayoutTests/webarchive/resources/test-css-import.css</string>
+               </dict>
+       </array>
+</dict>
+</plist>
diff --git a/LayoutTests/webarchive/test-css-import.html b/LayoutTests/webarchive/test-css-import.html
new file mode 100644 (file)
index 0000000..5e23f57
--- /dev/null
@@ -0,0 +1,18 @@
+<html>
+<head>
+<script>
+    if (window.layoutTestController)
+        layoutTestController.dumpDOMAsWebArchive();
+</script>
+<link rel="stylesheet" href="resources/test-css-link.css" type="text/css">
+<style type="text/css">
+    @import url('resources/test-css-import.css');
+</style>
+</head>
+<body>
+<div class="blue">This text should be blue.</div>
+<div class="red">This text should be red.</div>
+<div class="green">This text should be green.</div>
+<div class="purple">This text should be purple.</div>
+</body>
+</html>
index 564de39..0d513a8 100644 (file)
@@ -1,3 +1,25 @@
+2008-04-02  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Mitz Pettel
+
+        <rdar://problem/5838347> and http://bugs.webkit.org/show_bug.cgi?id=11839
+        Webarchive fails to save CSS files in @import statements
+
+        * css/CSSStyleSheet.cpp:
+        (WebCore::CSSStyleSheet::addSubresourceURLStrings): Recursively add the URL each @import rule under the current style sheet.
+        * css/CSSStyleSheet.h:
+        * css/StyleSheet.h:
+        (WebCore::StyleSheet::addSubresourceURLStrings):
+
+        * html/HTMLLinkElement.cpp:
+        (WebCore::HTMLLinkElement::getSubresourceAttributeStrings): Add the linked URL as well as all @import
+          rules rooted at the linked stylesheet.
+
+        * html/HTMLStyleElement.cpp:
+        (WebCore::HTMLStyleElement::getSubresourceAttributeStrings): Walk all @import rules rooted at this
+          stylesheet to add to the list.
+        * html/HTMLStyleElement.h:
+
 2008-04-02  Mark Rowe  <mrowe@apple.com>
 
         Reviewed by Oliver Hunt.
index acd0955..1facad6 100644 (file)
@@ -203,4 +203,25 @@ void CSSStyleSheet::styleSheetChanged()
         documentToUpdate->updateStyleSelector();
 }
 
+void CSSStyleSheet::addSubresourceURLStrings(HashSet<String>& urls, const String& base) const
+{        
+    OwnPtr<CSSRuleList> ruleList(const_cast<CSSStyleSheet*>(this)->cssRules());
+    
+    // Add the URLs for each child import rule, and recurse for the stylesheet belonging to each of those rules.
+    for (unsigned i = 0; i < ruleList->length(); ++i) {
+        CSSRule* rule = ruleList->item(i);
+        if (rule->type() != CSSRule::IMPORT_RULE)
+            continue;
+
+        CSSImportRule* importRule = static_cast<CSSImportRule*>(rule);
+        CSSStyleSheet* ruleSheet = importRule->styleSheet();
+        if (!ruleSheet)
+            continue;
+
+        KURL fullURL(KURL(base), importRule->href());
+        urls.add(fullURL.string());
+        ruleSheet->addSubresourceURLStrings(urls, fullURL.string());
+    }
+}
+
 }
index 30cbd2a..b3f8f2e 100644 (file)
@@ -72,6 +72,8 @@ public:
     const String& charset() const { return m_charset; }
 
     bool loadCompleted() const { return m_loadCompleted; }
+    
+    virtual void addSubresourceURLStrings(HashSet<String>&, const String& baseURL) const;
 
 protected:
     Document* m_doc;
index 7fac44d..8bfafce 100644 (file)
@@ -26,6 +26,8 @@
 #include "StyleList.h"
 #include "PlatformString.h"
 
+#include <wtf/HashSet.h>
+
 namespace WebCore {
 
 class Node;
@@ -59,6 +61,8 @@ public:
 
     virtual void styleSheetChanged() { }
     
+    virtual void addSubresourceURLStrings(HashSet<String>&, const String& baseURL) const { }
+
 protected:
     Node* m_parentNode;
     String m_strHref;
index b3a954c..a335f4d 100644 (file)
@@ -348,11 +348,27 @@ void HTMLLinkElement::setType(const String& value)
 }
 
 void HTMLLinkElement::getSubresourceAttributeStrings(Vector<String>& urls) const
-{
-    if (!m_isStyleSheet && !m_isIcon)
+{    
+    if (m_isIcon) {
+        urls.append(href().string());
         return;
+    }
     
+    if (!m_isStyleSheet)
+        return;
+        
+    // Append the URL of this link element.
     urls.append(href().string());
+    
+    // Walk the URLs linked by the linked-to stylesheet.
+    HashSet<String> styleURLs;
+    StyleSheet* styleSheet = const_cast<HTMLLinkElement*>(this)->sheet();
+    if (styleSheet)
+        styleSheet->addSubresourceURLStrings(styleURLs, href());
+    
+    HashSet<String>::iterator end = styleURLs.end();
+    for (HashSet<String>::iterator i = styleURLs.begin(); i != end; ++i)
+        urls.append(*i);
 }
 
 }
index 9403ace..79c0ce0 100644 (file)
@@ -130,4 +130,16 @@ void HTMLStyleElement::setType(const AtomicString &value)
     setAttribute(typeAttr, value);
 }
 
+void HTMLStyleElement::getSubresourceAttributeStrings(Vector<String>& urls) const
+{    
+    HashSet<String> styleURLs;
+    StyleSheet* styleSheet = const_cast<HTMLStyleElement*>(this)->sheet();
+    if (styleSheet)
+        styleSheet->addSubresourceURLStrings(styleURLs, ownerDocument()->baseURL());
+    
+    HashSet<String>::iterator end = styleURLs.end();
+    for (HashSet<String>::iterator i = styleURLs.begin(); i != end; ++i)
+        urls.append(*i);
+}
+
 }
index 3ba1e18..a85916f 100644 (file)
@@ -64,6 +64,8 @@ public:
 
     virtual void setLoading(bool loading) { m_loading = loading; }
 
+    virtual void getSubresourceAttributeStrings(Vector<String>&) const;
+
 protected:
     String m_media;
     bool m_loading;