Bug 671634 - Update Fennec useragent to more closely match stock browser. r=dougt

This commit is contained in:
Wes Johnston 2011-11-07 15:03:53 -08:00
parent cbbfa6055b
commit a2f4279fa4
6 changed files with 69 additions and 9 deletions

View File

@ -1615,4 +1615,17 @@ public class GeckoAppShell
public static float[] getCurrentBatteryInformation() {
return GeckoBatteryManager.getCurrentInformation();
}
public static boolean isTablet() {
if (android.os.Build.VERSION.SDK_INT >= 9) {
Configuration config = GeckoApp.mAppContext.getResources().getConfiguration();
// xlarge is defined by android as screens larger than 960dp x 720dp
// and should include most devices ~7in and up.
// http://developer.android.com/guide/practices/screens_support.html
if ((config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE) {
return true;
}
}
return false;
}
}

View File

@ -615,6 +615,8 @@ nsHttpHandler::BuildUserAgent()
mAppName.Length() +
mAppVersion.Length() +
mCompatFirefox.Length() +
mDeviceType.Length() +
mDeviceName.Length() +
13);
// Application portion
@ -632,6 +634,10 @@ nsHttpHandler::BuildUserAgent()
mUserAgent += mOscpu;
mUserAgent.AppendLiteral("; ");
mUserAgent += mMisc;
if (!mDeviceName.IsEmpty()) {
mUserAgent.AppendLiteral("; ");
mUserAgent += mDeviceName;
}
mUserAgent += ')';
// Product portion
@ -646,6 +652,11 @@ nsHttpHandler::BuildUserAgent()
mUserAgent += mCompatFirefox;
}
if (!mDeviceType.IsEmpty()) {
mUserAgent += ' ';
mUserAgent += mDeviceType;
}
// App portion
mUserAgent += ' ';
mUserAgent += mAppName;
@ -683,6 +694,32 @@ nsHttpHandler::InitUserAgentComponents()
#endif
);
#if defined(ANDROID)
nsCOMPtr<nsIPropertyBag2> 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("isTablet"), &isTablet);
if (!isTablet) {
mDeviceType.AssignLiteral("Mobile");
}
infoService->GetPropertyAsACString(NS_LITERAL_STRING("device"),
mDeviceName);
nsXPIDLCString buildid;
infoService->GetPropertyAsACString(NS_LITERAL_STRING("buildid"),
buildid);
if (!buildid.IsEmpty()) {
mDeviceName += " Build/";
mDeviceName += buildid;
}
nsXPIDLCString shellVersion;
infoService->GetPropertyAsACString(NS_LITERAL_STRING("shellVersion"),
shellVersion);
mPlatform += " ";
mPlatform += shellVersion;
#endif
// Gather OS/CPU.
#if defined(XP_OS2)
ULONG os2ver = 0;

View File

@ -313,6 +313,8 @@ private:
nsXPIDLCString mProductSub;
nsXPIDLCString mAppName;
nsXPIDLCString mAppVersion;
nsXPIDLCString mDeviceType;
nsXPIDLCString mDeviceName;
nsCString mCompatFirefox;
nsCString mUserAgent;

View File

@ -154,6 +154,7 @@ AndroidBridge::Init(JNIEnv *jEnv,
jPostToJavaThread = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "postToJavaThread", "(Z)V");
jInitCamera = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "initCamera", "(Ljava/lang/String;III)[I");
jCloseCamera = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "closeCamera", "()V");
jIsTablet = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "isTablet", "()Z");
jEnableBatteryNotifications = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "enableBatteryNotifications", "()V");
jDisableBatteryNotifications = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "disableBatteryNotifications", "()V");
jGetCurrentBatteryInformation = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getCurrentBatteryInformation", "()[F");
@ -1317,3 +1318,9 @@ AndroidBridge::UnlockWindow(void* window)
return true;
}
bool
AndroidBridge::IsTablet()
{
return mJNIEnv->CallStaticBooleanMethod(mGeckoAppShellClass, jIsTablet);
}

View File

@ -295,6 +295,8 @@ public:
void DisableBatteryNotifications();
void GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo);
bool IsTablet();
protected:
static AndroidBridge *sBridge;
@ -366,6 +368,7 @@ protected:
jmethodID jPostToJavaThread;
jmethodID jInitCamera;
jmethodID jCloseCamera;
jmethodID jIsTablet;
jmethodID jEnableBatteryNotifications;
jmethodID jDisableBatteryNotifications;
jmethodID jGetCurrentBatteryInformation;

View File

@ -181,22 +181,20 @@ nsSystemInfo::Init()
SetPropertyAsAString(NS_LITERAL_STRING("device"), str);
if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "MANUFACTURER", str))
SetPropertyAsAString(NS_LITERAL_STRING("manufacturer"), str);
PRInt32 version;
if (!mozilla::AndroidBridge::Bridge()->GetStaticIntField("android/os/Build$VERSION", "SDK_INT", &version))
version = 0;
if (version >= 8 && mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "HARDWARE", str))
SetPropertyAsAString(NS_LITERAL_STRING("hardware"), str);
if (version >= 8 && mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "ID", str))
SetPropertyAsAString(NS_LITERAL_STRING("buildid"), str);
SetPropertyAsAString(NS_LITERAL_STRING("shellName"), NS_LITERAL_STRING("Android"));
if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build$VERSION", "CODENAME", str)) {
if (version) {
str.Append(NS_LITERAL_STRING(" ("));
str.AppendInt(version);
str.Append(NS_LITERAL_STRING(")"));
}
if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build$VERSION", "RELEASE", str))
SetPropertyAsAString(NS_LITERAL_STRING("shellVersion"), str);
}
SetPropertyAsBool(NS_LITERAL_STRING("isTablet"),
mozilla::AndroidBridge::Bridge()->IsTablet());
}
#endif
return NS_OK;