From 12640bf26e8a47293815670b03eec92a2965fcb6 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Fri, 11 Aug 2017 13:30:55 +0200 Subject: Read Firefox UA compatmode from a pref instead of hard-coded. In case of a missing pref, a hard-coded value is still used from the ctor. --- netwerk/protocol/http/nsHttpHandler.cpp | 30 +++++++++++++++++++++++------- netwerk/protocol/http/nsHttpHandler.h | 1 + 2 files changed, 24 insertions(+), 7 deletions(-) (limited to 'netwerk/protocol') diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp index 3c46bbf80..b94728b37 100644 --- a/netwerk/protocol/http/nsHttpHandler.cpp +++ b/netwerk/protocol/http/nsHttpHandler.cpp @@ -103,9 +103,6 @@ #define NS_HTTP_PROTOCOL_FLAGS (URI_STD | ALLOWS_PROXY | ALLOWS_PROXY_HTTP | URI_LOADABLE_BY_ANYONE) -// Firefox compatibility version we claim in our UA by default -#define MOZILLA_COMPATVERSION "52.9" - //----------------------------------------------------------------------------- namespace mozilla { @@ -204,6 +201,7 @@ nsHttpHandler::nsHttpHandler() , mLegacyAppVersion("5.0") , mProduct("Gecko") , mCompatFirefoxEnabled(false) + , mCompatFirefoxVersion("52.9") , mUserAgentIsDirty(true) , mPromptTempRedirect(true) , mEnablePersistentHttpsCaching(false) @@ -320,10 +318,12 @@ nsHttpHandler::Init() nsHttpChannelAuthProvider::InitializePrefs(); // rv: should have the Firefox/Gecko compatversion for web compatibility - mMisc.AssignLiteral("rv:" MOZILLA_COMPATVERSION); + mMisc.AssignLiteral("rv:"); + mMisc += mCompatFirefoxVersion; mCompatGecko.AssignLiteral("Gecko/20100101"); - mCompatFirefox.AssignLiteral("Firefox/" MOZILLA_COMPATVERSION); + mCompatFirefox.AssignLiteral("Firefox/"); + mCompatFirefox += mCompatFirefoxVersion; nsCOMPtr appInfo = do_GetService("@mozilla.org/xre/app-info;1"); @@ -352,7 +352,7 @@ nsHttpHandler::Init() appInfo->GetVersion(mAppVersion); } else { // Fall back to platform if appInfo is unavailable - mAppVersion.Assign(MOZILLA_UAVERSION); + mAppVersion.AssignLiteral(MOZILLA_UAVERSION); } // If there's no override set, set it to the dynamic BuildID @@ -1015,10 +1015,26 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref) mUserAgentIsDirty = true; } + // general.useragent.compatMode.version + // This is the version number used in rv: for Gecko compatibility + // and in the Firefox/nn.nn slice when compatMode.firefox is enabled. + if (PREF_CHANGED(UA_PREF("compatMode.version"))) { + prefs->GetCharPref(UA_PREF("compatMode.version"), + getter_Copies(mCompatFirefoxVersion)); + + // rebuild mMisc and compatMode slice + mMisc.AssignLiteral("rv:"); + mMisc += mCompatFirefoxVersion; + mCompatFirefox.AssignLiteral("Firefox/"); + mCompatFirefox += mCompatFirefoxVersion; + + mUserAgentIsDirty = true; + } + // general.useragent.override if (PREF_CHANGED(UA_PREF("override"))) { prefs->GetCharPref(UA_PREF("override"), - getter_Copies(mUserAgentOverride)); + getter_Copies(mUserAgentOverride)); mUserAgentIsDirty = true; } diff --git a/netwerk/protocol/http/nsHttpHandler.h b/netwerk/protocol/http/nsHttpHandler.h index 7121d4bc2..d51662db9 100644 --- a/netwerk/protocol/http/nsHttpHandler.h +++ b/netwerk/protocol/http/nsHttpHandler.h @@ -489,6 +489,7 @@ private: nsCString mCompatGecko; bool mCompatGeckoEnabled; nsCString mCompatFirefox; + nsCString mCompatFirefoxVersion; bool mCompatFirefoxEnabled; nsXPIDLCString mCompatDevice; nsCString mDeviceModelId; -- cgit v1.2.3