Bug 11850: Webarchive fails to save images referenced in CSS
authorddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Dec 2008 00:00:14 +0000 (00:00 +0000)
committerddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Dec 2008 00:00:14 +0000 (00:00 +0000)
commite6bebaccce60c2bae882bbc62184968030d93345
tree6b374413563d97214fd427dbe9c46ee3ffa89bc3
parent7d299e693b43066667dea1d990cc9956e4f0ec6f
    Bug 11850: Webarchive fails to save images referenced in CSS

        <https://bugs.webkit.org/show_bug.cgi?id=11850>

        Reviewed by Darin Adler.

WebCore:

        This entry contains two parts since the tests for adding a
        completeURL() method to StyleSheet and CSSStyleSheet (part 1) depend
        on Bug 11850 being fixed (part 2).

        --

        Tests: http/tests/webarchive/test-css-url-encoding-shift-jis.html
               http/tests/webarchive/test-css-url-encoding-utf-8.html
               http/tests/webarchive/test-css-url-encoding.html

        Added completeURL() methods to StyleSheet and CSSStyleSheet that
        match the behavior of Document::completeURL().  Most notably,
        CSSStyleSheet::completeURL() uses the charset of the stylesheet
        (if it exists) to construct URLs, just like Document::completeURL().

        * css/CSSParser.cpp:
        (WebCore::CSSParser::parseValue): Use CSSStyleSheet::completeURL().
        (WebCore::CSSParser::parseContent): Ditto.
        (WebCore::CSSParser::parseFillImage): Ditto.
        (WebCore::CSSParser::parseFontFaceSrc): Ditto.
        (WebCore::CSSParser::parseBorderImage): Ditto.

        * css/CSSStyleSheet.cpp:
        (WebCore::CSSStyleSheet::completeURL): Added.
        * css/CSSStyleSheet.h:
        (WebCore::CSSStyleSheet::completeURL): Added declaration.

        * css/StyleSheet.cpp:
        (WebCore::StyleSheet::completeURL): Added.
        * css/StyleSheet.h:
        (WebCore::StyleSheet::completeURL): Added declaration.

        * dom/Document.cpp:
        (WebCore::Document::completeURL): Added comment referring to the new
        completeURL() methods in StyleSheet and CSSStyleSheet.

        --

        Tests: webarchive/test-css-url-resources-in-stylesheets.html
               webarchive/test-css-url-resources-inline-styles.html

        Walk stylesheets and inline style attributes for url() references
        when building a list of URLs to include in a webarchive.  Note that
        not all URLs found this way will be included in the webarchive if
        they were not used (and thus not downloaded) when laying out the
        page.

        The key method for CSS stylesheets is
        CSSStyleSheet::addSubresourceStyleURLs() which iterates over all
        CSSStyleSheet objects recursively referenced from its own stylesheet
        through @import rules.  Starting with the CSSRule objects in each
        sheet and continuing down through the CSSMutableStyleDeclaration and
        CSSValue objects, addSubresourceStyleURLs() methods are called to
        gather URLs.

        For inline style attributes in HTML DOM elements,
        StyledElement::addSubresourceAttributeURLs() calls
        CSSMutableStyleDeclaration::addSubresourceStyleURLs() to gather URLs
        from each element, hence the need to call
        addSubresourceAttributeURLs() on superclasses when the method is
        implemented on the element class itself.

        * css/CSSBorderImageValue.cpp:
        (WebCore::CSSBorderImageValue::addSubresourceStyleURLs): Added.
        * css/CSSBorderImageValue.h:
        (WebCore::CSSBorderImageValue::addSubresourceStyleURLs): Added
        declaration.

        * css/CSSFontFaceRule.cpp:
        (WebCore::CSSFontFaceRule::addSubresourceStyleURLs): Added.
        * css/CSSFontFaceRule.h:
        (WebCore::CSSFontFaceRule::addSubresourceStyleURLs): Added
        declaration.

        * css/CSSFontFaceSrcValue.cpp:
        (WebCore::CSSFontFaceSrcValue::addSubresourceStyleURLs): Added.
        * css/CSSFontFaceSrcValue.h:
        (WebCore::CSSFontFaceSrcValue::addSubresourceStyleURLs): Added
        declaration.

        * css/CSSImportRule.cpp:
        (WebCore::CSSImportRule::addSubresourceStyleURLs): Added.
        * css/CSSImportRule.h:
        (WebCore::CSSImportRule::addSubresourceStyleURLs): Added
        declaration.

        * css/CSSMutableStyleDeclaration.cpp:
        (WebCore::CSSMutableStyleDeclaration::addSubresourceStyleURLs): Added.
        Iterates over m_properties vector of CSSProperty objects calling
        addSubresourceStyleURLs() on each property's CSSValue object.
        * css/CSSMutableStyleDeclaration.h:
        (WebCore::CSSMutableStyleDeclaration::addSubresourceStyleURLs): Added
        declaration.

        * css/CSSPrimitiveValue.cpp:
        (WebCore::CSSPrimitiveValue::addSubresourceStyleURLs): Added.
        * css/CSSPrimitiveValue.h:
        (WebCore::CSSPrimitiveValue::addSubresourceStyleURLs): Added
        declaration.

        * css/CSSReflectValue.cpp:
        (WebCore::CSSReflectValue::addSubresourceStyleURLs): Added.
        * css/CSSReflectValue.h:
        (WebCore::CSSReflectValue::addSubresourceStyleURLs): Added
        declaration.

        * css/CSSRule.h:
        (WebCore::CSSRule::addSubresourceStyleURLs): Added.  Virtual
        method with empty implementation that's overridden by subclasses
        as needed.

        * css/CSSStyleRule.cpp:
        (WebCore::CSSStyleRule::addSubresourceStyleURLs): Added.
        * css/CSSStyleRule.h:
        (WebCore::CSSStyleRule::addSubresourceStyleURLs): Added
        declaration.

        * css/CSSStyleSheet.cpp:
        (WebCore::CSSStyleSheet::addSubresourceStyleURLs): Updated to
        call CSSRule::addSubresourceStyleURLs on each rule to extract
        URLs.  Removed unneeded baseURL parameter now that the
        completeURL() method exists.
        * css/CSSStyleSheet.h:
        (WebCore::CSSStyleSheet::addSubresourceStyleURLs): Updated
        declaration.

        * css/CSSValue.h:
        (WebCore::CSSValue::addSubresourceStyleURLs): Added.  Virtual
        method with empty implementation that's overridden by subclasses
        as needed.

        * css/CSSValueList.cpp:
        (WebCore::CSSValueList::addSubresourceStyleURLs): Added.
        Iterates over m_values vector of CSSValue objects calling
        addSubresourceStyleURLs() on each.
        * css/CSSValueList.h:
        (WebCore::CSSValueList::addSubresourceStyleURLs): Added
        declaration.

        * css/StyleSheet.h:
        (WebCore::StyleSheet::addSubresourceStyleURLs): Updated
        declaration to remove unneeded baseURL parameter.

        * dom/ProcessingInstruction.cpp:
        (WebCore::ProcessingInstruction::addSubresourceAttributeURLs):
        Fixed to use the StyleBase::baseURL() method to get the
        stylesheet's URL instead of calling Document::completeURL().

        * dom/StyledElement.cpp:
        (WebCore::StyledElement::addSubresourceAttributeURLs): Added method
        to extract URLs from inline style declarations.
        * dom/StyledElement.h:
        (WebCore::StyledElement::addSubresourceAttributeURLs): Added
        declaration.

        * html/HTMLBodyElement.cpp:
        (WebCore::HTMLBodyElement::addSubresourceAttributeURLs): Call
        addSubresourceAttributeURLs() in superclass to extract URLs
        from inline style declarations.
        * html/HTMLEmbedElement.cpp:
        (WebCore::HTMLEmbedElement::addSubresourceAttributeURLs): Ditto.
        * html/HTMLImageElement.cpp:
        (WebCore::HTMLImageElement::addSubresourceAttributeURLs): Ditto.
        * html/HTMLInputElement.cpp:
        (WebCore::HTMLInputElement::addSubresourceAttributeURLs): Ditto.
        * html/HTMLLinkElement.cpp:
        (WebCore::HTMLLinkElement::addSubresourceAttributeURLs): Ditto.
        * html/HTMLObjectElement.cpp:
        (WebCore::HTMLObjectElement::addSubresourceAttributeURLs): Ditto.
        * html/HTMLParamElement.cpp:
        (WebCore::HTMLParamElement::addSubresourceAttributeURLs): Ditto.
        * html/HTMLScriptElement.cpp:
        (WebCore::HTMLScriptElement::addSubresourceAttributeURLs): Ditto.
        * html/HTMLStyleElement.cpp:
        (WebCore::HTMLStyleElement::addSubresourceAttributeURLs): Ditto.
        * html/HTMLTableCellElement.cpp:
        (WebCore::HTMLTableCellElement::addSubresourceAttributeURLs): Ditto.
        * html/HTMLTableElement.cpp:
        (WebCore::HTMLTableElement::addSubresourceAttributeURLs): Ditto.
        * svg/SVGCursorElement.cpp:
        (WebCore::SVGCursorElement::addSubresourceAttributeURLs): Ditto.
        * svg/SVGFEImageElement.cpp:
        (WebCore::SVGFEImageElement::addSubresourceAttributeURLs): Ditto.
        * svg/SVGImageElement.cpp:
        (WebCore::SVGImageElement::addSubresourceAttributeURLs): Ditto.
        * svg/SVGScriptElement.cpp:
        (WebCore::SVGScriptElement::addSubresourceAttributeURLs): Ditto.

LayoutTests:

        The first set of files below tests that URLs are encoded properly
        based on the charset of the stylesheet.  Normally this behavior may
        only be tested by looking at web server logs with manual tests, but
        webarchives represent this information in such a way that they may
        be tested by DumpRenderTree.  Note that these tests depend on Bug
        11850 being fixed, so it's not possible to separate them.

        The second set of files below tests that all types of resources
        referenced by url() in CSS stylesheets are now saved in webarchives.

        * http/tests/webarchive/resources/.htaccess: Added.
        * http/tests/webarchive/resources/apple.gif: Copied from LayoutTests/fast/canvas/resources/apple.gif.
        * http/tests/webarchive/resources/test-no-charset.css: Added.
        * http/tests/webarchive/resources/test-shift-jis.css: Added.
        * http/tests/webarchive/resources/test-utf-8.css: Added.
        * http/tests/webarchive/test-css-url-encoding-expected.webarchive: Added.
        * http/tests/webarchive/test-css-url-encoding-shift-jis-expected.webarchive: Added.
        * http/tests/webarchive/test-css-url-encoding-shift-jis.html: Added.
        * http/tests/webarchive/test-css-url-encoding-utf-8-expected.webarchive: Added.
        * http/tests/webarchive/test-css-url-encoding-utf-8.html: Added.
        * http/tests/webarchive/test-css-url-encoding.html: Added.

        * webarchive/resources/Ahem.ttf: Copied from LayoutTests/fast/css/resources/Ahem.ttf.
        * webarchive/test-css-url-resources-in-stylesheets-expected.webarchive: Added.
        * webarchive/test-css-url-resources-in-stylesheets.html: Added.
        * webarchive/test-css-url-resources-inline-styles-expected.webarchive: Added.
        * webarchive/test-css-url-resources-inline-styles.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@39441 268f45cc-cd09-0410-ab3c-d52691b4dbfc
62 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/webarchive/resources/.htaccess [new file with mode: 0644]
LayoutTests/http/tests/webarchive/resources/apple.gif [new file with mode: 0644]
LayoutTests/http/tests/webarchive/resources/test-no-charset.css [new file with mode: 0644]
LayoutTests/http/tests/webarchive/resources/test-shift-jis.css [new file with mode: 0644]
LayoutTests/http/tests/webarchive/resources/test-utf-8.css [new file with mode: 0644]
LayoutTests/http/tests/webarchive/test-css-url-encoding-expected.webarchive [new file with mode: 0644]
LayoutTests/http/tests/webarchive/test-css-url-encoding-shift-jis-expected.webarchive [new file with mode: 0644]
LayoutTests/http/tests/webarchive/test-css-url-encoding-shift-jis.html [new file with mode: 0644]
LayoutTests/http/tests/webarchive/test-css-url-encoding-utf-8-expected.webarchive [new file with mode: 0644]
LayoutTests/http/tests/webarchive/test-css-url-encoding-utf-8.html [new file with mode: 0644]
LayoutTests/http/tests/webarchive/test-css-url-encoding.html [new file with mode: 0644]
LayoutTests/webarchive/resources/Ahem.ttf [new file with mode: 0644]
LayoutTests/webarchive/test-css-url-resources-in-stylesheets-expected.webarchive [new file with mode: 0644]
LayoutTests/webarchive/test-css-url-resources-in-stylesheets.html [new file with mode: 0644]
LayoutTests/webarchive/test-css-url-resources-inline-styles-expected.webarchive [new file with mode: 0644]
LayoutTests/webarchive/test-css-url-resources-inline-styles.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/css/CSSBorderImageValue.cpp
WebCore/css/CSSBorderImageValue.h
WebCore/css/CSSFontFaceRule.cpp
WebCore/css/CSSFontFaceRule.h
WebCore/css/CSSFontFaceSrcValue.cpp
WebCore/css/CSSFontFaceSrcValue.h
WebCore/css/CSSImportRule.cpp
WebCore/css/CSSImportRule.h
WebCore/css/CSSMutableStyleDeclaration.cpp
WebCore/css/CSSMutableStyleDeclaration.h
WebCore/css/CSSParser.cpp
WebCore/css/CSSPrimitiveValue.cpp
WebCore/css/CSSPrimitiveValue.h
WebCore/css/CSSReflectValue.cpp
WebCore/css/CSSReflectValue.h
WebCore/css/CSSRule.h
WebCore/css/CSSStyleRule.cpp
WebCore/css/CSSStyleRule.h
WebCore/css/CSSStyleSheet.cpp
WebCore/css/CSSStyleSheet.h
WebCore/css/CSSValue.h
WebCore/css/CSSValueList.cpp
WebCore/css/CSSValueList.h
WebCore/css/StyleSheet.cpp
WebCore/css/StyleSheet.h
WebCore/dom/Document.cpp
WebCore/dom/ProcessingInstruction.cpp
WebCore/dom/StyledElement.cpp
WebCore/dom/StyledElement.h
WebCore/html/HTMLBodyElement.cpp
WebCore/html/HTMLEmbedElement.cpp
WebCore/html/HTMLImageElement.cpp
WebCore/html/HTMLInputElement.cpp
WebCore/html/HTMLLinkElement.cpp
WebCore/html/HTMLObjectElement.cpp
WebCore/html/HTMLParamElement.cpp
WebCore/html/HTMLScriptElement.cpp
WebCore/html/HTMLStyleElement.cpp
WebCore/html/HTMLTableCellElement.cpp
WebCore/html/HTMLTableElement.cpp
WebCore/svg/SVGCursorElement.cpp
WebCore/svg/SVGFEImageElement.cpp
WebCore/svg/SVGImageElement.cpp
WebCore/svg/SVGScriptElement.cpp