Bug 1366711 - Make it possible to hide applications launched with nsIProcess; r?bsmedberg
MozReview-Commit-ID: K3vadzPg8SR
--- 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;
}