Bug 982491 - Group apps in activities chains in the same process r=cervantes,gene

This commit is contained in:
Fabrice Desré 2014-03-25 21:56:35 -07:00
Родитель e1dce7953a
Коммит 874f87e5ff
9 изменённых файлов: 75 добавлений и 22 удалений

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

@ -703,6 +703,8 @@ pref("dom.ipc.processPrelaunch.enabled", true);
pref("dom.ipc.processPrelaunch.delayMs", 5000);
#endif
pref("dom.ipc.reuse_parent_app", false);
// When a process receives a system message, we hold a CPU wake lock on its
// behalf for this many seconds, or until it handles the system message,
// whichever comes first.

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

@ -855,6 +855,7 @@ GK_ATOM(panel, "panel")
GK_ATOM(param, "param")
GK_ATOM(parameter, "parameter")
GK_ATOM(parent, "parent")
GK_ATOM(parentapp, "parentapp")
GK_ATOM(parentfocused, "parentfocused")
GK_ATOM(parsetype, "parsetype")
GK_ATOM(pattern, "pattern")

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

@ -58,6 +58,15 @@ CreateIframe(Element* aOpenerFrameElement, const nsAString& aName, bool aRemote)
mozapp, /* aNotify = */ false);
}
// Copy the opener frame's parentApp attribute to the popup frame.
if (aOpenerFrameElement->HasAttr(kNameSpaceID_None, nsGkAtoms::parentapp)) {
nsAutoString parentApp;
aOpenerFrameElement->GetAttr(kNameSpaceID_None, nsGkAtoms::parentapp,
parentApp);
popupFrameElement->SetAttr(kNameSpaceID_None, nsGkAtoms::parentapp,
parentApp, /* aNotify = */ false);
}
// Copy the window name onto the iframe.
popupFrameElement->SetAttr(kNameSpaceID_None, nsGkAtoms::name,
aName, /* aNotify = */ false);

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

@ -75,12 +75,6 @@ AssertAppProcess(PBrowserParent* aActor,
break;
}
}
if (!aValid) {
printf_stderr("Security problem: Content process does not have `%s'. It will be killed.\n", aCapability);
ContentParent* process = tab->Manager();
process->KillHard();
}
return aValid;
}
@ -105,12 +99,6 @@ AssertAppStatus(PBrowserParent* aActor,
}
}
if (!valid) {
printf_stderr("Security problem: Content process does not have `%d' status. It will be killed.\n", aStatus);
ContentParent* process = tab->Manager();
process->KillHard();
}
return valid;
}
@ -126,6 +114,10 @@ AssertAppProcess(PContentParent* aActor,
return true;
}
}
printf_stderr("Security problem: Content process does not have `%s'. It will be killed.\n", aCapability);
static_cast<ContentParent*>(aActor)->KillHard();
return false;
}
@ -140,6 +132,10 @@ AssertAppStatus(PContentParent* aActor,
return true;
}
}
printf_stderr("Security problem: Content process does not have `%d' status. It will be killed.\n", aStatus);
static_cast<ContentParent*>(aActor)->KillHard();
return false;
}

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

