Bug 820200 - Pass application directory to XRE_InitEmbedding2 in content process. r=bsmedberg

This commit is contained in:
Jim Mathies 2012-12-18 10:24:42 -06:00
Родитель 5e6610fecb
Коммит d768d99a05
6 изменённых файлов: 93 добавлений и 7 удалений

Просмотреть файл

@ -13,6 +13,12 @@ using mozilla::ipc::IOThreadChild;
namespace mozilla {
namespace dom {
void
ContentProcess::SetAppDir(const nsACString& aPath)
{
mXREEmbed.SetAppDir(aPath);
}
bool
ContentProcess::Init()
{

Просмотреть файл

@ -36,6 +36,8 @@ public:
virtual bool Init() MOZ_OVERRIDE;
virtual void CleanUp() MOZ_OVERRIDE;
void SetAppDir(const nsACString& aPath);
private:
ContentChild mContent;
mozilla::ipc::ScopedXREEmbed mXREEmbed;

Просмотреть файл

@ -410,6 +410,40 @@ GeckoChildProcessHost::PerformAsyncLaunch(std::vector<std::string> aExtraOpts, b
return retval;
}
void
#if defined(XP_WIN)
AddAppDirToCommandLine(CommandLine& aCmdLine)
#else
AddAppDirToCommandLine(std::vector<std::string>& aCmdLine)
#endif
{
// Content processes need access to application resources, so pass
// the full application directory path to the child process.
if (ShouldHaveDirectoryService()) {
nsCOMPtr<nsIProperties> directoryService(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));
NS_ASSERTION(directoryService, "Expected XPCOM to be available");
if (directoryService) {
nsCOMPtr<nsIFile> appDir;
// NS_XPCOM_CURRENT_PROCESS_DIR really means the app dir, not the
// current process dir.
nsresult rv = directoryService->Get(NS_XPCOM_CURRENT_PROCESS_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(appDir));
if (NS_SUCCEEDED(rv)) {
nsAutoCString path;
appDir->GetNativePath(path);
#if defined(XP_WIN)
aCmdLine.AppendLooseValue(UTF8ToWide("-appdir"));
aCmdLine.AppendLooseValue(UTF8ToWide(path.get()));
#else
aCmdLine.push_back("-appdir");
aCmdLine.push_back(path.get());
#endif
}
}
}
}
bool
GeckoChildProcessHost::PerformAsyncLaunchInternal(std::vector<std::string>& aExtraOpts, base::ProcessArchitecture arch)
{
@ -575,6 +609,9 @@ GeckoChildProcessHost::PerformAsyncLaunchInternal(std::vector<std::string>& aExt
}
}
// Add the application directory path (-appdir path)
AddAppDirToCommandLine(childArgv);
childArgv.push_back(pidstring);
#if defined(MOZ_CRASHREPORTER)
@ -674,8 +711,6 @@ GeckoChildProcessHost::PerformAsyncLaunchInternal(std::vector<std::string>& aExt
cmdLine.AppendLooseValue(UTF8ToWide(*it));
}
cmdLine.AppendLooseValue(std::wstring(mGroupId.get()));
if (Omnijar::IsInitialized()) {
// Make sure the child process can find the omnijar
// See XRE_InitCommandLine in nsAppRunner.cpp
@ -692,6 +727,17 @@ GeckoChildProcessHost::PerformAsyncLaunchInternal(std::vector<std::string>& aExt
}
}
// Add the application directory path (-appdir path)
AddAppDirToCommandLine(cmdLine);
// XXX Command line params past this point are expected to be at
// the end of the command line string, and in a specific order.
// See XRE_InitChildProcess in nsEmbedFunction.
// Win app model id
cmdLine.AppendLooseValue(std::wstring(mGroupId.get()));
// Process id
cmdLine.AppendLooseValue(UTF8ToWide(pidstring));
#if defined(MOZ_CRASHREPORTER)
@ -699,6 +745,7 @@ GeckoChildProcessHost::PerformAsyncLaunchInternal(std::vector<std::string>& aExt
UTF8ToWide(CrashReporter::GetChildNotificationPipe()));
#endif
// Process type
cmdLine.AppendLooseValue(UTF8ToWide(childProcessType));
base::LaunchApp(cmdLine, false, false, &process);

Просмотреть файл

@ -28,6 +28,19 @@ ScopedXREEmbed::~ScopedXREEmbed()
NS_LogTerm();
}
void
ScopedXREEmbed::SetAppDir(const nsACString& aPath)
{
bool flag;
nsresult rv =
XRE_GetFileFromPath(aPath.BeginReading(), getter_AddRefs(mAppDir));
if (NS_FAILED(rv) ||
NS_FAILED(mAppDir->Exists(&flag)) || !flag) {
NS_WARNING("Invalid application directory passed to content process.");
mAppDir = nullptr;
}
}
void
ScopedXREEmbed::Start()
{
@ -80,7 +93,10 @@ ScopedXREEmbed::Start()
}
#endif
rv = XRE_InitEmbedding2(localFile, localFile, nullptr);
if (mAppDir)
rv = XRE_InitEmbedding2(localFile, mAppDir, nullptr);
else
rv = XRE_InitEmbedding2(localFile, localFile, nullptr);
if (NS_FAILED(rv))
return;

Просмотреть файл

@ -5,6 +5,10 @@
#ifndef __IPC_GLUE_SCOPEDXREEMBED_H__
#define __IPC_GLUE_SCOPEDXREEMBED_H__
#include "nsString.h"
#include "nsAutoPtr.h"
#include "nsIFile.h"
namespace mozilla {
namespace ipc {
@ -16,9 +20,11 @@ public:
void Start();
void Stop();
void SetAppDir(const nsACString& aPath);
private:
bool mShouldKillEmbedding;
nsCOMPtr<nsIFile> mAppDir;
};
} /* namespace ipc */

Просмотреть файл

@ -403,8 +403,7 @@ XRE_InitChildProcess(int aArgc,
// 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.
const char* const appModelUserId = aArgv[aArgc-1];
--aArgc;
const char* const appModelUserId = aArgv[--aArgc];
if (appModelUserId) {
// '-' implies no support
if (*appModelUserId != '-') {
@ -460,8 +459,18 @@ XRE_InitChildProcess(int aArgc,
process = new PluginProcessChild(parentHandle);
break;
case GeckoProcessType_Content:
process = new ContentProcess(parentHandle);
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;
}
}
}
break;
case GeckoProcessType_IPDLUnitTest: