summaryrefslogtreecommitdiffstats
path: root/netwerk/protocol/http/nsHttpHandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'netwerk/protocol/http/nsHttpHandler.cpp')
-rw-r--r--netwerk/protocol/http/nsHttpHandler.cpp203
1 files changed, 79 insertions, 124 deletions
diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp
index 0f4c94202..7a29e041b 100644
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -127,30 +127,6 @@ NewURI(const nsACString &aSpec,
return NS_OK;
}
-#ifdef ANDROID
-static nsCString
-GetDeviceModelId() {
- // Assumed to be running on the main thread
- // We need the device property in either case
- nsAutoCString deviceModelId;
- nsCOMPtr<nsIPropertyBag2> infoService = do_GetService("@mozilla.org/system-info;1");
- MOZ_ASSERT(infoService, "Could not find a system info service");
- nsAutoString androidDevice;
- nsresult rv = infoService->GetPropertyAsAString(NS_LITERAL_STRING("device"), androidDevice);
- if (NS_SUCCEEDED(rv)) {
- deviceModelId = NS_LossyConvertUTF16toASCII(androidDevice);
- }
- nsAutoCString deviceString;
- rv = Preferences::GetCString(UA_PREF("device_string"), &deviceString);
- if (NS_SUCCEEDED(rv)) {
- deviceString.Trim(" ", true, true);
- deviceString.ReplaceSubstring(NS_LITERAL_CSTRING("%DEVICEID%"), deviceModelId);
- return deviceString;
- }
- return deviceModelId;
-}
-#endif
-
//-----------------------------------------------------------------------------
// nsHttpHandler <public>
//-----------------------------------------------------------------------------
@@ -198,8 +174,10 @@ nsHttpHandler::nsHttpHandler()
, mLegacyAppName("Mozilla")
, mLegacyAppVersion("5.0")
, mProduct("Goanna")
+ , mCompatGeckoEnabled(false)
+ , mAppBuildID("20200101")
, mCompatFirefoxEnabled(false)
- , mCompatFirefoxVersion("52.9")
+ , mCompatFirefoxVersion("68.9")
, mUserAgentIsDirty(true)
, mAcceptLanguagesIsDirty(true)
, mPromptTempRedirect(true)
@@ -315,8 +293,13 @@ nsHttpHandler::Init()
nsHttpChannelAuthProvider::InitializePrefs();
// rv: should have the Firefox/Gecko compatversion for web compatibility
+ // when in either compatmodes
mMisc.AssignLiteral("rv:");
- mMisc += mCompatFirefoxVersion;
+ if (mCompatGeckoEnabled) {
+ mMisc += mCompatFirefoxVersion;
+ } else {
+ mMisc += MOZILLA_UAVERSION;
+ }
mCompatGecko.AssignLiteral("Gecko/20100101");
mCompatFirefox.AssignLiteral("Firefox/");
@@ -325,6 +308,14 @@ nsHttpHandler::Init()
nsCOMPtr<nsIXULAppInfo> appInfo =
do_GetService("@mozilla.org/xre/app-info;1");
+ nsCString dynamicBuildID;
+ if (appInfo) {
+ appInfo->GetPlatformBuildID(dynamicBuildID);
+ if (dynamicBuildID.Length() > 8 )
+ dynamicBuildID.Left(dynamicBuildID, 8);
+ }
+ mAppBuildID.Assign(dynamicBuildID);
+
mAppName.AssignLiteral(MOZ_APP_UA_NAME);
if (mAppName.Length() == 0 && appInfo) {
// Try to get the UA name from appInfo, falling back to the name
@@ -334,28 +325,9 @@ nsHttpHandler::Init()
}
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 {
- // Fall back to platform if appInfo is unavailable
- mAppVersion.AssignLiteral(MOZILLA_UAVERSION);
- }
+ BuildAppVersion();
- // If there's no override set, set it to the dynamic BuildID
- if (mAppVersion.IsEmpty())
- mAppVersion.Assign(dynamicBuildID);
-
mSessionStartTime = NowInSeconds();
mHandlerActive = true;
@@ -372,10 +344,15 @@ nsHttpHandler::Init()
do_GetService("@mozilla.org/network/request-context-service;1");
// Goanna slice version
- mProductSub.AssignLiteral(MOZILLA_UAVERSION);
-
- if (mProductSub.IsEmpty())
- mProductSub.Assign(dynamicBuildID);
+ if (mCompatGeckoEnabled) {
+ mProductSub.AssignLiteral(MOZILLA_UAVERSION);
+ } else {
+ mProductSub.Assign(mAppBuildID);
+ }
+ // In case MOZILLA_UAVERSION is empty for some odd reason...
+ if (mProductSub.IsEmpty()) {
+ mProductSub.Assign(mAppBuildID);
+ }
#if DEBUG
// dump user agent prefs
@@ -681,6 +658,30 @@ nsHttpHandler::GenerateHostPort(const nsCString& host, int32_t port,
// nsHttpHandler <private>
//-----------------------------------------------------------------------------
+void
+nsHttpHandler::BuildAppVersion()
+{
+ nsCOMPtr<nsIXULAppInfo> appInfo = do_GetService("@mozilla.org/xre/app-info;1");
+
+ if (mAppVersionIsBuildID) {
+ // Override with BuildID
+ mAppVersion.Assign(mAppBuildID);
+ } else if (appInfo) {
+ appInfo->GetVersion(mAppVersion);
+ } else {
+ // Fall back to platform if appInfo is unavailable
+ mAppVersion.AssignLiteral(MOZILLA_UAVERSION);
+ }
+
+ // If there's still no version set, set it to a fixed BuildID
+ if (mAppVersion.IsEmpty()) {
+ mAppVersion.AssignLiteral(MOZ_UA_BUILDID);
+ }
+ if (mAppVersion.IsEmpty()) {
+ mAppVersion.AssignLiteral("20200101");
+ }
+}
+
const nsAFlatCString &
nsHttpHandler::UserAgent()
{
@@ -792,9 +793,7 @@ nsHttpHandler::InitUserAgentComponents()
#ifndef MOZ_UA_OS_AGNOSTIC
// Gather platform.
mPlatform.AssignLiteral(
-#if defined(ANDROID)
- "Android"
-#elif defined(XP_WIN)
+#if defined(XP_WIN)
"Windows"
#elif defined(XP_MACOSX)
"Macintosh"
@@ -808,64 +807,6 @@ nsHttpHandler::InitUserAgentComponents()
);
#endif
-
-#ifdef ANDROID
- nsCOMPtr<nsIPropertyBag2> infoService = do_GetService("@mozilla.org/system-info;1");
- MOZ_ASSERT(infoService, "Could not find a system info service");
- nsresult rv;
- // Add the Android version number to the Fennec platform identifier.
-#if defined MOZ_WIDGET_ANDROID
-#ifndef MOZ_UA_OS_AGNOSTIC // Don't add anything to mPlatform since it's empty.
- nsAutoString androidVersion;
- rv = infoService->GetPropertyAsAString(
- NS_LITERAL_STRING("release_version"), androidVersion);
- if (NS_SUCCEEDED(rv)) {
- mPlatform += " ";
- // If the 2nd character is a ".", we know the major version is a single
- // digit. If we're running on a version below 4 we pretend to be on
- // Android KitKat (4.4) to work around scripts sniffing for low versions.
- if (androidVersion[1] == 46 && androidVersion[0] < 52) {
- mPlatform += "4.4";
- } else {
- mPlatform += NS_LossyConvertUTF16toASCII(androidVersion);
- }
- }
-#endif
-#endif
- // Add the `Mobile` or `Tablet` or `TV` token when running on device.
- bool isTablet;
- rv = infoService->GetPropertyAsBool(NS_LITERAL_STRING("tablet"), &isTablet);
- if (NS_SUCCEEDED(rv) && isTablet) {
- mCompatDevice.AssignLiteral("Tablet");
- } else {
- bool isTV;
- rv = infoService->GetPropertyAsBool(NS_LITERAL_STRING("tv"), &isTV);
- if (NS_SUCCEEDED(rv) && isTV) {
- mCompatDevice.AssignLiteral("TV");
- } else {
- mCompatDevice.AssignLiteral("Mobile");
- }
- }
-
- if (Preferences::GetBool(UA_PREF("use_device"), false)) {
- mDeviceModelId = mozilla::net::GetDeviceModelId();
- }
-#endif // ANDROID
-
-#ifdef MOZ_MULET
- {
- // Add the `Mobile` or `Tablet` or `TV` token when running in the b2g
- // desktop simulator via preference.
- nsCString deviceType;
- nsresult rv = Preferences::GetCString("devtools.useragent.device_type", &deviceType);
- if (NS_SUCCEEDED(rv)) {
- mCompatDevice.Assign(deviceType);
- } else {
- mCompatDevice.AssignLiteral("Mobile");
- }
- }
-#endif // MOZ_MULET
-
#ifndef MOZ_UA_OS_AGNOSTIC
// Gather OS/CPU.
#if defined(XP_WIN)
@@ -993,12 +934,34 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
if (PREF_CHANGED(UA_PREF("appVersionIsBuildID"))) {
rv = prefs->GetBoolPref(UA_PREF("appVersionIsBuildID"), &cVar);
mAppVersionIsBuildID = (NS_SUCCEEDED(rv) && cVar);
+
+ // Rebuild application version string.
+ BuildAppVersion();
+
mUserAgentIsDirty = true;
}
if (PREF_CHANGED(UA_PREF("compatMode.gecko"))) {
rv = prefs->GetBoolPref(UA_PREF("compatMode.gecko"), &cVar);
mCompatGeckoEnabled = (NS_SUCCEEDED(rv) && cVar);
+
+ // Rebuild rv: and Goanna slice version
+ mMisc.AssignLiteral("rv:");
+ if (mCompatGeckoEnabled) {
+ mMisc += mCompatFirefoxVersion;
+ } else {
+ mMisc += MOZILLA_UAVERSION;
+ }
+
+ if (mCompatGeckoEnabled) {
+ mProductSub.AssignLiteral(MOZILLA_UAVERSION);
+ } else {
+ mProductSub.Assign(mAppBuildID);
+ }
+ // In case MOZILLA_UAVERSION is empty for some odd reason...
+ if (mProductSub.IsEmpty()) {
+ mProductSub.Assign(mAppBuildID);
+ }
mUserAgentIsDirty = true;
}
@@ -1017,7 +980,11 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
// rebuild mMisc and compatMode slice
mMisc.AssignLiteral("rv:");
- mMisc += mCompatFirefoxVersion;
+ if (mCompatGeckoEnabled) {
+ mMisc += mCompatFirefoxVersion;
+ } else {
+ mMisc += MOZILLA_UAVERSION;
+ }
mCompatFirefox.AssignLiteral("Firefox/");
mCompatFirefox += mCompatFirefoxVersion;
@@ -1031,18 +998,6 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
mUserAgentIsDirty = true;
}
-#ifdef ANDROID
- // general.useragent.use_device
- if (PREF_CHANGED(UA_PREF("use_device"))) {
- if (Preferences::GetBool(UA_PREF("use_device"), false)) {
- mDeviceModelId = mozilla::net::GetDeviceModelId();
- } else {
- mDeviceModelId = EmptyCString();
- }
- mUserAgentIsDirty = true;
- }
-#endif
-
//
// HTTP options
//