2012-05-21 15:12:37 +04: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/. */
|
2005-08-29 23:27:16 +04:00
|
|
|
|
2012-12-15 03:58:45 +04:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
|
2009-08-29 03:16:19 +04:00
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
2005-08-29 23:27:16 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
2005-09-01 17:21:55 +04:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
2012-06-16 10:06:10 +04:00
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
2009-10-19 20:28:42 +04:00
|
|
|
#include <glib.h>
|
|
|
|
#endif
|
2005-09-01 17:21:55 +04:00
|
|
|
|
2009-06-30 23:21:25 +04:00
|
|
|
#include "prenv.h"
|
|
|
|
|
|
|
|
#include "nsIAppShell.h"
|
2005-09-01 17:21:55 +04:00
|
|
|
#include "nsIAppStartupNotifier.h"
|
|
|
|
#include "nsIDirectoryService.h"
|
2012-06-06 06:08:30 +04:00
|
|
|
#include "nsIFile.h"
|
2005-09-01 17:21:55 +04:00
|
|
|
#include "nsIToolkitChromeRegistry.h"
|
2009-06-30 23:21:25 +04:00
|
|
|
#include "nsIToolkitProfile.h"
|
2005-09-01 17:21:55 +04:00
|
|
|
|
2010-02-04 01:17:09 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <process.h>
|
2017-03-17 05:04:33 +03:00
|
|
|
#include <shobjidl.h>
|
2014-05-18 07:16:51 +04:00
|
|
|
#include "mozilla/ipc/WindowsMessageLoop.h"
|
2010-02-04 01:17:09 +03:00
|
|
|
#endif
|
|
|
|
|
2005-09-01 17:21:55 +04:00
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
2006-01-12 18:29:10 +03:00
|
|
|
#include "nsAppRunner.h"
|
2009-07-11 10:33:10 +04:00
|
|
|
#include "nsAutoRef.h"
|
2005-09-01 17:21:55 +04:00
|
|
|
#include "nsDirectoryServiceDefs.h"
|
2010-01-13 00:14:38 +03:00
|
|
|
#include "nsExceptionHandler.h"
|
2005-09-01 17:21:55 +04:00
|
|
|
#include "nsString.h"
|
2009-06-30 23:21:25 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2010-12-03 11:24:17 +03:00
|
|
|
#include "nsJSUtils.h"
|
2009-06-30 23:21:25 +04:00
|
|
|
#include "nsWidgetsCID.h"
|
2006-01-12 18:29:10 +03:00
|
|
|
#include "nsXREDirProvider.h"
|
2017-02-07 13:57:23 +03:00
|
|
|
#include "ThreadAnnotation.h"
|
2009-06-30 23:21:25 +04:00
|
|
|
|
2010-08-13 08:31:59 +04:00
|
|
|
#include "mozilla/Omnijar.h"
|
2010-09-10 21:09:30 +04:00
|
|
|
#if defined(XP_MACOSX)
|
2011-10-27 06:57:26 +04:00
|
|
|
#include "nsVersionComparator.h"
|
2010-09-10 21:09:30 +04:00
|
|
|
#include "chrome/common/mach_ipc_mac.h"
|
|
|
|
#endif
|
2010-02-25 01:25:16 +03:00
|
|
|
#include "nsX11ErrorHandler.h"
|
2014-06-16 12:54:00 +04:00
|
|
|
#include "nsGDKErrorHandler.h"
|
2009-07-20 23:04:52 +04:00
|
|
|
#include "base/at_exit.h"
|
|
|
|
#include "base/command_line.h"
|
|
|
|
#include "base/message_loop.h"
|
2009-10-28 00:52:37 +03:00
|
|
|
#include "base/process_util.h"
|
2009-07-20 23:04:52 +04:00
|
|
|
#include "chrome/common/child_process.h"
|
2016-10-06 02:46:53 +03:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
#include "chrome/common/ipc_channel.h"
|
Bug 1343075 - Use GeckoEditableSupport from PuppetWidget; r=masayuki r=rbarker r=snorp r=esawin
Bug 1343075 - 1a. Add TextEventDispatcherListener::GetIMEUpdatePreference; r=masayuki
Add a GetIMEUpdatePreference method to TextEventDispatcherListener to
optionally control which IME notifications are received by NotifyIME.
This patch also makes nsBaseWidget forward its GetIMEUpdatePreference
call to the widget's native TextEventDispatcherListener.
Bug 1343075 - 1b. Implement GetIMEUpdatePreference for all TextEventDispatcherListener; r=masayuki
This patch implements GetIMEUpdatePreference for all
TextEventDispatcherListener implementations, by moving previous
implementations of nsIWidget::GetIMEUpdatePreference.
Bug 1343075 - 2. Allow setting a PuppetWidget's native TextEventDispatcherListener; r=masayuki
In PuppetWidget, add getter and setter for the widget's native
TextEventDispatcherListener. This allows overriding of PuppetWidget's
default IME handling. For example, on Android, the PuppetWidget's native
TextEventDispatcherListener will communicate directly with Java IME code
in the main process.
Bug 1343075 - 3. Add AIDL interface for main process; r=rbarker
Add AIDL definition and implementation for an interface for the main
process that child processes can access.
Bug 1343075 - 4. Set Gecko thread JNIEnv for child process; r=snorp
Add a JNIEnv* parameter to XRE_SetAndroidChildFds, which is used to set
the Gecko thread JNIEnv for child processes. XRE_SetAndroidChildFds is
the only Android-specific entry point for child processes, so I think
it's the most logical place to initialize JNI.
Bug 1343075 - 5. Support multiple remote GeckoEditableChild; r=esawin
Support remote GeckoEditableChild instances that are created in the
content processes and connect to the parent process GeckoEditableParent
through binders.
Support having multiple GeckoEditableChild instances in GeckoEditable by
keeping track of which child is currently focused, and only allow
calls to/from the focused child by using access tokens.
Bug 1343075 - 6. Add method to get GeckoEditableParent instance; r=esawin
Add IProcessManager.getEditableParent, which a content process can call
to get the GeckoEditableParent instance that corresponds to a given
content process tab, from the main process.
Bug 1343075 - 7. Support GeckoEditableSupport in content processes; r=esawin
Support creating and running GeckoEditableSupport attached to a
PuppetWidget in content processes.
Because we don't know PuppetWidget's lifetime as well as nsWindow's,
when attached to PuppetWidget, we need to attach/detach our native
object on focus/blur, respectively.
Bug 1343075 - 8. Connect GeckoEditableSupport on PuppetWidget creation; r=esawin
Listen to the "tab-child-created" notification and attach our content
process GeckoEditableSupport to the new PuppetWidget.
Bug 1343075 - 9. Update auto-generated bindings; r=me
2017-03-08 06:34:39 +03:00
|
|
|
#include "mozilla/jni/Utils.h"
|
2016-10-06 02:46:53 +03:00
|
|
|
#endif // defined(MOZ_WIDGET_ANDROID)
|
2009-07-20 23:04:52 +04:00
|
|
|
|
2017-04-19 08:24:09 +03:00
|
|
|
#include "mozilla/AbstractThread.h"
|
|
|
|
|
2010-02-04 01:17:09 +03:00
|
|
|
#include "mozilla/ipc/BrowserProcessSubThread.h"
|
2010-05-11 08:18:00 +04:00
|
|
|
#include "mozilla/ipc/GeckoChildProcessHost.h"
|
|
|
|
#include "mozilla/ipc/IOThreadChild.h"
|
|
|
|
#include "mozilla/ipc/ProcessChild.h"
|
2009-06-30 23:21:25 +04:00
|
|
|
#include "ScopedXREEmbed.h"
|
|
|
|
|
2010-05-11 08:18:00 +04:00
|
|
|
#include "mozilla/plugins/PluginProcessChild.h"
|
2010-07-19 22:33:33 +04:00
|
|
|
#include "mozilla/dom/ContentProcess.h"
|
|
|
|
#include "mozilla/dom/ContentParent.h"
|
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2009-06-30 23:21:25 +04:00
|
|
|
|
2009-07-11 10:33:10 +04:00
|
|
|
#include "mozilla/ipc/TestShellParent.h"
|
|
|
|
#include "mozilla/ipc/XPCShellEnvironment.h"
|
2017-07-29 00:56:49 +03:00
|
|
|
#include "mozilla/Scheduler.h"
|
2015-02-18 04:09:32 +03:00
|
|
|
#include "mozilla/WindowsDllBlocklist.h"
|
2009-07-11 10:33:10 +04:00
|
|
|
|
2014-05-18 07:05:46 +04:00
|
|
|
#include "GMPProcessChild.h"
|
2016-06-11 05:27:24 +03:00
|
|
|
#include "mozilla/gfx/GPUProcessImpl.h"
|
2014-05-18 07:05:46 +04:00
|
|
|
|
2013-03-18 18:25:50 +04:00
|
|
|
#include "GeckoProfiler.h"
|
2012-07-27 22:57:48 +04:00
|
|
|
|
2014-11-29 20:12:18 +03:00
|
|
|
#if defined(MOZ_SANDBOX) && defined(XP_WIN)
|
2016-05-15 18:35:22 +03:00
|
|
|
#include "mozilla/sandboxTarget.h"
|
2014-11-29 20:12:18 +03:00
|
|
|
#include "mozilla/sandboxing/loggingCallbacks.h"
|
2014-06-11 18:32:37 +04:00
|
|
|
#endif
|
|
|
|
|
2017-05-13 00:04:42 +03:00
|
|
|
#if defined(MOZ_CONTENT_SANDBOX)
|
|
|
|
#include "mozilla/SandboxSettings.h"
|
2016-07-25 14:21:00 +03:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#endif
|
|
|
|
|
2016-11-09 00:23:47 +03:00
|
|
|
#if defined(XP_LINUX) && defined(MOZ_GMP_SANDBOX)
|
|
|
|
#include "mozilla/Sandbox.h"
|
|
|
|
#include "mozilla/SandboxInfo.h"
|
|
|
|
#endif
|
|
|
|
|
2017-01-27 17:44:21 +03:00
|
|
|
#if defined(XP_LINUX)
|
|
|
|
#include <sys/prctl.h>
|
|
|
|
#ifndef PR_SET_PTRACER
|
|
|
|
#define PR_SET_PTRACER 0x59616d61
|
|
|
|
#endif
|
|
|
|
#ifndef PR_SET_PTRACER_ANY
|
|
|
|
#define PR_SET_PTRACER_ANY ((unsigned long)-1)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2009-10-06 22:02:26 +04:00
|
|
|
#ifdef MOZ_IPDL_TESTS
|
|
|
|
#include "mozilla/_ipdltest/IPDLUnitTests.h"
|
2010-05-11 08:18:00 +04:00
|
|
|
#include "mozilla/_ipdltest/IPDLUnitTestProcessChild.h"
|
2009-10-06 22:02:26 +04:00
|
|
|
|
2010-05-11 08:18:00 +04:00
|
|
|
using mozilla::_ipdltest::IPDLUnitTestProcessChild;
|
2009-10-06 22:02:26 +04:00
|
|
|
#endif // ifdef MOZ_IPDL_TESTS
|
|
|
|
|
2016-05-21 05:57:31 +03:00
|
|
|
#ifdef MOZ_JPROF
|
|
|
|
#include "jprof.h"
|
|
|
|
#endif
|
|
|
|
|
2017-10-16 11:22:07 +03:00
|
|
|
#if defined(XP_WIN) && defined(MOZ_ENABLE_SKIA_PDF)
|
|
|
|
#include "mozilla/widget/PDFiumProcessChild.h"
|
|
|
|
#endif
|
|
|
|
|
2011-10-11 09:50:08 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2009-09-03 04:18:27 +04:00
|
|
|
using mozilla::ipc::BrowserProcessSubThread;
|
2010-05-11 08:18:00 +04:00
|
|
|
using mozilla::ipc::GeckoChildProcessHost;
|
|
|
|
using mozilla::ipc::IOThreadChild;
|
|
|
|
using mozilla::ipc::ProcessChild;
|
2009-06-30 23:21:25 +04:00
|
|
|
using mozilla::ipc::ScopedXREEmbed;
|
|
|
|
|
2010-05-11 08:18:00 +04:00
|
|
|
using mozilla::plugins::PluginProcessChild;
|
2010-07-19 22:33:33 +04:00
|
|
|
using mozilla::dom::ContentProcess;
|
|
|
|
using mozilla::dom::ContentParent;
|
|
|
|
using mozilla::dom::ContentChild;
|
2009-11-06 23:43:39 +03:00
|
|
|
|
2014-11-14 11:26:24 +03:00
|
|
|
using mozilla::gmp::GMPProcessChild;
|
|
|
|
|
2009-07-11 10:33:10 +04:00
|
|
|
using mozilla::ipc::TestShellParent;
|
2009-08-29 03:16:19 +04:00
|
|
|
using mozilla::ipc::TestShellCommandParent;
|
2009-07-11 10:33:10 +04:00
|
|
|
using mozilla::ipc::XPCShellEnvironment;
|
2009-12-15 01:13:00 +03:00
|
|
|
|
|
|
|
using mozilla::startup::sChildProcessType;
|
2009-06-30 23:21:25 +04:00
|
|
|
|
|
|
|
static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
|
2005-08-29 23:27:16 +04:00
|
|
|
|
2006-01-12 18:29:10 +03:00
|
|
|
nsresult
|
2012-06-06 06:08:30 +04:00
|
|
|
XRE_LockProfileDirectory(nsIFile* aDirectory,
|
2006-01-12 18:29:10 +03:00
|
|
|
nsISupports* *aLockObject)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIProfileLock> lock;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsresult rv = NS_LockProfilePath(aDirectory, nullptr, nullptr,
|
2006-01-12 18:29:10 +03:00
|
|
|
getter_AddRefs(lock));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
NS_ADDREF(*aLockObject = lock);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static int32_t sInitCounter;
|
2005-09-01 17:21:55 +04:00
|
|
|
|
|
|
|
nsresult
|
2012-06-06 06:08:30 +04:00
|
|
|
XRE_InitEmbedding2(nsIFile *aLibXULDirectory,
|
2015-05-27 20:59:13 +03:00
|
|
|
nsIFile *aAppDirectory,
|
|
|
|
nsIDirectoryServiceProvider *aAppDirProvider)
|
2005-09-01 17:21:55 +04:00
|
|
|
{
|
2006-01-12 18:29:10 +03:00
|
|
|
// Initialize some globals to make nsXREDirProvider happy
|
2012-07-30 18:20:58 +04:00
|
|
|
static char* kNullCommandLine[] = { nullptr };
|
2006-01-12 18:29:10 +03:00
|
|
|
gArgv = kNullCommandLine;
|
|
|
|
gArgc = 0;
|
2005-09-01 17:21:55 +04:00
|
|
|
|
|
|
|
NS_ENSURE_ARG(aLibXULDirectory);
|
2005-12-23 17:51:39 +03:00
|
|
|
|
2006-01-12 18:29:10 +03:00
|
|
|
if (++sInitCounter > 1) // XXXbsmedberg is this really the right solution?
|
|
|
|
return NS_OK;
|
|
|
|
|
2005-12-23 17:51:39 +03:00
|
|
|
if (!aAppDirectory)
|
|
|
|
aAppDirectory = aLibXULDirectory;
|
2005-09-01 17:21:55 +04:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
2006-01-12 18:29:10 +03:00
|
|
|
new nsXREDirProvider; // This sets gDirServiceProvider
|
|
|
|
if (!gDirServiceProvider)
|
2005-09-01 17:21:55 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2006-01-12 18:29:10 +03:00
|
|
|
rv = gDirServiceProvider->Initialize(aAppDirectory, aLibXULDirectory,
|
|
|
|
aAppDirProvider);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = NS_InitXPCOM2(nullptr, aAppDirectory, gDirServiceProvider);
|
2005-09-01 17:21:55 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2010-03-13 11:03:27 +03: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.
|
2005-09-01 17:21:55 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIObserver> startupNotifier
|
|
|
|
(do_CreateInstance(NS_APPSTARTUPNOTIFIER_CONTRACTID));
|
|
|
|
if (!startupNotifier)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
startupNotifier->Observe(nullptr, APPSTARTUP_TOPIC, nullptr);
|
2005-09-01 17:21:55 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-01-12 18:29:10 +03:00
|
|
|
void
|
|
|
|
XRE_NotifyProfile()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(gDirServiceProvider, "XRE_InitEmbedding was not called!");
|
|
|
|
gDirServiceProvider->DoStartup();
|
|
|
|
}
|
|
|
|
|
2005-09-01 17:21:55 +04:00
|
|
|
void
|
|
|
|
XRE_TermEmbedding()
|
|
|
|
{
|
|
|
|
if (--sInitCounter != 0)
|
|
|
|
return;
|
|
|
|
|
2006-01-12 18:29:10 +03:00
|
|
|
NS_ASSERTION(gDirServiceProvider,
|
|
|
|
"XRE_TermEmbedding without XRE_InitEmbedding");
|
|
|
|
|
|
|
|
gDirServiceProvider->DoShutdown();
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ShutdownXPCOM(nullptr);
|
2006-01-12 18:29:10 +03:00
|
|
|
delete gDirServiceProvider;
|
2005-09-01 17:21:55 +04:00
|
|
|
}
|
2009-06-30 23:21:25 +04:00
|
|
|
|
2009-07-10 23:03:09 +04:00
|
|
|
const char*
|
2009-08-19 21:09:51 +04:00
|
|
|
XRE_ChildProcessTypeToString(GeckoProcessType aProcessType)
|
2009-07-10 23:03:09 +04:00
|
|
|
{
|
2009-08-19 21:09:51 +04:00
|
|
|
return (aProcessType < GeckoProcessType_End) ?
|
2016-06-02 01:13:59 +03:00
|
|
|
kGeckoProcessTypeString[aProcessType] : "invalid";
|
2009-07-10 23:03:09 +04:00
|
|
|
}
|
|
|
|
|
2014-08-09 04:52:12 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace startup {
|
|
|
|
GeckoProcessType sChildProcessType = GeckoProcessType_Default;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace startup
|
|
|
|
} // namespace mozilla
|
2014-08-09 04:52:12 +04:00
|
|
|
|
2016-10-06 02:46:53 +03:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
void
|
Bug 1343075 - Use GeckoEditableSupport from PuppetWidget; r=masayuki r=rbarker r=snorp r=esawin
Bug 1343075 - 1a. Add TextEventDispatcherListener::GetIMEUpdatePreference; r=masayuki
Add a GetIMEUpdatePreference method to TextEventDispatcherListener to
optionally control which IME notifications are received by NotifyIME.
This patch also makes nsBaseWidget forward its GetIMEUpdatePreference
call to the widget's native TextEventDispatcherListener.
Bug 1343075 - 1b. Implement GetIMEUpdatePreference for all TextEventDispatcherListener; r=masayuki
This patch implements GetIMEUpdatePreference for all
TextEventDispatcherListener implementations, by moving previous
implementations of nsIWidget::GetIMEUpdatePreference.
Bug 1343075 - 2. Allow setting a PuppetWidget's native TextEventDispatcherListener; r=masayuki
In PuppetWidget, add getter and setter for the widget's native
TextEventDispatcherListener. This allows overriding of PuppetWidget's
default IME handling. For example, on Android, the PuppetWidget's native
TextEventDispatcherListener will communicate directly with Java IME code
in the main process.
Bug 1343075 - 3. Add AIDL interface for main process; r=rbarker
Add AIDL definition and implementation for an interface for the main
process that child processes can access.
Bug 1343075 - 4. Set Gecko thread JNIEnv for child process; r=snorp
Add a JNIEnv* parameter to XRE_SetAndroidChildFds, which is used to set
the Gecko thread JNIEnv for child processes. XRE_SetAndroidChildFds is
the only Android-specific entry point for child processes, so I think
it's the most logical place to initialize JNI.
Bug 1343075 - 5. Support multiple remote GeckoEditableChild; r=esawin
Support remote GeckoEditableChild instances that are created in the
content processes and connect to the parent process GeckoEditableParent
through binders.
Support having multiple GeckoEditableChild instances in GeckoEditable by
keeping track of which child is currently focused, and only allow
calls to/from the focused child by using access tokens.
Bug 1343075 - 6. Add method to get GeckoEditableParent instance; r=esawin
Add IProcessManager.getEditableParent, which a content process can call
to get the GeckoEditableParent instance that corresponds to a given
content process tab, from the main process.
Bug 1343075 - 7. Support GeckoEditableSupport in content processes; r=esawin
Support creating and running GeckoEditableSupport attached to a
PuppetWidget in content processes.
Because we don't know PuppetWidget's lifetime as well as nsWindow's,
when attached to PuppetWidget, we need to attach/detach our native
object on focus/blur, respectively.
Bug 1343075 - 8. Connect GeckoEditableSupport on PuppetWidget creation; r=esawin
Listen to the "tab-child-created" notification and attach our content
process GeckoEditableSupport to the new PuppetWidget.
Bug 1343075 - 9. Update auto-generated bindings; r=me
2017-03-08 06:34:39 +03:00
|
|
|
XRE_SetAndroidChildFds (JNIEnv* env, int crashFd, int ipcFd)
|
2016-10-06 02:46:53 +03:00
|
|
|
{
|
Bug 1343075 - Use GeckoEditableSupport from PuppetWidget; r=masayuki r=rbarker r=snorp r=esawin
Bug 1343075 - 1a. Add TextEventDispatcherListener::GetIMEUpdatePreference; r=masayuki
Add a GetIMEUpdatePreference method to TextEventDispatcherListener to
optionally control which IME notifications are received by NotifyIME.
This patch also makes nsBaseWidget forward its GetIMEUpdatePreference
call to the widget's native TextEventDispatcherListener.
Bug 1343075 - 1b. Implement GetIMEUpdatePreference for all TextEventDispatcherListener; r=masayuki
This patch implements GetIMEUpdatePreference for all
TextEventDispatcherListener implementations, by moving previous
implementations of nsIWidget::GetIMEUpdatePreference.
Bug 1343075 - 2. Allow setting a PuppetWidget's native TextEventDispatcherListener; r=masayuki
In PuppetWidget, add getter and setter for the widget's native
TextEventDispatcherListener. This allows overriding of PuppetWidget's
default IME handling. For example, on Android, the PuppetWidget's native
TextEventDispatcherListener will communicate directly with Java IME code
in the main process.
Bug 1343075 - 3. Add AIDL interface for main process; r=rbarker
Add AIDL definition and implementation for an interface for the main
process that child processes can access.
Bug 1343075 - 4. Set Gecko thread JNIEnv for child process; r=snorp
Add a JNIEnv* parameter to XRE_SetAndroidChildFds, which is used to set
the Gecko thread JNIEnv for child processes. XRE_SetAndroidChildFds is
the only Android-specific entry point for child processes, so I think
it's the most logical place to initialize JNI.
Bug 1343075 - 5. Support multiple remote GeckoEditableChild; r=esawin
Support remote GeckoEditableChild instances that are created in the
content processes and connect to the parent process GeckoEditableParent
through binders.
Support having multiple GeckoEditableChild instances in GeckoEditable by
keeping track of which child is currently focused, and only allow
calls to/from the focused child by using access tokens.
Bug 1343075 - 6. Add method to get GeckoEditableParent instance; r=esawin
Add IProcessManager.getEditableParent, which a content process can call
to get the GeckoEditableParent instance that corresponds to a given
content process tab, from the main process.
Bug 1343075 - 7. Support GeckoEditableSupport in content processes; r=esawin
Support creating and running GeckoEditableSupport attached to a
PuppetWidget in content processes.
Because we don't know PuppetWidget's lifetime as well as nsWindow's,
when attached to PuppetWidget, we need to attach/detach our native
object on focus/blur, respectively.
Bug 1343075 - 8. Connect GeckoEditableSupport on PuppetWidget creation; r=esawin
Listen to the "tab-child-created" notification and attach our content
process GeckoEditableSupport to the new PuppetWidget.
Bug 1343075 - 9. Update auto-generated bindings; r=me
2017-03-08 06:34:39 +03:00
|
|
|
mozilla::jni::SetGeckoThreadEnv(env);
|
2016-10-06 02:46:53 +03:00
|
|
|
CrashReporter::SetNotificationPipeForChild(crashFd);
|
|
|
|
IPC::Channel::SetClientChannelFd(ipcFd);
|
|
|
|
}
|
|
|
|
#endif // defined(MOZ_WIDGET_ANDROID)
|
|
|
|
|
2014-08-09 04:52:12 +04:00
|
|
|
void
|
|
|
|
XRE_SetProcessType(const char* aProcessTypeString)
|
2009-07-10 23:03:09 +04:00
|
|
|
{
|
2014-08-09 04:55:22 +04:00
|
|
|
static bool called = false;
|
|
|
|
if (called) {
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
|
|
|
called = true;
|
|
|
|
|
2014-08-09 04:52:12 +04:00
|
|
|
sChildProcessType = GeckoProcessType_Invalid;
|
2009-07-10 23:03:09 +04:00
|
|
|
for (int i = 0;
|
2011-10-11 09:50:08 +04:00
|
|
|
i < (int) ArrayLength(kGeckoProcessTypeString);
|
2009-07-10 23:03:09 +04:00
|
|
|
++i) {
|
2009-08-19 21:09:51 +04:00
|
|
|
if (!strcmp(kGeckoProcessTypeString[i], aProcessTypeString)) {
|
2014-08-09 04:52:12 +04:00
|
|
|
sChildProcessType = static_cast<GeckoProcessType>(i);
|
|
|
|
return;
|
2009-07-10 23:03:09 +04:00
|
|
|
}
|
|
|
|
}
|
2009-12-15 01:13:00 +03:00
|
|
|
}
|
2009-08-19 21:09:51 +04:00
|
|
|
|
2010-03-19 05:01:10 +03: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-29 10:19:26 +04:00
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
XRE_TakeMinidumpForChild(uint32_t aChildPid, nsIFile** aDump,
|
|
|
|
uint32_t* aSequence)
|
2010-03-19 05:01:10 +03:00
|
|
|
{
|
2012-07-11 06:20:05 +04:00
|
|
|
return CrashReporter::TakeMinidumpForChild(aChildPid, aDump, aSequence);
|
2010-03-19 05:01:10 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-01-13 00:14:38 +03:00
|
|
|
XRE_SetRemoteExceptionHandler(const char* aPipe/*= 0*/)
|
|
|
|
{
|
2010-08-16 23:05:09 +04:00
|
|
|
#if defined(XP_WIN) || defined(XP_MACOSX)
|
2010-01-13 00:14:38 +03:00
|
|
|
return CrashReporter::SetRemoteExceptionHandler(nsDependentCString(aPipe));
|
|
|
|
#else
|
2017-11-24 05:31:42 +03:00
|
|
|
return CrashReporter::SetRemoteExceptionHandler();
|
2010-01-13 00:14:38 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-05-15 04:25:10 +04:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
void
|
|
|
|
SetTaskbarGroupId(const nsString& aId)
|
|
|
|
{
|
2017-03-17 05:04:33 +03:00
|
|
|
if (FAILED(SetCurrentProcessExplicitAppUserModelID(aId.get()))) {
|
2010-05-15 04:25:10 +04:00
|
|
|
NS_WARNING("SetCurrentProcessExplicitAppUserModelID failed for child process.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-07-19 11:38:48 +03:00
|
|
|
#if defined(MOZ_CONTENT_SANDBOX)
|
2016-07-25 14:21:00 +03:00
|
|
|
void
|
|
|
|
AddContentSandboxLevelAnnotation()
|
|
|
|
{
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
2017-05-13 00:04:42 +03:00
|
|
|
int level = GetEffectiveContentSandboxLevel();
|
2016-07-25 14:21:00 +03:00
|
|
|
nsAutoCString levelString;
|
|
|
|
levelString.AppendInt(level);
|
|
|
|
CrashReporter::AnnotateCrashReport(
|
|
|
|
NS_LITERAL_CSTRING("ContentSandboxLevel"), levelString);
|
|
|
|
}
|
|
|
|
}
|
2017-07-19 11:38:48 +03:00
|
|
|
#endif /* MOZ_CONTENT_SANDBOX */
|
2016-07-25 14:21:00 +03:00
|
|
|
|
2017-03-08 20:15:47 +03:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
int GetDebugChildPauseTime() {
|
|
|
|
auto pauseStr = PR_GetEnv("MOZ_DEBUG_CHILD_PAUSE");
|
|
|
|
if (pauseStr && *pauseStr) {
|
|
|
|
int pause = atoi(pauseStr);
|
|
|
|
if (pause != 1) { // must be !=1 since =1 enables the default pause time
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
pause *= 1000; // convert to ms
|
|
|
|
#endif
|
|
|
|
return pause;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef OS_POSIX
|
|
|
|
return 30; // seconds
|
|
|
|
#elif defined(OS_WIN)
|
|
|
|
return 10000; // milliseconds
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2009-06-30 23:21:25 +04:00
|
|
|
nsresult
|
|
|
|
XRE_InitChildProcess(int aArgc,
|
2014-11-14 11:26:24 +03:00
|
|
|
char* aArgv[],
|
2016-05-15 18:35:22 +03:00
|
|
|
const XREChildData* aChildData)
|
2009-06-30 23:21:25 +04:00
|
|
|
{
|
2009-10-28 00:52:37 +03:00
|
|
|
NS_ENSURE_ARG_MIN(aArgc, 2);
|
2009-06-30 23:21:25 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aArgv);
|
|
|
|
NS_ENSURE_ARG_POINTER(aArgv[0]);
|
2016-05-15 18:35:22 +03:00
|
|
|
MOZ_ASSERT(aChildData);
|
2013-05-30 17:23:50 +04:00
|
|
|
|
2016-11-09 00:40:44 +03:00
|
|
|
#if defined(XP_LINUX) && defined(MOZ_SANDBOX)
|
|
|
|
// This has to happen while we're still single-threaded.
|
|
|
|
mozilla::SandboxEarlyInit(XRE_GetProcessType());
|
|
|
|
#endif
|
|
|
|
|
2016-05-21 05:57:31 +03:00
|
|
|
#ifdef MOZ_JPROF
|
|
|
|
// Call the code to install our handler
|
|
|
|
setupProfilingStuff();
|
|
|
|
#endif
|
|
|
|
|
2013-05-30 17:23:50 +04: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);
|
|
|
|
}
|
2016-05-15 18:35:22 +03:00
|
|
|
|
|
|
|
#if defined(MOZ_SANDBOX)
|
|
|
|
if (aChildData->sandboxTargetServices) {
|
|
|
|
SandboxTarget::Instance()->SetTargetServices(aChildData->sandboxTargetServices);
|
|
|
|
}
|
|
|
|
#endif
|
2013-05-30 17:23:50 +04:00
|
|
|
#endif
|
|
|
|
|
2015-06-10 03:44:46 +03:00
|
|
|
// NB: This must be called before profiler_init
|
2016-09-26 20:06:38 +03:00
|
|
|
ScopedLogging logger;
|
2015-06-10 03:44:46 +03:00
|
|
|
|
2015-10-19 22:22:11 +03:00
|
|
|
mozilla::LogModule::Init();
|
|
|
|
|
2017-10-04 01:11:18 +03:00
|
|
|
AUTO_PROFILER_INIT;
|
Bug 1375392 - Tweak the PROFILER_LABEL* macros. r=mstange.
This patch makes the following changes to the macros.
- Removes PROFILER_LABEL_FUNC. It's only suitable for use in functions outside
classes, due to PROFILER_FUNCTION_NAME not getting class names, and it was
mostly misused.
- Removes PROFILER_FUNCTION_NAME. It's no longer used, and __func__ is
universally available now anyway.
- Combines the first two string literal arguments of PROFILER_LABEL and
PROFILER_LABEL_DYNAMIC into a single argument. There was no good reason for
them to be separate, and it forced a '::' in the label, which isn't always
appropriate. Also, the meaning of the "name_space" argument was interpreted
in an interesting variety of ways.
- Adds an "AUTO_" prefix to PROFILER_LABEL and PROFILER_LABEL_DYNAMIC, to make
it clearer they construct RAII objects rather than just being function calls.
(I myself have screwed up the scoping because of this in the past.)
- Fills in the 'js::ProfileEntry::Category::' qualifier within the macro, so
the caller doesn't need to. This makes a *lot* more of the uses fit onto a
single line.
The patch also makes the following changes to the macro uses (beyond those
required by the changes described above).
- Fixes a bunch of labels that had gotten out of sync with the name of the
class and/or function that encloses them.
- Removes a useless PROFILER_LABEL use within a trivial scope in
EventStateManager::DispatchMouseOrPointerEvent(). It clearly wasn't serving
any useful purpose. It also serves as extra evidence that the AUTO_ prefix is
a good idea.
- Tweaks DecodePool::SyncRunIf{Preferred,Possible} so that the labelling is
done within them, instead of at their callsites, because that's a more
standard way of doing things.
--HG--
extra : rebase_source : 318d1bc6fc1425a94aacbf489dd46e4f83211de4
2017-06-22 10:08:53 +03:00
|
|
|
AUTO_PROFILER_LABEL("XRE_InitChildProcess", OTHER);
|
2009-06-30 23:21:25 +04:00
|
|
|
|
2017-04-19 08:24:09 +03:00
|
|
|
// Ensure AbstractThread is minimally setup, so async IPC messages
|
|
|
|
// work properly.
|
|
|
|
AbstractThread::InitTLS();
|
|
|
|
|
2010-09-10 21:09:30 +04: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 13:24:36 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-09-10 21:09:30 +04:00
|
|
|
const char* const mach_port_name = aArgv[--aArgc];
|
|
|
|
|
|
|
|
const int kTimeoutMs = 1000;
|
|
|
|
|
|
|
|
MachSendMessage child_message(0);
|
2014-09-01 05:12:55 +04:00
|
|
|
if (!child_message.AddDescriptor(MachMsgPortDescriptor(mach_task_self()))) {
|
2010-09-10 21:09:30 +04:00
|
|
|
NS_WARNING("child AddDescriptor(mach_task_self()) failed.");
|
2012-07-30 13:24:36 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-09-10 21:09:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ReceivePort child_recv_port;
|
|
|
|
mach_port_t raw_child_recv_port = child_recv_port.GetPort();
|
2014-09-01 05:12:55 +04:00
|
|
|
if (!child_message.AddDescriptor(MachMsgPortDescriptor(raw_child_recv_port))) {
|
2010-09-10 21:09:30 +04:00
|
|
|
NS_WARNING("Adding descriptor to message failed");
|
2012-07-30 13:24:36 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-09-10 21:09:30 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 07:38:38 +03:00
|
|
|
ReceivePort* ports_out_receiver = new ReceivePort();
|
|
|
|
if (!child_message.AddDescriptor(MachMsgPortDescriptor(ports_out_receiver->GetPort()))) {
|
|
|
|
NS_WARNING("Adding descriptor to message failed");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReceivePort* ports_in_receiver = new ReceivePort();
|
|
|
|
if (!child_message.AddDescriptor(MachMsgPortDescriptor(ports_in_receiver->GetPort()))) {
|
|
|
|
NS_WARNING("Adding descriptor to message failed");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2010-09-10 21:09:30 +04: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 13:24:36 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-09-10 21:09:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
MachReceiveMessage parent_message;
|
|
|
|
err = child_recv_port.WaitForMessage(&parent_message, kTimeoutMs);
|
|
|
|
if (err != KERN_SUCCESS) {
|
|
|
|
NS_WARNING("child WaitForMessage() failed");
|
2012-07-30 13:24:36 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-09-10 21:09:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (parent_message.GetTranslatedPort(0) == MACH_PORT_NULL) {
|
|
|
|
NS_WARNING("child GetTranslatedPort(0) failed");
|
2012-07-30 13:24:36 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-09-10 21:09:30 +04:00
|
|
|
}
|
2015-06-17 07:38:38 +03:00
|
|
|
|
2010-09-10 21:09:30 +04:00
|
|
|
err = task_set_bootstrap_port(mach_task_self(),
|
|
|
|
parent_message.GetTranslatedPort(0));
|
2015-06-17 07:38:38 +03:00
|
|
|
|
|
|
|
if (parent_message.GetTranslatedPort(1) == MACH_PORT_NULL) {
|
|
|
|
NS_WARNING("child GetTranslatedPort(1) failed");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
MachPortSender* ports_out_sender = new MachPortSender(parent_message.GetTranslatedPort(1));
|
|
|
|
|
|
|
|
if (parent_message.GetTranslatedPort(2) == MACH_PORT_NULL) {
|
|
|
|
NS_WARNING("child GetTranslatedPort(2) failed");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
MachPortSender* ports_in_sender = new MachPortSender(parent_message.GetTranslatedPort(2));
|
|
|
|
|
2010-09-10 21:09:30 +04:00
|
|
|
if (err != KERN_SUCCESS) {
|
|
|
|
NS_WARNING("child task_set_bootstrap_port() failed");
|
2012-07-30 13:24:36 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-09-10 21:09:30 +04:00
|
|
|
}
|
2015-06-17 07:38:38 +03:00
|
|
|
|
2010-09-10 21:09:30 +04:00
|
|
|
#endif
|
2011-06-24 03:30:31 +04:00
|
|
|
|
2017-01-19 05:39:03 +03:00
|
|
|
SetupErrorHandling(aArgv[0]);
|
2011-06-24 03:30:31 +04:00
|
|
|
|
2017-10-10 16:56:48 +03:00
|
|
|
if (!CrashReporter::IsDummy()) {
|
|
|
|
if (aArgc < 1) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
|
|
|
if (0 != strcmp("-", crashReporterArg) &&
|
|
|
|
!XRE_SetRemoteExceptionHandler(crashReporterArg)) {
|
|
|
|
// Bug 684322 will add better visibility into this condition
|
|
|
|
NS_WARNING("Could not setup crash reporting\n");
|
|
|
|
}
|
2017-11-24 05:31:42 +03:00
|
|
|
#else
|
2017-10-10 16:56:48 +03:00
|
|
|
// on POSIX, |crashReporterArg| is "true" if crash reporting is
|
|
|
|
// enabled, false otherwise
|
|
|
|
if (0 != strcmp("false", crashReporterArg) &&
|
|
|
|
!XRE_SetRemoteExceptionHandler(nullptr)) {
|
|
|
|
// Bug 684322 will add better visibility into this condition
|
|
|
|
NS_WARNING("Could not setup crash reporting\n");
|
|
|
|
}
|
|
|
|
#endif
|
2017-11-23 01:11:44 +03:00
|
|
|
}
|
2017-02-07 13:57:23 +03:00
|
|
|
|
|
|
|
// For Init/Shutdown thread name annotations in the crash reporter.
|
|
|
|
CrashReporter::InitThreadAnnotationRAII annotation;
|
2010-09-10 21:09:30 +04:00
|
|
|
|
2010-01-29 09:50:44 +03:00
|
|
|
gArgv = aArgv;
|
|
|
|
gArgc = aArgc;
|
|
|
|
|
2015-03-30 14:30:36 +03:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
XInitThreads();
|
|
|
|
#endif
|
2015-06-26 20:59:52 +03:00
|
|
|
#if MOZ_WIDGET_GTK == 2
|
|
|
|
XRE_GlibInit();
|
2009-10-19 20:28:42 +04:00
|
|
|
#endif
|
2016-05-27 02:50:26 +03:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
|
|
|
// Setting the name here avoids the need to pass this through to gtk_init().
|
|
|
|
g_set_prgname(aArgv[0]);
|
|
|
|
#endif
|
2009-10-19 20:28:42 +04:00
|
|
|
|
2016-03-07 20:08:15 +03:00
|
|
|
#ifdef OS_POSIX
|
|
|
|
if (PR_GetEnv("MOZ_DEBUG_CHILD_PROCESS") ||
|
|
|
|
PR_GetEnv("MOZ_DEBUG_CHILD_PAUSE")) {
|
2017-01-27 17:44:21 +03:00
|
|
|
#if defined(XP_LINUX) && defined(DEBUG)
|
|
|
|
if (prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0) != 0) {
|
|
|
|
printf_stderr("Could not allow ptrace from any process.\n");
|
|
|
|
}
|
|
|
|
#endif
|
2018-01-08 17:23:49 +03:00
|
|
|
printf_stderr("\n\nCHILDCHILDCHILDCHILD (process type %s)\n debug me @ %d\n\n",
|
|
|
|
XRE_ChildProcessTypeToString(XRE_GetProcessType()),
|
2016-03-03 14:09:25 +03:00
|
|
|
base::GetCurrentProcId());
|
2017-03-08 20:15:47 +03:00
|
|
|
sleep(GetDebugChildPauseTime());
|
2016-03-07 20:08:15 +03:00
|
|
|
}
|
2009-07-07 20:26:49 +04:00
|
|
|
#elif defined(OS_WIN)
|
2016-03-07 20:08:15 +03:00
|
|
|
if (PR_GetEnv("MOZ_DEBUG_CHILD_PROCESS")) {
|
|
|
|
NS_DebugBreak(NS_DEBUG_BREAK,
|
|
|
|
"Invoking NS_DebugBreak() to debug child process",
|
|
|
|
nullptr, __FILE__, __LINE__);
|
|
|
|
} else if (PR_GetEnv("MOZ_DEBUG_CHILD_PAUSE")) {
|
2018-01-08 17:23:49 +03:00
|
|
|
printf_stderr("\n\nCHILDCHILDCHILDCHILD (process type %s)\n debug me @ %d\n\n",
|
|
|
|
XRE_ChildProcessTypeToString(XRE_GetProcessType()),
|
2016-03-07 20:08:15 +03:00
|
|
|
base::GetCurrentProcId());
|
2017-03-08 20:15:47 +03:00
|
|
|
::Sleep(GetDebugChildPauseTime());
|
2009-06-30 23:21:25 +04:00
|
|
|
}
|
2016-03-07 20:08:15 +03:00
|
|
|
#endif
|
2009-06-30 23:21:25 +04:00
|
|
|
|
2009-10-28 00:52:37 +03:00
|
|
|
// child processes launched by GeckoChildProcessHost get this magic
|
|
|
|
// argument appended to their command lines
|
|
|
|
const char* const parentPIDString = aArgv[aArgc-1];
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(parentPIDString, "NULL parent PID");
|
2009-10-28 00:52:37 +03:00
|
|
|
--aArgc;
|
|
|
|
|
|
|
|
char* end = 0;
|
|
|
|
base::ProcessId parentPID = strtol(parentPIDString, &end, 10);
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!*end, "invalid parent PID");
|
2009-11-18 01:18:06 +03:00
|
|
|
|
2017-09-13 18:26:25 +03:00
|
|
|
nsCOMPtr<nsIFile> crashReportTmpDir;
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_GPU) {
|
|
|
|
aArgc--;
|
|
|
|
if (strlen(aArgv[aArgc])) { // if it's empty, ignore it
|
|
|
|
nsresult rv = XRE_GetFileFromPath(aArgv[aArgc], getter_AddRefs(crashReportTmpDir));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// If we don't have a valid tmp dir we can probably still run ok, but
|
|
|
|
// crash report .extra files might not get picked up by the parent
|
|
|
|
// process. Debug-assert because this shouldn't happen in practice.
|
|
|
|
MOZ_ASSERT(false, "GPU process started without valid tmp dir!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-17 07:38:38 +03:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
mozilla::ipc::SharedMemoryBasic::SetupMachMemory(parentPID, ports_in_receiver, ports_in_sender,
|
|
|
|
ports_out_sender, ports_out_receiver, true);
|
|
|
|
#endif
|
|
|
|
|
2010-05-15 04:25:10 +04: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 20:24:42 +04:00
|
|
|
const char* const appModelUserId = aArgv[--aArgc];
|
2010-05-15 04:25:10 +04:00
|
|
|
if (appModelUserId) {
|
|
|
|
// '-' implies no support
|
|
|
|
if (*appModelUserId != '-') {
|
|
|
|
nsString appId;
|
2017-07-24 20:23:52 +03:00
|
|
|
CopyASCIItoUTF16(nsDependentCString(appModelUserId), appId);
|
2010-05-15 04:25:10 +04:00
|
|
|
// The version string is encased in quotes
|
2017-03-14 05:26:27 +03:00
|
|
|
appId.Trim("\"");
|
2010-05-15 04:25:10 +04:00
|
|
|
// Set the id
|
|
|
|
SetTaskbarGroupId(appId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-06-30 23:21:25 +04:00
|
|
|
base::AtExitManager exitManager;
|
2009-11-04 08:12:18 +03:00
|
|
|
|
2012-08-06 16:02:31 +04:00
|
|
|
nsresult rv = XRE_InitCommandLine(aArgc, aArgv);
|
2009-11-20 01:57:56 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2009-11-04 08:12:18 +03:00
|
|
|
|
2010-05-14 10:41:14 +04:00
|
|
|
MessageLoop::Type uiLoopType;
|
2014-08-09 04:52:12 +04:00
|
|
|
switch (XRE_GetProcessType()) {
|
2010-05-14 10:41:14 +04:00
|
|
|
case GeckoProcessType_Content:
|
2016-08-23 08:57:36 +03:00
|
|
|
case GeckoProcessType_GPU:
|
2010-05-14 10:41:14 +04:00
|
|
|
// Content processes need the XPCOM/chromium frankenventloop
|
|
|
|
uiLoopType = MessageLoop::TYPE_MOZILLA_CHILD;
|
|
|
|
break;
|
2014-12-16 01:04:21 +03:00
|
|
|
case GeckoProcessType_GMPlugin:
|
2017-10-16 11:22:07 +03:00
|
|
|
case GeckoProcessType_PDFium:
|
2014-12-16 01:04:21 +03:00
|
|
|
uiLoopType = MessageLoop::TYPE_DEFAULT;
|
|
|
|
break;
|
2010-05-14 10:41:14 +04:00
|
|
|
default:
|
|
|
|
uiLoopType = MessageLoop::TYPE_UI;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-06-30 23:21:25 +04:00
|
|
|
{
|
2010-08-06 02:11:23 +04: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-18 07:16:51 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
mozilla::ipc::windows::InitUIThread();
|
|
|
|
#endif
|
|
|
|
|
2014-08-09 04:52:12 +04:00
|
|
|
switch (XRE_GetProcessType()) {
|
2010-08-06 02:11:23 +04:00
|
|
|
case GeckoProcessType_Default:
|
2016-12-03 00:46:53 +03:00
|
|
|
MOZ_CRASH("This makes no sense");
|
2010-08-06 02:11:23 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GeckoProcessType_Plugin:
|
2015-04-01 11:40:35 +03:00
|
|
|
process = new PluginProcessChild(parentPID);
|
2010-08-06 02:11:23 +04:00
|
|
|
break;
|
|
|
|
|
2017-02-05 08:52:38 +03:00
|
|
|
case GeckoProcessType_Content:
|
|
|
|
process = new ContentProcess(parentPID);
|
2010-08-06 02:11:23 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GeckoProcessType_IPDLUnitTest:
|
2009-10-06 22:02:26 +04:00
|
|
|
#ifdef MOZ_IPDL_TESTS
|
2015-04-01 11:40:35 +03:00
|
|
|
process = new IPDLUnitTestProcessChild(parentPID);
|
2017-01-19 05:39:03 +03:00
|
|
|
#else
|
2016-12-03 00:46:53 +03:00
|
|
|
MOZ_CRASH("rebuild with --enable-ipdl-tests");
|
2009-10-06 22:02:26 +04:00
|
|
|
#endif
|
2010-08-06 02:11:23 +04:00
|
|
|
break;
|
2009-10-06 22:02:26 +04:00
|
|
|
|
2014-05-18 07:05:46 +04:00
|
|
|
case GeckoProcessType_GMPlugin:
|
2015-04-01 11:40:35 +03:00
|
|
|
process = new gmp::GMPProcessChild(parentPID);
|
2014-05-18 07:05:46 +04:00
|
|
|
break;
|
|
|
|
|
2017-10-16 11:22:07 +03:00
|
|
|
#if defined(XP_WIN) && defined(MOZ_ENABLE_SKIA_PDF)
|
|
|
|
case GeckoProcessType_PDFium:
|
|
|
|
process = new widget::PDFiumProcessChild(parentPID);
|
|
|
|
break;
|
|
|
|
#endif
|
2016-06-11 05:27:24 +03:00
|
|
|
case GeckoProcessType_GPU:
|
|
|
|
process = new gfx::GPUProcessImpl(parentPID);
|
|
|
|
break;
|
|
|
|
|
2010-08-06 02:11:23 +04:00
|
|
|
default:
|
2016-12-03 00:46:53 +03:00
|
|
|
MOZ_CRASH("Unknown main thread class");
|
2010-08-06 02:11:23 +04:00
|
|
|
}
|
2009-06-30 23:21:25 +04:00
|
|
|
|
2017-02-05 08:52:38 +03:00
|
|
|
if (!process->Init(aArgc, aArgv)) {
|
2010-08-06 02:11:23 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2009-09-03 04:18:27 +04:00
|
|
|
|
2016-03-16 21:35:50 +03:00
|
|
|
#if defined(XP_WIN) || defined(XP_MACOSX)
|
2017-09-13 18:26:25 +03:00
|
|
|
CrashReporter::InitChildProcessTmpDir(crashReportTmpDir);
|
2016-03-16 21:35:50 +03:00
|
|
|
#endif
|
|
|
|
|
2015-07-16 14:24:34 +03:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
// Set child processes up such that they will get killed after the
|
|
|
|
// chrome process is killed in cases where the user shuts the system
|
|
|
|
// down or logs off.
|
|
|
|
::SetProcessShutdownParameters(0x280 - 1, SHUTDOWN_NORETRY);
|
|
|
|
#endif
|
|
|
|
|
2014-11-29 20:12:18 +03:00
|
|
|
#if defined(MOZ_SANDBOX) && defined(XP_WIN)
|
2014-06-11 18:32:37 +04:00
|
|
|
// We need to do this after the process has been initialised, as
|
2014-11-29 20:12:18 +03:00
|
|
|
// InitLoggingIfRequired may need access to prefs.
|
2016-05-15 18:35:22 +03:00
|
|
|
mozilla::sandboxing::InitLoggingIfRequired(aChildData->ProvideLogFunction);
|
2014-06-11 18:32:37 +04:00
|
|
|
#endif
|
|
|
|
|
2015-12-29 15:56:00 +03:00
|
|
|
OverrideDefaultLocaleIfNeeded();
|
|
|
|
|
2017-07-19 11:38:48 +03:00
|
|
|
#if defined(MOZ_CONTENT_SANDBOX)
|
2016-07-25 14:21:00 +03:00
|
|
|
AddContentSandboxLevelAnnotation();
|
|
|
|
#endif
|
|
|
|
|
2010-08-06 02:11:23 +04:00
|
|
|
// Run the UI event loop on the main thread.
|
|
|
|
uiMessageLoop.MessageLoop::Run();
|
2009-09-03 04:18:27 +04:00
|
|
|
|
2010-08-06 02:11:23 +04:00
|
|
|
// Allow ProcessChild to clean up after itself before going out of
|
|
|
|
// scope and being deleted
|
|
|
|
process->CleanUp();
|
2011-02-25 14:53:36 +03:00
|
|
|
mozilla::Omnijar::CleanUp();
|
2016-05-27 01:07:24 +03:00
|
|
|
|
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
// Everybody should be done using shared memory by now.
|
|
|
|
mozilla::ipc::SharedMemoryBasic::Shutdown();
|
|
|
|
#endif
|
2010-08-06 02:11:23 +04:00
|
|
|
}
|
2009-06-30 23:21:25 +04:00
|
|
|
}
|
|
|
|
|
2009-12-05 03:15:44 +03:00
|
|
|
return XRE_DeinitCommandLine();
|
2009-06-30 23:21:25 +04:00
|
|
|
}
|
|
|
|
|
2009-09-03 04:18:27 +04:00
|
|
|
MessageLoop*
|
|
|
|
XRE_GetIOMessageLoop()
|
|
|
|
{
|
|
|
|
if (sChildProcessType == GeckoProcessType_Default) {
|
|
|
|
return BrowserProcessSubThread::GetMessageLoop(BrowserProcessSubThread::IO);
|
|
|
|
}
|
2010-05-11 08:18:00 +04:00
|
|
|
return IOThreadChild::message_loop();
|
2009-09-03 04:18:27 +04:00
|
|
|
}
|
|
|
|
|
2009-06-30 23:21:25 +04:00
|
|
|
namespace {
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class MainFunctionRunnable : public Runnable
|
2009-06-30 23:21:25 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
2017-06-12 22:34:10 +03:00
|
|
|
MainFunctionRunnable(MainFunction aFunction, void* aData)
|
|
|
|
: mozilla::Runnable("MainFunctionRunnable")
|
|
|
|
, mFunction(aFunction)
|
|
|
|
, mData(aData)
|
2017-01-19 05:39:03 +03:00
|
|
|
{
|
2009-06-30 23:21:25 +04:00
|
|
|
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]);
|
|
|
|
|
2017-04-10 20:35:44 +03:00
|
|
|
// Set main thread before we initialize the profiler
|
|
|
|
NS_SetMainThread();
|
|
|
|
|
2017-03-16 12:36:15 +03:00
|
|
|
mozilla::LogModule::Init();
|
|
|
|
|
2017-10-04 01:11:18 +03:00
|
|
|
AUTO_PROFILER_INIT;
|
2017-04-10 20:35:44 +03:00
|
|
|
|
2011-06-03 22:33:55 +04:00
|
|
|
ScopedXREEmbed embed;
|
|
|
|
|
2010-08-19 23:50:17 +04:00
|
|
|
gArgc = aArgc;
|
|
|
|
gArgv = aArgv;
|
2012-08-06 16:02:31 +04:00
|
|
|
nsresult rv = XRE_InitCommandLine(gArgc, gArgv);
|
2009-11-04 08:12:18 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_ERROR_FAILURE;
|
2009-08-28 23:46:21 +04:00
|
|
|
|
2009-06-30 23:21:25 +04: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-05 03:15:44 +03:00
|
|
|
return XRE_DeinitCommandLine();
|
2009-06-30 23:21:25 +04:00
|
|
|
}
|
|
|
|
|
2009-10-06 22:02:26 +04: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 23:46:21 +04:00
|
|
|
nsresult
|
|
|
|
XRE_RunAppShell()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAppShell> appShell(do_GetService(kAppShellCID));
|
2012-12-10 18:14:52 +04:00
|
|
|
NS_ENSURE_TRUE(appShell, NS_ERROR_FAILURE);
|
2011-02-01 22:53:53 +03:00
|
|
|
#if defined(XP_MACOSX)
|
2017-07-22 02:16:59 +03:00
|
|
|
if (XRE_UseNativeEventProcessing()) {
|
2011-02-01 22:53:53 +03:00
|
|
|
// 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.
|
2017-01-19 05:39:03 +03:00
|
|
|
//
|
2011-02-01 22:53:53 +03:00
|
|
|
// 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).
|
2017-01-19 05:39:03 +03:00
|
|
|
//
|
2011-02-01 22:53:53 +03:00
|
|
|
// 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);
|
2016-04-28 03:06:05 +03:00
|
|
|
RefPtr<Runnable> task = new MessageLoop::QuitTask();
|
|
|
|
loop->PostTask(task.forget());
|
2011-02-01 22:53:53 +03:00
|
|
|
loop->Run();
|
|
|
|
|
|
|
|
loop->SetNestableTasksAllowed(couldNest);
|
|
|
|
}
|
|
|
|
#endif // XP_MACOSX
|
2009-08-28 23:46:21 +04:00
|
|
|
return appShell->Run();
|
|
|
|
}
|
|
|
|
|
2009-08-26 03:39:30 +04:00
|
|
|
void
|
2009-12-03 11:16:28 +03:00
|
|
|
XRE_ShutdownChildProcess()
|
2009-08-28 23:46:21 +04:00
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
2009-12-03 11:16:28 +03:00
|
|
|
|
2011-07-19 14:04:54 +04:00
|
|
|
mozilla::DebugOnly<MessageLoop*> ioLoop = XRE_GetIOMessageLoop();
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!!ioLoop, "Bad shutdown order");
|
2009-12-03 11:16:28 +03:00
|
|
|
|
2017-07-29 00:56:49 +03:00
|
|
|
Scheduler::Shutdown();
|
|
|
|
|
2010-05-11 08:18:00 +04: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 22:53:53 +03:00
|
|
|
MessageLoop::current()->Quit();
|
2017-07-29 00:56:49 +03:00
|
|
|
|
2011-02-01 22:53:53 +03:00
|
|
|
#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-29 03:16:19 +04:00
|
|
|
}
|
2009-08-28 23:46:21 +04:00
|
|
|
|
2009-08-29 03:16:19 +04:00
|
|
|
namespace {
|
2011-06-24 03:31:58 +04:00
|
|
|
ContentParent* gContentParent; //long-lived, manually refcounted
|
2009-11-06 23:43:39 +03:00
|
|
|
TestShellParent* GetOrCreateTestShellParent()
|
|
|
|
{
|
2011-06-24 03:31:58 +04:00
|
|
|
if (!gContentParent) {
|
2017-09-01 09:24:47 +03:00
|
|
|
// Use a "web" child process by default. File a bug if you don't like
|
|
|
|
// this and you're sure you wouldn't be better off writing a "browser"
|
|
|
|
// chrome mochitest where you can have multiple types of content
|
|
|
|
// processes.
|
|
|
|
RefPtr<ContentParent> parent =
|
|
|
|
ContentParent::GetNewOrUsedBrowserProcess(
|
|
|
|
NS_LITERAL_STRING(DEFAULT_REMOTE_TYPE));
|
2013-04-03 03:52:51 +04:00
|
|
|
parent.forget(&gContentParent);
|
2011-06-24 03:31:58 +04:00
|
|
|
} else if (!gContentParent->IsAlive()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-11-06 23:43:39 +03:00
|
|
|
}
|
2011-06-24 03:31:58 +04:00
|
|
|
TestShellParent* tsp = gContentParent->GetTestShellSingleton();
|
|
|
|
if (!tsp) {
|
|
|
|
tsp = gContentParent->CreateTestShell();
|
|
|
|
}
|
|
|
|
return tsp;
|
2009-11-06 23:43:39 +03:00
|
|
|
}
|
2015-07-13 18:25:42 +03:00
|
|
|
|
|
|
|
} // namespace
|
2009-08-28 23:46:21 +04:00
|
|
|
|
2009-08-29 03:16:19 +04:00
|
|
|
bool
|
|
|
|
XRE_SendTestShellCommand(JSContext* aCx,
|
|
|
|
JSString* aCommand,
|
|
|
|
void* aCallback)
|
2009-08-28 23:46:21 +04:00
|
|
|
{
|
2013-05-13 00:58:02 +04:00
|
|
|
JS::RootedString cmd(aCx, aCommand);
|
2009-11-06 23:43:39 +03:00
|
|
|
TestShellParent* tsp = GetOrCreateTestShellParent();
|
|
|
|
NS_ENSURE_TRUE(tsp, false);
|
2009-08-28 23:46:21 +04:00
|
|
|
|
2014-07-05 19:30:54 +04:00
|
|
|
nsAutoJSString command;
|
2013-05-13 00:58:02 +04:00
|
|
|
NS_ENSURE_TRUE(command.init(aCx, cmd), false);
|
2010-12-03 11:24:17 +03:00
|
|
|
|
2009-08-29 03:16:19 +04:00
|
|
|
if (!aCallback) {
|
2009-11-06 23:43:39 +03:00
|
|
|
return tsp->SendExecuteCommand(command);
|
2009-08-26 03:39:30 +04:00
|
|
|
}
|
2009-08-29 03:16:19 +04:00
|
|
|
|
|
|
|
TestShellCommandParent* callback = static_cast<TestShellCommandParent*>(
|
2009-11-06 23:43:39 +03:00
|
|
|
tsp->SendPTestShellCommandConstructor(command));
|
2009-08-29 03:16:19 +04:00
|
|
|
NS_ENSURE_TRUE(callback, false);
|
|
|
|
|
2013-03-07 01:16:46 +04:00
|
|
|
JS::Value callbackVal = *reinterpret_cast<JS::Value*>(aCallback);
|
2009-08-29 03:16:19 +04:00
|
|
|
NS_ENSURE_TRUE(callback->SetCallback(aCx, callbackVal), false);
|
|
|
|
|
|
|
|
return true;
|
2009-08-26 03:39:30 +04:00
|
|
|
}
|
|
|
|
|
2009-11-11 11:34:08 +03:00
|
|
|
bool
|
|
|
|
XRE_ShutdownTestShell()
|
|
|
|
{
|
2011-06-24 03:31:58 +04:00
|
|
|
if (!gContentParent) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool ret = true;
|
|
|
|
if (gContentParent->IsAlive()) {
|
|
|
|
ret = gContentParent->DestroyTestShell(
|
|
|
|
gContentParent->GetTestShellSingleton());
|
|
|
|
}
|
|
|
|
NS_RELEASE(gContentParent);
|
|
|
|
return ret;
|
2009-11-11 11:34:08 +03:00
|
|
|
}
|
|
|
|
|
2010-02-25 01:25:16 +03:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
void
|
|
|
|
XRE_InstallX11ErrorHandler()
|
|
|
|
{
|
2014-06-16 12:54:00 +04:00
|
|
|
#if (MOZ_WIDGET_GTK == 3)
|
|
|
|
InstallGdkErrorHandler();
|
|
|
|
#else
|
2010-02-25 01:25:16 +03:00
|
|
|
InstallX11ErrorHandler();
|
2014-06-16 12:54:00 +04:00
|
|
|
#endif
|
2010-02-25 01:25:16 +03:00
|
|
|
}
|
|
|
|
#endif
|