Bug 1430038 - Part 1: Add VR process to the process list; r?kip, jimm draft
authorDaosheng Mu <daoshengmu@gmail.com>
Fri, 22 Jun 2018 16:30:14 -0700
changeset 827381 a482d83c6702316ded19add6eb8a2c55857425d1
parent 825336 af6a7edf0069549543f2fba6a8ee3ea251b20829
child 827382 401b81d450ba648d982b8e433834e5f728bd8803
push id118524
push userbmo:dmu@mozilla.com
push dateTue, 07 Aug 2018 23:12:13 +0000
reviewerskip, jimm
bugs1430038
milestone63.0a1
Bug 1430038 - Part 1: Add VR process to the process list; r?kip, jimm Summary: MozReview-Commit-ID: AWyFur2gLCQ Tags: #secure-revision Differential Revision: https://phabricator.services.mozilla.com/D2876 MozReview-Commit-ID: HHGDiXyaqnB
gfx/thebes/gfxPrefs.h
ipc/glue/GeckoChildProcessHost.cpp
modules/libpref/init/all.js
toolkit/xre/nsAppRunner.cpp
toolkit/xre/nsEmbedFunctions.cpp
tools/fuzzing/faulty/Faulty.cpp
xpcom/build/nsXULAppAPI.h
xpcom/system/nsIXULRuntime.idl
--- a/gfx/thebes/gfxPrefs.h
+++ b/gfx/thebes/gfxPrefs.h
@@ -385,16 +385,17 @@ private:
   DECL_GFX_PREF(Live, "dom.vr.controller.enumerate.interval",  VRControllerEnumerateInterval, int32_t, 1000);
   DECL_GFX_PREF(Live, "dom.vr.display.enumerate.interval",     VRDisplayEnumerateInterval, int32_t, 5000);
   DECL_GFX_PREF(Live, "dom.vr.inactive.timeout",               VRInactiveTimeout, int32_t, 5000);
   DECL_GFX_PREF(Live, "dom.vr.poseprediction.enabled",         VRPosePredictionEnabled, bool, true);
   DECL_GFX_PREF(Live, "dom.vr.require-gesture",                VRRequireGesture, bool, true);
   DECL_GFX_PREF(Live, "dom.vr.puppet.enabled",                 VRPuppetEnabled, bool, false);
   DECL_GFX_PREF(Live, "dom.vr.puppet.submitframe",             VRPuppetSubmitFrame, uint32_t, 0);
   DECL_GFX_PREF(Live, "dom.vr.display.rafMaxDuration",         VRDisplayRafMaxDuration, uint32_t, 50);
+  DECL_GFX_PREF(Once, "dom.vr.process.enabled",                VRProcessEnabled, bool, false);
   DECL_GFX_PREF(Once, "dom.vr.service.enabled",                VRServiceEnabled, bool, false);
   DECL_GFX_PREF(Live, "dom.w3c_pointer_events.enabled",        PointerEventsEnabled, bool, false);
 
   DECL_GFX_PREF(Live, "general.smoothScroll",                  SmoothScrollEnabled, bool, true);
   DECL_GFX_PREF(Live, "general.smoothScroll.currentVelocityWeighting",
                 SmoothScrollCurrentVelocityWeighting, float, 0.25);
   DECL_GFX_PREF(Live, "general.smoothScroll.durationToIntervalRatio",
                 SmoothScrollDurationToIntervalRatio, int32_t, 200);
--- a/ipc/glue/GeckoChildProcessHost.cpp
+++ b/ipc/glue/GeckoChildProcessHost.cpp
@@ -138,17 +138,18 @@ GeckoChildProcessHost::~GeckoChildProces
   }
 }
 
 //static
 auto
 GeckoChildProcessHost::GetPathToBinary(FilePath& exePath, GeckoProcessType processType) -> BinaryPathType
 {
   if (sRunSelfAsContentProc &&
-      (processType == GeckoProcessType_Content || processType == GeckoProcessType_GPU)) {
+      (processType == GeckoProcessType_Content || processType == GeckoProcessType_GPU ||
+       processType == GeckoProcessType_VR)) {
 #if defined(OS_WIN)
     wchar_t exePathBuf[MAXPATHLEN];
     if (!::GetModuleFileNameW(nullptr, exePathBuf, MAXPATHLEN)) {
       MOZ_CRASH("GetModuleFileNameW failed (FIXME)");
     }
 #if defined(MOZ_SANDBOX)
     // We need to start the child process using the real path, so that the
     // sandbox policy rules will match for DLLs loaded from the bin dir after
@@ -755,17 +756,17 @@ GeckoChildProcessHost::PerformAsyncLaunc
     }
   }
 
   // Add the application directory path (-appdir path)
   AddAppDirToCommandLine(childArgv);
 
   // Tmp dir that the GPU process should use for crash reports. This arg is
   // always populated (but possibly with an empty value) for a GPU child process.
