Bug 417994 - "navigator object does not fully reflect user agent settings" [p=gfleischer+bugzilla@gmail.com (Gregory Fleischer) r+sr=jst a1.9=beltzner]
--- 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))