Bug 1093611 - Stage 2 - Make hash getters not do percent decoding if dom.url.getters_decode_hash is false r=smaug

This commit is contained in:
Valentin Gosu 2015-06-15 15:55:02 +03:00
parent 94c872bed1
commit 1a499bbee5
7 changed files with 19 additions and 4 deletions

View File

@ -444,7 +444,7 @@ Link::GetHash(nsAString &_hash, ErrorResult& aError)
nsresult rv = uri->GetRef(ref);
if (NS_SUCCEEDED(rv) && !ref.IsEmpty()) {
_hash.Assign(char16_t('#'));
if (nsContentUtils::EncodeDecodeURLHash()) {
if (nsContentUtils::GettersDecodeURLHash()) {
NS_UnescapeURL(ref); // XXX may result in random non-ASCII bytes!
}
AppendUTF8toUTF16(ref, _hash);

View File

@ -525,7 +525,7 @@ URL::GetHash(nsAString& aHash, ErrorResult& aRv) const
nsresult rv = mURI->GetRef(ref);
if (NS_SUCCEEDED(rv) && !ref.IsEmpty()) {
aHash.Assign(char16_t('#'));
if (nsContentUtils::EncodeDecodeURLHash()) {
if (nsContentUtils::GettersDecodeURLHash()) {
NS_UnescapeURL(ref); // XXX may result in random non-ASCII bytes!
}
AppendUTF8toUTF16(ref, aHash);

View File

@ -256,6 +256,7 @@ bool nsContentUtils::sIsResourceTimingEnabled = false;
bool nsContentUtils::sIsUserTimingLoggingEnabled = false;
bool nsContentUtils::sIsExperimentalAutocompleteEnabled = false;
bool nsContentUtils::sEncodeDecodeURLHash = false;
bool nsContentUtils::sGettersDecodeURLHash = false;
bool nsContentUtils::sPrivacyResistFingerprinting = false;
uint32_t nsContentUtils::sHandlingInputTimeout = 1000;
@ -538,6 +539,9 @@ nsContentUtils::Init()
Preferences::AddBoolVarCache(&sEncodeDecodeURLHash,
"dom.url.encode_decode_hash", false);
Preferences::AddBoolVarCache(&sGettersDecodeURLHash,
"dom.url.getters_decode_hash", false);
Preferences::AddBoolVarCache(&sPrivacyResistFingerprinting,
"privacy.resistFingerprinting", false);

View File

@ -1948,6 +1948,14 @@ public:
return sEncodeDecodeURLHash;
}
/*
* Returns true if URL getters should percent decode the value of the segment
*/
static bool GettersDecodeURLHash()
{
return sGettersDecodeURLHash && sEncodeDecodeURLHash;
}
/*
* Returns true if the browser should attempt to prevent content scripts
* from collecting distinctive information about the browser that could
@ -2499,6 +2507,7 @@ private:
static bool sIsUserTimingLoggingEnabled;
static bool sIsExperimentalAutocompleteEnabled;
static bool sEncodeDecodeURLHash;
static bool sGettersDecodeURLHash;
static bool sPrivacyResistFingerprinting;
static nsHtml5StringParser* sHTMLFragmentParser;

View File

@ -299,7 +299,7 @@ nsLocation::GetHash(nsAString& aHash)
rv = uri->GetRef(ref);
if (nsContentUtils::EncodeDecodeURLHash()) {
if (nsContentUtils::GettersDecodeURLHash()) {
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsITextToSubURI> textToSubURI(
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv));

View File

@ -4095,7 +4095,7 @@ WorkerPrivateParent<Derived>::SetBaseURI(nsIURI* aBaseURI)
if (NS_SUCCEEDED(aBaseURI->GetRef(temp)) && !temp.IsEmpty()) {
nsCOMPtr<nsITextToSubURI> converter =
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID);
if (converter && nsContentUtils::EncodeDecodeURLHash()) {
if (converter && nsContentUtils::GettersDecodeURLHash()) {
nsCString charset;
nsAutoString unicodeRef;
if (NS_SUCCEEDED(aBaseURI->GetOriginCharset(charset)) &&

View File

@ -169,6 +169,8 @@ pref("dom.undo_manager.enabled", false);
// Whether URL,nsLocation,Link::GetHash should be percent encoded
// in setter and percent decoded in getter (old behaviour = true)
pref("dom.url.encode_decode_hash", true);
// Whether ::GetHash should do percent decoding (old behaviour = true)
pref("dom.url.getters_decode_hash", false);
// Whether to run add-on code in different compartments from browser code. This
// causes a separate compartment for each (addon, global) combination, which may