-  if (mProcessType == GeckoProcessType_GPU) {
+  if (mProcessType == GeckoProcessType_GPU || mProcessType == GeckoProcessType_VR) {
     nsCOMPtr<nsIFile> file;
     CrashReporter::GetChildProcessTmpDir(getter_AddRefs(file));
     nsAutoCString path;
     if (file) {
       file->GetNativePath(path);
     }
     childArgv.push_back(path.get());
   }
@@ -992,16 +993,21 @@ GeckoChildProcessHost::PerformAsyncLaunc
       if (mSandboxLevel > 0 && !PR_GetEnv("MOZ_DISABLE_GPU_SANDBOX")) {
         // For now we treat every failure as fatal in SetSecurityLevelForGPUProcess
         // and just crash there right away. Should this change in the future then we
         // should also handle the error here.
         mSandboxBroker.SetSecurityLevelForGPUProcess(mSandboxLevel);
         shouldSandboxCurrentProcess = true;
       }
       break;
+    case GeckoProcessType_VR:
+      if (mSandboxLevel > 0 && !PR_GetEnv("MOZ_DISABLE_VR_SANDBOX")) {
+        // TODO: Implement sandbox for VR process, Bug 1430043.
+      }
+      break;
     case GeckoProcessType_Default:
     default:
       MOZ_CRASH("Bad process type in GeckoChildProcessHost");
       break;
   };
 
   if (shouldSandboxCurrentProcess) {
     for (auto it = mAllowedFilesRead.begin();
@@ -1074,16 +1080,17 @@ GeckoChildProcessHost::PerformAsyncLaunc
   {
     base::LaunchApp(cmdLine, *mLaunchOptions, &process);
 
 # ifdef MOZ_SANDBOX
     // We need to be able to duplicate handles to some types of non-sandboxed
     // child processes.
     if (mProcessType == GeckoProcessType_Content ||
         mProcessType == GeckoProcessType_GPU ||
+        mProcessType == GeckoProcessType_VR ||
         mProcessType == GeckoProcessType_GMPlugin) {
       if (!mSandboxBroker.AddTargetPeer(process)) {
         NS_WARNING("Failed to add content process as target peer.");
       }
     }
 # endif // MOZ_SANDBOX
   }
 
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -5271,26 +5271,28 @@ pref("dom.vr.inactive.timeout", 5000);
 // poses to callers of the WebVR API.  This currently only has an effect for
 // Oculus Rift on SDK 0.8 or greater.
 pref("dom.vr.poseprediction.enabled", true);
 // Starting VR presentation is only allowed within a user gesture or event such
 // as VRDisplayActivate triggered by the system.  dom.vr.require-gesture allows
 // this requirement to be disabled for special cases such as during automated
 // tests or in a headless kiosk system.
 pref("dom.vr.require-gesture", true);
+// Enable a separate process for VR module.
+pref("dom.vr.process.enabled", false);
+// Puppet device, used for simulating VR hardware within tests and dev tools
+pref("dom.vr.puppet.enabled", false);
+// Allow displaying the result of vr submitframe (0: disable, 1: store the
+// result as a base64 image, 2: show it on the screen).
+pref("dom.vr.puppet.submitframe", 0);
 // path to OSVR DLLs
 pref("gfx.vr.osvr.utilLibPath", "");
 pref("gfx.vr.osvr.commonLibPath", "");
 pref("gfx.vr.osvr.clientLibPath", "");
 pref("gfx.vr.osvr.clientKitLibPath", "");
-// Puppet device, used for simulating VR hardware within tests and dev tools
-pref("dom.vr.puppet.enabled", false);
-// Allow displaying the result of vr submitframe (0: disable, 1: store the
-// result as a base64 image, 2: show it on the screen).
-pref("dom.vr.puppet.submitframe", 0);
 // The number of milliseconds since last frame start before triggering a new frame.
 // When content is failing to submit frames on time or the lower level VR platform API's
 // are rejecting frames, it determines the rate at which RAF callbacks will be called.
 pref("dom.vr.display.rafMaxDuration", 50);
 // VR test system.
 pref("dom.vr.test.enabled", false);
 // Enable the VR Service, which interfaces with VR hardware in a separate thread
 pref("dom.vr.service.enabled", false);
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -790,19 +790,20 @@ nsXULAppInfo::GetWidgetToolkit(nsACStrin
 
 SYNC_ENUMS(DEFAULT, Default)
 SYNC_ENUMS(PLUGIN, Plugin)
 SYNC_ENUMS(CONTENT, Content)
 SYNC_ENUMS(IPDLUNITTEST, IPDLUnitTest)
 SYNC_ENUMS(GMPLUGIN, GMPlugin)
 SYNC_ENUMS(GPU, GPU)
 SYNC_ENUMS(PDFIUM, PDFium)
+SYNC_ENUMS(VR, VR)
 
 // .. and ensure that that is all of them:
-static_assert(GeckoProcessType_PDFium + 1 == GeckoProcessType_End,
+static_assert(GeckoProcessType_VR + 1 == GeckoProcessType_End,
               "Did not find the final GeckoProcessType");
 
 NS_IMETHODIMP
 nsXULAppInfo::GetProcessType(uint32_t* aResult)
 {
   NS_ENSURE_ARG_POINTER(aResult);
   *aResult = XRE_GetProcessType();
   return NS_OK;
@@ -5097,16 +5098,22 @@ XRE_GetProcessType()
 }
 
 bool
 XRE_IsGPUProcess()
 {
   return XRE_GetProcessType() == GeckoProcessType_GPU;
 }
 
+bool
+XRE_IsVRProcess()
+{
+  return XRE_GetProcessType() == GeckoProcessType_VR;
+}
+
 /**
  * Returns true in the e10s parent process and in the main process when e10s
  * is disabled.
  */
 bool
 XRE_IsParentProcess()
 {
   return XRE_GetProcessType() == GeckoProcessType_Default;
--- a/toolkit/xre/nsEmbedFunctions.cpp
+++ b/toolkit/xre/nsEmbedFunctions.cpp
@@ -117,16 +117,18 @@ using mozilla::_ipdltest::IPDLUnitTestPr
 #ifdef MOZ_JPROF
 #include "jprof.h"
 #endif
 
 #if defined(XP_WIN) && defined(MOZ_ENABLE_SKIA_PDF)
 #include "mozilla/widget/PDFiumProcessChild.h"
 #endif
 
+#include "VRProcessChild.h"
+
 using namespace mozilla;
 
 using mozilla::ipc::BrowserProcessSubThread;
 using mozilla::ipc::GeckoChildProcessHost;
 using mozilla::ipc::IOThreadChild;
 using mozilla::ipc::ProcessChild;
 using mozilla::ipc::ScopedXREEmbed;
 
@@ -668,16 +670,17 @@ XRE_InitChildProcess(int aArgc,
   switch (XRE_GetProcessType()) {
   case GeckoProcessType_Content:
   case GeckoProcessType_GPU:
       // Content processes need the XPCOM/chromium frankenventloop
       uiLoopType = MessageLoop::TYPE_MOZILLA_CHILD;
       break;
   case GeckoProcessType_GMPlugin:
   case GeckoProcessType_PDFium:
+  case GeckoProcessType_VR:
       uiLoopType = MessageLoop::TYPE_DEFAULT;
       break;
   default:
       uiLoopType = MessageLoop::TYPE_UI;
       break;
   }
 
   // If we are recording or replaying, initialize state and update arguments
@@ -730,16 +733,20 @@ XRE_InitChildProcess(int aArgc,
       case GeckoProcessType_PDFium:
         process = new widget::PDFiumProcessChild(parentPID);
         break;
 #endif
       case GeckoProcessType_GPU:
         process = new gfx::GPUProcessImpl(parentPID);
         break;
 
+      case GeckoProcessType_VR:
+        process = new gfx::VRProcessChild(parentPID);
+        break;
+
       default:
         MOZ_CRASH("Unknown main thread class");
       }
 
       if (!process->Init(aArgc, aArgv)) {
         return NS_ERROR_FAILURE;
       }
 
--- a/tools/fuzzing/faulty/Faulty.cpp
+++ b/tools/fuzzing/faulty/Faulty.cpp
@@ -278,17 +278,18 @@ Faulty::IsValidProcessType(void)
   if (targetChildren && !targetParent) {
     // Fuzz every child process type but not the parent process.
     isValidProcessType = currentProcessType == GeckoProcessType_Default;
   } else if (!targetChildren && targetParent
           && (currentProcessType == GeckoProcessType_Plugin
           || currentProcessType == GeckoProcessType_Content
           || currentProcessType == GeckoProcessType_GMPlugin
           || currentProcessType == GeckoProcessType_GPU
-          || currentProcessType == GeckoProcessType_PDFium)) {
+          || currentProcessType == GeckoProcessType_PDFium
+          || currentProcessType == GeckoProcessType_VR)) {
     // Fuzz inside any of the above child process only.
     isValidProcessType = true;
   } else if (targetChildren && targetParent) {
     // Fuzz every process type.
     isValidProcessType = true;
   } else {
     // Fuzz no process type at all.
     isValidProcessType = false;
--- a/xpcom/build/nsXULAppAPI.h
+++ b/xpcom/build/nsXULAppAPI.h
@@ -370,28 +370,30 @@ enum GeckoProcessType
   GeckoProcessType_Content,
 
   GeckoProcessType_IPDLUnitTest,
 
   GeckoProcessType_GMPlugin, // Gecko Media Plugin
 
   GeckoProcessType_GPU,      // GPU and compositor process
   GeckoProcessType_PDFium,   // Gecko PDFium process
+  GeckoProcessType_VR,       // VR process
   GeckoProcessType_End,
   GeckoProcessType_Invalid = GeckoProcessType_End
 };
 
 static const char* const kGeckoProcessTypeString[] = {
   "default",
   "plugin",
   "tab",
   "ipdlunittest",
   "geckomediaplugin",
   "gpu",
-  "pdfium"
+  "pdfium",
+  "vr"
 };
 
 static_assert(MOZ_ARRAY_LENGTH(kGeckoProcessTypeString) ==
               GeckoProcessType_End,
               "Array length mismatch");
 
 XRE_API(const char*,
         XRE_ChildProcessTypeToString, (GeckoProcessType aProcessType))
@@ -460,16 +462,19 @@ XRE_API(bool,
 
 XRE_API(bool,
         XRE_IsContentProcess, ())
 
 XRE_API(bool,
         XRE_IsGPUProcess, ())
 
 XRE_API(bool,
+        XRE_IsVRProcess, ())
+
+XRE_API(bool,
         XRE_IsPluginProcess, ())
 
 /**
  * Returns true if the appshell should run its own native event loop. Returns
  * false if we should rely solely on the Gecko event loop.
  */
 XRE_API(bool,
         XRE_UseNativeEventProcessing, ())
--- a/xpcom/system/nsIXULRuntime.idl
+++ b/xpcom/system/nsIXULRuntime.idl
@@ -72,16 +72,17 @@ interface nsIXULRuntime : nsISupports
    */
   const unsigned long PROCESS_TYPE_DEFAULT = 0;
   const unsigned long PROCESS_TYPE_PLUGIN = 1;
   const unsigned long PROCESS_TYPE_CONTENT = 2;
   const unsigned long PROCESS_TYPE_IPDLUNITTEST = 3;
   const unsigned long PROCESS_TYPE_GMPLUGIN = 4;
   const unsigned long PROCESS_TYPE_GPU = 5;
   const unsigned long PROCESS_TYPE_PDFIUM = 6;
+  const unsigned long PROCESS_TYPE_VR = 7;
 
   /**
    * The type of the caller's process.  Returns one of the values above.
    */
   readonly attribute unsigned long processType;
 
   /**
    * The system process ID of the caller's process.