Bug 1220344 - remote some of nsSystemInfo to make it e10s ready on Android r=nchen,froydnj
☠☠ backed out by 0d761deb68d9 ☠ ☠
authorFabrice Desré <fabrice@mozilla.com>
Wed, 04 Nov 2015 11:08:14 -0800
changeset 306578 8d3ff1d1a8097b865b9e3123ee89d4f75cb6867a
parent 306577 c787c2eb8c32085905a9ea28ce353de7f4a1ab99
child 306579 664ea2dd904a73427973b21aff5fa52fd44d418b
push id7160
push usergarndt@mozilla.com
push dateWed, 04 Nov 2015 22:20:12 +0000
reviewersnchen, froydnj
bugs1220344
milestone45.0a1
Bug 1220344 - remote some of nsSystemInfo to make it e10s ready on Android r=nchen,froydnj
dom/ipc/ContentParent.cpp
dom/ipc/ContentParent.h
dom/ipc/PContent.ipdl
xpcom/base/nsSystemInfo.cpp
xpcom/base/nsSystemInfo.h
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -5733,16 +5733,28 @@ ContentParent::RecvGetDeviceStorageLocat
 #ifdef MOZ_WIDGET_ANDROID
   mozilla::AndroidBridge::GetExternalPublicDirectory(aType, *aPath);
   return true;
 #else
   return false;
 #endif
 }
 
+bool
+ContentParent::RecvGetAndroidSystemInfo(AndroidSystemInfo* aInfo)
+{
+#ifdef MOZ_WIDGET_ANDROID
+  nsSystemInfo::GetAndroidSystemInfo(aInfo);
+  return true;
+#else
+  MOZ_CRASH("wrong platform!");
+  return false;
+#endif
+}
+
 } // namespace dom
 } // namespace mozilla
 
 NS_IMPL_ISUPPORTS(ParentIdleListener, nsIObserver)
 
 NS_IMETHODIMP
 ParentIdleListener::Observe(nsISupports*, const char* aTopic, const char16_t* aData) {
     mozilla::Unused << mParent->SendNotifyIdleObserver(mObserver,
--- a/dom/ipc/ContentParent.h
+++ b/dom/ipc/ContentParent.h
@@ -935,16 +935,19 @@ private:
 
     virtual bool RecvGamepadListenerAdded() override;
     virtual bool RecvGamepadListenerRemoved() override;
     virtual bool RecvProfile(const nsCString& aProfile) override;
     virtual bool RecvGetGraphicsDeviceInitData(DeviceInitData* aOut) override;
 
     virtual bool RecvGetDeviceStorageLocation(const nsString& aType,
                                               nsString* aPath) override;
+
+    virtual bool RecvGetAndroidSystemInfo(AndroidSystemInfo* aInfo) override;
+
     // If you add strong pointers to cycle collected objects here, be sure to
     // release these objects in ShutDownProcess.  See the comment there for more
     // details.
 
     GeckoChildProcessHost* mSubprocess;
     ContentParent* mOpener;
 
     ContentParentId mChildID;
--- a/dom/ipc/PContent.ipdl
+++ b/dom/ipc/PContent.ipdl
@@ -411,16 +411,26 @@ union GamepadChangeEvent {
 };
 
 struct FrameScriptInfo
 {
     nsString url;
     bool runInGlobalScope;
 };
 
+struct AndroidSystemInfo
+{
+    nsString device;
+    nsString manufacturer;
+    nsString release_version;
+    nsString hardware;
+    uint32_t sdk_version;
+    bool     isTablet;
+};
+
 prio(normal upto urgent) sync protocol PContent
 {
     parent spawns PPluginModule;
 
     parent opens PCompositor;
     parent opens PProcessHangMonitor;
     parent opens PSharedBufferManager;
     parent opens PImageBridge;
@@ -1129,15 +1139,18 @@ parent:
       returns (nsresult rv,
                bool windowOpened,
                FrameScriptInfo[] frameScripts,
                nsCString urlToLoad);
 
     sync GetDeviceStorageLocation(nsString type)
         returns (nsString path);
 
+    sync GetAndroidSystemInfo()
+        returns (AndroidSystemInfo info);
+
 both:
      AsyncMessage(nsString aMessage, ClonedMessageData aData,
                   CpowEntry[] aCpows, Principal aPrincipal);
 };
 
 }
 }
