From 11dd9028dcee3162d4d39a7870d930beeaee1705 Mon Sep 17 00:00:00 2001 From: Mark Finkle Date: Tue, 31 Jan 2012 20:04:23 -0800 Subject: [PATCH] Bug 671634 - Fennec UA changes. Useragent should be different between phones and tablets. r=me sr=bz a=gerv Please read http://groups.google.com/group/mozilla.dev.platform/msg/8133920a2ccf4d5b for the details. Also see https://wiki.mozilla.org/Fennec/User_Agent for Gerv's accepted proposal. --- mobile/android/app/mobile.js | 1 - mobile/android/confvars.sh | 1 + netwerk/protocol/http/nsHttpHandler.cpp | 27 +++++++++++++++++++++++-- netwerk/protocol/http/nsHttpHandler.h | 1 + xpcom/base/nsSystemInfo.cpp | 2 +- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/mobile/android/app/mobile.js b/mobile/android/app/mobile.js index 036411ba5fe..2dc51c66f98 100644 --- a/mobile/android/app/mobile.js +++ b/mobile/android/app/mobile.js @@ -57,7 +57,6 @@ pref("toolkit.browser.cacheRatioHeight", 3000); pref("toolkit.browser.contentViewExpire", 3000); pref("toolkit.defaultChromeURI", "chrome://browser/content/browser.xul"); -pref("general.useragent.compatMode.firefox", true); pref("browser.chromeURL", "chrome://browser/content/"); pref("browser.tabs.warnOnClose", true); diff --git a/mobile/android/confvars.sh b/mobile/android/confvars.sh index febe50a0d0d..1de42e51365 100644 --- a/mobile/android/confvars.sh +++ b/mobile/android/confvars.sh @@ -39,6 +39,7 @@ MOZ_APP_BASENAME=Fennec MOZ_APP_VENDOR=Mozilla MOZ_APP_VERSION=13.0a1 +MOZ_APP_UA_NAME=Firefox MOZ_BRANDING_DIRECTORY=mobile/android/branding/unofficial MOZ_OFFICIAL_BRANDING_DIRECTORY=mobile/android/branding/official diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp index b94dafca1e0..20d886b238d 100644 --- a/netwerk/protocol/http/nsHttpHandler.cpp +++ b/netwerk/protocol/http/nsHttpHandler.cpp @@ -307,7 +307,11 @@ nsHttpHandler::Init() rv = InitConnectionMgr(); if (NS_FAILED(rv)) return rv; +#ifdef ANDROID + mProductSub.AssignLiteral(MOZ_APP_UA_VERSION); +#else mProductSub.AssignLiteral(MOZ_UA_BUILDID); +#endif if (mProductSub.IsEmpty() && appInfo) appInfo->GetPlatformBuildID(mProductSub); if (mProductSub.Length() > 8) @@ -602,6 +606,7 @@ nsHttpHandler::BuildUserAgent() mAppName.Length() + mAppVersion.Length() + mCompatFirefox.Length() + + mCompatDevice.Length() + 13); // Application portion @@ -616,8 +621,15 @@ nsHttpHandler::BuildUserAgent() mUserAgent += mPlatform; mUserAgent.AppendLiteral("; "); #endif +#ifdef ANDROID + if (!mCompatDevice.IsEmpty()) { + mUserAgent += mCompatDevice; + mUserAgent.AppendLiteral("; "); + } +#else mUserAgent += mOscpu; mUserAgent.AppendLiteral("; "); +#endif mUserAgent += mMisc; mUserAgent += ')'; @@ -650,8 +662,7 @@ typedef BOOL (WINAPI *IsWow64ProcessP) (HANDLE, PBOOL); void nsHttpHandler::InitUserAgentComponents() { - - // Gather platform. + // Gather platform. mPlatform.AssignLiteral( #if defined(ANDROID) "Android" @@ -670,6 +681,18 @@ nsHttpHandler::InitUserAgentComponents() #endif ); +#if defined(ANDROID) + nsCOMPtr infoService = do_GetService("@mozilla.org/system-info;1"); + NS_ASSERTION(infoService, "Could not find a system info service"); + + bool isTablet; + infoService->GetPropertyAsBool(NS_LITERAL_STRING("tablet"), &isTablet); + if (isTablet) + mCompatDevice.AssignLiteral("Tablet"); + else + mCompatDevice.AssignLiteral("Mobile"); +#endif + // Gather OS/CPU. #if defined(XP_OS2) ULONG os2ver = 0; diff --git a/netwerk/protocol/http/nsHttpHandler.h b/netwerk/protocol/http/nsHttpHandler.h index 9f0d74bd691..03e7a5683df 100644 --- a/netwerk/protocol/http/nsHttpHandler.h +++ b/netwerk/protocol/http/nsHttpHandler.h @@ -321,6 +321,7 @@ private: nsXPIDLCString mAppName; nsXPIDLCString mAppVersion; nsCString mCompatFirefox; + nsXPIDLCString mCompatDevice; nsCString mUserAgent; nsXPIDLCString mUserAgentOverride; diff --git a/xpcom/base/nsSystemInfo.cpp b/xpcom/base/nsSystemInfo.cpp index 87cf07b12ba..d29af934743 100644 --- a/xpcom/base/nsSystemInfo.cpp +++ b/xpcom/base/nsSystemInfo.cpp @@ -201,7 +201,7 @@ nsSystemInfo::Init() SetPropertyAsAString(NS_LITERAL_STRING("shellVersion"), str); } bool isTablet = mozilla::AndroidBridge::Bridge()->IsTablet(); - SetPropertyAsBool(NS_LITERAL_STRING("isTablet"), isTablet); + SetPropertyAsBool(NS_LITERAL_STRING("tablet"), isTablet); } #endif return NS_OK;