@ -379,6 +379,7 @@ ContentChild::ContentChild()
#ifdef ANDROID
,mScreenSize(0, 0)
#endif
, mCanOverrideProcessName(true)
{
// This process is a content process, so it's clearly running in
// multiprocess mode!
@ -444,22 +445,26 @@ ContentChild::Init(MessageLoop* aIOLoop,
#ifdef MOZ_NUWA_PROCESS
if (IsNuwaProcess()) {
SetProcessName(NS_LITERAL_STRING("(Nuwa)"));
SetProcessName(NS_LITERAL_STRING("(Nuwa)"), false);
return true;
}
#endif
if (mIsForApp && !mIsForBrowser) {
SetProcessName(NS_LITERAL_STRING("(Preallocated app)"));
SetProcessName(NS_LITERAL_STRING("(Preallocated app)"), false);
} else {
SetProcessName(NS_LITERAL_STRING("Browser"));
SetProcessName(NS_LITERAL_STRING("Browser"), false);
}
return true;
}
void
ContentChild::SetProcessName(const nsAString& aName)
ContentChild::SetProcessName(const nsAString& aName, bool aDontOverride)
{
if (!mCanOverrideProcessName) {
return;
}
char* name;
if ((name = PR_GetEnv("MOZ_DEBUG_APP_PROCESS")) &&
aName.EqualsASCII(name)) {
@ -477,6 +482,10 @@ ContentChild::SetProcessName(const nsAString& aName)
mProcessName = aName;
mozilla::ipc::SetThisProcessName(NS_LossyConvertUTF16toASCII(aName).get());
if (aDontOverride) {
mCanOverrideProcessName = false;
}
}
void
@ -1705,7 +1714,7 @@ public:
// In the new process.
ContentChild* child = ContentChild::GetSingleton();
child->SetProcessName(NS_LITERAL_STRING("(Preallocated app)"));
child->SetProcessName(NS_LITERAL_STRING("(Preallocated app)"), false);
mozilla::ipc::Transport* transport = child->GetTransport();
int fd = transport->GetFileDescriptor();
transport->ResetFileDescriptor(fd);

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

@ -75,7 +75,7 @@ public:
return mAppInfo;
}
void SetProcessName(const nsAString& aName);
void SetProcessName(const nsAString& aName, bool aDontOverride = false);
void GetProcessName(nsAString& aName);
void GetProcessName(nsACString& aName);
static void AppendProcessId(nsACString& aName);
@ -314,6 +314,7 @@ private:
bool mIsForApp;
bool mIsForBrowser;
bool mCanOverrideProcessName;
nsString mProcessName;
static ContentChild* sSingleton;

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

@ -686,7 +686,8 @@ ContentParent::CreateBrowserOrApp(const TabContext& aContext,
new nsDataHashtable<nsStringHashKey, ContentParent*>();
}
// Each app gets its own ContentParent instance.
// Each app gets its own ContentParent instance unless it shares it with
// a parent app.
nsAutoString manifestURL;
if (NS_FAILED(ownApp->GetManifestURL(manifestURL))) {
NS_ERROR("Failed to get manifest URL");
@ -694,8 +695,41 @@ ContentParent::CreateBrowserOrApp(const TabContext& aContext,
}
ProcessPriority initialPriority = GetInitialProcessPriority(aFrameElement);
nsRefPtr<ContentParent> p = sAppContentParents->Get(manifestURL);
if (!p && Preferences::GetBool("dom.ipc.reuse_parent_app")) {
nsAutoString parentAppURL;
aFrameElement->GetAttr(kNameSpaceID_None,
nsGkAtoms::parentapp, parentAppURL);
nsAdoptingString systemAppURL =
Preferences::GetString("browser.homescreenURL");
nsCOMPtr<nsIAppsService> appsService =
do_GetService(APPS_SERVICE_CONTRACTID);
if (!parentAppURL.IsEmpty() &&
!parentAppURL.Equals(systemAppURL) &&
appsService) {
nsCOMPtr<mozIApplication> parentApp;
nsCOMPtr<mozIApplication> app;
appsService->GetAppByManifestURL(parentAppURL,
getter_AddRefs(parentApp));
appsService->GetAppByManifestURL(manifestURL,
getter_AddRefs(app));
// Only let certified apps re-use the same process.
unsigned short parentAppStatus = 0;
unsigned short appStatus = 0;
if (app &&
NS_SUCCEEDED(app->GetAppStatus(&appStatus)) &&
appStatus == nsIPrincipal::APP_STATUS_CERTIFIED &&
parentApp &&
NS_SUCCEEDED(parentApp->GetAppStatus(&parentAppStatus)) &&
parentAppStatus == nsIPrincipal::APP_STATUS_CERTIFIED) {
// Check if we can re-use the process of the parent app.
p = sAppContentParents->Get(parentAppURL);
}
}
}
if (p) {
// Check that the process is still alive and set its priority.
// Hopefully the process won't die after this point, if this call

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

@ -1344,7 +1344,7 @@ TabChild::SetProcessNameToAppName()
return;
}
ContentChild::GetSingleton()->SetProcessName(appName);
ContentChild::GetSingleton()->SetProcessName(appName, true);
}
bool

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

@ -342,7 +342,8 @@ SystemMessageInternal.prototype = {
// To prevent the hacked child process from sending commands to parent
// to manage system messages, we need to check its manifest URL.
if (["SystemMessageManager:Register",
"SystemMessageManager:Unregister",
// TODO: fix bug 988142 to re-enable.
// "SystemMessageManager:Unregister",
"SystemMessageManager:GetPendingMessages",
"SystemMessageManager:HasPendingMessages",
"SystemMessageManager:Message:Return:OK",