diff --git a/content/xbl/src/nsXBLResourceLoader.cpp b/content/xbl/src/nsXBLResourceLoader.cpp index 7b04e3bb49c..dca235db25d 100644 --- a/content/xbl/src/nsXBLResourceLoader.cpp +++ b/content/xbl/src/nsXBLResourceLoader.cpp @@ -165,7 +165,7 @@ nsXBLResourceLoader::LoadResources(PRBool* aResult) } else { - rv = cssLoader->LoadSheet(url, docPrincipal, this); + rv = cssLoader->LoadSheet(url, docPrincipal, EmptyCString(), this); if (NS_SUCCEEDED(rv)) ++mPendingSheets; } diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index 69f9316e0a7..c7c483d435a 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -3899,7 +3899,8 @@ nsXULDocument::AddPrototypeSheets() nsCOMPtr incompleteSheet; rv = CSSLoader()->LoadSheet(uri, mCurrentPrototype->DocumentPrincipal(), - this, getter_AddRefs(incompleteSheet)); + EmptyCString(), this, + getter_AddRefs(incompleteSheet)); // XXXldb We need to prevent bogus sheets from being held in the // prototype's list, but until then, don't propagate the failure diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index 99002642ca2..6e0fbb2ade8 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -3401,7 +3401,7 @@ nsHTMLEditor::ReplaceStyleSheet(const nsAString& aURL) rv = NS_NewURI(getter_AddRefs(uaURI), aURL); NS_ENSURE_SUCCESS(rv, rv); - rv = cssLoader->LoadSheet(uaURI, nsnull, this); + rv = cssLoader->LoadSheet(uaURI, nsnull, EmptyCString(), this); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; diff --git a/layout/reftests/bugs/485012-1-ref.html b/layout/reftests/bugs/485012-1-ref.html new file mode 100644 index 00000000000..a9ccb1b9fd6 --- /dev/null +++ b/layout/reftests/bugs/485012-1-ref.html @@ -0,0 +1,12 @@ + + + + + + + This should be green + + + diff --git a/layout/reftests/bugs/485012-1.html b/layout/reftests/bugs/485012-1.html new file mode 100644 index 00000000000..ee7d4af5a7a --- /dev/null +++ b/layout/reftests/bugs/485012-1.html @@ -0,0 +1,16 @@ + + + + + + + + + This should be green + + + diff --git a/layout/reftests/bugs/reftest.list b/layout/reftests/bugs/reftest.list index d139dbba504..15b57cac2c8 100644 --- a/layout/reftests/bugs/reftest.list +++ b/layout/reftests/bugs/reftest.list @@ -1192,6 +1192,7 @@ fails == 472020-2.xul 472020-2-ref.xul == 482659-1c.html 482659-1-ref.html == 482659-1d.html 482659-1-ref.html == 483565.xul 483565-ref.xul +== 485012-1.html 485012-1-ref.html == 485275-1.html 485275-1-ref.html == 485275-1.svg 485275-1-ref.html == 486052-1.html 486052-1-ref.html diff --git a/layout/style/nsCSSLoader.cpp b/layout/style/nsCSSLoader.cpp index a57638c574c..78a6f58f3eb 100644 --- a/layout/style/nsCSSLoader.cpp +++ b/layout/style/nsCSSLoader.cpp @@ -221,6 +221,7 @@ SheetLoadData::SheetLoadData(CSSLoaderImpl* aLoader, PRBool aSyncLoad, PRBool aAllowUnsafeRules, PRBool aUseSystemPrincipal, + const nsCString& aCharset, nsICSSLoaderObserver* aObserver, nsIPrincipal* aLoaderPrincipal) : mLoader(aLoader), @@ -240,7 +241,8 @@ SheetLoadData::SheetLoadData(CSSLoaderImpl* aLoader, mUseSystemPrincipal(aUseSystemPrincipal), mOwningElement(nsnull), mObserver(aObserver), - mLoaderPrincipal(aLoaderPrincipal) + mLoaderPrincipal(aLoaderPrincipal), + mCharsetHint(aCharset) { NS_PRECONDITION(mLoader, "Must have a loader!"); NS_ADDREF(mLoader); @@ -607,6 +609,9 @@ SheetLoadData::OnDetermineCharset(nsIUnicharStreamLoader* aLoader, PRUint32 aDataLength, nsACString& aCharset) { + NS_PRECONDITION(!mOwningElement || mCharsetHint.IsEmpty(), + "Can't have element _and_ charset hint"); + LOG_URI("SheetLoadData::OnDetermineCharset for '%s'", mURI); nsCOMPtr channel; nsresult result = aLoader->GetChannel(getter_AddRefs(channel)); @@ -662,6 +667,9 @@ SheetLoadData::OnDetermineCharset(nsIUnicharStreamLoader* aLoader, PromiseFlatCString(aCharset).get())); } #endif + } else { + // If mCharsetHint is empty, that's ok; aCharset is known empty here + aCharset = mCharsetHint; } } @@ -1995,30 +2003,32 @@ CSSLoaderImpl::LoadSheetSync(nsIURI* aURL, PRBool aAllowUnsafeRules, LOG(("CSSLoaderImpl::LoadSheetSync")); return InternalLoadNonDocumentSheet(aURL, aAllowUnsafeRules, aUseSystemPrincipal, nsnull, - aSheet, nsnull); + EmptyCString(), aSheet, nsnull); } NS_IMETHODIMP CSSLoaderImpl::LoadSheet(nsIURI* aURL, nsIPrincipal* aOriginPrincipal, + const nsCString& aCharset, nsICSSLoaderObserver* aObserver, nsICSSStyleSheet** aSheet) { LOG(("CSSLoaderImpl::LoadSheet(aURL, aObserver, aSheet) api call")); NS_PRECONDITION(aSheet, "aSheet is null"); return InternalLoadNonDocumentSheet(aURL, PR_FALSE, PR_FALSE, - aOriginPrincipal, + aOriginPrincipal, aCharset, aSheet, aObserver); } NS_IMETHODIMP CSSLoaderImpl::LoadSheet(nsIURI* aURL, nsIPrincipal* aOriginPrincipal, + const nsCString& aCharset, nsICSSLoaderObserver* aObserver) { LOG(("CSSLoaderImpl::LoadSheet(aURL, aObserver) api call")); return InternalLoadNonDocumentSheet(aURL, PR_FALSE, PR_FALSE, - aOriginPrincipal, + aOriginPrincipal, aCharset, nsnull, aObserver); } @@ -2027,6 +2037,7 @@ CSSLoaderImpl::InternalLoadNonDocumentSheet(nsIURI* aURL, PRBool aAllowUnsafeRules, PRBool aUseSystemPrincipal, nsIPrincipal* aOriginPrincipal, + const nsCString& aCharset, nsICSSStyleSheet** aSheet, nsICSSLoaderObserver* aObserver) { @@ -2077,7 +2088,8 @@ CSSLoaderImpl::InternalLoadNonDocumentSheet(nsIURI* aURL, SheetLoadData* data = new SheetLoadData(this, aURL, sheet, syncLoad, aAllowUnsafeRules, - aUseSystemPrincipal, aObserver, aOriginPrincipal); + aUseSystemPrincipal, aCharset, aObserver, + aOriginPrincipal); if (!data) { sheet->SetComplete(); diff --git a/layout/style/nsCSSLoader.h b/layout/style/nsCSSLoader.h index 497f0be9366..0b96869c64c 100644 --- a/layout/style/nsCSSLoader.h +++ b/layout/style/nsCSSLoader.h @@ -136,6 +136,7 @@ public: PRBool aSyncLoad, PRBool aAllowUnsafeRules, PRBool aUseSystemPrincipal, + const nsCString& aCharset, nsICSSLoaderObserver* aObserver, nsIPrincipal* aLoaderPrincipal); @@ -223,6 +224,10 @@ public: // The principal that identifies who started loading us. nsCOMPtr mLoaderPrincipal; + + // The charset to use if the transport and sheet don't indicate one. + // May be empty. Must be empty if mOwningElement is non-null. + nsCString mCharsetHint; }; class nsURIAndPrincipalHashKey : public nsURIHashKey @@ -350,11 +355,13 @@ public: NS_IMETHOD LoadSheet(nsIURI* aURL, nsIPrincipal* aOriginPrincipal, + const nsCString& aCharset, nsICSSLoaderObserver* aObserver, nsICSSStyleSheet** aSheet); NS_IMETHOD LoadSheet(nsIURI* aURL, nsIPrincipal* aOriginPrincipal, + const nsCString& aCharset, nsICSSLoaderObserver* aObserver); // stop loading all sheets @@ -424,6 +431,7 @@ private: PRBool aAllowUnsafeRules, PRBool aUseSystemPrincipal, nsIPrincipal* aOriginPrincipal, + const nsCString& aCharset, nsICSSStyleSheet** aSheet, nsICSSLoaderObserver* aObserver); diff --git a/layout/style/nsICSSLoader.h b/layout/style/nsICSSLoader.h index a961dc434a0..64c7d7bb1a8 100644 --- a/layout/style/nsICSSLoader.h +++ b/layout/style/nsICSSLoader.h @@ -209,6 +209,11 @@ public: * @param aOriginPrincipal the principal to use for security checks. This * can be null to indicate that these checks should * be skipped. + * @param aCharset the encoding to use for converting the sheet data + * from bytes to Unicode. May be empty to indicate that the + * charset of the CSSLoader's document should be used. This + * is only used if neither the network transport nor the + * sheet itself indicate an encoding. * @param aObserver the observer to notify when the load completes. * Must not be null. * @param [out] aSheet the sheet to load. Note that the sheet may well @@ -216,6 +221,7 @@ public: */ NS_IMETHOD LoadSheet(nsIURI* aURL, nsIPrincipal* aOriginPrincipal, + const nsCString& aCharset, nsICSSLoaderObserver* aObserver, nsICSSStyleSheet** aSheet) = 0; @@ -225,6 +231,7 @@ public: */ NS_IMETHOD LoadSheet(nsIURI* aURL, nsIPrincipal* aOriginPrincipal, + const nsCString& aCharset, nsICSSLoaderObserver* aObserver) = 0; /** diff --git a/parser/htmlparser/src/nsParser.cpp b/parser/htmlparser/src/nsParser.cpp index 25c72a472fb..e6ff03f8540 100644 --- a/parser/htmlparser/src/nsParser.cpp +++ b/parser/htmlparser/src/nsParser.cpp @@ -384,7 +384,9 @@ nsPreloadURIs::PreloadURIs(const nsAutoTArray obs = new nsDummyCSSLoaderObserver(); - doc->CSSLoader()->LoadSheet(uri, doc->NodePrincipal(), obs); + doc->CSSLoader()->LoadSheet(uri, doc->NodePrincipal(), + NS_LossyConvertUTF16toASCII(pe.charset), + obs); break; } }