Bug 1264076 - Allow customized device string for user agent on Fennec; r=mcmanus a=lizzard FIREFOX_46_0b11_BUILD1 FIREFOX_46_0b11_RELEASE
authorMichael Kaply <mozilla@kaply.com>
Thu, 14 Apr 2016 17:19:47 -0500
changeset 317791 076bf6a0ac85ec6a4f3ee7c3efe653964d92b9f2
parent 317790 3407730c74e4add5d9fb1b49882474524364afdc
child 317792 a6c0d2903cb6571c5120c12447fae677b82813e9
push id5897
push usermozilla@kaply.com
push dateThu, 14 Apr 2016 22:22:47 +0000
treeherdermozilla-beta@076bf6a0ac85 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus, lizzard
bugs1264076
milestone46.0
Bug 1264076 - Allow customized device string for user agent on Fennec; r=mcmanus a=lizzard
netwerk/protocol/http/nsHttpHandler.cpp
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -121,24 +121,34 @@ NewURI(const nsACString &aSpec,
 
     url.forget(aURI);
     return NS_OK;
 }
 
 #ifdef ANDROID
 static nsCString
 GetDeviceModelId() {
+    // Assumed to be running on the main thread
+    // We need the device property in either case
+    nsAutoCString deviceModelId;
     nsCOMPtr<nsIPropertyBag2> infoService = do_GetService("@mozilla.org/system-info;1");
     MOZ_ASSERT(infoService, "Could not find a system info service");
     nsAutoString androidDevice;
     nsresult rv = infoService->GetPropertyAsAString(NS_LITERAL_STRING("device"), androidDevice);
     if (NS_SUCCEEDED(rv)) {
-        return NS_LossyConvertUTF16toASCII(androidDevice);
+        deviceModelId = NS_LossyConvertUTF16toASCII(androidDevice);
     }
-    return EmptyCString();
+    nsAutoCString deviceString;
+    rv = Preferences::GetCString(UA_PREF("device_string"), &deviceString);
+    if (NS_SUCCEEDED(rv)) {
+        deviceString.Trim(" ", true, true);
+        deviceString.ReplaceSubstring(NS_LITERAL_CSTRING("%DEVICEID%"), deviceModelId);
+        return deviceString;
+    }
+    return deviceModelId;
 }
 #endif
 
 //-----------------------------------------------------------------------------
 // nsHttpHandler <public>
 //-----------------------------------------------------------------------------
 
 nsHttpHandler *gHttpHandler = nullptr;