2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-14 15:58:45 -08:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
|
2011-01-05 05:48:21 -08:00
|
|
|
#if defined(MOZ_WIDGET_QT)
|
|
|
|
#include "nsQAppInstance.h"
|
|
|
|
#endif
|
|
|
|
|
2009-08-28 16:16:19 -07:00
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2012-06-15 23:06:10 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
2009-10-19 09:28:42 -07:00
|
|
|
#include <glib.h>
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-06-30 12:21:25 -07:00
|
|
|
#include "prenv.h"
|
|
|
|
|
|
|
|
#include "nsIAppShell.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIAppStartupNotifier.h"
|
|
|
|
#include "nsIDirectoryService.h"
|
2012-06-05 19:08:30 -07:00
|
|
|
#include "nsIFile.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIToolkitChromeRegistry.h"
|
2009-06-30 12:21:25 -07:00
|
|
|
#include "nsIToolkitProfile.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-02-03 14:17:09 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <process.h>
|
2014-05-17 20:16:51 -07:00
|
|
|
#include "mozilla/ipc/WindowsMessageLoop.h"
|
2010-02-03 14:17:09 -08:00
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
|
|
|
#include "nsAppRunner.h"
|
2009-07-10 23:33:10 -07:00
|
|
|
#include "nsAutoRef.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsDirectoryServiceDefs.h"
|
2010-01-12 13:14:38 -08:00
|
|
|
#include "nsExceptionHandler.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsString.h"
|
2009-06-30 12:21:25 -07:00
|
|
|
#include "nsThreadUtils.h"
|
2010-12-03 00:24:17 -08:00
|
|
|
#include "nsJSUtils.h"
|
2009-06-30 12:21:25 -07:00
|
|
|
#include "nsWidgetsCID.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsXREDirProvider.h"
|
2009-06-30 12:21:25 -07:00
|
|
|
|
2010-08-12 21:31:59 -07:00
|
|
|
#include "mozilla/Omnijar.h"
|
2010-09-10 10:09:30 -07:00
|
|
|
#if defined(XP_MACOSX)
|
2011-10-26 19:57:26 -07:00
|
|
|
#include "nsVersionComparator.h"
|
2010-09-10 10:09:30 -07:00
|
|
|
#include "chrome/common/mach_ipc_mac.h"
|
|
|
|
#endif
|
2010-02-24 14:25:16 -08:00
|
|
|
#include "nsX11ErrorHandler.h"
|
2009-07-20 12:04:52 -07:00
|
|
|
#include "base/at_exit.h"
|
|
|
|
#include "base/command_line.h"
|
|
|
|
#include "base/message_loop.h"
|
2009-10-27 14:52:37 -07:00
|
|
|
#include "base/process_util.h"
|
2009-07-20 12:04:52 -07:00
|
|
|
#include "chrome/common/child_process.h"
|
2010-04-20 11:43:51 -07:00
|
|
|
#include "chrome/common/notification_service.h"
|
2009-07-20 12:04:52 -07:00
|
|
|
|
2010-02-03 14:17:09 -08:00
|
|
|
#include "mozilla/ipc/BrowserProcessSubThread.h"
|
2010-05-10 21:18:00 -07:00
|
|
|
#include "mozilla/ipc/GeckoChildProcessHost.h"
|
|
|
|
#include "mozilla/ipc/IOThreadChild.h"
|
|
|
|
#include "mozilla/ipc/ProcessChild.h"
|
2009-06-30 12:21:25 -07:00
|
|
|
#include "ScopedXREEmbed.h"
|
|
|
|
|
2010-05-10 21:18:00 -07:00
|
|
|
#include "mozilla/plugins/PluginProcessChild.h"
|
2010-07-19 11:33:33 -07:00
|
|
|
#include "mozilla/dom/ContentProcess.h"
|
|
|
|
#include "mozilla/dom/ContentParent.h"
|
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2009-06-30 12:21:25 -07:00
|
|
|
|
2009-07-10 23:33:10 -07:00
|
|
|
#include "mozilla/ipc/TestShellParent.h"
|
|
|
|
#include "mozilla/ipc/XPCShellEnvironment.h"
|
|
|
|
|
2014-05-17 20:05:46 -07:00
|
|
|
#include "GMPProcessChild.h"
|
|
|
|
|
2013-03-18 07:25:50 -07:00
|
|
|
#include "GeckoProfiler.h"
|
2012-07-27 11:57:48 -07:00
|
|
|
|
2009-10-06 11:02:26 -07:00
|
|
|
#ifdef MOZ_IPDL_TESTS
|
|
|
|
#include "mozilla/_ipdltest/IPDLUnitTests.h"
|
2010-05-10 21:18:00 -07:00
|
|
|
#include "mozilla/_ipdltest/IPDLUnitTestProcessChild.h"
|
2009-10-06 11:02:26 -07:00
|
|
|
|
2010-05-10 21:18:00 -07:00
|
|
|
using mozilla::_ipdltest::IPDLUnitTestProcessChild;
|
2009-10-06 11:02:26 -07:00
|
|
|
#endif // ifdef MOZ_IPDL_TESTS
|
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2009-09-02 17:18:27 -07:00
|
|
|
using mozilla::ipc::BrowserProcessSubThread;
|
2010-05-10 21:18:00 -07:00
|
|
|
using mozilla::ipc::GeckoChildProcessHost;
|
|
|
|
using mozilla::ipc::IOThreadChild;
|
|
|
|
using mozilla::ipc::ProcessChild;
|
2009-06-30 12:21:25 -07:00
|
|
|
using mozilla::ipc::ScopedXREEmbed;
|
|
|
|
|
2010-05-10 21:18:00 -07:00
|
|
|
using mozilla::plugins::PluginProcessChild;
|
2010-07-19 11:33:33 -07:00
|
|
|
using mozilla::dom::ContentProcess;
|
|
|
|
using mozilla::dom::ContentParent;
|
|
|
|
using mozilla::dom::ContentChild;
|
2009-11-06 12:43:39 -08:00
|
|
|
|
2009-07-10 23:33:10 -07:00
|
|
|
using mozilla::ipc::TestShellParent;
|
2009-08-28 16:16:19 -07:00
|
|
|
using mozilla::ipc::TestShellCommandParent;
|
2009-07-10 23:33:10 -07:00
|
|
|
using mozilla::ipc::XPCShellEnvironment;
|
2009-12-14 14:13:00 -08:00
|
|
|
|
|
|
|
using mozilla::startup::sChildProcessType;
|
2009-06-30 12:21:25 -07:00
|
|
|
|
|
|
|
static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-14 17:25:10 -07:00
|
|
|
#ifdef XP_WIN
|
2013-12-03 07:07:22 -08:00
|
|
|
static const wchar_t kShellLibraryName[] = L"shell32.dll";
|
2010-05-14 17:25:10 -07:00
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2012-06-05 19:08:30 -07:00
|
|
|
XRE_LockProfileDirectory(nsIFile* aDirectory,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsISupports* *aLockObject)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIProfileLock> lock;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsresult rv = NS_LockProfilePath(aDirectory, nullptr, nullptr,
|
2007-03-22 10:30:00 -07:00
|
|
|
getter_AddRefs(lock));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
NS_ADDREF(*aLockObject = lock);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t sInitCounter;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult
|
2012-06-05 19:08:30 -07:00
|
|
|
XRE_InitEmbedding2(nsIFile *aLibXULDirectory,
|
|
|
|
nsIFile *aAppDirectory,
|
2010-06-10 11:11:11 -07:00
|
|
|
nsIDirectoryServiceProvider *aAppDirProvider)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Initialize some globals to make nsXREDirProvider happy
|
2012-07-30 07:20:58 -07:00
|
|
|
static char* kNullCommandLine[] = { nullptr };
|
2007-03-22 10:30:00 -07:00
|
|
|
gArgv = kNullCommandLine;
|
|
|
|
gArgc = 0;
|
|
|
|
|
|
|
|
NS_ENSURE_ARG(aLibXULDirectory);
|
|
|
|
|
|
|
|
if (++sInitCounter > 1) // XXXbsmedberg is this really the right solution?
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (!aAppDirectory)
|
|
|
|
aAppDirectory = aLibXULDirectory;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
new nsXREDirProvider; // This sets gDirServiceProvider
|
|
|
|
if (!gDirServiceProvider)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
rv = gDirServiceProvider->Initialize(aAppDirectory, aLibXULDirectory,
|
|
|
|
aAppDirProvider);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
rv = NS_InitXPCOM2(nullptr, aAppDirectory, gDirServiceProvider);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2010-03-13 00:03:27 -08:00
|
|
|
// We do not need to autoregister components here. The CheckCompatibility()
|
|
|
|
// bits in nsAppRunner.cpp check for an invalidation flag in
|
|
|
|
// compatibility.ini.
|
|
|
|
// If the app wants to autoregister every time (for instance, if it's debug),
|
|
|
|
// it can do so after we return from this function.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIObserver> startupNotifier
|
|
|
|
(do_CreateInstance(NS_APPSTARTUPNOTIFIER_CONTRACTID));
|
|
|
|
if (!startupNotifier)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
startupNotifier->Observe(nullptr, APPSTARTUP_TOPIC, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
XRE_NotifyProfile()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(gDirServiceProvider, "XRE_InitEmbedding was not called!");
|
|
|
|
gDirServiceProvider->DoStartup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
XRE_TermEmbedding()
|
|
|
|
{
|
|
|
|
if (--sInitCounter != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NS_ASSERTION(gDirServiceProvider,
|
|
|
|
"XRE_TermEmbedding without XRE_InitEmbedding");
|
|
|
|
|
|
|
|
gDirServiceProvider->DoShutdown();
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ShutdownXPCOM(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
delete gDirServiceProvider;
|
|
|
|
}
|
2009-06-30 12:21:25 -07:00
|
|
|
|
2009-07-10 12:03:09 -07:00
|
|
|
const char*
|
2009-08-19 10:09:51 -07:00
|
|
|
XRE_ChildProcessTypeToString(GeckoProcessType aProcessType)
|
2009-07-10 12:03:09 -07:00
|
|
|
{
|
2009-08-19 10:09:51 -07:00
|
|
|
return (aProcessType < GeckoProcessType_End) ?
|
2012-07-30 07:20:58 -07:00
|
|
|
kGeckoProcessTypeString[aProcessType] : nullptr;
|
2009-07-10 12:03:09 -07:00
|
|
|
}
|
|
|
|
|
2009-08-19 10:09:51 -07:00
|
|
|
GeckoProcessType
|
2009-07-10 12:03:09 -07:00
|
|
|
XRE_StringToChildProcessType(const char* aProcessTypeString)
|
|
|
|
{
|
|
|
|
for (int i = 0;
|
2011-10-10 22:50:08 -07:00
|
|
|
i < (int) ArrayLength(kGeckoProcessTypeString);
|
2009-07-10 12:03:09 -07:00
|
|
|
++i) {
|
2009-08-19 10:09:51 -07:00
|
|
|
if (!strcmp(kGeckoProcessTypeString[i], aProcessTypeString)) {
|
|
|
|
return static_cast<GeckoProcessType>(i);
|
2009-07-10 12:03:09 -07:00
|
|
|
}
|
|
|
|
}
|
2009-08-19 10:09:51 -07:00
|
|
|
return GeckoProcessType_Invalid;
|
2009-07-10 12:03:09 -07:00
|
|
|
}
|
|
|
|
|
2009-12-14 14:13:00 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace startup {
|
|
|
|
GeckoProcessType sChildProcessType = GeckoProcessType_Default;
|
|
|
|
}
|
|
|
|
}
|
2009-08-19 10:09:51 -07:00
|
|
|
|
2010-01-12 13:14:38 -08:00
|
|
|
#if defined(MOZ_CRASHREPORTER)
|
2010-03-18 19:01:10 -07:00
|
|
|
// FIXME/bug 539522: this out-of-place function is stuck here because
|
|
|
|
// IPDL wants access to this crashreporter interface, and
|
|
|
|
// crashreporter is built in such a way to make that awkward
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
XRE_TakeMinidumpForChild(uint32_t aChildPid, nsIFile** aDump,
|
|
|
|
uint32_t* aSequence)
|
2010-03-18 19:01:10 -07:00
|
|
|
{
|
2012-07-10 19:20:05 -07:00
|
|
|
return CrashReporter::TakeMinidumpForChild(aChildPid, aDump, aSequence);
|
2010-03-18 19:01:10 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-01-12 13:14:38 -08:00
|
|
|
XRE_SetRemoteExceptionHandler(const char* aPipe/*= 0*/)
|
|
|
|
{
|
2010-08-16 12:05:09 -07:00
|
|
|
#if defined(XP_WIN) || defined(XP_MACOSX)
|
2010-01-12 13:14:38 -08:00
|
|
|
return CrashReporter::SetRemoteExceptionHandler(nsDependentCString(aPipe));
|
|
|
|
#elif defined(OS_LINUX)
|
|
|
|
return CrashReporter::SetRemoteExceptionHandler();
|
|
|
|
#else
|
|
|
|
# error "OOP crash reporter unsupported on this platform"
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif // if defined(MOZ_CRASHREPORTER)
|
|
|
|
|
2010-05-14 17:25:10 -07:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
void
|
|
|
|
SetTaskbarGroupId(const nsString& aId)
|
|
|
|
{
|
|
|
|
typedef HRESULT (WINAPI * SetCurrentProcessExplicitAppUserModelIDPtr)(PCWSTR AppID);
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
SetCurrentProcessExplicitAppUserModelIDPtr funcAppUserModelID = nullptr;
|
2010-05-14 17:25:10 -07:00
|
|
|
|
|
|
|
HMODULE hDLL = ::LoadLibraryW(kShellLibraryName);
|
|
|
|
|
|
|
|
funcAppUserModelID = (SetCurrentProcessExplicitAppUserModelIDPtr)
|
|
|
|
GetProcAddress(hDLL, "SetCurrentProcessExplicitAppUserModelID");
|
|
|
|
|
|
|
|
if (!funcAppUserModelID) {
|
|
|
|
::FreeLibrary(hDLL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(funcAppUserModelID(aId.get()))) {
|
|
|
|
NS_WARNING("SetCurrentProcessExplicitAppUserModelID failed for child process.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hDLL)
|
|
|
|
::FreeLibrary(hDLL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-06-30 12:21:25 -07:00
|
|
|
nsresult
|
|
|
|
XRE_InitChildProcess(int aArgc,
|
|
|
|
char* aArgv[],
|
2009-08-19 10:09:51 -07:00
|
|
|
GeckoProcessType aProcess)
|
2009-06-30 12:21:25 -07:00
|
|
|
{
|
2009-10-27 14:52:37 -07:00
|
|
|
NS_ENSURE_ARG_MIN(aArgc, 2);
|
2009-06-30 12:21:25 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aArgv);
|
|
|
|
NS_ENSURE_ARG_POINTER(aArgv[0]);
|
2013-05-30 06:23:50 -07:00
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
// From the --attach-console support in nsNativeAppSupportWin.cpp, but
|
|
|
|
// here we are a content child process, so we always attempt to attach
|
|
|
|
// to the parent's (ie, the browser's) console.
|
|
|
|
// Try to attach console to the parent process.
|
|
|
|
// It will succeed when the parent process is a command line,
|
|
|
|
// so that stdio will be displayed in it.
|
|
|
|
if (AttachConsole(ATTACH_PARENT_PROCESS)) {
|
|
|
|
// Change std handles to refer to new console handles.
|
|
|
|
// Before doing so, ensure that stdout/stderr haven't been
|
|
|
|
// redirected to a valid file
|
|
|
|
if (_fileno(stdout) == -1 ||
|
|
|
|
_get_osfhandle(fileno(stdout)) == -1)
|
|
|
|
freopen("CONOUT$", "w", stdout);
|
|
|
|
// Merge stderr into CONOUT$ since there isn't any `CONERR$`.
|
|
|
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms683231%28v=vs.85%29.aspx
|
|
|
|
if (_fileno(stderr) == -1 ||
|
|
|
|
_get_osfhandle(fileno(stderr)) == -1)
|
|
|
|
freopen("CONOUT$", "w", stderr);
|
|
|
|
if (_fileno(stdin) == -1 || _get_osfhandle(fileno(stdin)) == -1)
|
|
|
|
freopen("CONIN$", "r", stdin);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-05-28 05:03:38 -07:00
|
|
|
char aLocal;
|
|
|
|
profiler_init(&aLocal);
|
2013-03-15 21:47:02 -07:00
|
|
|
PROFILER_LABEL("Startup", "XRE_InitChildProcess");
|
2009-06-30 12:21:25 -07:00
|
|
|
|
2009-11-10 11:16:12 -08:00
|
|
|
sChildProcessType = aProcess;
|
2010-01-27 20:23:16 -08:00
|
|
|
|
2010-09-10 10:09:30 -07:00
|
|
|
// Complete 'task_t' exchange for Mac OS X. This structure has the same size
|
|
|
|
// regardless of architecture so we don't have any cross-arch issues here.
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
if (aArgc < 1)
|
2012-07-30 02:24:36 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-09-10 10:09:30 -07:00
|
|
|
const char* const mach_port_name = aArgv[--aArgc];
|
|
|
|
|
|
|
|
const int kTimeoutMs = 1000;
|
|
|
|
|
|
|
|
MachSendMessage child_message(0);
|
|
|
|
if (!child_message.AddDescriptor(mach_task_self())) {
|
|
|
|
NS_WARNING("child AddDescriptor(mach_task_self()) failed.");
|
2012-07-30 02:24:36 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-09-10 10:09:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ReceivePort child_recv_port;
|
|
|
|
mach_port_t raw_child_recv_port = child_recv_port.GetPort();
|
|
|
|
if (!child_message.AddDescriptor(raw_child_recv_port)) {
|
|
|
|
NS_WARNING("Adding descriptor to message failed");
|
2012-07-30 02:24:36 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-09-10 10:09:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
MachPortSender child_sender(mach_port_name);
|
|
|
|
kern_return_t err = child_sender.SendMessage(child_message, kTimeoutMs);
|
|
|
|
if (err != KERN_SUCCESS) {
|
|
|
|
NS_WARNING("child SendMessage() failed");
|
2012-07-30 02:24:36 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-09-10 10:09:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
MachReceiveMessage parent_message;
|
|
|
|
err = child_recv_port.WaitForMessage(&parent_message, kTimeoutMs);
|
|
|
|
if (err != KERN_SUCCESS) {
|
|
|
|
NS_WARNING("child WaitForMessage() failed");
|
2012-07-30 02:24:36 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-09-10 10:09:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (parent_message.GetTranslatedPort(0) == MACH_PORT_NULL) {
|
|
|
|
NS_WARNING("child GetTranslatedPort(0) failed");
|
2012-07-30 02:24:36 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-09-10 10:09:30 -07:00
|
|
|
}
|
|
|
|
err = task_set_bootstrap_port(mach_task_self(),
|
|
|
|
parent_message.GetTranslatedPort(0));
|
|
|
|
if (err != KERN_SUCCESS) {
|
|
|
|
NS_WARNING("child task_set_bootstrap_port() failed");
|
2012-07-30 02:24:36 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-09-10 10:09:30 -07:00
|
|
|
}
|
|
|
|
#endif
|
2011-06-23 16:30:31 -07:00
|
|
|
|
|
|
|
SetupErrorHandling(aArgv[0]);
|
|
|
|
|
2010-09-10 10:09:30 -07:00
|
|
|
#if defined(MOZ_CRASHREPORTER)
|
|
|
|
if (aArgc < 1)
|
2012-07-30 02:24:36 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-09-10 10:09:30 -07:00
|
|
|
const char* const crashReporterArg = aArgv[--aArgc];
|
|
|
|
|
|
|
|
# if defined(XP_WIN) || defined(XP_MACOSX)
|
|
|
|
// on windows and mac, |crashReporterArg| is the named pipe on which the
|
|
|
|
// server is listening for requests, or "-" if crash reporting is
|
|
|
|
// disabled.
|
2011-09-08 09:11:52 -07:00
|
|
|
if (0 != strcmp("-", crashReporterArg) &&
|
|
|
|
!XRE_SetRemoteExceptionHandler(crashReporterArg)) {
|
|
|
|
// Bug 684322 will add better visibility into this condition
|
|
|
|
NS_WARNING("Could not setup crash reporting\n");
|
|
|
|
}
|
2010-09-10 10:09:30 -07:00
|
|
|
# elif defined(OS_LINUX)
|
|
|
|
// on POSIX, |crashReporterArg| is "true" if crash reporting is
|
|
|
|
// enabled, false otherwise
|
2011-09-08 09:11:52 -07:00
|
|
|
if (0 != strcmp("false", crashReporterArg) &&
|
2013-10-10 13:36:42 -07:00
|
|
|
!XRE_SetRemoteExceptionHandler(nullptr)) {
|
2011-09-08 09:11:52 -07:00
|
|
|
// Bug 684322 will add better visibility into this condition
|
|
|
|
NS_WARNING("Could not setup crash reporting\n");
|
|
|
|
}
|
2010-09-10 10:09:30 -07:00
|
|
|
# else
|
|
|
|
# error "OOP crash reporting unsupported on this platform"
|
|
|
|
# endif
|
|
|
|
#endif // if defined(MOZ_CRASHREPORTER)
|
|
|
|
|
2010-01-28 22:50:44 -08:00
|
|
|
gArgv = aArgv;
|
|
|
|
gArgc = aArgc;
|
|
|
|
|
2012-06-15 23:06:10 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
2013-10-10 13:36:42 -07:00
|
|
|
g_thread_init(nullptr);
|
2009-10-19 09:28:42 -07:00
|
|
|
#endif
|
|
|
|
|
2011-01-05 05:48:21 -08:00
|
|
|
#if defined(MOZ_WIDGET_QT)
|
|
|
|
nsQAppInstance::AddRef();
|
|
|
|
#endif
|
|
|
|
|
2009-06-30 12:21:25 -07:00
|
|
|
if (PR_GetEnv("MOZ_DEBUG_CHILD_PROCESS")) {
|
2009-07-07 09:26:49 -07:00
|
|
|
#ifdef OS_POSIX
|
2014-03-06 05:52:54 -08:00
|
|
|
printf("\n\nCHILDCHILDCHILDCHILD\n debug me @ %d\n\n", getpid());
|
2009-06-30 12:21:25 -07:00
|
|
|
sleep(30);
|
2009-07-07 09:26:49 -07:00
|
|
|
#elif defined(OS_WIN)
|
2013-08-16 16:38:17 -07:00
|
|
|
// Windows has a decent JIT debugging story, so NS_DebugBreak does the
|
|
|
|
// right thing.
|
|
|
|
NS_DebugBreak(NS_DEBUG_BREAK,
|
|
|
|
"Invoking NS_DebugBreak() to debug child process",
|
|
|
|
nullptr, __FILE__, __LINE__);
|
2009-07-07 09:26:49 -07:00
|
|
|
#endif
|
2009-06-30 12:21:25 -07:00
|
|
|
}
|
|
|
|
|
2009-10-27 14:52:37 -07:00
|
|
|
// child processes launched by GeckoChildProcessHost get this magic
|
|
|
|
// argument appended to their command lines
|
|
|
|
const char* const parentPIDString = aArgv[aArgc-1];
|
|
|
|
NS_ABORT_IF_FALSE(parentPIDString, "NULL parent PID");
|
|
|
|
--aArgc;
|
|
|
|
|
|
|
|
char* end = 0;
|
|
|
|
base::ProcessId parentPID = strtol(parentPIDString, &end, 10);
|
|
|
|
NS_ABORT_IF_FALSE(!*end, "invalid parent PID");
|
2009-11-17 14:18:06 -08:00
|
|
|
|
2009-10-27 14:52:37 -07:00
|
|
|
base::ProcessHandle parentHandle;
|
2011-07-19 03:04:54 -07:00
|
|
|
mozilla::DebugOnly<bool> ok = base::OpenProcessHandle(parentPID, &parentHandle);
|
2009-11-17 14:18:06 -08:00
|
|
|
NS_ABORT_IF_FALSE(ok, "can't open handle to parent");
|
2009-10-27 14:52:37 -07:00
|
|
|
|
2010-05-14 17:25:10 -07:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
// On Win7+, register the application user model id passed in by
|
|
|
|
// parent. This insures windows created by the container properly
|
|
|
|
// group with the parent app on the Win7 taskbar.
|
2012-12-18 08:24:42 -08:00
|
|
|
const char* const appModelUserId = aArgv[--aArgc];
|
2010-05-14 17:25:10 -07:00
|
|
|
if (appModelUserId) {
|
|
|
|
// '-' implies no support
|
|
|
|
if (*appModelUserId != '-') {
|
|
|
|
nsString appId;
|
|
|
|
appId.AssignWithConversion(nsDependentCString(appModelUserId));
|
|
|
|
// The version string is encased in quotes
|
|
|
|
appId.Trim(NS_LITERAL_CSTRING("\"").get());
|
|
|
|
// Set the id
|
|
|
|
SetTaskbarGroupId(appId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-06-30 12:21:25 -07:00
|
|
|
base::AtExitManager exitManager;
|
2010-04-20 11:43:51 -07:00
|
|
|
NotificationService notificationService;
|
2009-11-03 21:12:18 -08:00
|
|
|
|
2009-11-19 14:57:56 -08:00
|
|
|
NS_LogInit();
|
|
|
|
|
2012-08-06 05:02:31 -07:00
|
|
|
nsresult rv = XRE_InitCommandLine(aArgc, aArgv);
|
2009-11-19 14:57:56 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
2013-04-18 08:34:49 -07:00
|
|
|
profiler_shutdown();
|
2009-11-19 14:57:56 -08:00
|
|
|
NS_LogTerm();
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2009-11-03 21:12:18 -08:00
|
|
|
|
2010-05-13 23:41:14 -07:00
|
|
|
MessageLoop::Type uiLoopType;
|
|
|
|
switch (aProcess) {
|
|
|
|
case GeckoProcessType_Content:
|
|
|
|
// Content processes need the XPCOM/chromium frankenventloop
|
|
|
|
uiLoopType = MessageLoop::TYPE_MOZILLA_CHILD;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
uiLoopType = MessageLoop::TYPE_UI;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-06-30 12:21:25 -07:00
|
|
|
{
|
2010-08-05 15:11:23 -07:00
|
|
|
// This is a lexical scope for the MessageLoop below. We want it
|
|
|
|
// to go out of scope before NS_LogTerm() so that we don't get
|
|
|
|
// spurious warnings about XPCOM objects being destroyed from a
|
|
|
|
// static context.
|
|
|
|
|
|
|
|
// Associate this thread with a UI MessageLoop
|
|
|
|
MessageLoop uiMessageLoop(uiLoopType);
|
|
|
|
{
|
|
|
|
nsAutoPtr<ProcessChild> process;
|
|
|
|
|
2014-05-17 20:16:51 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
mozilla::ipc::windows::InitUIThread();
|
|
|
|
#endif
|
|
|
|
|
2010-08-05 15:11:23 -07:00
|
|
|
switch (aProcess) {
|
|
|
|
case GeckoProcessType_Default:
|
|
|
|
NS_RUNTIMEABORT("This makes no sense");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GeckoProcessType_Plugin:
|
|
|
|
process = new PluginProcessChild(parentHandle);
|
|
|
|
break;
|
|
|
|
|
2012-12-18 08:24:42 -08:00
|
|
|
case GeckoProcessType_Content: {
|
|
|
|
process = new ContentProcess(parentHandle);
|
|
|
|
// If passed in grab the application path for xpcom init
|
|
|
|
nsCString appDir;
|
|
|
|
for (int idx = aArgc; idx > 0; idx--) {
|
|
|
|
if (aArgv[idx] && !strcmp(aArgv[idx], "-appdir")) {
|
|
|
|
appDir.Assign(nsDependentCString(aArgv[idx+1]));
|
|
|
|
static_cast<ContentProcess*>(process.get())->SetAppDir(appDir);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-05 15:11:23 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GeckoProcessType_IPDLUnitTest:
|
2009-10-06 11:02:26 -07:00
|
|
|
#ifdef MOZ_IPDL_TESTS
|
2010-08-05 15:11:23 -07:00
|
|
|
process = new IPDLUnitTestProcessChild(parentHandle);
|
2010-05-10 21:18:00 -07:00
|
|
|
#else
|
2010-08-05 15:11:23 -07:00
|
|
|
NS_RUNTIMEABORT("rebuild with --enable-ipdl-tests");
|
2009-10-06 11:02:26 -07:00
|
|
|
#endif
|
2010-08-05 15:11:23 -07:00
|
|
|
break;
|
2009-10-06 11:02:26 -07:00
|
|
|
|
2014-05-17 20:05:46 -07:00
|
|
|
case GeckoProcessType_GMPlugin:
|
|
|
|
process = new gmp::GMPProcessChild(parentHandle);
|
|
|
|
break;
|
|
|
|
|
2010-08-05 15:11:23 -07:00
|
|
|
default:
|
|
|
|
NS_RUNTIMEABORT("Unknown main thread class");
|
|
|
|
}
|
2009-06-30 12:21:25 -07:00
|
|
|
|
2010-08-05 15:11:23 -07:00
|
|
|
if (!process->Init()) {
|
2013-04-18 08:34:49 -07:00
|
|
|
profiler_shutdown();
|
2010-08-05 15:11:23 -07:00
|
|
|
NS_LogTerm();
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2009-09-02 17:18:27 -07:00
|
|
|
|
2010-08-05 15:11:23 -07:00
|
|
|
// Run the UI event loop on the main thread.
|
|
|
|
uiMessageLoop.MessageLoop::Run();
|
2009-09-02 17:18:27 -07:00
|
|
|
|
2010-08-05 15:11:23 -07:00
|
|
|
// Allow ProcessChild to clean up after itself before going out of
|
|
|
|
// scope and being deleted
|
|
|
|
process->CleanUp();
|
2011-02-25 03:53:36 -08:00
|
|
|
mozilla::Omnijar::CleanUp();
|
2010-08-05 15:11:23 -07:00
|
|
|
}
|
2009-06-30 12:21:25 -07:00
|
|
|
}
|
|
|
|
|
2013-04-18 08:34:49 -07:00
|
|
|
profiler_shutdown();
|
2009-11-19 14:57:56 -08:00
|
|
|
NS_LogTerm();
|
2009-12-04 16:15:44 -08:00
|
|
|
return XRE_DeinitCommandLine();
|
2009-06-30 12:21:25 -07:00
|
|
|
}
|
|
|
|
|
2009-09-02 17:18:27 -07:00
|
|
|
MessageLoop*
|
|
|
|
XRE_GetIOMessageLoop()
|
|
|
|
{
|
|
|
|
if (sChildProcessType == GeckoProcessType_Default) {
|
|
|
|
return BrowserProcessSubThread::GetMessageLoop(BrowserProcessSubThread::IO);
|
|
|
|
}
|
2010-05-10 21:18:00 -07:00
|
|
|
return IOThreadChild::message_loop();
|
2009-09-02 17:18:27 -07:00
|
|
|
}
|
|
|
|
|
2009-06-30 12:21:25 -07:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class MainFunctionRunnable : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
|
|
|
MainFunctionRunnable(MainFunction aFunction,
|
|
|
|
void* aData)
|
|
|
|
: mFunction(aFunction),
|
|
|
|
mData(aData)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFunction, "Don't give me a null pointer!");
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
MainFunction mFunction;
|
|
|
|
void* mData;
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* anonymous namespace */
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MainFunctionRunnable::Run()
|
|
|
|
{
|
|
|
|
mFunction(mData);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
XRE_InitParentProcess(int aArgc,
|
|
|
|
char* aArgv[],
|
|
|
|
MainFunction aMainFunction,
|
|
|
|
void* aMainFunctionData)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_MIN(aArgc, 1);
|
|
|
|
NS_ENSURE_ARG_POINTER(aArgv);
|
|
|
|
NS_ENSURE_ARG_POINTER(aArgv[0]);
|
|
|
|
|
2011-06-03 11:33:55 -07:00
|
|
|
ScopedXREEmbed embed;
|
|
|
|
|
2010-08-19 12:50:17 -07:00
|
|
|
gArgc = aArgc;
|
|
|
|
gArgv = aArgv;
|
2012-08-06 05:02:31 -07:00
|
|
|
nsresult rv = XRE_InitCommandLine(gArgc, gArgv);
|
2009-11-03 21:12:18 -08:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_ERROR_FAILURE;
|
2009-08-28 12:46:21 -07:00
|
|
|
|
2009-06-30 12:21:25 -07:00
|
|
|
{
|
|
|
|
embed.Start();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAppShell> appShell(do_GetService(kAppShellCID));
|
|
|
|
NS_ENSURE_TRUE(appShell, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
if (aMainFunction) {
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
|
|
|
new MainFunctionRunnable(aMainFunction, aMainFunctionData);
|
|
|
|
NS_ENSURE_TRUE(runnable, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
nsresult rv = NS_DispatchToCurrentThread(runnable);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do event loop
|
|
|
|
if (NS_FAILED(appShell->Run())) {
|
|
|
|
NS_WARNING("Failed to run appshell");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-04 16:15:44 -08:00
|
|
|
return XRE_DeinitCommandLine();
|
2009-06-30 12:21:25 -07:00
|
|
|
}
|
|
|
|
|
2009-10-06 11:02:26 -07:00
|
|
|
#ifdef MOZ_IPDL_TESTS
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// IPDL unit test
|
|
|
|
|
|
|
|
int
|
|
|
|
XRE_RunIPDLTest(int aArgc, char** aArgv)
|
|
|
|
{
|
|
|
|
if (aArgc < 2) {
|
|
|
|
fprintf(stderr, "TEST-UNEXPECTED-FAIL | <---> | insufficient #args, need at least 2\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* data = reinterpret_cast<void*>(aArgv[aArgc-1]);
|
|
|
|
|
|
|
|
nsresult rv =
|
|
|
|
XRE_InitParentProcess(
|
|
|
|
--aArgc, aArgv, mozilla::_ipdltest::IPDLUnitTestMain, data);
|
|
|
|
NS_ENSURE_SUCCESS(rv, 1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif // ifdef MOZ_IPDL_TESTS
|
|
|
|
|
2009-08-28 12:46:21 -07:00
|
|
|
nsresult
|
|
|
|
XRE_RunAppShell()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAppShell> appShell(do_GetService(kAppShellCID));
|
2012-12-10 06:14:52 -08:00
|
|
|
NS_ENSURE_TRUE(appShell, NS_ERROR_FAILURE);
|
2011-02-01 11:53:53 -08:00
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
{
|
|
|
|
// In content processes that want XPCOM (and hence want
|
|
|
|
// AppShell), we usually run our hybrid event loop through
|
|
|
|
// MessagePump::Run(), by way of nsBaseAppShell::Run(). The
|
|
|
|
// Cocoa nsAppShell impl, however, implements its own Run()
|
|
|
|
// that's unaware of MessagePump. That's all rather suboptimal,
|
|
|
|
// but oddly enough not a problem... usually.
|
|
|
|
//
|
|
|
|
// The problem with this setup comes during startup.
|
|
|
|
// XPCOM-in-subprocesses depends on IPC, e.g. to init the pref
|
|
|
|
// service, so we have to init IPC first. But, IPC also
|
|
|
|
// indirectly kinda-depends on XPCOM, because MessagePump
|
|
|
|
// schedules work from off-main threads (e.g. IO thread) by
|
|
|
|
// using NS_DispatchToMainThread(). If the IO thread receives a
|
|
|
|
// Message from the parent before nsThreadManager is
|
|
|
|
// initialized, then DispatchToMainThread() will fail, although
|
|
|
|
// MessagePump will remember the task. This race condition
|
|
|
|
// isn't a problem when appShell->Run() ends up in
|
|
|
|
// MessagePump::Run(), because MessagePump will immediate see it
|
|
|
|
// has work to do. It *is* a problem when we end up in [NSApp
|
|
|
|
// run], because it's not aware that MessagePump has work that
|
|
|
|
// needs to be processed; that was supposed to be signaled by
|
|
|
|
// nsIRunnable(s).
|
|
|
|
//
|
|
|
|
// So instead of hacking Cocoa nsAppShell or rewriting the
|
|
|
|
// event-loop system, we compromise here by processing any tasks
|
|
|
|
// that might have been enqueued on MessagePump, *before*
|
|
|
|
// MessagePump::ScheduleWork was able to successfully
|
|
|
|
// DispatchToMainThread().
|
|
|
|
MessageLoop* loop = MessageLoop::current();
|
|
|
|
bool couldNest = loop->NestableTasksAllowed();
|
|
|
|
|
|
|
|
loop->SetNestableTasksAllowed(true);
|
|
|
|
loop->PostTask(FROM_HERE, new MessageLoop::QuitTask());
|
|
|
|
loop->Run();
|
|
|
|
|
|
|
|
loop->SetNestableTasksAllowed(couldNest);
|
|
|
|
}
|
|
|
|
#endif // XP_MACOSX
|
2009-08-28 12:46:21 -07:00
|
|
|
return appShell->Run();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2010-07-19 11:33:33 -07:00
|
|
|
struct RunnableMethodTraits<ContentChild>
|
2009-08-28 12:46:21 -07:00
|
|
|
{
|
2010-07-19 11:33:33 -07:00
|
|
|
static void RetainCallee(ContentChild* obj) { }
|
|
|
|
static void ReleaseCallee(ContentChild* obj) { }
|
2009-08-28 12:46:21 -07:00
|
|
|
};
|
|
|
|
|
2009-08-25 16:39:30 -07:00
|
|
|
void
|
2009-12-03 00:16:28 -08:00
|
|
|
XRE_ShutdownChildProcess()
|
2009-08-28 12:46:21 -07:00
|
|
|
{
|
2010-02-03 14:17:09 -08:00
|
|
|
NS_ABORT_IF_FALSE(MessageLoopForUI::current(), "Wrong thread!");
|
2009-12-03 00:16:28 -08:00
|
|
|
|
2011-07-19 03:04:54 -07:00
|
|
|
mozilla::DebugOnly<MessageLoop*> ioLoop = XRE_GetIOMessageLoop();
|
2010-02-03 14:17:09 -08:00
|
|
|
NS_ABORT_IF_FALSE(!!ioLoop, "Bad shutdown order");
|
2009-12-03 00:16:28 -08:00
|
|
|
|
2010-05-10 21:18:00 -07:00
|
|
|
// Quit() sets off the following chain of events
|
|
|
|
// (1) UI loop starts quitting
|
|
|
|
// (2) UI loop returns from Run() in XRE_InitChildProcess()
|
|
|
|
// (3) ProcessChild goes out of scope and terminates the IO thread
|
|
|
|
// (4) ProcessChild joins the IO thread
|
|
|
|
// (5) exit()
|
2011-02-01 11:53:53 -08:00
|
|
|
MessageLoop::current()->Quit();
|
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
nsCOMPtr<nsIAppShell> appShell(do_GetService(kAppShellCID));
|
|
|
|
if (appShell) {
|
|
|
|
// On Mac, we might be only above nsAppShell::Run(), not
|
|
|
|
// MessagePump::Run(). See XRE_RunAppShell(). To account for
|
|
|
|
// that case, we fire off an Exit() here. If we were indeed
|
|
|
|
// above MessagePump::Run(), this Exit() is just superfluous.
|
|
|
|
appShell->Exit();
|
|
|
|
}
|
|
|
|
#endif // XP_MACOSX
|
2009-08-28 16:16:19 -07:00
|
|
|
}
|
2009-08-28 12:46:21 -07:00
|
|
|
|
2009-08-28 16:16:19 -07:00
|
|
|
namespace {
|
2011-06-23 16:31:58 -07:00
|
|
|
ContentParent* gContentParent; //long-lived, manually refcounted
|
2009-11-06 12:43:39 -08:00
|
|
|
TestShellParent* GetOrCreateTestShellParent()
|
|
|
|
{
|
2011-06-23 16:31:58 -07:00
|
|
|
if (!gContentParent) {
|
2014-03-15 12:00:15 -07:00
|
|
|
nsRefPtr<ContentParent> parent = ContentParent::GetNewOrUsed();
|
2013-04-02 16:52:51 -07:00
|
|
|
parent.forget(&gContentParent);
|
2011-06-23 16:31:58 -07:00
|
|
|
} else if (!gContentParent->IsAlive()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-11-06 12:43:39 -08:00
|
|
|
}
|
2011-06-23 16:31:58 -07:00
|
|
|
TestShellParent* tsp = gContentParent->GetTestShellSingleton();
|
|
|
|
if (!tsp) {
|
|
|
|
tsp = gContentParent->CreateTestShell();
|
|
|
|
}
|
|
|
|
return tsp;
|
2009-11-06 12:43:39 -08:00
|
|
|
}
|
2009-08-28 12:46:21 -07:00
|
|
|
}
|
|
|
|
|
2009-08-28 16:16:19 -07:00
|
|
|
bool
|
|
|
|
XRE_SendTestShellCommand(JSContext* aCx,
|
|
|
|
JSString* aCommand,
|
|
|
|
void* aCallback)
|
2009-08-28 12:46:21 -07:00
|
|
|
{
|
2013-05-12 13:58:02 -07:00
|
|
|
JS::RootedString cmd(aCx, aCommand);
|
2009-11-06 12:43:39 -08:00
|
|
|
TestShellParent* tsp = GetOrCreateTestShellParent();
|
|
|
|
NS_ENSURE_TRUE(tsp, false);
|
2009-08-28 12:46:21 -07:00
|
|
|
|
2010-12-03 00:24:17 -08:00
|
|
|
nsDependentJSString command;
|
2013-05-12 13:58:02 -07:00
|
|
|
NS_ENSURE_TRUE(command.init(aCx, cmd), false);
|
2010-12-03 00:24:17 -08:00
|
|
|
|
2009-08-28 16:16:19 -07:00
|
|
|
if (!aCallback) {
|
2009-11-06 12:43:39 -08:00
|
|
|
return tsp->SendExecuteCommand(command);
|
2009-08-25 16:39:30 -07:00
|
|
|
}
|
2009-08-28 16:16:19 -07:00
|
|
|
|
|
|
|
TestShellCommandParent* callback = static_cast<TestShellCommandParent*>(
|
2009-11-06 12:43:39 -08:00
|
|
|
tsp->SendPTestShellCommandConstructor(command));
|
2009-08-28 16:16:19 -07:00
|
|
|
NS_ENSURE_TRUE(callback, false);
|
|
|
|
|
2013-03-06 13:16:46 -08:00
|
|
|
JS::Value callbackVal = *reinterpret_cast<JS::Value*>(aCallback);
|
2009-08-28 16:16:19 -07:00
|
|
|
NS_ENSURE_TRUE(callback->SetCallback(aCx, callbackVal), false);
|
|
|
|
|
|
|
|
return true;
|
2009-08-25 16:39:30 -07:00
|
|
|
}
|
|
|
|
|
2009-11-11 00:34:08 -08:00
|
|
|
bool
|
|
|
|
XRE_ShutdownTestShell()
|
|
|
|
{
|
2011-06-23 16:31:58 -07:00
|
|
|
if (!gContentParent) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool ret = true;
|
|
|
|
if (gContentParent->IsAlive()) {
|
|
|
|
ret = gContentParent->DestroyTestShell(
|
|
|
|
gContentParent->GetTestShellSingleton());
|
|
|
|
}
|
|
|
|
NS_RELEASE(gContentParent);
|
|
|
|
return ret;
|
2009-11-11 00:34:08 -08:00
|
|
|
}
|
|
|
|
|
2010-02-24 14:25:16 -08:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
void
|
|
|
|
XRE_InstallX11ErrorHandler()
|
|
|
|
{
|
|
|
|
InstallX11ErrorHandler();
|
|
|
|
}
|
|
|
|
#endif
|
2012-05-25 03:01:29 -07:00
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
static WindowsEnvironmentType
|
|
|
|
sWindowsEnvironmentType = WindowsEnvironmentType_Desktop;
|
|
|
|
|
|
|
|
void
|
|
|
|
SetWindowsEnvironment(WindowsEnvironmentType aEnvID)
|
|
|
|
{
|
|
|
|
sWindowsEnvironmentType = aEnvID;
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowsEnvironmentType
|
|
|
|
XRE_GetWindowsEnvironment()
|
|
|
|
{
|
|
|
|
return sWindowsEnvironmentType;
|
|
|
|
}
|
|
|
|
#endif // XP_WIN
|
|
|
|
|