Bug 1366711 - Make it possible to hide applications launched with nsIProcess; r?bsmedberg draft
authorGabriele Svelto <gsvelto@mozilla.com>
Mon, 22 May 2017 10:23:00 +0200
changeset 584409 f0fef5d6f0f6b9e5cd209fb1a9b0a8ef2200a287
parent 582001 5b74bbf20e803e299790d266fc6ebf5d53b7a1b7
child 630369 85d608a2f0364a2322de333154da81fd371ae7cc
push id60728
push usergsvelto@mozilla.com
push dateThu, 25 May 2017 13:06:45 +0000
reviewersbsmedberg
bugs1366711
milestone55.0a1
Bug 1366711 - Make it possible to hide applications launched with nsIProcess; r?bsmedberg MozReview-Commit-ID: K3vadzPg8SR
xpcom/threads/nsIProcess.idl
xpcom/threads/nsProcess.h
xpcom/threads/nsProcessCommon.cpp
--- a/xpcom/threads/nsIProcess.idl
+++ b/xpcom/threads/nsIProcess.idl
@@ -70,16 +70,23 @@ interface nsIProcess : nsISupports
    *                   observer will be notified on the main thread.
    * @param holdWeak   Whether to use a weak reference to hold the observer.
    */
   void runwAsync([array, size_is(count)] in wstring args,
 		 in unsigned long count,
 		 [optional] in nsIObserver observer, [optional] in boolean holdWeak);
 
   /**
+   * When set to true the process will not open a new window when started and
+   * will run hidden from the user. This currently affects only the Windows
+   * platform.
+   */
+  attribute boolean startHidden;
+
+  /**
    * The process identifier of the currently running process. This will only
    * be available after the process has started and may not be available on
    * some platforms.
    */
   readonly attribute unsigned long pid;
 
   /**
    * The exit value of the process. This is only valid after the process has
--- a/xpcom/threads/nsProcess.h
+++ b/xpcom/threads/nsProcess.h
@@ -57,16 +57,17 @@ private:
   // The 'args' array is null-terminated.
   nsresult RunProcess(bool aBlocking, char** aArgs, nsIObserver* aObserver,
                       bool aHoldWeak, bool aArgsUTF8);
 
   PRThread* mThread;
   mozilla::Mutex mLock;
   bool mShutdown;
   bool mBlocking;
+  bool mStartHidden;
 
   nsCOMPtr<nsIFile> mExecutable;
   nsString mTargetPath;
   int32_t mPid;
   nsCOMPtr<nsIObserver> mObserver;
   nsWeakPtr mWeakObserver;
 
   // These members are modified by multiple threads, any accesses should be
--- a/xpcom/threads/nsProcessCommon.cpp
+++ b/xpcom/threads/nsProcessCommon.cpp
@@ -67,16 +67,17 @@ NS_IMPL_ISUPPORTS(nsProcess, nsIProcess,
                   nsIObserver)
 
 //Constructor
 nsProcess::nsProcess()
   : mThread(nullptr)
   , mLock("nsProcess.mLock")
   , mShutdown(false)
   , mBlocking(false)
+  , mStartHidden(false)
   , mPid(-1)
   , mObserver(nullptr)
   , mWeakObserver(nullptr)
   , mExitValue(-1)
 #if !defined(XP_MACOSX)
   , mProcess(nullptr)
 #endif
 {
@@ -482,17 +483,17 @@ nsProcess::RunProcess(bool aBlocking, ch
   // The program name in aMyArgv[0] is always UTF-8
   NS_ConvertUTF8toUTF16 wideFile(aMyArgv[0]);
 
   SHELLEXECUTEINFOW sinfo;
   memset(&sinfo, 0, sizeof(SHELLEXECUTEINFOW));
   sinfo.cbSize = sizeof(SHELLEXECUTEINFOW);
   sinfo.hwnd   = nullptr;
   sinfo.lpFile = wideFile.get();
-  sinfo.nShow  = SW_SHOWNORMAL;
+  sinfo.nShow  = mStartHidden ? SW_HIDE : SW_SHOWNORMAL;
   sinfo.fMask  = SEE_MASK_FLAG_DDEWAIT |
                  SEE_MASK_NO_CONSOLE |
                  SEE_MASK_NOCLOSEPROCESS;
 
   if (cmdLine) {
     sinfo.lpParameters = cmdLine;
   }
 
@@ -584,16 +585,30 @@ nsProcess::GetIsRunning(bool* aIsRunning
   } else {
     *aIsRunning = false;
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsProcess::GetStartHidden(bool* aStartHidden)
+{
+  *aStartHidden = mStartHidden;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsProcess::SetStartHidden(bool aStartHidden)
+{
+  mStartHidden = aStartHidden;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsProcess::GetPid(uint32_t* aPid)
 {
   if (!mThread) {
     return NS_ERROR_FAILURE;
   }
   if (mPid < 0) {
     return NS_ERROR_NOT_IMPLEMENTED;
   }