mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-30 04:17:31 +09:00
Issue #2653 - Part 1: Initial cleanup of AppId and isolated mozbrowser.
This removes a lot of the plumbing for having the platform embed itself through IPC which was required for B2G running the browser as both shell and browser application.
This commit is contained in:
parent
a6c54d0736
commit
7b6e3a2d4a
77 changed files with 295 additions and 1799 deletions
|
|
@ -27,7 +27,6 @@
|
|||
#include "HandlerServiceParent.h"
|
||||
#include "IHistory.h"
|
||||
#include "imgIContainer.h"
|
||||
#include "mozIApplication.h"
|
||||
#if defined(XP_WIN) && defined(ACCESSIBILITY)
|
||||
#include "mozilla/a11y/AccessibleWrap.h"
|
||||
#endif
|
||||
|
|
@ -460,8 +459,7 @@ ContentParentsMemoryReporter::CollectReports(
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsDataHashtable<nsStringHashKey, ContentParent*>* ContentParent::sAppContentParents;
|
||||
nsTArray<ContentParent*>* ContentParent::sNonAppContentParents;
|
||||
nsTArray<ContentParent*>* ContentParent::sBrowserContentParents;
|
||||
nsTArray<ContentParent*>* ContentParent::sLargeAllocationContentParents;
|
||||
nsTArray<ContentParent*>* ContentParent::sPrivateContent;
|
||||
StaticAutoPtr<LinkedList<ContentParent> > ContentParent::sContentParents;
|
||||
|
|
@ -477,11 +475,6 @@ static bool sDisableUnsafeCPOWWarnings = false;
|
|||
// The first content child has ID 1, so the chrome process can have ID 0.
|
||||
static uint64_t gContentChildID = 1;
|
||||
|
||||
// We want the prelaunched process to know that it's for apps, but not
|
||||
// actually for any app in particular. Use a magic manifest URL.
|
||||
// Can't be a static constant.
|
||||
#define MAGIC_PREALLOCATED_APP_MANIFEST_URL NS_LITERAL_STRING("{{template}}")
|
||||
|
||||
static const char* sObserverTopics[] = {
|
||||
"xpcom-shutdown",
|
||||
"profile-before-change",
|
||||
|
|
@ -507,8 +500,7 @@ static const char* sObserverTopics[] = {
|
|||
ContentParent::PreallocateAppProcess()
|
||||
{
|
||||
RefPtr<ContentParent> process =
|
||||
new ContentParent(/* app = */ nullptr,
|
||||
/* aOpener = */ nullptr,
|
||||
new ContentParent(/* aOpener = */ nullptr,
|
||||
/* isForBrowserElement = */ false,
|
||||
/* isForPreallocated = */ true);
|
||||
|
||||
|
|
@ -520,57 +512,6 @@ ContentParent::PreallocateAppProcess()
|
|||
return process.forget();
|
||||
}
|
||||
|
||||
/*static*/ already_AddRefed<ContentParent>
|
||||
ContentParent::GetNewOrPreallocatedAppProcess(mozIApplication* aApp,
|
||||
ProcessPriority aInitialPriority,
|
||||
ContentParent* aOpener,
|
||||
/*out*/ bool* aTookPreAllocated)
|
||||
{
|
||||
MOZ_ASSERT(aApp);
|
||||
RefPtr<ContentParent> process = PreallocatedProcessManager::Take();
|
||||
|
||||
if (process) {
|
||||
if (!process->SetPriorityAndCheckIsAlive(aInitialPriority)) {
|
||||
// Kill the process just in case it's not actually dead; we don't want
|
||||
// to "leak" this process!
|
||||
process->KillHard("GetNewOrPreallocatedAppProcess");
|
||||
}
|
||||
else {
|
||||
nsAutoString manifestURL;
|
||||
if (NS_FAILED(aApp->GetManifestURL(manifestURL))) {
|
||||
NS_ERROR("Failed to get manifest URL");
|
||||
return nullptr;
|
||||
}
|
||||
process->TransformPreallocatedIntoApp(aOpener, manifestURL);
|
||||
process->ForwardKnownInfo();
|
||||
|
||||
if (aTookPreAllocated) {
|
||||
*aTookPreAllocated = true;
|
||||
}
|
||||
return process.forget();
|
||||
}
|
||||
}
|
||||
|
||||
NS_WARNING("Unable to use pre-allocated app process");
|
||||
process = new ContentParent(aApp,
|
||||
/* aOpener = */ aOpener,
|
||||
/* isForBrowserElement = */ false,
|
||||
/* isForPreallocated = */ false);
|
||||
|
||||
if (!process->LaunchSubprocess(aInitialPriority)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
process->Init();
|
||||
process->ForwardKnownInfo();
|
||||
|
||||
if (aTookPreAllocated) {
|
||||
*aTookPreAllocated = false;
|
||||
}
|
||||
|
||||
return process.forget();
|
||||
}
|
||||
|
||||
/*static*/ void
|
||||
ContentParent::StartUp()
|
||||
{
|
||||
|
|
@ -672,10 +613,10 @@ ContentParent::GetNewOrUsedBrowserProcess(bool aForBrowserElement,
|
|||
|
||||
maxContentParents = Preferences::GetInt("dom.ipc.dedicatedProcessCount", 2);
|
||||
} else {
|
||||
if (!sNonAppContentParents) {
|
||||
sNonAppContentParents = new nsTArray<ContentParent*>();
|
||||
if (!sBrowserContentParents) {
|
||||
sBrowserContentParents = new nsTArray<ContentParent*>();
|
||||
}
|
||||
contentParents = sNonAppContentParents;
|
||||
contentParents = sBrowserContentParents;
|
||||
|
||||
maxContentParents = Preferences::GetInt("dom.ipc.processCount", 1);
|
||||
}
|
||||
|
|
@ -691,7 +632,7 @@ ContentParent::GetNewOrUsedBrowserProcess(bool aForBrowserElement,
|
|||
uint32_t currIdx = startIdx;
|
||||
do {
|
||||
RefPtr<ContentParent> p = (*contentParents)[currIdx];
|
||||
NS_ASSERTION(p->IsAlive(), "Non-alive contentparent in sNonAppContntParents?");
|
||||
NS_ASSERTION(p->IsAlive(), "Non-alive contentparent in sBrowserContntParents?");
|
||||
if (p->mOpener == aOpener) {
|
||||
return p.forget();
|
||||
}
|
||||
|
|
@ -705,8 +646,7 @@ ContentParent::GetNewOrUsedBrowserProcess(bool aForBrowserElement,
|
|||
p->TransformPreallocatedIntoBrowser(aOpener);
|
||||
} else {
|
||||
// Failed in using the preallocated process: fork from the chrome process.
|
||||
p = new ContentParent(/* app = */ nullptr,
|
||||
aOpener,
|
||||
p = new ContentParent(aOpener,
|
||||
aForBrowserElement,
|
||||
/* isForPreallocated = */ false);
|
||||
|
||||
|
|
@ -782,7 +722,6 @@ ContentParent::RecvCreateChildProcess(const IPCTabContext& aContext,
|
|||
const hal::ProcessPriority& aPriority,
|
||||
const TabId& aOpenerTabId,
|
||||
ContentParentId* aCpId,
|
||||
bool* aIsForApp,
|
||||
bool* aIsForBrowser,
|
||||
TabId* aTabId)
|
||||
{
|
||||
|
|
@ -800,24 +739,16 @@ ContentParent::RecvCreateChildProcess(const IPCTabContext& aContext,
|
|||
return false;
|
||||
}
|
||||
|
||||
nsCOMPtr<mozIApplication> ownApp = tc.GetTabContext().GetOwnApp();
|
||||
if (ownApp) {
|
||||
cp = GetNewOrPreallocatedAppProcess(ownApp, aPriority, this);
|
||||
}
|
||||
else {
|
||||
cp = GetNewOrUsedBrowserProcess(/* isBrowserElement = */ true,
|
||||
aPriority, this);
|
||||
}
|
||||
cp = GetNewOrUsedBrowserProcess(/* isBrowserElement = */ true,
|
||||
aPriority, this);
|
||||
|
||||
if (!cp) {
|
||||
*aCpId = 0;
|
||||
*aIsForApp = false;
|
||||
*aIsForBrowser = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
*aCpId = cp->ChildID();
|
||||
*aIsForApp = cp->IsForApp();
|
||||
*aIsForBrowser = cp->IsForBrowser();
|
||||
|
||||
ContentProcessManager *cpm = ContentProcessManager::GetSingleton();
|
||||
|
|
@ -950,10 +881,10 @@ ContentParent::RecvFindPlugins(const uint32_t& aPluginEpoch,
|
|||
}
|
||||
|
||||
/*static*/ TabParent*
|
||||
ContentParent::CreateBrowserOrApp(const TabContext& aContext,
|
||||
Element* aFrameElement,
|
||||
ContentParent* aOpenerContentParent,
|
||||
bool aFreshProcess)
|
||||
ContentParent::CreateBrowser(const TabContext& aContext,
|
||||
Element* aFrameElement,
|
||||
ContentParent* aOpenerContentParent,
|
||||
bool aFreshProcess)
|
||||
{
|
||||
PROFILER_LABEL_FUNC(js::ProfileEntry::Category::OTHER);
|
||||
|
||||
|
|
@ -976,222 +907,74 @@ ContentParent::CreateBrowserOrApp(const TabContext& aContext,
|
|||
openerTabId = TabParent::GetTabIdFrom(docShell);
|
||||
}
|
||||
|
||||
if (aContext.IsMozBrowserElement() || !aContext.HasOwnApp()) {
|
||||
RefPtr<nsIContentParent> constructorSender;
|
||||
if (isInContentProcess) {
|
||||
MOZ_ASSERT(aContext.IsMozBrowserElement());
|
||||
constructorSender = CreateContentBridgeParent(aContext, initialPriority,
|
||||
openerTabId, &tabId);
|
||||
} else {
|
||||
if (aOpenerContentParent) {
|
||||
constructorSender = aOpenerContentParent;
|
||||
} else {
|
||||
constructorSender =
|
||||
GetNewOrUsedBrowserProcess(aContext.IsMozBrowserElement(),
|
||||
initialPriority,
|
||||
nullptr,
|
||||
aFreshProcess);
|
||||
if (!constructorSender) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
tabId = AllocateTabId(openerTabId,
|
||||
aContext.AsIPCTabContext(),
|
||||
constructorSender->ChildID());
|
||||
}
|
||||
if (constructorSender) {
|
||||
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
||||
docShell->GetTreeOwner(getter_AddRefs(treeOwner));
|
||||
if (!treeOwner) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIWebBrowserChrome> wbc = do_GetInterface(treeOwner);
|
||||
if (!wbc) {
|
||||
return nullptr;
|
||||
}
|
||||
uint32_t chromeFlags = 0;
|
||||
wbc->GetChromeFlags(&chromeFlags);
|
||||
|
||||
nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(docShell);
|
||||
if (loadContext && loadContext->UsePrivateBrowsing()) {
|
||||
chromeFlags |= nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW;
|
||||
}
|
||||
if (docShell->GetAffectPrivateSessionLifetime()) {
|
||||
chromeFlags |= nsIWebBrowserChrome::CHROME_PRIVATE_LIFETIME;
|
||||
}
|
||||
|
||||
if (tabId == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
RefPtr<TabParent> tp(new TabParent(constructorSender, tabId,
|
||||
aContext, chromeFlags));
|
||||
tp->SetInitedByParent();
|
||||
|
||||
PBrowserParent* browser =
|
||||
constructorSender->SendPBrowserConstructor(
|
||||
// DeallocPBrowserParent() releases this ref.
|
||||
tp.forget().take(), tabId,
|
||||
aContext.AsIPCTabContext(),
|
||||
chromeFlags,
|
||||
constructorSender->ChildID(),
|
||||
constructorSender->IsForApp(),
|
||||
constructorSender->IsForBrowser());
|
||||
|
||||
if (aFreshProcess) {
|
||||
Unused << browser->SendSetFreshProcess();
|
||||
}
|
||||
|
||||
if (browser) {
|
||||
RefPtr<TabParent> constructedTabParent = TabParent::GetFrom(browser);
|
||||
constructedTabParent->SetOwnerElement(aFrameElement);
|
||||
return constructedTabParent;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// If we got here, we have an app and we're not a browser element. ownApp
|
||||
// shouldn't be null, because we otherwise would have gone into the
|
||||
// !HasOwnApp() branch above.
|
||||
RefPtr<nsIContentParent> parent;
|
||||
bool reused = false;
|
||||
bool tookPreallocated = false;
|
||||
nsAutoString manifestURL;
|
||||
|
||||
RefPtr<nsIContentParent> constructorSender;
|
||||
if (isInContentProcess) {
|
||||
parent = CreateContentBridgeParent(aContext,
|
||||
initialPriority,
|
||||
openerTabId,
|
||||
&tabId);
|
||||
}
|
||||
else {
|
||||
nsCOMPtr<mozIApplication> ownApp = aContext.GetOwnApp();
|
||||
|
||||
if (!sAppContentParents) {
|
||||
sAppContentParents =
|
||||
new nsDataHashtable<nsStringHashKey, ContentParent*>();
|
||||
MOZ_ASSERT(aContext.IsMozBrowserElement());
|
||||
constructorSender = CreateContentBridgeParent(aContext, initialPriority,
|
||||
openerTabId, &tabId);
|
||||
} else {
|
||||
constructorSender =
|
||||
GetNewOrUsedBrowserProcess(aContext.IsMozBrowserElement(),
|
||||
initialPriority, nullptr, aFreshProcess);
|
||||
if (!constructorSender) {
|
||||
return nullptr;
|
||||
}
|
||||
tabId = AllocateTabId(openerTabId,
|
||||
aContext.AsIPCTabContext(),
|
||||
constructorSender->ChildID());
|
||||
}
|
||||
|
||||
// Each app gets its own ContentParent instance unless it shares it with
|
||||
// a parent app.
|
||||
if (NS_FAILED(ownApp->GetManifestURL(manifestURL))) {
|
||||
NS_ERROR("Failed to get manifest URL");
|
||||
if (constructorSender) {
|
||||
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
||||
docShell->GetTreeOwner(getter_AddRefs(treeOwner));
|
||||
if (!treeOwner) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<ContentParent> p = sAppContentParents->Get(manifestURL);
|
||||
|
||||
if (!p && Preferences::GetBool("dom.ipc.reuse_parent_app")) {
|
||||
nsAutoString parentAppManifestURL;
|
||||
aFrameElement->GetAttr(kNameSpaceID_None,
|
||||
nsGkAtoms::parentapp, parentAppManifestURL);
|
||||
nsAdoptingString systemAppManifestURL =
|
||||
Preferences::GetString("b2g.system_manifest_url");
|
||||
nsCOMPtr<nsIAppsService> appsService =
|
||||
do_GetService(APPS_SERVICE_CONTRACTID);
|
||||
if (!parentAppManifestURL.IsEmpty() &&
|
||||
!parentAppManifestURL.Equals(systemAppManifestURL) &&
|
||||
appsService) {
|
||||
nsCOMPtr<mozIApplication> parentApp;
|
||||
nsCOMPtr<mozIApplication> app;
|
||||
appsService->GetAppByManifestURL(parentAppManifestURL,
|
||||
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(parentAppManifestURL);
|
||||
}
|
||||
}
|
||||
nsCOMPtr<nsIWebBrowserChrome> wbc = do_GetInterface(treeOwner);
|
||||
if (!wbc) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
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
|
||||
// succeeds.
|
||||
if (!p->SetPriorityAndCheckIsAlive(initialPriority)) {
|
||||
p = nullptr;
|
||||
}
|
||||
uint32_t chromeFlags = 0;
|
||||
wbc->GetChromeFlags(&chromeFlags);
|
||||
|
||||
nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(docShell);
|
||||
if (loadContext && loadContext->UsePrivateBrowsing()) {
|
||||
chromeFlags |= nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW;
|
||||
}
|
||||
|
||||
reused = !!p;
|
||||
if (!p) {
|
||||
p = GetNewOrPreallocatedAppProcess(ownApp, initialPriority, nullptr,
|
||||
&tookPreallocated);
|
||||
MOZ_ASSERT(p);
|
||||
sAppContentParents->Put(manifestURL, p);
|
||||
}
|
||||
tabId = AllocateTabId(openerTabId, aContext.AsIPCTabContext(),
|
||||
p->ChildID());
|
||||
parent = static_cast<nsIContentParent*>(p);
|
||||
}
|
||||
|
||||
if (!parent || (tabId == 0)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint32_t chromeFlags = 0;
|
||||
|
||||
RefPtr<TabParent> tp = new TabParent(parent, tabId, aContext, chromeFlags);
|
||||
tp->SetInitedByParent();
|
||||
PBrowserParent* browser = parent->SendPBrowserConstructor(
|
||||
// DeallocPBrowserParent() releases this ref.
|
||||
RefPtr<TabParent>(tp).forget().take(),
|
||||
tabId,
|
||||
aContext.AsIPCTabContext(),
|
||||
chromeFlags,
|
||||
parent->ChildID(),
|
||||
parent->IsForApp(),
|
||||
parent->IsForBrowser());
|
||||
|
||||
if (aFreshProcess) {
|
||||
Unused << browser->SendSetFreshProcess();
|
||||
}
|
||||
|
||||
if (browser) {
|
||||
RefPtr<TabParent> constructedTabParent = TabParent::GetFrom(browser);
|
||||
constructedTabParent->SetOwnerElement(aFrameElement);
|
||||
}
|
||||
|
||||
if (isInContentProcess) {
|
||||
// Just return directly without the following check in content process.
|
||||
return TabParent::GetFrom(browser);
|
||||
}
|
||||
|
||||
if (!browser) {
|
||||
// We failed to actually start the PBrowser. This can happen if the
|
||||
// other process has already died.
|
||||
if (!reused) {
|
||||
// Don't leave a broken ContentParent in the hashtable.
|
||||
parent->AsContentParent()->KillHard("CreateBrowserOrApp");
|
||||
sAppContentParents->Remove(manifestURL);
|
||||
parent = nullptr;
|
||||
if (docShell->GetAffectPrivateSessionLifetime()) {
|
||||
chromeFlags |= nsIWebBrowserChrome::CHROME_PRIVATE_LIFETIME;
|
||||
}
|
||||
|
||||
// If we took the preallocated process and it was already dead, try
|
||||
// again with a non-preallocated process. We can be sure this won't
|
||||
// loop forever, because the next time through there will be no
|
||||
// preallocated process to take.
|
||||
if (tookPreallocated) {
|
||||
return ContentParent::CreateBrowserOrApp(aContext, aFrameElement,
|
||||
aOpenerContentParent);
|
||||
if (tabId == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
RefPtr<TabParent> tp(new TabParent(constructorSender, tabId,
|
||||
aContext, chromeFlags));
|
||||
tp->SetInitedByParent();
|
||||
|
||||
PBrowserParent* browser =
|
||||
constructorSender->SendPBrowserConstructor(
|
||||
// DeallocPBrowserParent() releases this ref.
|
||||
tp.forget().take(), tabId,
|
||||
aContext.AsIPCTabContext(),
|
||||
chromeFlags,
|
||||
constructorSender->ChildID(),
|
||||
constructorSender->IsForBrowser());
|
||||
|
||||
if (aFreshProcess) {
|
||||
Unused << browser->SendSetFreshProcess();
|
||||
}
|
||||
|
||||
// Otherwise just give up.
|
||||
return nullptr;
|
||||
if (browser) {
|
||||
RefPtr<TabParent> constructedTabParent = TabParent::GetFrom(browser);
|
||||
constructedTabParent->SetOwnerElement(aFrameElement);
|
||||
return constructedTabParent;
|
||||
}
|
||||
}
|
||||
|
||||
return TabParent::GetFrom(browser);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*static*/ ContentBridgeParent*
|
||||
|
|
@ -1204,13 +987,11 @@ ContentParent::CreateContentBridgeParent(const TabContext& aContext,
|
|||
|
||||
ContentChild* child = ContentChild::GetSingleton();
|
||||
ContentParentId cpId;
|
||||
bool isForApp;
|
||||
bool isForBrowser;
|
||||
if (!child->SendCreateChildProcess(aContext.AsIPCTabContext(),
|
||||
aPriority,
|
||||
aOpenerTabId,
|
||||
&cpId,
|
||||
&isForApp,
|
||||
&isForBrowser,
|
||||
aTabId)) {
|
||||
return nullptr;
|
||||
|
|
@ -1223,7 +1004,6 @@ ContentParent::CreateContentBridgeParent(const TabContext& aContext,
|
|||
}
|
||||
ContentBridgeParent* parent = child->GetLastBridge();
|
||||
parent->SetChildID(cpId);
|
||||
parent->SetIsForApp(isForApp);
|
||||
parent->SetIsForBrowser(isForBrowser);
|
||||
return parent;
|
||||
}
|
||||
|
|
@ -1344,48 +1124,12 @@ ContentParent::SetPriorityAndCheckIsAlive(ProcessPriority aPriority)
|
|||
return true;
|
||||
}
|
||||
|
||||
// Helper for ContentParent::TransformPreallocatedIntoApp.
|
||||
static void
|
||||
TryGetNameFromManifestURL(const nsAString& aManifestURL,
|
||||
nsAString& aName)
|
||||
{
|
||||
aName.Truncate();
|
||||
if (aManifestURL.IsEmpty() ||
|
||||
aManifestURL == MAGIC_PREALLOCATED_APP_MANIFEST_URL) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIAppsService> appsService = do_GetService(APPS_SERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE_VOID(appsService);
|
||||
|
||||
nsCOMPtr<mozIApplication> app;
|
||||
appsService->GetAppByManifestURL(aManifestURL, getter_AddRefs(app));
|
||||
|
||||
if (!app) {
|
||||
return;
|
||||
}
|
||||
|
||||
app->GetName(aName);
|
||||
}
|
||||
|
||||
void
|
||||
ContentParent::TransformPreallocatedIntoApp(ContentParent* aOpener,
|
||||
const nsAString& aAppManifestURL)
|
||||
{
|
||||
MOZ_ASSERT(IsPreallocated());
|
||||
mMetamorphosed = true;
|
||||
mOpener = aOpener;
|
||||
mAppManifestURL = aAppManifestURL;
|
||||
TryGetNameFromManifestURL(aAppManifestURL, mAppName);
|
||||
}
|
||||
|
||||
void
|
||||
ContentParent::TransformPreallocatedIntoBrowser(ContentParent* aOpener)
|
||||
{
|
||||
// Reset mAppManifestURL, mIsForBrowser and mOSPrivileges for browser.
|
||||
// Reset mIsForBrowser and mOSPrivileges for browser.
|
||||
mMetamorphosed = true;
|
||||
mOpener = aOpener;
|
||||
mAppManifestURL.Truncate();
|
||||
mIsForBrowser = true;
|
||||
}
|
||||
|
||||
|
|
@ -1472,29 +1216,19 @@ ContentParent::ShutDownMessageManager()
|
|||
void
|
||||
ContentParent::MarkAsDead()
|
||||
{
|
||||
if (!mAppManifestURL.IsEmpty()) {
|
||||
if (sAppContentParents) {
|
||||
sAppContentParents->Remove(mAppManifestURL);
|
||||
if (!sAppContentParents->Count()) {
|
||||
delete sAppContentParents;
|
||||
sAppContentParents = nullptr;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (sNonAppContentParents) {
|
||||
sNonAppContentParents->RemoveElement(this);
|
||||
if (!sNonAppContentParents->Length()) {
|
||||
delete sNonAppContentParents;
|
||||
sNonAppContentParents = nullptr;
|
||||
}
|
||||
if (sBrowserContentParents) {
|
||||
sBrowserContentParents->RemoveElement(this);
|
||||
if (!sBrowserContentParents->Length()) {
|
||||
delete sBrowserContentParents;
|
||||
sBrowserContentParents = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (sLargeAllocationContentParents) {
|
||||
sLargeAllocationContentParents->RemoveElement(this);
|
||||
if (!sLargeAllocationContentParents->Length()) {
|
||||
delete sLargeAllocationContentParents;
|
||||
sLargeAllocationContentParents = nullptr;
|
||||
}
|
||||
if (sLargeAllocationContentParents) {
|
||||
sLargeAllocationContentParents->RemoveElement(this);
|
||||
if (!sLargeAllocationContentParents->Length()) {
|
||||
delete sLargeAllocationContentParents;
|
||||
sLargeAllocationContentParents = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1797,7 +1531,7 @@ ContentParent::NotifyTabDestroying(const TabId& aTabId,
|
|||
return;
|
||||
}
|
||||
|
||||
uint32_t numberOfParents = sNonAppContentParents ? sNonAppContentParents->Length() : 0;
|
||||
uint32_t numberOfParents = sBrowserContentParents ? sBrowserContentParents->Length() : 0;
|
||||
int32_t processesToKeepAlive = Preferences::GetInt("dom.ipc.keepProcessesAlive", 0);
|
||||
if (!cp->mLargeAllocationProcess && static_cast<int32_t>(numberOfParents) <= processesToKeepAlive) {
|
||||
return;
|
||||
|
|
@ -1854,7 +1588,7 @@ ContentParent::NotifyTabDestroyed(const TabId& aTabId,
|
|||
|
||||
// We might want to keep alive some content processes for testing, because of performance
|
||||
// reasons, but we don't want to alter behavior if the pref is not set.
|
||||
uint32_t numberOfParents = sNonAppContentParents ? sNonAppContentParents->Length() : 0;
|
||||
uint32_t numberOfParents = sBrowserContentParents ? sBrowserContentParents->Length() : 0;
|
||||
int32_t processesToKeepAlive = Preferences::GetInt("dom.ipc.keepProcessesAlive", 0);
|
||||
bool shouldKeepAliveAny = !mLargeAllocationProcess && processesToKeepAlive > 0;
|
||||
bool shouldKeepAliveThis = shouldKeepAliveAny && static_cast<int32_t>(numberOfParents) <= processesToKeepAlive;
|
||||
|
|
@ -1948,20 +1682,20 @@ ContentParent::LaunchSubprocess(ProcessPriority aInitialPriority /* = PROCESS_PR
|
|||
return true;
|
||||
}
|
||||
|
||||
ContentParent::ContentParent(mozIApplication* aApp,
|
||||
ContentParent* aOpener,
|
||||
ContentParent::ContentParent(ContentParent* aOpener,
|
||||
bool aIsForBrowser,
|
||||
bool aIsForPreallocated)
|
||||
: nsIContentParent()
|
||||
, mOpener(aOpener)
|
||||
, mIsForBrowser(aIsForBrowser)
|
||||
, mIsPreallocated(aIsForPreallocated)
|
||||
, mLargeAllocationProcess(false)
|
||||
{
|
||||
InitializeMembers(); // Perform common initialization.
|
||||
|
||||
// No more than one of !!aApp, aIsForBrowser, aIsForPreallocated should be
|
||||
// No more than one of aIsForBrowser, aIsForPreallocated should be
|
||||
// true.
|
||||
MOZ_ASSERT(!!aApp + aIsForBrowser + aIsForPreallocated <= 1);
|
||||
MOZ_ASSERT(aIsForBrowser + aIsForPreallocated <= 1);
|
||||
|
||||
mMetamorphosed = true;
|
||||
|
||||
|
|
@ -1971,13 +1705,6 @@ ContentParent::ContentParent(mozIApplication* aApp,
|
|||
}
|
||||
sContentParents->insertBack(this);
|
||||
|
||||
if (aApp) {
|
||||
aApp->GetManifestURL(mAppManifestURL);
|
||||
aApp->GetName(mAppName);
|
||||
} else if (aIsForPreallocated) {
|
||||
mAppManifestURL = MAGIC_PREALLOCATED_APP_MANIFEST_URL;
|
||||
}
|
||||
|
||||
// From this point on, NS_WARNING, NS_ASSERTION, etc. should print out the
|
||||
// PID along with the warning.
|
||||
nsDebugImpl::SetMultiprocessMode("Parent");
|
||||
|
|
@ -2004,19 +1731,10 @@ ContentParent::~ContentParent()
|
|||
|
||||
// We should be removed from all these lists in ActorDestroy.
|
||||
MOZ_ASSERT(!sPrivateContent || !sPrivateContent->Contains(this));
|
||||
if (mAppManifestURL.IsEmpty()) {
|
||||
MOZ_ASSERT((!sNonAppContentParents ||
|
||||
!sNonAppContentParents->Contains(this)) &&
|
||||
(!sLargeAllocationContentParents ||
|
||||
!sLargeAllocationContentParents->Contains(this)));
|
||||
} else {
|
||||
// In general, we expect sAppContentParents->Get(mAppManifestURL) to be
|
||||
// nullptr. But it could be that we created another ContentParent for
|
||||
// this app after we did this->ActorDestroy(), so the right check is
|
||||
// that sAppContentParents->Get(mAppManifestURL) != this.
|
||||
MOZ_ASSERT(!sAppContentParents ||
|
||||
sAppContentParents->Get(mAppManifestURL) != this);
|
||||
}
|
||||
MOZ_ASSERT((!sBrowserContentParents ||
|
||||
!sBrowserContentParents->Contains(this)) &&
|
||||
(!sLargeAllocationContentParents ||
|
||||
!sLargeAllocationContentParents->Contains(this)));
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -2152,12 +1870,6 @@ ContentParent::IsAlive() const
|
|||
return mIsAlive;
|
||||
}
|
||||
|
||||
bool
|
||||
ContentParent::IsForApp() const
|
||||
{
|
||||
return !mAppManifestURL.IsEmpty();
|
||||
}
|
||||
|
||||
int32_t
|
||||
ContentParent::Pid() const
|
||||
{
|
||||
|
|
@ -2585,10 +2297,9 @@ ContentParent::AllocPProcessHangMonitorParent(Transport* aTransport,
|
|||
|
||||
bool
|
||||
ContentParent::RecvGetProcessAttributes(ContentParentId* aCpId,
|
||||
bool* aIsForApp, bool* aIsForBrowser)
|
||||
bool* aIsForBrowser)
|
||||
{
|
||||
*aCpId = mChildID;
|
||||
*aIsForApp = IsForApp();
|
||||
*aIsForBrowser = mIsForBrowser;
|
||||
|
||||
return true;
|
||||
|
|
@ -2697,14 +2408,12 @@ ContentParent::AllocPBrowserParent(const TabId& aTabId,
|
|||
const IPCTabContext& aContext,
|
||||
const uint32_t& aChromeFlags,
|
||||
const ContentParentId& aCpId,
|
||||
const bool& aIsForApp,
|
||||
const bool& aIsForBrowser)
|
||||
{
|
||||
return nsIContentParent::AllocPBrowserParent(aTabId,
|
||||
aContext,
|
||||
aChromeFlags,
|
||||
aCpId,
|
||||
aIsForApp,
|
||||
aIsForBrowser);
|
||||
}
|
||||
|
||||
|
|
@ -2805,7 +2514,7 @@ ContentParent::KillHard(const char* aReason)
|
|||
bool
|
||||
ContentParent::IsPreallocated() const
|
||||
{
|
||||
return mAppManifestURL == MAGIC_PREALLOCATED_APP_MANIFEST_URL;
|
||||
return mIsPreallocated;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -2818,11 +2527,6 @@ ContentParent::FriendlyName(nsAString& aName, bool aAnonymize)
|
|||
aName.AssignLiteral("Browser");
|
||||
} else if (aAnonymize) {
|
||||
aName.AssignLiteral("<anonymized-name>");
|
||||
} else if (!mAppName.IsEmpty()) {
|
||||
aName = mAppName;
|
||||
} else if (!mAppManifestURL.IsEmpty()) {
|
||||
aName.AssignLiteral("Unknown app: ");
|
||||
aName.Append(mAppManifestURL);
|
||||
} else {
|
||||
aName.AssignLiteral("???");
|
||||
}
|
||||
|
|
@ -3659,7 +3363,6 @@ ContentParent::SendPBrowserConstructor(PBrowserParent* aActor,
|
|||
const IPCTabContext& aContext,
|
||||
const uint32_t& aChromeFlags,
|
||||
const ContentParentId& aCpId,
|
||||
const bool& aIsForApp,
|
||||
const bool& aIsForBrowser)
|
||||
{
|
||||
return PContentParent::SendPBrowserConstructor(aActor,
|
||||
|
|
@ -3667,7 +3370,6 @@ ContentParent::SendPBrowserConstructor(PBrowserParent* aActor,
|
|||
aContext,
|
||||
aChromeFlags,
|
||||
aCpId,
|
||||
aIsForApp,
|
||||
aIsForBrowser);
|
||||
}
|
||||
|
||||
|
|
@ -3785,12 +3487,9 @@ ContentParent::RecvRecordingDeviceEvents(const nsString& aRecordingStatus,
|
|||
// recording-device-ipc-events needs to gather more information from content process
|
||||
RefPtr<nsHashPropertyBag> props = new nsHashPropertyBag();
|
||||
props->SetPropertyAsUint64(NS_LITERAL_STRING("childID"), ChildID());
|
||||
props->SetPropertyAsBool(NS_LITERAL_STRING("isApp"), IsForApp());
|
||||
props->SetPropertyAsBool(NS_LITERAL_STRING("isAudio"), aIsAudio);
|
||||
props->SetPropertyAsBool(NS_LITERAL_STRING("isVideo"), aIsVideo);
|
||||
|
||||
nsString requestURL = IsForApp() ? AppManifestURL() : aPageURL;
|
||||
props->SetPropertyAsAString(NS_LITERAL_STRING("requestURL"), requestURL);
|
||||
props->SetPropertyAsAString(NS_LITERAL_STRING("requestURL"), aPageURL);
|
||||
|
||||
obs->NotifyObservers((nsIPropertyBag2*) props,
|
||||
"recording-device-ipc-events",
|
||||
|
|
@ -4245,7 +3944,7 @@ ContentParent::RecvCreateWindow(PBrowserParent* aThisTab,
|
|||
thisTabParent = TabParent::GetFrom(aThisTab);
|
||||
}
|
||||
|
||||
if (NS_WARN_IF(thisTabParent && thisTabParent->IsMozBrowserOrApp())) {
|
||||
if (NS_WARN_IF(thisTabParent && thisTabParent->IsMozBrowser())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue