Commit e08cbe85 authored by ap's avatar ap
Browse files

Reviewed by Darin.

        http://bugs.webkit.org/show_bug.cgi?id=11011
        External CSS is parsed as iso-8859-1 even though the main document is utf-8

        Test: fast/encoding/css-charset-default.xhtml

        * loader/CachedResourceClient.h:
        (WebCore::CachedResourceClient::setCSSStyleSheet):
        (WebCore::CachedResourceClient::setXSLStyleSheet):
        Divided setStyleSheet into setCSSStyleSheet and setXSLStyleSheet. The former
        takes an additional charset parameter, to be passed to CSSStyleSheet constructor.

        * css/CSSImportRule.cpp:
        (WebCore::CSSImportRule::setCSSStyleSheet):
        (WebCore::CSSImportRule::insertedIntoParent): Default to parent stylesheet's charset.
        * css/CSSImportRule.h:

        * css/CSSStyleSheet.cpp:
        (WebCore::CSSStyleSheet::CSSStyleSheet):
        * css/CSSStyleSheet.h:
        Added an m_charset member to be used when loading child stylesheets. Removed an unused m_implicit
        member. Changed some String...
parent 1f4fa6e6
2006-09-30 Alexey Proskuryakov <ap@nypop.com>
Reviewed by Darin.
Test for http://bugs.webkit.org/show_bug.cgi?id=11011
External CSS is parsed as iso-8859-1 even though the main document is utf-8
* fast/encoding/css-charset-default-expected.txt: Added.
* fast/encoding/css-charset-default.xhtml: Added.
* fast/encoding/css-charset-import.css: Added.
* fast/encoding/css-charset-inherit-iso-8859-5.css: Added.
* fast/encoding/css-charset-inherit-koi-8.css: Added.
2006-09-30 Rob Buis <buis@kde.org>
 
Reviewed by eseidel.
Test for bug 11011: External CSS is parsed as iso-8859-1 even though the main document is utf-8.
Stylesheet 1 (inherit document charset using xml-stylesheet processing instruction): SUССЕSS
Stylesheet 2 (inherit document charset using link): SUССЕSS
Stylesheet 3 (inherit referring stylesheet charset): SUССЕSS
Stylesheet 4 (inherit referring inline stylesheet charset): SUССЕSS
<?xml version="1.0" encoding="iso-8859-5"?>
<?xml-stylesheet href="css-charset-inherit-iso-8859-5.css?1" type="text/css"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CSS Default charset</title>
<link rel="stylesheet" type="text/css" href="css-charset-inherit-iso-8859-5.css?2"/>
<link rel="stylesheet" type="text/css" href="css-charset-import.css"/>
<style type="text/css">
@import "css-charset-inherit-iso-8859-5.css?4";
</style>
</head>
<body onload="test()">
<p>Test for <a href="http://bugs.webkit.org/show_bug.cgi?id=11011">bug 11011</a>:
External CSS is parsed as iso-8859-1 even though the main document is utf-8.</p>
<p id="res1">Stylesheet 1 (inherit document charset using xml-stylesheet processing instruction): </p>
<p id="res2">Stylesheet 2 (inherit document charset using link): </p>
<p id="res3">Stylesheet 3 (inherit referring stylesheet charset): </p>
<p id="res4">Stylesheet 4 (inherit referring inline stylesheet charset): </p>
<script type="text/javascript">
if (window.layoutTestController)
layoutTestController.dumpAsText();
function test() {
try {
document.getElementById("res1").innerHTML += document.styleSheets[0].cssRules[0].style.content;
document.getElementById("res2").innerHTML += document.styleSheets[1].cssRules[0].style.content;
document.getElementById("res3").innerHTML += document.styleSheets[2].cssRules[1].styleSheet.cssRules[0].style.content;
document.getElementById("res4").innerHTML += document.styleSheets[3].cssRules[0].styleSheet.cssRules[0].style.content;
} catch (ex) {
alert(ex.toString());
}
}
</script>
</body>
</html>
@charset "koi8-r";
@import "css-charset-inherit-koi-8.css";
/* iso-8859-5 encoding */
#dummy:before { content: "SUÁÁµSS"; }
/* koi-8 encoding */
#dummy:before { content: "SUóóåSS"; }
2006-09-30 Alexey Proskuryakov <ap@nypop.com>
Reviewed by Darin.
http://bugs.webkit.org/show_bug.cgi?id=11011
External CSS is parsed as iso-8859-1 even though the main document is utf-8
Test: fast/encoding/css-charset-default.xhtml
* loader/CachedResourceClient.h:
(WebCore::CachedResourceClient::setCSSStyleSheet):
(WebCore::CachedResourceClient::setXSLStyleSheet):
Divided setStyleSheet into setCSSStyleSheet and setXSLStyleSheet. The former
takes an additional charset parameter, to be passed to CSSStyleSheet constructor.
* css/CSSImportRule.cpp:
(WebCore::CSSImportRule::setCSSStyleSheet):
(WebCore::CSSImportRule::insertedIntoParent): Default to parent stylesheet's charset.
* css/CSSImportRule.h:
* css/CSSStyleSheet.cpp:
(WebCore::CSSStyleSheet::CSSStyleSheet):
* css/CSSStyleSheet.h:
Added an m_charset member to be used when loading child stylesheets. Removed an unused m_implicit
member. Changed some String parameters to const String&.
* css/StyleSheet.cpp:
(WebCore::StyleSheet::StyleSheet):
* css/StyleSheet.h:
Changed some String parameters to const String&. Removed an unused (even unimplemented) constructor.
* css/StyleSheetList.cpp:
(WebCore::StyleSheetList::length):
(WebCore::StyleSheetList::item):
* css/StyleSheetList.h:
Special-casing implicit stylesheets seemed to be dead code, removed.
* dom/Document.cpp:
(WebCore::Document::setCSSStyleSheet):
(WebCore::Document::recalcStyleSelector):
* dom/Document.h:
Renamed setStyleSheet() to setCSSStyleSheet().
* dom/ProcessingInstruction.cpp:
(WebCore::ProcessingInstruction::checkStyleSheet): Pass a correct charset to requestCSSStyleSheet().
(WebCore::ProcessingInstruction::setCSSStyleSheet):
(WebCore::ProcessingInstruction::setXSLStyleSheet):
(WebCore::ProcessingInstruction::parseStyleSheet):
* dom/ProcessingInstruction.h:
* html/HTMLLinkElement.cpp:
(WebCore::HTMLLinkElement::process): Default to document encoding if a charset attribute
is not specified.
(WebCore::HTMLLinkElement::setCSSStyleSheet):
* html/HTMLLinkElement.h:
* html/HTMLStyleElement.cpp:
(WebCore::HTMLStyleElement::childrenChanged):
* ksvg2/svg/SVGStyleElement.cpp:
(WebCore::SVGStyleElement::childrenChanged):
Inherit URL and charset from the document.
* loader/Cache.cpp:
(WebCore::Cache::requestCSSStyleSheet):
* loader/Cache.h:
Adjust for setStyleSheet() renaming.
* loader/CachedCSSStyleSheet.h: Removed an unused constructor.
* loader/CachedCSSStyleSheet.cpp:
(WebCore::CachedCSSStyleSheet::ref):
(WebCore::CachedCSSStyleSheet::deref):
(WebCore::CachedCSSStyleSheet::checkNotify):
Pass the encoding to setCSSStyleSheet().
* loader/CachedXSLStyleSheet.cpp:
(WebCore::CachedXSLStyleSheet::ref):
(WebCore::CachedXSLStyleSheet::checkNotify):
* loader/DocLoader.cpp:
(WebCore::DocLoader::requestCSSStyleSheet):
* loader/DocLoader.h:
* page/Frame.cpp:
(WebCore::UserStyleSheetLoader::UserStyleSheetLoader):
(WebCore::UserStyleSheetLoader::setCSSStyleSheet):
* xml/XSLImportRule.cpp:
(WebCore::XSLImportRule::setXSLStyleSheet):
(WebCore::XSLImportRule::loadSheet):
* xml/XSLImportRule.h:
Adjust for setStyleSheet() renaming.
2006-09-30 Rob Buis <buis@kde.org>
 
