Bug 417994 - "navigator object does not fully reflect user agent settings" [p=gfleischer+bugzilla@gmail.com (Gregory Fleischer) r+sr=jst a1.9=beltzner]
authorreed@reedloden.com
Sat, 08 Mar 2008 03:19:22 -0800
changeset 12788 3d3924dbed92cf02ffa07c4a9e036bbf6e524a9d
parent 12787 50aeb00ad125c5e4cd2fb2559434ed0dbcf79ab3
child 12789 14995bd9c0f300202060fce3d2b548399077b1ee
push idunknown
push userunknown
push dateunknown
bugs417994
milestone1.9b5pre
Bug 417994 - "navigator object does not fully reflect user agent settings" [p=gfleischer+bugzilla@gmail.com (Gregory Fleischer) r+sr=jst a1.9=beltzner]
dom/src/base/nsGlobalWindow.cpp
--- a/dom/src/base/nsGlobalWindow.cpp
+++ b/dom/src/base/nsGlobalWindow.cpp
@@ -9023,16 +9023,26 @@ nsNavigator::GetPlatform(nsAString& aPla
   }
 
   return rv;
 }
 
 NS_IMETHODIMP
 nsNavigator::GetOscpu(nsAString& aOSCPU)
 {
+  if (!nsContentUtils::IsCallerTrustedForRead()) {
+    const nsAdoptingCString& override =
+      nsContentUtils::GetCharPref("general.oscpu.override");
+
+    if (override) {
+      CopyUTF8toUTF16(override, aOSCPU);
+      return NS_OK;
+    }
+  }
+
   nsresult rv;
   nsCOMPtr<nsIHttpProtocolHandler>
     service(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &rv));
   if (NS_SUCCEEDED(rv)) {
     nsCAutoString oscpu;
     rv = service->GetOscpu(oscpu);
     CopyASCIItoUTF16(oscpu, aOSCPU);
   }
@@ -9084,16 +9094,35 @@ nsNavigator::GetProduct(nsAString& aProd
   }
 
   return rv;
 }
 
 NS_IMETHODIMP
 nsNavigator::GetProductSub(nsAString& aProductSub)
 {
+  if (!nsContentUtils::IsCallerTrustedForRead()) {
+    const nsAdoptingCString& override =
+      nsContentUtils::GetCharPref("general.productSub.override");
+
+    if (override) {
+      CopyUTF8toUTF16(override, aProductSub);
+      return NS_OK;
+    } else {
+      // 'general.useragent.productSub' backwards compatible with 1.8 branch.
+      const nsAdoptingCString& override2 =
+        nsContentUtils::GetCharPref("general.useragent.productSub");
+
+      if (override2) {
+        CopyUTF8toUTF16(override2, aProductSub);
+        return NS_OK;
+      }
+    }
+  }
+
   nsresult rv;
   nsCOMPtr<nsIHttpProtocolHandler>
     service(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &rv));
   if (NS_SUCCEEDED(rv)) {
     nsCAutoString productSub;
     rv = service->GetProductSub(productSub);
     CopyASCIItoUTF16(productSub, aProductSub);
   }
@@ -9159,16 +9188,26 @@ nsNavigator::GetOnLine(PRBool* aOnline)
   
   *aOnline = !NS_IsOffline();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsNavigator::GetBuildID(nsAString& aBuildID)
 {
+  if (!nsContentUtils::IsCallerTrustedForRead()) {
+    const nsAdoptingCString& override =
+      nsContentUtils::GetCharPref("general.buildID.override");
+
+    if (override) {
+      CopyUTF8toUTF16(override, aBuildID);
+      return NS_OK;
+    }
+  }
+
   nsCOMPtr<nsIXULAppInfo> appInfo =
     do_GetService("@mozilla.org/xre/app-info;1");
   if (!appInfo)
     return NS_ERROR_NOT_IMPLEMENTED;
 
   nsCAutoString buildID;
   nsresult rv = appInfo->GetAppBuildID(buildID);
   if (NS_FAILED(rv))