From 785d3c9b2f059875b0e8a7e040426bb77afb1244 Mon Sep 17 00:00:00 2001 From: Justin Lebar Date: Fri, 9 Nov 2012 16:37:39 -0800 Subject: [PATCH] Bug 802366 - The main event: Let a browser process inherit its app's id. r=bz,cjones The main bug fixed here is that in half of our interfaces, we use "is browser frame/element" to mean "browser or app", and in the other half, we use it to mean "is browser not app". There's a related, functional bug also fixed here, which is that a browser process doesn't inherit its parent's app-id. This causes problems e.g. for IndexedDB: If a browser inside an app uses IndexedDB, the DB should have the app's app-id. I also modified Tab{Parent,Child} and nsFrameLoader to call "app" "ownOrContainingApp", to emphasize that we might have inherited the app from a parent process. I left nsIDocShell::appId alone, because changing that would have necessitated changing nsILoadGroup and therefore a /lot/ of users in Necko; it's also not clear it would have clarified anything in those cases. --- content/base/src/nsDocument.cpp | 2 +- content/base/src/nsFrameLoader.cpp | 158 ++++++---- content/base/src/nsFrameLoader.h | 22 +- .../base/src/nsInProcessTabChildGlobal.cpp | 13 +- content/base/src/nsInProcessTabChildGlobal.h | 7 +- content/events/src/nsEventStateManager.cpp | 10 +- .../content/src/nsGenericHTMLFrameElement.cpp | 23 +- docshell/base/nsDSURIContentListener.cpp | 2 +- docshell/base/nsDocShell.cpp | 161 ++++------ docshell/base/nsDocShell.h | 21 +- docshell/base/nsIDocShell.idl | 106 ++++--- dom/base/nsGlobalWindow.cpp | 17 +- dom/interfaces/html/nsIMozBrowserFrame.idl | 8 +- dom/ipc/AppProcessPermissions.cpp | 2 +- dom/ipc/ContentChild.cpp | 20 +- dom/ipc/ContentChild.h | 10 +- dom/ipc/ContentParent.cpp | 110 +++---- dom/ipc/ContentParent.h | 16 +- dom/ipc/Makefile.in | 2 + dom/ipc/PContent.ipdl | 85 ++++- dom/ipc/TabChild.cpp | 120 ++++--- dom/ipc/TabChild.h | 26 +- dom/ipc/TabContext.cpp | 292 ++++++++++++++++++ dom/ipc/TabContext.h | 209 +++++++++++++ dom/ipc/TabParent.cpp | 30 +- dom/ipc/TabParent.h | 13 +- .../windowwatcher/src/nsWindowWatcher.cpp | 8 +- gfx/thebes/gfxAndroidPlatform.cpp | 5 +- xpfe/appshell/src/nsContentTreeOwner.cpp | 2 +- 29 files changed, 1028 insertions(+), 472 deletions(-) create mode 100644 dom/ipc/TabContext.cpp create mode 100644 dom/ipc/TabContext.h diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index 04c762ddd4b9..e79fa6bbf26e 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -8359,7 +8359,7 @@ HasCrossProcessParent(nsIDocument* aDocument) if (!docShell) { return false; } - return docShell->GetIsContentBoundary(); + return docShell->GetIsBrowserOrApp(); } static bool diff --git a/content/base/src/nsFrameLoader.cpp b/content/base/src/nsFrameLoader.cpp index bbf60ef88520..998d0d213944 100644 --- a/content/base/src/nsFrameLoader.cpp +++ b/content/base/src/nsFrameLoader.cpp @@ -944,7 +944,7 @@ nsFrameLoader::ShowRemoteFrame(const nsIntSize& size) EnsureMessageManager(); nsCOMPtr os = services::GetObserverService(); - if (OwnerIsBrowserFrame() && os && !mRemoteBrowserInitialized) { + if (OwnerIsBrowserOrAppFrame() && os && !mRemoteBrowserInitialized) { os->NotifyObservers(NS_ISUPPORTS_CAST(nsIFrameLoader*, this), "remote-browser-frame-shown", NULL); mRemoteBrowserInitialized = true; @@ -1393,25 +1393,23 @@ nsFrameLoader::SetOwnerContent(Element* aContent) } bool -nsFrameLoader::OwnerIsBrowserFrame() +nsFrameLoader::OwnerIsBrowserOrAppFrame() { nsCOMPtr browserFrame = do_QueryInterface(mOwnerContent); - bool isBrowser = false; - if (browserFrame) { - browserFrame->GetReallyIsBrowser(&isBrowser); - } - return isBrowser; + return browserFrame ? browserFrame->GetReallyIsBrowserOrApp() : false; } bool nsFrameLoader::OwnerIsAppFrame() { nsCOMPtr browserFrame = do_QueryInterface(mOwnerContent); - bool isApp = false; - if (browserFrame) { - browserFrame->GetReallyIsApp(&isApp); - } - return isApp; + return browserFrame ? browserFrame->GetReallyIsApp() : false; +} + +bool +nsFrameLoader::OwnerIsBrowserFrame() +{ + return OwnerIsBrowserOrAppFrame() && !OwnerIsAppFrame(); } void @@ -1424,6 +1422,50 @@ nsFrameLoader::GetOwnerAppManifestURL(nsAString& aOut) } } +already_AddRefed +nsFrameLoader::GetOwnApp() +{ + nsAutoString manifest; + GetOwnerAppManifestURL(manifest); + if (manifest.IsEmpty()) { + return nullptr; + } + + nsCOMPtr appsService = do_GetService(APPS_SERVICE_CONTRACTID); + NS_ENSURE_TRUE(appsService, nullptr); + + nsCOMPtr domApp; + appsService->GetAppByManifestURL(manifest, getter_AddRefs(domApp)); + + nsCOMPtr app = do_QueryInterface(domApp); + MOZ_ASSERT_IF(domApp, app); + return app.forget(); +} + +already_AddRefed +nsFrameLoader::GetContainingApp() +{ + // See if our owner content's principal has an associated app. + uint32_t appId = mOwnerContent->NodePrincipal()->GetAppId(); + MOZ_ASSERT(appId != nsIScriptSecurityManager::UNKNOWN_APP_ID); + + if (appId == nsIScriptSecurityManager::NO_APP_ID || + appId == nsIScriptSecurityManager::UNKNOWN_APP_ID) { + return nullptr; + } + + nsCOMPtr appsService = do_GetService(APPS_SERVICE_CONTRACTID); + NS_ENSURE_TRUE(appsService, nullptr); + + nsCOMPtr domApp; + appsService->GetAppByLocalId(appId, getter_AddRefs(domApp)); + MOZ_ASSERT(domApp); + + nsCOMPtr app = do_QueryInterface(domApp); + MOZ_ASSERT_IF(domApp, app); + return app.forget(); +} + bool nsFrameLoader::ShouldUseRemoteProcess() { @@ -1440,7 +1482,7 @@ nsFrameLoader::ShouldUseRemoteProcess() // If we're an