Bug 747990: Add ability to specify the "application name" used in the user agent in application.ini, r=bsmedberg
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -286,17 +286,21 @@ nsHttpHandler::Init()
mMisc.AssignLiteral("rv:" MOZILLA_UAVERSION);
nsCOMPtr<nsIXULAppInfo> appInfo =
do_GetService("@mozilla.org/xre/app-info;1");
mAppName.AssignLiteral(MOZ_APP_UA_NAME);
if (mAppName.Length() == 0 && appInfo) {
- appInfo->GetName(mAppName);
+ // Try to get the UA name from appInfo, falling back to the name
+ appInfo->GetUAName(mAppName);
+ if (mAppName.Length() == 0) {
+ appInfo->GetName(mAppName);
+ }
appInfo->GetVersion(mAppVersion);
mAppName.StripChars(" ()<>@,;:\\\"/[]?={}");
} else {
mAppVersion.AssignLiteral(MOZ_APP_UA_VERSION);
}
#if DEBUG
// dump user agent prefs
--- a/toolkit/xre/nsAppData.cpp
+++ b/toolkit/xre/nsAppData.cpp
@@ -86,16 +86,20 @@ ScopedAppData::ScopedAppData(const nsXRE
SetStrongPtr(this->xreDirectory, aAppData->xreDirectory);
SetAllocatedString(this->minVersion, aAppData->minVersion);
SetAllocatedString(this->maxVersion, aAppData->maxVersion);
}
if (aAppData->size > offsetof(nsXREAppData, crashReporterURL)) {
SetAllocatedString(this->crashReporterURL, aAppData->crashReporterURL);
}
+
+ if (aAppData->size > offsetof(nsXREAppData, UAName)) {
+ SetAllocatedString(this->UAName, aAppData->UAName);
+ }
}
ScopedAppData::~ScopedAppData()
{
SetAllocatedString(this->vendor, nsnull);
SetAllocatedString(this->name, nsnull);
SetAllocatedString(this->version, nsnull);
SetAllocatedString(this->buildID, nsnull);
@@ -105,16 +109,17 @@ ScopedAppData::~ScopedAppData()
NS_IF_RELEASE(this->directory);
SetStrongPtr(this->xreDirectory, (nsILocalFile*) nsnull);
SetAllocatedString(this->minVersion, nsnull);
SetAllocatedString(this->maxVersion, nsnull);
SetAllocatedString(this->crashReporterURL, nsnull);
+ SetAllocatedString(this->UAName, nsnull);
}
nsresult
XRE_CreateAppData(nsILocalFile* aINIFile, nsXREAppData **aAppData)
{
NS_ENSURE_ARG(aINIFile && aAppData);
nsAutoPtr<ScopedAppData> data(new ScopedAppData());
@@ -239,16 +244,24 @@ XRE_ParseAppData(nsILocalFile* aINIFile,
ReadStrings(parser, strings3);
ReadFlag flags2[] = {
{ "Crash Reporter", "Enabled", NS_XRE_ENABLE_CRASH_REPORTER },
{ nsnull }
};
ReadFlags(parser, flags2, &aAppData->flags);
}
+ if (aAppData->size > offsetof(nsXREAppData, UAName)) {
+ ReadString strings4[] = {
+ { "App", "UAName", &aAppData->UAName },
+ { nsnull }
+ };
+ ReadStrings(parser, strings4);
+ }
+
return NS_OK;
}
void
XRE_FreeAppData(nsXREAppData *aAppData)
{
if (!aAppData) {
NS_ERROR("Invalid arg");
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -709,16 +709,28 @@ NS_IMETHODIMP
nsXULAppInfo::GetPlatformBuildID(nsACString& aResult)
{
aResult.Assign(gToolkitBuildID);
return NS_OK;
}
NS_IMETHODIMP
+nsXULAppInfo::GetUAName(nsACString& aResult)
+{
+ if (XRE_GetProcessType() == GeckoProcessType_Content) {
+ NS_WARNING("Attempt to get unavailable information in content process.");
+ return NS_ERROR_NOT_AVAILABLE;
+ }
+ aResult.Assign(gAppData->UAName);
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP
nsXULAppInfo::GetLogConsoleErrors(bool *aResult)
{
*aResult = gLogConsoleErrors;
return NS_OK;
}
NS_IMETHODIMP
nsXULAppInfo::SetLogConsoleErrors(bool aValue)
--- a/xpcom/build/nsXREAppData.h
+++ b/xpcom/build/nsXREAppData.h
@@ -143,16 +143,21 @@ struct nsXREAppData
* UAppData = $HOME[/$vendor]/$name
*
* If present, the 'profile' string will be used instead of the combination of
* vendor and name as follows:
*
* UAppData = $HOME/$profile
*/
const char *profile;
+
+ /**
+ * The application name to use in the User Agent string.
+ */
+ const char *UAName;
};
/**
* Indicates whether or not the profile migrator service may be
* invoked at startup when creating a profile.
*/
#define NS_XRE_ENABLE_PROFILE_MIGRATOR (1 << 1)
--- a/xpcom/system/nsIXULAppInfo.idl
+++ b/xpcom/system/nsIXULAppInfo.idl
@@ -81,9 +81,15 @@ interface nsIXULAppInfo : nsISupports
* The version of the XULRunner platform.
*/
readonly attribute ACString platformVersion;
/**
* The build ID/date of gecko and the XULRunner platform.
*/
readonly attribute ACString platformBuildID;
+
+ /**
+ * @see nsXREAppData.UAName
+ * @returns an empty string if nsXREAppData.UAName is not set.
+ */
+ readonly attribute ACString UAName;
};