Reviewed by eseidel.
......@@ -56,11 +56,11 @@ CSSImportRule::~CSSImportRule()
m_cachedSheet->deref(this);
}
void CSSImportRule::setStyleSheet(const String &url, const String &sheet)
void CSSImportRule::setCSSStyleSheet(const String &url, const String& charset, const String &sheet)
{
if (m_styleSheet)
m_styleSheet->setParent(0);
m_styleSheet = new CSSStyleSheet(this, url);
m_styleSheet = new CSSStyleSheet(this, url, charset);
CSSStyleSheet *parent = parentStyleSheet();
m_styleSheet->parseString(sheet, !parent || parent->useStrictParsing());
......@@ -98,8 +98,7 @@ void CSSImportRule::insertedIntoParent()
if (absHref == parent->baseURL())
return;
// ### pass correct charset here!!
m_cachedSheet = docLoader->requestStyleSheet(absHref, String());
m_cachedSheet = docLoader->requestCSSStyleSheet(absHref, parentSheet->charset());
if (m_cachedSheet) {
m_loading = true;
m_cachedSheet->ref(this);
......
......@@ -49,7 +49,7 @@ public:
bool isLoading() const;
// from CachedResourceClient
virtual void setStyleSheet(const String& url, const String& sheet);
virtual void setCSSStyleSheet(const String& url, const String& charset, const String& sheet);
virtual void insertedIntoParent();
......
......@@ -32,27 +32,27 @@
namespace WebCore {
CSSStyleSheet::CSSStyleSheet(CSSStyleSheet* parentSheet, String href)
CSSStyleSheet::CSSStyleSheet(CSSStyleSheet* parentSheet, const String& href, const String& charset)
: StyleSheet(parentSheet, href)
, m_doc(parentSheet ? parentSheet->doc() : 0)
, m_implicit(false)
, m_namespaces(0)
, m_charset(charset)
{
}
CSSStyleSheet::CSSStyleSheet(Node *parentNode, String href, bool _implicit)
CSSStyleSheet::CSSStyleSheet(Node *parentNode, const String& href, const String& charset)
: StyleSheet(parentNode, href)
, m_doc(parentNode->document())
, m_implicit(_implicit)
, m_namespaces(0)
, m_charset(charset)
{
}
CSSStyleSheet::CSSStyleSheet(CSSRule *ownerRule, String href)
CSSStyleSheet::CSSStyleSheet(CSSRule *ownerRule, const String& href, const String& charset)
: StyleSheet(ownerRule, href)
, m_doc(0)
, m_implicit(false)
, m_namespaces(0)
, m_charset(charset)
{
}
......
......@@ -39,9 +39,9 @@ typedef int ExceptionCode;
class CSSStyleSheet : public StyleSheet
{
public:
CSSStyleSheet(Node* parentNode, String href = String(), bool _implicit = false);
CSSStyleSheet(CSSStyleSheet* parentSheet, String href = String());
CSSStyleSheet(CSSRule* ownerRule, String href = String());
CSSStyleSheet(Node* parentNode, const String& href = String(), const String& charset = String());
CSSStyleSheet(CSSStyleSheet* parentSheet, const String& href = String(), const String& charset = String());
CSSStyleSheet(CSSRule* ownerRule, const String& href = String(), const String& charset = String());
~CSSStyleSheet();
......@@ -68,12 +68,12 @@ public:
virtual void checkLoaded();
DocLoader* docLoader();
Document* doc() { return m_doc; }
bool implicit() { return m_implicit; }
const String& charset() const { return m_charset; }
protected:
Document* m_doc;
bool m_implicit;
CSSNamespace* m_namespaces;
String m_charset;
};
} // namespace
......
......@@ -26,7 +26,7 @@
namespace WebCore {
StyleSheet::StyleSheet(StyleSheet* parentSheet, String href)
StyleSheet::StyleSheet(StyleSheet* parentSheet, const String& href)
: StyleList(parentSheet)
, m_parentNode(0)
, m_strHref(href)
......@@ -35,7 +35,7 @@ StyleSheet::StyleSheet(StyleSheet* parentSheet, String href)
}
StyleSheet::StyleSheet(Node* parentNode, String href)
StyleSheet::StyleSheet(Node* parentNode, const String& href)
: StyleList(0)
, m_parentNode(parentNode)
, m_strHref(href)
......@@ -43,7 +43,7 @@ StyleSheet::StyleSheet(Node* parentNode, String href)
{
}
StyleSheet::StyleSheet(StyleBase* owner, String href)
StyleSheet::StyleSheet(StyleBase* owner, const String& href)
: StyleList(owner)
, m_parentNode(0)
, m_strHref(href)
......
......@@ -34,10 +34,9 @@ class MediaList;
class StyleSheet : public StyleList {
public:
StyleSheet(Node* ownerNode, String href = String());
StyleSheet(StyleSheet* parentSheet, String href = String());
StyleSheet(StyleBase* owner, String href = String());
StyleSheet(CachedCSSStyleSheet*, String href = String());
StyleSheet(Node* ownerNode, const String& href = String());
StyleSheet(StyleSheet* parentSheet, const String& href = String());
StyleSheet(StyleBase* owner, const String& href = String());
virtual ~StyleSheet();
virtual bool isStyleSheet() const { return true; }
......
......@@ -48,28 +48,12 @@ void StyleSheetList::remove(StyleSheet* s)
unsigned StyleSheetList::length() const
{
// hack so implicit BODY stylesheets don't get counted here
unsigned l = 0;
DeprecatedPtrListIterator<StyleSheet> it(styleSheets);
for (; it.current(); ++it) {
if (!it.current()->isCSSStyleSheet() || !static_cast<CSSStyleSheet*>(it.current())->implicit())
l++;
}
return l;
return styleSheets.count();
}
StyleSheet *StyleSheetList::item (unsigned index)
StyleSheet* StyleSheetList::item(unsigned index)
{
unsigned l = 0;
DeprecatedPtrListIterator<StyleSheet> it(styleSheets);
for (; it.current(); ++it) {
if (!it.current()->isCSSStyleSheet() || !static_cast<CSSStyleSheet*>(it.current())->implicit()) {
if (l == index)
return it.current();
l++;
}
}
return 0;
return index < length() ? styleSheets.at(index) : 0;
}
}
......@@ -35,7 +35,6 @@ class StyleSheetList : public Shared<StyleSheetList>
public:
~StyleSheetList();
// the following two ignore implicit stylesheets
unsigned length() const;
StyleSheet* item(unsigned index);
......
......@@ -1374,9 +1374,9 @@ void Document::setURL(const DeprecatedString& url)
m_styleSelector->setEncodedURL(m_url);
}
void Document::setStyleSheet(const String &url, const String &sheet)
void Document::setCSSStyleSheet(const String &url, const String& charset, const String &sheet)
{
m_sheet = new CSSStyleSheet(this, url);
m_sheet = new CSSStyleSheet(this, url, charset);
m_sheet->parseString(sheet);
m_loadingSheet = false;
......@@ -1855,7 +1855,7 @@ void Document::recalcStyleSelector()
CSSStyleSheet *cssSheet = new CSSStyleSheet(this);
cssSheet->parseString(sheetText);
pi->setStyleSheet(cssSheet);
pi->setCSSStyleSheet(cssSheet);
sheet = cssSheet;
}
}
......
......@@ -331,7 +331,7 @@ public:
String completeURL(const String&);
// from cachedObjectClient
virtual void setStyleSheet(const String& url, const String& sheetStr);
virtual void setCSSStyleSheet(const String& url, const String& charset, const String& sheetStr);
void setUserStyleSheet(const String& sheet);
const String& userStyleSheet() const { return m_usersheet; }
void setPrintStyleSheet(const String& sheet) { m_printSheet = sheet; }
......
......@@ -28,6 +28,7 @@
#include "Document.h"
#include "DocLoader.h"
#include "ExceptionCode.h"
#include "Frame.h"
#include "XSLStyleSheet.h"
#include "XMLTokenizer.h" // for parseAttributes()
......@@ -146,8 +147,7 @@ bool ProcessingInstruction::checkStyleSheet()
}
else
{
// ### some validation on the URL?
// ### FIXME charset
// FIXME: some validation on the URL?
if (document()->frame()) {
m_loading = true;
document()->addPendingSheet();
......@@ -158,7 +158,13 @@ bool ProcessingInstruction::checkStyleSheet()
m_cachedSheet = document()->docLoader()->requestXSLStyleSheet(document()->completeURL(href));
else
#endif
m_cachedSheet = document()->docLoader()->requestStyleSheet(document()->completeURL(href), String());
{
String charset = attrs.get("charset");
if (charset.isEmpty())
charset = document()->frame()->encoding();
m_cachedSheet = document()->docLoader()->requestCSSStyleSheet(document()->completeURL(href), charset);
}
if (m_cachedSheet)
m_cachedSheet->ref( this );
#if XSLT_SUPPORT
......@@ -188,14 +194,24 @@ void ProcessingInstruction::sheetLoaded()
document()->stylesheetLoaded();
}
void ProcessingInstruction::setStyleSheet(const String &url, const String &sheet)
void ProcessingInstruction::setCSSStyleSheet(const String &url, const String& charset, const String &sheet)
{
ASSERT(!m_isXSL);
m_sheet = new CSSStyleSheet(this, url, charset);
parseStyleSheet(sheet);
}
#if XSLT_SUPPORT
if (m_isXSL)
m_sheet = new XSLStyleSheet(this, url);
else
void ProcessingInstruction::setXSLStyleSheet(const String &url, const String &sheet)
{
ASSERT(m_isXSL);
m_sheet = new XSLStyleSheet(this, url);
parseStyleSheet(sheet);
}
#endif
m_sheet = new CSSStyleSheet(this, url);
void ProcessingInstruction::parseStyleSheet(const String &sheet)
{
m_sheet->parseString(sheet);
if (m_cachedSheet)
m_cachedSheet->deref(this);
......@@ -218,8 +234,10 @@ String ProcessingInstruction::toString() const
return result;
}
void ProcessingInstruction::setStyleSheet(StyleSheet* sheet)
void ProcessingInstruction::setCSSStyleSheet(CSSStyleSheet* sheet)
{
ASSERT(!m_cachedSheet);
ASSERT(!m_loading);
m_sheet = sheet;
}
......
......@@ -30,6 +30,7 @@
namespace WebCore {
class StyleSheet;
class CSSStyleSheet;
class ProcessingInstruction : public ContainerNode, private CachedResourceClient
{
......@@ -55,8 +56,11 @@ public:
String localHref() const { return m_localHref.get(); }
StyleSheet* sheet() const { return m_sheet.get(); }
bool checkStyleSheet();
virtual void setStyleSheet(const String& URL, const String& sheet);
void setStyleSheet(StyleSheet*);
virtual void setCSSStyleSheet(const String& URL, const String& charset, const String& sheet);
#if XSLT_SUPPORT
virtual void setXSLStyleSheet(const String& URL, const String& sheet);
#endif
void setCSSStyleSheet(CSSStyleSheet*);
bool isLoading() const;
void sheetLoaded();
virtual String toString() const;
......@@ -66,6 +70,8 @@ public:
#endif
private:
void parseStyleSheet(const String& sheet);
RefPtr<StringImpl> m_target;
RefPtr<StringImpl> m_data;
RefPtr<StringImpl> m_localHref;
......
......@@ -176,7 +176,10 @@ void HTMLLinkElement::process()
if (!isAlternate())
document()->addPendingSheet();
DeprecatedString chset = getAttribute(charsetAttr).deprecatedString();
String chset = getAttribute(charsetAttr);
if (chset.isEmpty() && document()->frame())
chset = document()->frame()->encoding();
if (m_cachedSheet) {
if (m_loading) {
document()->stylesheetLoaded();
......@@ -184,7 +187,7 @@ void HTMLLinkElement::process()
m_cachedSheet->deref(this);
}
m_loading = true;
m_cachedSheet = document()->docLoader()->requestStyleSheet(m_url, chset);
m_cachedSheet = document()->docLoader()->requestCSSStyleSheet(m_url, chset);
if (m_cachedSheet)
m_cachedSheet->ref(this);
}
......@@ -207,9 +210,9 @@ void HTMLLinkElement::removedFromDocument()
process();
}
void HTMLLinkElement::setStyleSheet(const String& url, const String& sheetStr)
void HTMLLinkElement::setCSSStyleSheet(const String& url, const String& charset, const String& sheetStr)
{
m_sheet = new CSSStyleSheet(this, url);
m_sheet = new CSSStyleSheet(this, url, charset);
m_sheet->parseString(sheetStr, !document()->inCompatMode());
RefPtr<MediaList> media = new MediaList((CSSStyleSheet*)0, m_media, true);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment