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
+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.
--- /dev/null
+@import url('test-css-import.css');
+.green { color: green; }
--- /dev/null
+@import url('test-css-import-recurse.css');
+.blue { color: blue; }
--- /dev/null
+@import url('test-css-link-recurse.css');
+.purple { color: purple; }
--- /dev/null
+@import url('test-css-link-recurse.css');
+.red { color: red; }
--- /dev/null
+<?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><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></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>
--- /dev/null
+<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>
+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.
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());
+ }
+}
+
}
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;
#include "StyleList.h"
#include "PlatformString.h"
+#include <wtf/HashSet.h>
+
namespace WebCore {
class Node;
virtual void styleSheetChanged() { }
+ virtual void addSubresourceURLStrings(HashSet<String>&, const String& baseURL) const { }
+
protected:
Node* m_parentNode;
String m_strHref;
}
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);
}
}
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);
+}
+
}
virtual void setLoading(bool loading) { m_loading = loading; }
+ virtual void getSubresourceAttributeStrings(Vector<String>&) const;
+
protected:
String m_media;
bool m_loading;