Bug 572417 - Release mouse capture in flash subclass after mouse events get delivered...
[mozilla-central.git] / xpcom / base / nsSystemInfo.cpp
blob028d941fa37a4b99029ebd369fef573dfae09662
1 /* -*- Mode: C++; tab-width: 50; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * mozilla.org
19 * Portions created by the Initial Developer are Copyright (C) 2005
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Seth Spitzer <sspitzer@mozilla.org> (original author)
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "nsSystemInfo.h"
40 #include "prsystem.h"
41 #include "nsString.h"
42 #include "prprf.h"
44 #ifdef MOZ_WIDGET_GTK2
45 #include <gtk/gtk.h>
46 #endif
48 #ifdef ANDROID
49 #include "AndroidBridge.h"
50 #endif
52 nsSystemInfo::nsSystemInfo()
56 nsSystemInfo::~nsSystemInfo()
60 nsresult
61 nsSystemInfo::Init()
63 nsresult rv = nsHashPropertyBag::Init();
64 NS_ENSURE_SUCCESS(rv, rv);
66 static const struct {
67 PRSysInfo cmd;
68 const char *name;
69 } items[] = {
70 { PR_SI_SYSNAME, "name" },
71 { PR_SI_HOSTNAME, "host" },
72 { PR_SI_ARCHITECTURE, "arch" },
73 { PR_SI_RELEASE, "version" }
76 for (PRUint32 i = 0; i < (sizeof(items) / sizeof(items[0])); i++) {
77 char buf[SYS_INFO_BUFFER_LENGTH];
78 if (PR_GetSystemInfo(items[i].cmd, buf, sizeof(buf)) == PR_SUCCESS) {
79 rv = SetPropertyAsACString(NS_ConvertASCIItoUTF16(items[i].name),
80 nsDependentCString(buf));
81 NS_ENSURE_SUCCESS(rv, rv);
83 else {
84 NS_WARNING("PR_GetSystemInfo failed");
88 // Additional informations not available through PR_GetSystemInfo.
89 SetInt32Property(NS_LITERAL_STRING("pagesize"), PR_GetPageSize());
90 SetInt32Property(NS_LITERAL_STRING("pageshift"), PR_GetPageShift());
91 SetInt32Property(NS_LITERAL_STRING("memmapalign"), PR_GetMemMapAlignment());
92 SetInt32Property(NS_LITERAL_STRING("cpucount"), PR_GetNumberOfProcessors());
93 SetUint64Property(NS_LITERAL_STRING("memsize"), PR_GetPhysicalMemorySize());
95 #ifdef MOZ_WIDGET_GTK2
96 // This must be done here because NSPR can only separate OS's when compiled, not libraries.
97 char* gtkver = PR_smprintf("GTK %u.%u.%u", gtk_major_version, gtk_minor_version, gtk_micro_version);
98 if (gtkver) {
99 rv = SetPropertyAsACString(NS_LITERAL_STRING("secondaryLibrary"),
100 nsDependentCString(gtkver));
101 PR_smprintf_free(gtkver);
102 NS_ENSURE_SUCCESS(rv, rv);
104 #endif
107 #ifdef MOZ_PLATFORM_MAEMO
108 char * line = nsnull;
109 size_t len = 0;
110 ssize_t read;
111 FILE *fp = fopen ("/proc/component_version", "r");
112 if (fp) {
113 while ((read = getline(&line, &len, fp)) != -1) {
114 if (line) {
115 if (strstr(line, "RX-51")) {
116 SetPropertyAsACString(NS_LITERAL_STRING("device"), NS_LITERAL_CSTRING("Nokia N900"));
117 SetPropertyAsACString(NS_LITERAL_STRING("manufacturer"), NS_LITERAL_CSTRING("Nokia"));
118 SetPropertyAsACString(NS_LITERAL_STRING("hardware"), NS_LITERAL_CSTRING("RX-51"));
119 break;
120 } else if (strstr(line, "RX-44") ||
121 strstr(line, "RX-48") ||
122 strstr(line, "RX-32") ) {
123 /* not as accurate as we can be, but these devices are deprecated */
124 SetPropertyAsACString(NS_LITERAL_STRING("device"), NS_LITERAL_CSTRING("Nokia N8xx"));
125 SetPropertyAsACString(NS_LITERAL_STRING("manufacturer"), NS_LITERAL_CSTRING("Nokia"));
126 SetPropertyAsACString(NS_LITERAL_STRING("hardware"), NS_LITERAL_CSTRING("N8xx"));
127 break;
131 if (line)
132 free(line);
133 fclose(fp);
135 #endif
137 #ifdef ANDROID
138 if (mozilla::AndroidBridge::Bridge()) {
139 nsAutoString str;
140 if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "MODEL", str))
141 SetPropertyAsAString(NS_LITERAL_STRING("device"), str);
142 if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "MANUFACTURER", str))
143 SetPropertyAsAString(NS_LITERAL_STRING("manufacturer"), str);
144 if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "HARDWARE", str))
145 SetPropertyAsAString(NS_LITERAL_STRING("hardware"), str);
147 #endif
148 return NS_OK;
151 void
152 nsSystemInfo::SetInt32Property(const nsAString &aPropertyName,
153 const PRInt32 aValue)
155 NS_WARN_IF_FALSE(aValue > 0, "Unable to read system value");
156 if (aValue > 0) {
157 #ifdef DEBUG
158 nsresult rv =
159 #endif
160 SetPropertyAsInt32(aPropertyName, aValue);
161 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Unable to set property");
165 void
166 nsSystemInfo::SetUint64Property(const nsAString &aPropertyName,
167 const PRUint64 aValue)
169 NS_WARN_IF_FALSE(aValue > 0, "Unable to read system value");
170 if (aValue > 0) {
171 #ifdef DEBUG
172 nsresult rv =
173 #endif
174 SetPropertyAsUint64(aPropertyName, aValue);
175 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Unable to set property");