diff options
author | wolfbeast <mcwerewolf@gmail.com> | 2017-08-10 23:16:51 +0200 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2018-02-21 20:09:30 +0100 |
commit | ef9aeb6a08749ecc43242ba523d67632a6ddc0dc (patch) | |
tree | 0a7b71bb57d64a6b3f060adf01438312d400ba48 /netwerk/protocol/http/nsHttpHandler.cpp | |
parent | 4fd939e8c9dd97c45e7fcd1314f3ab482a2cf23d (diff) | |
download | UXP-ef9aeb6a08749ecc43242ba523d67632a6ddc0dc.tar UXP-ef9aeb6a08749ecc43242ba523d67632a6ddc0dc.tar.gz UXP-ef9aeb6a08749ecc43242ba523d67632a6ddc0dc.tar.lz UXP-ef9aeb6a08749ecc43242ba523d67632a6ddc0dc.tar.xz UXP-ef9aeb6a08749ecc43242ba523d67632a6ddc0dc.zip |
Update UA construction.
Diffstat (limited to 'netwerk/protocol/http/nsHttpHandler.cpp')
-rw-r--r-- | netwerk/protocol/http/nsHttpHandler.cpp | 63 |
1 files changed, 53 insertions, 10 deletions
diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp index 1ddffabff..3c46bbf80 100644 --- a/netwerk/protocol/http/nsHttpHandler.cpp +++ b/netwerk/protocol/http/nsHttpHandler.cpp @@ -103,6 +103,9 @@ #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 { @@ -316,9 +319,11 @@ nsHttpHandler::Init() nsHttpChannelAuthProvider::InitializePrefs(); - mMisc.AssignLiteral("rv:" MOZILLA_UAVERSION); + // rv: should have the Firefox/Gecko compatversion for web compatibility + mMisc.AssignLiteral("rv:" MOZILLA_COMPATVERSION); - mCompatFirefox.AssignLiteral("Firefox/" MOZILLA_UAVERSION); + mCompatGecko.AssignLiteral("Gecko/20100101"); + mCompatFirefox.AssignLiteral("Firefox/" MOZILLA_COMPATVERSION); nsCOMPtr<nsIXULAppInfo> appInfo = do_GetService("@mozilla.org/xre/app-info;1"); @@ -330,12 +335,30 @@ nsHttpHandler::Init() if (mAppName.Length() == 0) { appInfo->GetName(mAppName); } - appInfo->GetVersion(mAppVersion); mAppName.StripChars(R"( ()<>@,;:\"/[]?={})"); + } + + nsCString dynamicBuildID; + if (appInfo) { + appInfo->GetPlatformBuildID(dynamicBuildID); + if (dynamicBuildID.Length() > 8 ) + dynamicBuildID.Left(dynamicBuildID, 8); + } + + if (mAppVersionIsBuildID) { + // Override BuildID + mAppVersion.AssignLiteral(MOZ_UA_BUILDID); + } else if (appInfo) { + appInfo->GetVersion(mAppVersion); } else { - mAppVersion.AssignLiteral(MOZ_APP_UA_VERSION); + // Fall back to platform if appInfo is unavailable + mAppVersion.Assign(MOZILLA_UAVERSION); } + // If there's no override set, set it to the dynamic BuildID + if (mAppVersion.IsEmpty()) + mAppVersion.Assign(dynamicBuildID); + mSessionStartTime = NowInSeconds(); mHandlerActive = true; @@ -351,11 +374,11 @@ nsHttpHandler::Init() mRequestContextService = do_GetService("@mozilla.org/network/request-context-service;1"); -#if defined(ANDROID) || defined(MOZ_MULET) + // Goanna slice version mProductSub.AssignLiteral(MOZILLA_UAVERSION); -#else - mProductSub.AssignLiteral("20100101"); -#endif + + if (mProductSub.IsEmpty()) + mProductSub.Assign(dynamicBuildID); #if DEBUG // dump user agent prefs @@ -369,6 +392,7 @@ nsHttpHandler::Init() LOG(("> app-name = %s\n", mAppName.get())); LOG(("> app-version = %s\n", mAppVersion.get())); LOG(("> compat-firefox = %s\n", mCompatFirefox.get())); + LOG(("> compat-gecko = %s\n", mCompatGecko.get())); LOG(("> user-agent = %s\n", UserAgent().get())); #endif @@ -678,9 +702,10 @@ nsHttpHandler::BuildUserAgent() mAppName.Length() + mAppVersion.Length() + mCompatFirefox.Length() + + mCompatGecko.Length() + mCompatDevice.Length() + mDeviceModelId.Length() + - 13); + 14); // Application portion mUserAgent.Assign(mLegacyAppName); @@ -710,6 +735,12 @@ nsHttpHandler::BuildUserAgent() } mUserAgent += mMisc; mUserAgent += ')'; + + if(mCompatGeckoEnabled) { + // Provide frozen Gecko/20100101 slice + mUserAgent += ' '; + mUserAgent += mCompatGecko; + } // Product portion mUserAgent += ' '; @@ -719,7 +750,7 @@ nsHttpHandler::BuildUserAgent() bool isFirefox = mAppName.EqualsLiteral("Firefox"); if (isFirefox || mCompatFirefoxEnabled) { - // "Firefox/x.y" (compatibility) app token + // Provide "Firefox/x.y" (compatibility) app token mUserAgent += ' '; mUserAgent += mCompatFirefox; } @@ -966,6 +997,18 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref) bool cVar = false; + if (PREF_CHANGED(UA_PREF("appVersionIsBuildID"))) { + rv = prefs->GetBoolPref(UA_PREF("appVersionIsBuildID"), &cVar); + mAppVersionIsBuildID = (NS_SUCCEEDED(rv) && cVar); + mUserAgentIsDirty = true; + } + + if (PREF_CHANGED(UA_PREF("compatMode.gecko"))) { + rv = prefs->GetBoolPref(UA_PREF("compatMode.gecko"), &cVar); + mCompatGeckoEnabled = (NS_SUCCEEDED(rv) && cVar); + mUserAgentIsDirty = true; + } + if (PREF_CHANGED(UA_PREF("compatMode.firefox"))) { rv = prefs->GetBoolPref(UA_PREF("compatMode.firefox"), &cVar); mCompatFirefoxEnabled = (NS_SUCCEEDED(rv) && cVar); |