зеркало из https://github.com/mozilla/gecko-dev.git
Bug 485012. Allow passing a charset hint (e.g. the element's 'charset' attribute for preloads) to nsICSSLoader::LoadSheet. r+sr=peterv
This commit is contained in:
Родитель
6f0b054294
Коммит
973f44492a
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -3899,7 +3899,8 @@ nsXULDocument::AddPrototypeSheets()
|
|||
nsCOMPtr<nsICSSStyleSheet> 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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
body { color: green }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
This should be green
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
body { color: red }
|
||||
</style>
|
||||
<script src="data:application/javascript,"></script>
|
||||
<link rel="stylesheet" type="text/css"
|
||||
charset="UTF-16BE"
|
||||
href="data:text/css,%00b%00o%00d%00y%00{%00c%00o%00l%00o%00r%00:%00g%00r%00e%00e%00n}">
|
||||
</head>
|
||||
<body>
|
||||
This should be green
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -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
|
||||
|
|
|
@ -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<nsIChannel> 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();
|
||||
|
|
|
@ -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<nsIPrincipal> 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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -384,7 +384,9 @@ nsPreloadURIs::PreloadURIs(const nsAutoTArray<nsSpeculativeScriptThread::Prefetc
|
|||
break;
|
||||
case nsSpeculativeScriptThread::STYLESHEET:
|
||||
nsCOMPtr<nsICSSLoaderObserver> obs = new nsDummyCSSLoaderObserver();
|
||||
doc->CSSLoader()->LoadSheet(uri, doc->NodePrincipal(), obs);
|
||||
doc->CSSLoader()->LoadSheet(uri, doc->NodePrincipal(),
|
||||
NS_LossyConvertUTF16toASCII(pe.charset),
|
||||
obs);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче