From ff02b582e24cd1b0ffef332d80e778275c24a091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A3o=20Gottwald?= Date: Fri, 27 Aug 2010 09:02:10 +0200 Subject: [PATCH] Bug 581008 - Remove support for appending arbitrary data to the User Agent string. r=jst,khuey sr=dveditz --- browser/app/Makefile.in | 2 - browser/app/profile/firefox.js | 1 - browser/branding/nightly/configure.sh | 1 + browser/branding/unofficial/configure.sh | 1 + config/autoconf.mk.in | 2 +- configure.in | 5 +- js/src/configure.in | 2 + layout/tools/reftest/reftest.js | 4 +- modules/libpref/src/init/all.js | 1 + netwerk/protocol/http/nsHttpHandler.cpp | 216 +++++------------- netwerk/protocol/http/nsHttpHandler.h | 10 +- .../protocol/http/nsIHttpProtocolHandler.idl | 24 +- 12 files changed, 77 insertions(+), 192 deletions(-) diff --git a/browser/app/Makefile.in b/browser/app/Makefile.in index 4f791f04e9b..43eab50cf34 100644 --- a/browser/app/Makefile.in +++ b/browser/app/Makefile.in @@ -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 diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js index 02fec7463eb..ecfd4fc93ac 100644 --- a/browser/app/profile/firefox.js +++ b/browser/app/profile/firefox.js @@ -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 diff --git a/browser/branding/nightly/configure.sh b/browser/branding/nightly/configure.sh index 8b5d27695d8..4c12175e5a7 100644 --- a/browser/branding/nightly/configure.sh +++ b/browser/branding/nightly/configure.sh @@ -1 +1,2 @@ MOZ_APP_DISPLAYNAME=Minefield +MOZ_APP_UA_NAME=Minefield diff --git a/browser/branding/unofficial/configure.sh b/browser/branding/unofficial/configure.sh index 21e080c7169..d5d00b6196b 100644 --- a/browser/branding/unofficial/configure.sh +++ b/browser/branding/unofficial/configure.sh @@ -1 +1,2 @@ MOZ_APP_DISPLAYNAME="MozillaDeveloperPreview" +MOZ_APP_UA_NAME="MozillaDeveloperPreview" diff --git a/config/autoconf.mk.in b/config/autoconf.mk.in index 5df7881de0e..a487e7a640a 100644 --- a/config/autoconf.mk.in +++ b/config/autoconf.mk.in @@ -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@ diff --git a/configure.in b/configure.in index ba57576a5bc..87c1e9cb558 100644 --- a/configure.in +++ b/configure.in @@ -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) diff --git a/js/src/configure.in b/js/src/configure.in index 402c77717ff..43f66c0d318 100644 --- a/js/src/configure.in +++ b/js/src/configure.in @@ -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) diff --git a/layout/tools/reftest/reftest.js b/layout/tools/reftest/reftest.js index a6440daee6e..b7328c68f33 100644 --- a/layout/tools/reftest/reftest.js +++ b/layout/tools/reftest/reftest.js @@ -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, diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js index 0197cc9f49f..da45e4e868a 100644 --- a/modules/libpref/src/init/all.js +++ b/modules/libpref/src/init/all.js @@ -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 diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp index cc202c7c644..e216ed495a5 100644 --- a/netwerk/protocol/http/nsHttpHandler.cpp +++ b/netwerk/protocol/http/nsHttpHandler.cpp @@ -30,6 +30,7 @@ * Bradley Baetz * Benjamin Smedberg * Josh Aas + * Dão Gottwald * * 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 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 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 service = - do_GetService(NS_PREFSERVICE_CONTRACTID); - nsCOMPtr 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 diff --git a/netwerk/protocol/http/nsHttpHandler.h b/netwerk/protocol/http/nsHttpHandler.h index 0c3c5f538d1..f7af20cad6c 100644 --- a/netwerk/protocol/http/nsHttpHandler.h +++ b/netwerk/protocol/http/nsHttpHandler.h @@ -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; diff --git a/netwerk/protocol/http/nsIHttpProtocolHandler.idl b/netwerk/protocol/http/nsIHttpProtocolHandler.idl index 127dd0ec3f0..9a575790579 100644 --- a/netwerk/protocol/http/nsIHttpProtocolHandler.idl +++ b/netwerk/protocol/http/nsIHttpProtocolHandler.idl @@ -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; };