summaryrefslogtreecommitdiffstats
path: root/netwerk
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2020-04-05 11:48:09 +0200
committerwolfbeast <mcwerewolf@wolfbeast.com>2020-04-05 11:48:09 +0200
commitd0cf67573ca6d69c9f00c7e9a70a64158fbca304 (patch)
treeb5f82e2f921cc61ae47950184851b624cdcbddf4 /netwerk
parentfd5e25ff472b3fd106c7028b150a637bd86e164f (diff)
downloadUXP-d0cf67573ca6d69c9f00c7e9a70a64158fbca304.tar
UXP-d0cf67573ca6d69c9f00c7e9a70a64158fbca304.tar.gz
UXP-d0cf67573ca6d69c9f00c7e9a70a64158fbca304.tar.lz
UXP-d0cf67573ca6d69c9f00c7e9a70a64158fbca304.tar.xz
UXP-d0cf67573ca6d69c9f00c7e9a70a64158fbca304.zip
Issue #1505 - Rebuild application version string
To respond dynamically to the pref change, the mAppVersion string needs to be rebuilt. Includes some minor improvements for corner cases and removes leftover b2g junk.
Diffstat (limited to 'netwerk')
-rw-r--r--netwerk/protocol/http/nsHttpHandler.cpp82
-rw-r--r--netwerk/protocol/http/nsHttpHandler.h1
2 files changed, 46 insertions, 37 deletions
diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp
index 32e50712f..cb3c7ae04 100644
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -310,28 +310,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;
@@ -350,8 +331,15 @@ nsHttpHandler::Init()
// Goanna slice version
mProductSub.AssignLiteral(MOZILLA_UAVERSION);
- if (mProductSub.IsEmpty())
- mProductSub.Assign(dynamicBuildID);
+ if (mProductSub.IsEmpty()) {
+ nsCString dynamicBuildID;
+ if (appInfo) {
+ appInfo->GetPlatformBuildID(dynamicBuildID);
+ if (dynamicBuildID.Length() > 8 )
+ dynamicBuildID.Left(dynamicBuildID, 8);
+ }
+ mProductSub.Assign(dynamicBuildID);
+ }
#if DEBUG
// dump user agent prefs
@@ -657,6 +645,37 @@ nsHttpHandler::GenerateHostPort(const nsCString& host, int32_t port,
// nsHttpHandler <private>
//-----------------------------------------------------------------------------
+void
+nsHttpHandler::BuildAppVersion()
+{
+ 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);
+ }
+
+ if (mAppVersionIsBuildID) {
+ // Override BuildID
+ mAppVersion.Assign(dynamicBuildID);
+ } 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()
{
@@ -782,21 +801,6 @@ nsHttpHandler::InitUserAgentComponents()
);
#endif
-
-#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)
@@ -924,6 +928,10 @@ 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;
}
diff --git a/netwerk/protocol/http/nsHttpHandler.h b/netwerk/protocol/http/nsHttpHandler.h
index 402147577..36fda6ace 100644
--- a/netwerk/protocol/http/nsHttpHandler.h
+++ b/netwerk/protocol/http/nsHttpHandler.h
@@ -391,6 +391,7 @@ private:
//
// Useragent/prefs helper methods
//
+ void BuildAppVersion();
void BuildUserAgent();
void InitUserAgentComponents();
void PrefsChanged(nsIPrefBranch *prefs, const char *pref);