Bug 581008 - Remove support for appending arbitrary data to the User Agent string. r=jst,khuey sr=dveditz

This commit is contained in:
Dão Gottwald 2010-08-27 09:02:10 +02:00
parent c570e41da2
commit ff02b582e2
12 changed files with 77 additions and 192 deletions

View File

@ -59,8 +59,6 @@ DEFINES += -DAB_CD=$(AB_CD)
APP_VERSION = $(shell cat $(srcdir)/../config/version.txt)
DEFINES += -DAPP_VERSION="$(APP_VERSION)"
APP_UA_NAME = $(shell echo $(MOZ_APP_DISPLAYNAME) | sed -e's/[^A-Za-z]//g')
DEFINES += -DAPP_UA_NAME="$(APP_UA_NAME)"
DIST_FILES = application.ini

View File

@ -191,7 +191,6 @@ pref("keyword.URL", "");
pref("general.useragent.locale", "@AB_CD@");
pref("general.skins.selectedSkin", "classic/1.0");
pref("general.useragent.extra.firefox", "@APP_UA_NAME@/@APP_VERSION@");
pref("general.smoothScroll", false);
#ifdef UNIX_BUT_NOT_MAC

View File

@ -1 +1,2 @@
MOZ_APP_DISPLAYNAME=Minefield
MOZ_APP_UA_NAME=Minefield

View File

@ -1 +1,2 @@
MOZ_APP_DISPLAYNAME="MozillaDeveloperPreview"
MOZ_APP_UA_NAME="MozillaDeveloperPreview"

View File

@ -50,8 +50,8 @@ FIREFOX_VERSION = @FIREFOX_VERSION@
MOZ_BUILD_APP = @MOZ_BUILD_APP@
MOZ_APP_NAME = @MOZ_APP_NAME@
MOZ_APP_DISPLAYNAME = @MOZ_APP_DISPLAYNAME@
MOZ_APP_UA_NAME = @MOZ_APP_UA_NAME@
MOZ_APP_VERSION = @MOZ_APP_VERSION@
MOZ_APP_UA_EXTRA = @MOZ_APP_UA_EXTRA@
MOZ_PKG_SPECIAL = @MOZ_PKG_SPECIAL@

View File

@ -8767,8 +8767,11 @@ AC_SUBST(OGLES_SDK_DIR)
AC_SUBST(MOZ_APP_NAME)
AC_SUBST(MOZ_APP_DISPLAYNAME)
AC_DEFINE_UNQUOTED(MOZ_APP_UA_NAME, "$MOZ_APP_UA_NAME")
AC_SUBST(MOZ_APP_UA_NAME)
AC_DEFINE_UNQUOTED(MOZ_APP_VERSION, "$MOZ_APP_VERSION")
AC_SUBST(MOZ_APP_VERSION)
AC_SUBST(MOZ_APP_UA_EXTRA)
AC_DEFINE_UNQUOTED(FIREFOX_VERSION, "$FIREFOX_VERSION")
AC_SUBST(FIREFOX_VERSION)
AC_SUBST(MOZ_PKG_SPECIAL)

View File

@ -5064,7 +5064,9 @@ AC_SUBST(WINCE_WINDOWS_MOBILE)
AC_SUBST(MOZ_APP_NAME)
AC_SUBST(MOZ_APP_DISPLAYNAME)
AC_SUBST(MOZ_APP_UA_NAME)
AC_SUBST(MOZ_APP_VERSION)
AC_SUBST(FIREFOX_VERSION)
AC_SUBST(MOZ_PKG_SPECIAL)

View File

@ -353,8 +353,8 @@ function BuildConditionSandbox(aURL) {
getService(CI.nsIHttpProtocolHandler);
sandbox.http = {};
for each (var prop in [ "userAgent", "appName", "appVersion",
"vendor", "vendorSub", "vendorComment",
"product", "productSub", "productComment",
"vendor", "vendorSub",
"product", "productSub",
"platform", "oscpu", "language", "misc" ])
sandbox.http[prop] = hh[prop];
// see if we have the test plugin available,

View File

@ -50,6 +50,7 @@
pref("keyword.URL", "http://www.google.com/search?ie=UTF-8&oe=utf-8&q=");
pref("keyword.enabled", false);
pref("general.useragent.locale", "chrome://global/locale/intl.properties");
pref("general.useragent.compatMode.firefox", false);
pref("general.config.obscure_value", 13); // for MCD .cfg files

View File

@ -30,6 +30,7 @@
* Bradley Baetz <bbaetz@netscape.com>
* Benjamin Smedberg <bsmedberg@covad.net>
* Josh Aas <josh@mozilla.com>
* Dão Gottwald <dao@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -119,8 +120,6 @@ static NS_DEFINE_CID(kCacheServiceCID, NS_CACHESERVICE_CID);
static NS_DEFINE_CID(kSocketProviderServiceCID, NS_SOCKETPROVIDERSERVICE_CID);
#define UA_PREF_PREFIX "general.useragent."
#define UA_APPNAME "Mozilla"
#define UA_APPVERSION "5.0"
#ifdef XP_WIN
#define UA_SPARE_PLATFORM
#endif
@ -191,6 +190,8 @@ nsHttpHandler::nsHttpHandler()
, mLastUniqueID(NowInSeconds())
, mSessionStartTime(0)
, mProduct("Gecko")
, mLegacyAppName("Mozilla")
, mLegacyAppVersion("5.0")
, mUserAgentIsDirty(PR_TRUE)
, mUseCache(PR_TRUE)
, mPromptTempRedirect(PR_TRUE)
@ -275,21 +276,32 @@ nsHttpHandler::Init()
mMisc.AssignLiteral("rv:" MOZILLA_VERSION);
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);
appInfo->GetVersion(mAppVersion);
} else {
mAppVersion.AssignLiteral(MOZ_APP_VERSION);
}
#if DEBUG
// dump user agent prefs
LOG(("> app-name = %s\n", mAppName.get()));
LOG(("> app-version = %s\n", mAppVersion.get()));
LOG(("> legacy-app-name = %s\n", mLegacyAppName.get()));
LOG(("> legacy-app-version = %s\n", mLegacyAppVersion.get()));
LOG(("> platform = %s\n", mPlatform.get()));
LOG(("> oscpu = %s\n", mOscpu.get()));
LOG(("> language = %s\n", mLanguage.get()));
LOG(("> misc = %s\n", mMisc.get()));
LOG(("> vendor = %s\n", mVendor.get()));
LOG(("> vendor-sub = %s\n", mVendorSub.get()));
LOG(("> vendor-comment = %s\n", mVendorComment.get()));
LOG(("> extra = %s\n", mExtraUA.get()));
LOG(("> product = %s\n", mProduct.get()));
LOG(("> product-sub = %s\n", mProductSub.get()));
LOG(("> product-comment = %s\n", mProductComment.get()));
LOG(("> app-name = %s\n", mAppName.get()));
LOG(("> app-version = %s\n", mAppVersion.get()));
LOG(("> compat-firefox = %s\n", mCompatFirefox.get()));
LOG(("> user-agent = %s\n", UserAgent().get()));
#endif
@ -301,8 +313,6 @@ nsHttpHandler::Init()
rv = InitConnectionMgr();
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIXULAppInfo> appInfo =
do_GetService("@mozilla.org/xre/app-info;1");
if (appInfo)
appInfo->GetPlatformBuildID(mProductSub);
if (mProductSub.Length() > 8)
@ -602,16 +612,16 @@ nsHttpHandler::BuildUserAgent()
{
LOG(("nsHttpHandler::BuildUserAgent\n"));
NS_ASSERTION(!mAppName.IsEmpty() &&
!mAppVersion.IsEmpty() &&
NS_ASSERTION(!mLegacyAppName.IsEmpty() &&
!mLegacyAppVersion.IsEmpty() &&
!mPlatform.IsEmpty() &&
!mOscpu.IsEmpty(),
"HTTP cannot send practical requests without this much");
// preallocate to worst-case size, which should always be better
// than if we didn't preallocate at all.
mUserAgent.SetCapacity(mAppName.Length() +
mAppVersion.Length() +
mUserAgent.SetCapacity(mLegacyAppName.Length() +
mLegacyAppVersion.Length() +
#ifndef UA_SPARE_PLATFORM
mPlatform.Length() +
#endif
@ -619,17 +629,17 @@ nsHttpHandler::BuildUserAgent()
mMisc.Length() +
mProduct.Length() +
mProductSub.Length() +
mProductComment.Length() +
mVendor.Length() +
mVendorSub.Length() +
mVendorComment.Length() +
mExtraUA.Length() +
22);
mAppName.Length() +
mAppVersion.Length() +
mCompatFirefox.Length() +
15);
// Application portion
mUserAgent.Assign(mAppName);
mUserAgent.Assign(mLegacyAppName);
mUserAgent += '/';
mUserAgent += mAppVersion;
mUserAgent += mLegacyAppVersion;
mUserAgent += ' ';
// Application comment
@ -639,26 +649,15 @@ nsHttpHandler::BuildUserAgent()
mUserAgent.AppendLiteral("; ");
#endif
mUserAgent += mOscpu;
if (!mMisc.IsEmpty()) {
mUserAgent.AppendLiteral("; ");
mUserAgent += mMisc;
}
mUserAgent.AppendLiteral("; ");
mUserAgent += mMisc;
mUserAgent += ')';
// Product portion
if (!mProduct.IsEmpty()) {
mUserAgent += ' ';
mUserAgent += mProduct;
if (!mProductSub.IsEmpty()) {
mUserAgent += '/';
mUserAgent += mProductSub;
}
if (!mProductComment.IsEmpty()) {
mUserAgent.AppendLiteral(" (");
mUserAgent += mProductComment;
mUserAgent += ')';
}
}
mUserAgent += ' ';
mUserAgent += mProduct;
mUserAgent += '/';
mUserAgent += mProductSub;
// Vendor portion
if (!mVendor.IsEmpty()) {
@ -668,15 +667,17 @@ nsHttpHandler::BuildUserAgent()
mUserAgent += '/';
mUserAgent += mVendorSub;
}
if (!mVendorComment.IsEmpty()) {
mUserAgent.AppendLiteral(" (");
mUserAgent += mVendorComment;
mUserAgent += ')';
}
}
if (!mExtraUA.IsEmpty())
mUserAgent += mExtraUA;
mUserAgent += ' ';
mUserAgent += mAppName;
mUserAgent += '/';
mUserAgent += mAppVersion;
if (!mCompatFirefox.IsEmpty()) {
mUserAgent += ' ';
mUserAgent += mCompatFirefox;
}
}
#ifdef XP_WIN
@ -827,22 +828,6 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
// UA components
//
// Gather application values.
if (PREF_CHANGED(UA_PREF("appName"))) {
prefs->GetCharPref(UA_PREF("appName"),
getter_Copies(mAppName));
if (mAppName.IsEmpty())
mAppName.AssignLiteral(UA_APPNAME);
mUserAgentIsDirty = PR_TRUE;
}
if (PREF_CHANGED(UA_PREF("appVersion"))) {
prefs->GetCharPref(UA_PREF("appVersion"),
getter_Copies(mAppVersion));
if (mAppVersion.IsEmpty())
mAppVersion.AssignLiteral(UA_APPVERSION);
mUserAgentIsDirty = PR_TRUE;
}
// Gather vendor values.
if (PREF_CHANGED(UA_PREF("vendor"))) {
prefs->GetCharPref(UA_PREF("vendor"),
@ -854,46 +839,16 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
getter_Copies(mVendorSub));
mUserAgentIsDirty = PR_TRUE;
}
if (PREF_CHANGED(UA_PREF("vendorComment"))) {
prefs->GetCharPref(UA_PREF("vendorComment"),
getter_Copies(mVendorComment));
mUserAgentIsDirty = PR_TRUE;
}
if (MULTI_PREF_CHANGED(UA_PREF("extra."))) {
mExtraUA.Truncate();
PRBool cVar = PR_FALSE;
// Unfortunately, we can't do this using the pref branch.
nsCOMPtr<nsIPrefService> service =
do_GetService(NS_PREFSERVICE_CONTRACTID);
nsCOMPtr<nsIPrefBranch> branch;
service->GetBranch(UA_PREF("extra."), getter_AddRefs(branch));
if (branch) {
PRUint32 extraCount;
char **extraItems;
rv = branch->GetChildList("", &extraCount, &extraItems);
if (NS_SUCCEEDED(rv) && extraItems) {
NS_QuickSort(extraItems, extraCount, sizeof(extraItems[0]),
StringCompare, nsnull);
for (char **item = extraItems,
**item_end = extraItems + extraCount;
item < item_end; ++item) {
nsXPIDLCString valStr;
branch->GetCharPref(*item, getter_Copies(valStr));
if (!valStr.IsEmpty())
mExtraUA += NS_LITERAL_CSTRING(" ") + valStr;
}
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(extraCount, extraItems);
}
if (PREF_CHANGED(UA_PREF("compatMode.firefox"))) {
rv = prefs->GetBoolPref(UA_PREF("compatMode.firefox"), &cVar);
if (NS_SUCCEEDED(rv) && cVar) {
mCompatFirefox.AssignLiteral("Firefox/" FIREFOX_VERSION);
} else {
mCompatFirefox.Truncate();
}
mUserAgentIsDirty = PR_TRUE;
}
// Gather product values.
if (PREF_CHANGED(UA_PREF("productComment"))) {
prefs->GetCharPref(UA_PREF("productComment"),
getter_Copies(mProductComment));
mUserAgentIsDirty = PR_TRUE;
}
@ -1032,8 +987,6 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
}
}
PRBool cVar = PR_FALSE;
if (PREF_CHANGED(HTTP_PREF("keep-alive"))) {
rv = prefs->GetBoolPref(HTTP_PREF("keep-alive"), &cVar);
if (NS_SUCCEEDED(rv)) {
@ -1607,14 +1560,14 @@ nsHttpHandler::GetUserAgent(nsACString &value)
NS_IMETHODIMP
nsHttpHandler::GetAppName(nsACString &value)
{
value = mAppName;
value = mLegacyAppName;
return NS_OK;
}
NS_IMETHODIMP
nsHttpHandler::GetAppVersion(nsACString &value)
{
value = mAppVersion;
value = mLegacyAppVersion;
return NS_OK;
}
@ -1624,13 +1577,6 @@ nsHttpHandler::GetVendor(nsACString &value)
value = mVendor;
return NS_OK;
}
NS_IMETHODIMP
nsHttpHandler::SetVendor(const nsACString &value)
{
mVendor = value;
mUserAgentIsDirty = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
nsHttpHandler::GetVendorSub(nsACString &value)
@ -1638,27 +1584,6 @@ nsHttpHandler::GetVendorSub(nsACString &value)
value = mVendorSub;
return NS_OK;
}
NS_IMETHODIMP
nsHttpHandler::SetVendorSub(const nsACString &value)
{
mVendorSub = value;
mUserAgentIsDirty = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
nsHttpHandler::GetVendorComment(nsACString &value)
{
value = mVendorComment;
return NS_OK;
}
NS_IMETHODIMP
nsHttpHandler::SetVendorComment(const nsACString &value)
{
mVendorComment = value;
mUserAgentIsDirty = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
nsHttpHandler::GetProduct(nsACString &value)
@ -1666,13 +1591,6 @@ nsHttpHandler::GetProduct(nsACString &value)
value = mProduct;
return NS_OK;
}
NS_IMETHODIMP
nsHttpHandler::SetProduct(const nsACString &value)
{
mProduct = value;
mUserAgentIsDirty = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
nsHttpHandler::GetProductSub(nsACString &value)
@ -1680,27 +1598,6 @@ nsHttpHandler::GetProductSub(nsACString &value)
value = mProductSub;
return NS_OK;
}
NS_IMETHODIMP
nsHttpHandler::SetProductSub(const nsACString &value)
{
mProductSub = value;
mUserAgentIsDirty = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
nsHttpHandler::GetProductComment(nsACString &value)
{
value = mProductComment;
return NS_OK;
}
NS_IMETHODIMP
nsHttpHandler::SetProductComment(const nsACString &value)
{
mProductComment = value;
mUserAgentIsDirty = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
nsHttpHandler::GetPlatform(nsACString &value)
@ -1729,13 +1626,6 @@ nsHttpHandler::GetMisc(nsACString &value)
value = mMisc;
return NS_OK;
}
NS_IMETHODIMP
nsHttpHandler::SetMisc(const nsACString &value)
{
mMisc = value;
mUserAgentIsDirty = PR_TRUE;
return NS_OK;
}
//-----------------------------------------------------------------------------
// nsHttpHandler::nsIObserver

View File

@ -303,19 +303,19 @@ private:
PRUint32 mSessionStartTime;
// useragent components
nsXPIDLCString mAppName;
nsXPIDLCString mAppVersion;
nsCString mLegacyAppName;
nsCString mLegacyAppVersion;
nsCString mPlatform;
nsCString mOscpu;
nsCString mLanguage;
nsCString mMisc;
nsXPIDLCString mVendor;
nsXPIDLCString mVendorSub;
nsXPIDLCString mVendorComment;
nsCString mProduct;
nsXPIDLCString mProductSub;
nsXPIDLCString mProductComment;
nsCString mExtraUA;
nsXPIDLCString mAppName;
nsXPIDLCString mAppVersion;
nsCString mCompatFirefox;
nsCString mUserAgent;
nsXPIDLCString mUserAgentOverride;

View File

@ -39,7 +39,7 @@
#include "nsIProxiedProtocolHandler.idl"
[scriptable, uuid(cf549f80-9423-11df-981c-0800200c9a66)]
[scriptable, uuid(36709064-d2c8-40cb-b754-d30d970be639)]
interface nsIHttpProtocolHandler : nsIProxiedProtocolHandler
{
/**
@ -64,32 +64,22 @@ interface nsIHttpProtocolHandler : nsIProxiedProtocolHandler
/**
* @return The vendor name.
*/
attribute ACString vendor;
readonly attribute ACString vendor;
/**
* @return The vendor sub string.
*/
attribute ACString vendorSub;
/**
* @return The vendor comment.
*/
attribute ACString vendorComment;
readonly attribute ACString vendorSub;
/**
* @return The product name.
*/
attribute ACString product;
readonly attribute ACString product;
/**
* @return A product sub string.
*/
attribute ACString productSub;
/**
* @return A product comment.
*/
attribute ACString productComment;
readonly attribute ACString productSub;
/**
* Get the current platform.
@ -114,9 +104,9 @@ interface nsIHttpProtocolHandler : nsIProxiedProtocolHandler
readonly attribute ACString language;
/**
* Get/Set the application comment misc portion.
* Get the application comment misc portion.
*/
attribute ACString misc;
readonly attribute ACString misc;
};