--- a/xpcom/base/nsSystemInfo.cpp
+++ b/xpcom/base/nsSystemInfo.cpp
@@ -37,16 +37,17 @@
 #include "nsCharSeparatedTokenizer.h"
 
 #include <map>
 #include <string>
 #endif
 
 #ifdef MOZ_WIDGET_ANDROID
 #include "AndroidBridge.h"
+#include "mozilla/dom/ContentChild.h"
 #endif
 
 #ifdef MOZ_WIDGET_GONK
 #include <sys/system_properties.h>
 #include "mozilla/Preferences.h"
 #include "nsPrintfCString.h"
 #endif
 
@@ -687,50 +688,26 @@ nsSystemInfo::Init()
     PR_smprintf_free(gtkver);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 #endif
 
 #ifdef MOZ_WIDGET_ANDROID
-  if (mozilla::AndroidBridge::Bridge()) {
-    nsAutoString str;
-    if (mozilla::AndroidBridge::Bridge()->GetStaticStringField(
-          "android/os/Build", "MODEL", str)) {
-      SetPropertyAsAString(NS_LITERAL_STRING("device"), str);
-    }
-    if (mozilla::AndroidBridge::Bridge()->GetStaticStringField(
-          "android/os/Build", "MANUFACTURER", str)) {
-      SetPropertyAsAString(NS_LITERAL_STRING("manufacturer"), str);
-    }
-    if (mozilla::AndroidBridge::Bridge()->GetStaticStringField(
-          "android/os/Build$VERSION", "RELEASE", str)) {
-      SetPropertyAsAString(NS_LITERAL_STRING("release_version"), str);
+  AndroidSystemInfo info;
+  if (XRE_IsContentProcess()) {
+    dom::ContentChild* child = dom::ContentChild::GetSingleton();
+    if (child) {
+      child->SendGetAndroidSystemInfo(&info);
+      SetupAndroidInfo(info);
     }
-    int32_t version;
-    if (!mozilla::AndroidBridge::Bridge()->GetStaticIntField(
-          "android/os/Build$VERSION", "SDK_INT", &version)) {
-      version = 0;
-    }
-    android_sdk_version = version;
-    if (version >= 8 &&
-        mozilla::AndroidBridge::Bridge()->GetStaticStringField(
-          "android/os/Build", "HARDWARE", str)) {
-      SetPropertyAsAString(NS_LITERAL_STRING("hardware"), str);
-    }
-    bool isTablet = mozilla::widget::GeckoAppShell::IsTablet();
-    SetPropertyAsBool(NS_LITERAL_STRING("tablet"), isTablet);
-    // NSPR "version" is the kernel version. For Android we want the Android version.
-    // Rename SDK version to version and put the kernel version into kernel_version.
-    rv = GetPropertyAsAString(NS_LITERAL_STRING("version"), str);
-    if (NS_SUCCEEDED(rv)) {
-      SetPropertyAsAString(NS_LITERAL_STRING("kernel_version"), str);
-    }
-    SetPropertyAsInt32(NS_LITERAL_STRING("version"), android_sdk_version);
+  } else {
+    GetAndroidSystemInfo(&info);
+    SetupAndroidInfo(info);
   }
 #endif
 
 #ifdef MOZ_WIDGET_GONK
   char sdk[PROP_VALUE_MAX];
   if (__system_property_get("ro.build.version.sdk", sdk)) {
     android_sdk_version = atoi(sdk);
     SetPropertyAsInt32(NS_LITERAL_STRING("sdk_version"), android_sdk_version);
@@ -788,16 +765,81 @@ nsSystemInfo::Init()
     SetPropertyAsBool(NS_LITERAL_STRING("canSandboxMedia"),
                       sandInfo.CanSandboxMedia());
   }
 #endif // XP_LINUX && MOZ_SANDBOX
 
   return NS_OK;
 }
 
+#ifdef MOZ_WIDGET_ANDROID
+/* static */
+void
+nsSystemInfo::GetAndroidSystemInfo(AndroidSystemInfo* aInfo)
+{
+  MOZ_ASSERT(XRE_IsParentProcess());
+
+  if (!mozilla::AndroidBridge::Bridge()) {
+    return;
+  }
+
+  nsAutoString str;
+  if (mozilla::AndroidBridge::Bridge()->GetStaticStringField(
+      "android/os/Build", "MODEL", str)) {
+    aInfo->device() = str;
+  }
+  if (mozilla::AndroidBridge::Bridge()->GetStaticStringField(
+      "android/os/Build", "MANUFACTURER", str)) {
+    aInfo->manufacturer() = str;
+  }
+  if (mozilla::AndroidBridge::Bridge()->GetStaticStringField(
+      "android/os/Build$VERSION", "RELEASE", str)) {
+    aInfo->release_version() = str;
+  }
+  if (mozilla::AndroidBridge::Bridge()->GetStaticStringField(
+      "android/os/Build", "HARDWARE", str)) {
+    aInfo->hardware() = str;
+  }
+  int32_t sdk_version;
+  if (!mozilla::AndroidBridge::Bridge()->GetStaticIntField(
+      "android/os/Build$VERSION", "SDK_INT", &sdk_version)) {
+    sdk_version = 0;
+  }
+  aInfo->sdk_version() = sdk_version;
+  aInfo->isTablet() = mozilla::widget::GeckoAppShell::IsTablet();
+}
+
+void
+nsSystemInfo::SetupAndroidInfo(const AndroidSystemInfo& aInfo)
+{
+  if (!aInfo.device().IsEmpty()) {
+    SetPropertyAsAString(NS_LITERAL_STRING("device"), aInfo.device());
+  }
+  if (!aInfo.manufacturer().IsEmpty()) {
+    SetPropertyAsAString(NS_LITERAL_STRING("manufacturer"), aInfo.manufacturer());
+  }
+  if (!aInfo.release_version().IsEmpty()) {
+    SetPropertyAsAString(NS_LITERAL_STRING("release_version"), aInfo.release_version());
+  }
+  android_sdk_version = aInfo.sdk_version();
+  if (android_sdk_version >= 8 && !aInfo.hardware().IsEmpty()) {
+    SetPropertyAsAString(NS_LITERAL_STRING("hardware"), aInfo.hardware());
+  }
+  SetPropertyAsBool(NS_LITERAL_STRING("tablet"), aInfo.isTablet());
+  // NSPR "version" is the kernel version. For Android we want the Android version.
+  // Rename SDK version to version and put the kernel version into kernel_version.
+  nsAutoString str;
+  nsresult rv = GetPropertyAsAString(NS_LITERAL_STRING("version"), str);
+  if (NS_SUCCEEDED(rv)) {
+    SetPropertyAsAString(NS_LITERAL_STRING("kernel_version"), str);
+  }
+  SetPropertyAsInt32(NS_LITERAL_STRING("version"), android_sdk_version);
+}
+#endif // MOZ_WIDGET_ANDROID
+
 void
 nsSystemInfo::SetInt32Property(const nsAString& aPropertyName,
                                const int32_t aValue)
 {
   NS_WARN_IF_FALSE(aValue > 0, "Unable to read system value");
   if (aValue > 0) {
 #ifdef DEBUG
     nsresult rv =
--- a/xpcom/base/nsSystemInfo.h
+++ b/xpcom/base/nsSystemInfo.h
@@ -7,16 +7,20 @@
 #ifndef _NSSYSTEMINFO_H_
 #define _NSSYSTEMINFO_H_
 
 #include "nsHashPropertyBag.h"
 #if defined(XP_WIN)
 #include "nsIObserver.h"
 #endif // defined(XP_WIN)
 
+#ifdef MOZ_WIDGET_ANDROID
+#include "mozilla/dom/PContent.h"
+#endif // MOZ_WIDGET_ANDROID
+
 class nsSystemInfo final
   : public nsHashPropertyBag
 #if defined(XP_WIN)
   , public nsIObserver
 #endif // defined(XP_WIN)
 {
 public:
 #if defined(XP_WIN)
@@ -27,16 +31,22 @@ public:
   nsSystemInfo();
 
   nsresult Init();
 
   // Slot for NS_InitXPCOM2 to pass information to nsSystemInfo::Init.
   // See comments above the variable definition and in NS_InitXPCOM2.
   static uint32_t gUserUmask;
 
+#ifdef MOZ_WIDGET_ANDROID
+  static void GetAndroidSystemInfo(mozilla::dom::AndroidSystemInfo* aInfo);
+  protected:
+    void SetupAndroidInfo(const mozilla::dom::AndroidSystemInfo&);
+#endif
+
 protected:
   void SetInt32Property(const nsAString& aPropertyName,
                         const int32_t aValue);
   void SetUint32Property(const nsAString& aPropertyName,
                          const uint32_t aValue);
   void SetUint64Property(const nsAString& aPropertyName,
                          const uint64_t aValue);