зеркало из https://github.com/mozilla/gecko-dev.git
Bug 525245 - system-info should expose hardware specs to JS consumers, r=bsmedberg
This commit is contained in:
Родитель
63f30c88f7
Коммит
86d4f8bdcf
|
@ -74,12 +74,20 @@ nsSystemInfo::Init()
|
|||
if (PR_GetSystemInfo(items[i].cmd, buf, sizeof(buf)) == PR_SUCCESS) {
|
||||
rv = SetPropertyAsACString(NS_ConvertASCIItoUTF16(items[i].name),
|
||||
nsDependentCString(buf));
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
else
|
||||
else {
|
||||
NS_WARNING("PR_GetSystemInfo failed");
|
||||
}
|
||||
}
|
||||
|
||||
// Additional informations not available through PR_GetSystemInfo.
|
||||
SetInt32Property(NS_LITERAL_STRING("pagesize"), PR_GetPageSize());
|
||||
SetInt32Property(NS_LITERAL_STRING("pageshift"), PR_GetPageShift());
|
||||
SetInt32Property(NS_LITERAL_STRING("memmapalign"), PR_GetMemMapAlignment());
|
||||
SetInt32Property(NS_LITERAL_STRING("cpucount"), PR_GetNumberOfProcessors());
|
||||
SetUint64Property(NS_LITERAL_STRING("memsize"), PR_GetPhysicalMemorySize());
|
||||
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
// This must be done here because NSPR can only separate OS's when compiled, not libraries.
|
||||
char* gtkver = PR_smprintf("GTK %u.%u.%u", gtk_major_version, gtk_minor_version, gtk_micro_version);
|
||||
|
@ -119,3 +127,24 @@ nsSystemInfo::Init()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsSystemInfo::SetInt32Property(const nsAString &aPropertyName,
|
||||
const PRInt32 aValue)
|
||||
{
|
||||
NS_WARN_IF_FALSE(aValue > 0, "Unable to read system value");
|
||||
if (aValue > 0) {
|
||||
nsresult rv = SetPropertyAsInt32(aPropertyName, aValue);
|
||||
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Unable to set property");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsSystemInfo::SetUint64Property(const nsAString &aPropertyName,
|
||||
const PRUint64 aValue)
|
||||
{
|
||||
NS_WARN_IF_FALSE(aValue > 0, "Unable to read system value");
|
||||
if (aValue > 0) {
|
||||
nsresult rv = SetPropertyAsUint64(aPropertyName, aValue);
|
||||
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Unable to set property");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,6 +47,12 @@ public:
|
|||
|
||||
nsresult Init();
|
||||
|
||||
protected:
|
||||
void SetInt32Property(const nsAString &aPropertyName,
|
||||
const PRInt32 aValue);
|
||||
void SetUint64Property(const nsAString &aPropertyName,
|
||||
const PRUint64 aValue);
|
||||
|
||||
private:
|
||||
~nsSystemInfo();
|
||||
};
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is XPCOM unit tests.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Marco Bonardo <mak77@bonardo.net>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
function run_test() {
|
||||
const PROPERTIES = ["name", "host", "arch", "version", "pagesize",
|
||||
"pageshift", "memmapalign", "cpucount", "memsize"];
|
||||
let sysInfo = Components.classes["@mozilla.org/system-info;1"].
|
||||
getService(Components.interfaces.nsIPropertyBag2);
|
||||
|
||||
PROPERTIES.forEach(function(aPropertyName) {
|
||||
print("Testing property: " + aPropertyName);
|
||||
let value = sysInfo.getProperty(aPropertyName);
|
||||
do_check_true(!!value);
|
||||
});
|
||||
}
|
Загрузка…
Ссылка в новой задаче