mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 19:35:51 +00:00
Bug 507218 - Expose the process type (chrome/content) to client code via XRE_GetProcessType and nsIXULRuntime, r=bent
This commit is contained in:
parent
57c28a4b6c
commit
b4dc22d447
@ -34,7 +34,7 @@ ContentProcessParent::CreateTestShell()
|
||||
}
|
||||
|
||||
ContentProcessParent::ContentProcessParent()
|
||||
: mSubprocess(GeckoChildProcess_Tab)
|
||||
: mSubprocess(GeckoProcessType_Content)
|
||||
{
|
||||
// TODO: async launching!
|
||||
mSubprocess.SyncLaunch();
|
||||
|
@ -48,7 +48,7 @@ namespace plugins {
|
||||
|
||||
|
||||
PluginProcessParent::PluginProcessParent(const std::string& aPluginFilePath) :
|
||||
GeckoChildProcessHost(GeckoChildProcess_Plugin),
|
||||
GeckoChildProcessHost(GeckoProcessType_Plugin),
|
||||
mPluginFilePath(aPluginFilePath)
|
||||
{
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ main(int argc, char* argv[])
|
||||
MessageBox(NULL, L"Hi", L"Hi", MB_OK);
|
||||
#endif
|
||||
|
||||
GeckoChildProcessType proctype =
|
||||
GeckoProcessType proctype =
|
||||
XRE_StringToChildProcessType(argv[argc - 1]);
|
||||
|
||||
nsresult rv = XRE_InitChildProcess(argc - 1, argv, proctype);
|
||||
|
@ -53,7 +53,7 @@ struct RunnableMethodTraits<GeckoChildProcessHost>
|
||||
static void ReleaseCallee(GeckoChildProcessHost* obj) { }
|
||||
};
|
||||
|
||||
GeckoChildProcessHost::GeckoChildProcessHost(GeckoChildProcessType aProcessType)
|
||||
GeckoChildProcessHost::GeckoChildProcessHost(GeckoProcessType aProcessType)
|
||||
: ChildProcessHost(RENDER_PROCESS), // FIXME/cjones: we should own this enum
|
||||
mProcessType(aProcessType),
|
||||
mMonitor("mozilla.ipc.GeckChildProcessHost.mMonitor"),
|
||||
|
@ -45,7 +45,7 @@
|
||||
|
||||
#include "mozilla/Monitor.h"
|
||||
|
||||
#include "nsXULAppAPI.h" // for GeckoChildProcessType
|
||||
#include "nsXULAppAPI.h" // for GeckoProcessType
|
||||
|
||||
namespace mozilla {
|
||||
namespace ipc {
|
||||
@ -56,7 +56,7 @@ protected:
|
||||
typedef mozilla::Monitor Monitor;
|
||||
|
||||
public:
|
||||
GeckoChildProcessHost(GeckoChildProcessType aProcessType=GeckoChildProcess_Default);
|
||||
GeckoChildProcessHost(GeckoProcessType aProcessType=GeckoProcessType_Default);
|
||||
|
||||
bool SyncLaunch(std::vector<std::wstring> aExtraOpts=std::vector<std::wstring>());
|
||||
bool AsyncLaunch(std::vector<std::wstring> aExtraOpts=std::vector<std::wstring>());
|
||||
@ -76,7 +76,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
GeckoChildProcessType mProcessType;
|
||||
GeckoProcessType mProcessType;
|
||||
Monitor mMonitor;
|
||||
bool mLaunched;
|
||||
FilePath mProcessPath;
|
||||
|
@ -6,7 +6,7 @@ namespace test {
|
||||
|
||||
|
||||
TestProcessParent::TestProcessParent() :
|
||||
GeckoChildProcessHost(GeckoChildProcess_TestHarness)
|
||||
GeckoChildProcessHost(GeckoProcessType_TestHarness)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -49,9 +49,10 @@ void xxxNeverCalledXUL()
|
||||
XRE_CreateAppData(nsnull, nsnull);
|
||||
XRE_ParseAppData(nsnull, nsnull);
|
||||
XRE_FreeAppData(nsnull);
|
||||
XRE_ChildProcessTypeToString(GeckoChildProcess_Default);
|
||||
XRE_ChildProcessTypeToString(GeckoProcessType_Default);
|
||||
XRE_StringToChildProcessType("");
|
||||
XRE_InitChildProcess(0, nsnull, GeckoChildProcess_Default);
|
||||
XRE_InitChildProcess(0, nsnull, GeckoProcessType_Default);
|
||||
XRE_InitParentProcess(0, nsnull, nsnull, nsnull);
|
||||
XRE_RunTestShell(0, nsnull);
|
||||
XRE_GetProcessType();
|
||||
}
|
||||
|
@ -753,6 +753,29 @@ nsXULAppInfo::GetWidgetToolkit(nsACString& aResult)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Ensure that the GeckoProcessType enum, defined in xpcom/build/nsXULAppAPI.h,
|
||||
// is synchronized with the const unsigned longs defined in
|
||||
// xpcom/system/nsIXULRuntime.idl.
|
||||
#define SYNC_ENUMS(a,b) \
|
||||
PR_STATIC_ASSERT(nsIXULRuntime::PROCESS_TYPE_ ## a == \
|
||||
static_cast<int>(GeckoProcessType_ ## b));
|
||||
|
||||
SYNC_ENUMS(DEFAULT, Default)
|
||||
SYNC_ENUMS(PLUGIN, Plugin)
|
||||
SYNC_ENUMS(CONTENT, Content)
|
||||
SYNC_ENUMS(TESTHARNESS, TestHarness)
|
||||
|
||||
// .. and ensure that that is all of them:
|
||||
PR_STATIC_ASSERT(GeckoProcessType_TestHarness + 1 == GeckoProcessType_End);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXULAppInfo::GetProcessType(PRUint32* aResult)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
*aResult = XRE_GetProcessType();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifdef XP_WIN
|
||||
// Matches the enum in WinNT.h for the Vista SDK but renamed so that we can
|
||||
// safely build with the Vista SDK and without it.
|
||||
|
@ -212,30 +212,32 @@ XRE_TermEmbedding()
|
||||
}
|
||||
|
||||
const char*
|
||||
XRE_ChildProcessTypeToString(GeckoChildProcessType aProcessType)
|
||||
XRE_ChildProcessTypeToString(GeckoProcessType aProcessType)
|
||||
{
|
||||
return (aProcessType < GeckoChildProcess_End) ?
|
||||
kGeckoChildProcessTypeString[aProcessType] : nsnull;
|
||||
return (aProcessType < GeckoProcessType_End) ?
|
||||
kGeckoProcessTypeString[aProcessType] : nsnull;
|
||||
}
|
||||
|
||||
GeckoChildProcessType
|
||||
GeckoProcessType
|
||||
XRE_StringToChildProcessType(const char* aProcessTypeString)
|
||||
{
|
||||
for (int i = 0;
|
||||
i < (int) NS_ARRAY_LENGTH(kGeckoChildProcessTypeString);
|
||||
i < (int) NS_ARRAY_LENGTH(kGeckoProcessTypeString);
|
||||
++i) {
|
||||
if (!strcmp(kGeckoChildProcessTypeString[i], aProcessTypeString)) {
|
||||
return static_cast<GeckoChildProcessType>(i);
|
||||
if (!strcmp(kGeckoProcessTypeString[i], aProcessTypeString)) {
|
||||
return static_cast<GeckoProcessType>(i);
|
||||
}
|
||||
}
|
||||
return GeckoChildProcess_Invalid;
|
||||
return GeckoProcessType_Invalid;
|
||||
}
|
||||
|
||||
#ifdef MOZ_IPC
|
||||
static GeckoProcessType sChildProcessType = GeckoProcessType_Default;
|
||||
|
||||
nsresult
|
||||
XRE_InitChildProcess(int aArgc,
|
||||
char* aArgv[],
|
||||
GeckoChildProcessType aProcess)
|
||||
GeckoProcessType aProcess)
|
||||
{
|
||||
NS_ENSURE_ARG_MIN(aArgc, 1);
|
||||
NS_ENSURE_ARG_POINTER(aArgv);
|
||||
@ -258,19 +260,19 @@ XRE_InitChildProcess(int aArgc,
|
||||
ChildThread* mainThread;
|
||||
|
||||
switch (aProcess) {
|
||||
case GeckoChildProcess_Default:
|
||||
case GeckoProcessType_Default:
|
||||
mainThread = new GeckoThread();
|
||||
break;
|
||||
|
||||
case GeckoChildProcess_Plugin:
|
||||
case GeckoProcessType_Plugin:
|
||||
mainThread = new PluginThreadChild();
|
||||
break;
|
||||
|
||||
case GeckoChildProcess_Tab:
|
||||
case GeckoProcessType_Content:
|
||||
mainThread = new ContentProcessThread();
|
||||
break;
|
||||
|
||||
case GeckoChildProcess_TestHarness:
|
||||
case GeckoProcessType_TestHarness:
|
||||
mainThread = new TestThreadChild();
|
||||
break;
|
||||
|
||||
@ -278,6 +280,7 @@ XRE_InitChildProcess(int aArgc,
|
||||
NS_RUNTIMEABORT("Unknown main thread class");
|
||||
}
|
||||
|
||||
sChildProcessType = aProcess;
|
||||
ChildProcess process(mainThread);
|
||||
|
||||
// Do IPC event loop
|
||||
@ -287,6 +290,12 @@ XRE_InitChildProcess(int aArgc,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
GeckoProcessType
|
||||
XRE_GetProcessType()
|
||||
{
|
||||
return sChildProcessType;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class MainFunctionRunnable : public nsRunnable
|
||||
|
@ -419,40 +419,43 @@ XRE_API(nsresult,
|
||||
XRE_API(void,
|
||||
XRE_FreeAppData, (nsXREAppData *aAppData))
|
||||
|
||||
enum GeckoChildProcessType {
|
||||
GeckoChildProcess_Default = 0,
|
||||
enum GeckoProcessType {
|
||||
GeckoProcessType_Default = 0,
|
||||
|
||||
GeckoChildProcess_Plugin,
|
||||
GeckoChildProcess_Tab,
|
||||
GeckoProcessType_Plugin,
|
||||
GeckoProcessType_Content,
|
||||
|
||||
GeckoChildProcess_TestHarness,
|
||||
GeckoProcessType_TestHarness,
|
||||
|
||||
GeckoChildProcess_End,
|
||||
GeckoChildProcess_Invalid = GeckoChildProcess_End
|
||||
GeckoProcessType_End,
|
||||
GeckoProcessType_Invalid = GeckoProcessType_End
|
||||
};
|
||||
|
||||
static const char* const kGeckoChildProcessTypeString[] = {
|
||||
static const char* const kGeckoProcessTypeString[] = {
|
||||
"default",
|
||||
"plugin",
|
||||
"tab",
|
||||
"testharness",
|
||||
};
|
||||
|
||||
PR_STATIC_ASSERT(sizeof(kGeckoChildProcessTypeString) /
|
||||
sizeof(kGeckoChildProcessTypeString[0]) ==
|
||||
GeckoChildProcess_End);
|
||||
PR_STATIC_ASSERT(sizeof(kGeckoProcessTypeString) /
|
||||
sizeof(kGeckoProcessTypeString[0]) ==
|
||||
GeckoProcessType_End);
|
||||
|
||||
|
||||
XRE_API(const char*,
|
||||
XRE_ChildProcessTypeToString, (GeckoChildProcessType aProcessType))
|
||||
XRE_ChildProcessTypeToString, (GeckoProcessType aProcessType))
|
||||
|
||||
XRE_API(GeckoChildProcessType,
|
||||
XRE_API(GeckoProcessType,
|
||||
XRE_StringToChildProcessType, (const char* aProcessTypeString))
|
||||
|
||||
XRE_API(nsresult,
|
||||
XRE_InitChildProcess, (int aArgc,
|
||||
char* aArgv[],
|
||||
GeckoChildProcessType aProcess))
|
||||
GeckoProcessType aProcess))
|
||||
|
||||
XRE_API(GeckoProcessType,
|
||||
XRE_GetProcessType, ())
|
||||
|
||||
typedef void (*MainFunction)(void* aData);
|
||||
|
||||
|
@ -86,4 +86,17 @@ interface nsIXULRuntime : nsISupports
|
||||
* This is taken from the MOZ_WIDGET_TOOLKIT configure variable.
|
||||
*/
|
||||
readonly attribute AUTF8String widgetToolkit;
|
||||
|
||||
/**
|
||||
* The legal values of processType.
|
||||
*/
|
||||
const unsigned long PROCESS_TYPE_DEFAULT = 0;
|
||||
const unsigned long PROCESS_TYPE_PLUGIN = 1;
|
||||
const unsigned long PROCESS_TYPE_CONTENT = 2;
|
||||
const unsigned long PROCESS_TYPE_TESTHARNESS = 3;
|
||||
|
||||
/**
|
||||
* The type of the caller's process. Returns one of the values above.
|
||||
*/
|
||||
readonly attribute unsigned long processType;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user