From b92335b98cd1978e3850df461cae17677c3606f8 Mon Sep 17 00:00:00 2001 From: Mounir Lamouri Date: Thu, 19 Jul 2012 10:32:49 -0700 Subject: [PATCH] Bug 770831 - Make nsIDocShell carry the app id. r=jlebar sr=sicking --- content/base/src/nsFrameLoader.cpp | 19 +++++++++++++++ docshell/base/nsDocShell.cpp | 39 ++++++++++++++++++++++++++++++ docshell/base/nsDocShell.h | 2 ++ docshell/base/nsIDocShell.idl | 21 +++++++++++++++- 4 files changed, 80 insertions(+), 1 deletion(-) diff --git a/content/base/src/nsFrameLoader.cpp b/content/base/src/nsFrameLoader.cpp index d5d16fc077f7..e38aa243ab50 100644 --- a/content/base/src/nsFrameLoader.cpp +++ b/content/base/src/nsFrameLoader.cpp @@ -80,6 +80,7 @@ #include "mozilla/unused.h" #include "mozilla/dom/Element.h" #include "mozilla/layout/RenderFrameParent.h" +#include "nsIAppsService.h" #include "jsapi.h" @@ -1476,6 +1477,24 @@ nsFrameLoader::MaybeCreateDocShell() mDocShell = do_CreateInstance("@mozilla.org/docshell;1"); NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE); + if (OwnerIsBrowserFrame() && + mOwnerContent->HasAttr(kNameSpaceID_None, nsGkAtoms::mozapp)) { + nsCOMPtr appsService = + do_GetService(APPS_SERVICE_CONTRACTID); + if (!appsService) { + NS_ERROR("Apps Service is not available!"); + return NS_ERROR_FAILURE; + } + + nsAutoString manifest; + mOwnerContent->GetAttr(kNameSpaceID_None, nsGkAtoms::mozapp, manifest); + + PRUint32 appId; + appsService->GetAppLocalIdByManifestURL(manifest, &appId); + + mDocShell->SetAppId(appId); + } + if (!mNetworkCreated) { nsCOMPtr history = do_QueryInterface(mDocShell); if (history) { diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 93610829e043..d31fa7877ce4 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -763,6 +763,7 @@ nsDocShell::nsDocShell(): #ifdef DEBUG mInEnsureScriptEnv(false), #endif + mAppId(nsIScriptSecurityManager::NO_APP_ID), mParentCharsetSource(0) { mHistoryID = ++gDocshellIDCounter; @@ -12064,6 +12065,10 @@ nsDocShell::GetInheritedFrameType() nsDocShell::FrameType nsDocShell::GetFrameType() { + if (mAppId != nsIScriptSecurityManager::NO_APP_ID) { + return eFrameTypeApp; + } + return mIsBrowserFrame ? eFrameTypeBrowser : eFrameTypeRegular; } @@ -12127,3 +12132,37 @@ nsDocShell::GetIsBelowContentBoundary(bool* aIsInContentBoundary) return NS_OK; } + +NS_IMETHODIMP +nsDocShell::SetAppId(PRUint32 aAppId) +{ + MOZ_ASSERT(mAppId == nsIScriptSecurityManager::NO_APP_ID); + MOZ_ASSERT(aAppId != nsIScriptSecurityManager::UNKNOWN_APP_ID); + + mAppId = aAppId; + return NS_OK; +} + +NS_IMETHODIMP +nsDocShell::GetAppId(PRUint32* aAppId) +{ + if (mAppId != nsIScriptSecurityManager::NO_APP_ID) { + MOZ_ASSERT(GetFrameType() == eFrameTypeApp); + + *aAppId = mAppId; + return NS_OK; + } + + MOZ_ASSERT(GetFrameType() != eFrameTypeApp); + + nsCOMPtr parentAsItem; + GetSameTypeParent(getter_AddRefs(parentAsItem)); + + nsCOMPtr parent = do_QueryInterface(parentAsItem); + if (!parent) { + *aAppId = nsIScriptSecurityManager::NO_APP_ID; + return NS_OK; + } + + return parent->GetAppId(aAppId); +} diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index 2c9136d5da24..574f08577f6e 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -824,6 +824,8 @@ protected: nsRefPtr mTiming; + PRUint32 mAppId; + private: nsCOMPtr mForcedCharset; nsCOMPtr mParentCharset; diff --git a/docshell/base/nsIDocShell.idl b/docshell/base/nsIDocShell.idl index 1587d97b38c5..33f5a08ff407 100644 --- a/docshell/base/nsIDocShell.idl +++ b/docshell/base/nsIDocShell.idl @@ -39,7 +39,7 @@ interface nsIWebBrowserPrint; interface nsIVariant; interface nsIPrivacyTransitionObserver; -[scriptable, builtinclass, uuid(57889367-590b-4ea2-a345-5211253babf5)] +[scriptable, builtinclass, uuid(c98f0f21-fe96-4f06-9978-0a9422a789fa)] interface nsIDocShell : nsISupports { /** @@ -630,4 +630,23 @@ interface nsIDocShell : nsISupports * in his parent hierarchy. */ readonly attribute boolean isBelowContentBoundary; + + /** + * Set the app id this docshell is associated with. The id has to be a valid + * app id. If the docshell isn't associated with any app, the value should be + * nsIScriptSecurityManager::NO_APP_ID. However, this is the default value if + * nothing is et. + * + * This method is [noscript] to reduce the scope. It should be used at very + * specific moments. + * + * Calling setAppId() will mark the frame as an app frame. + */ + [noscript] void setAppId(in unsigned long appId); + + /** + * Returns the app id of the app the docshell is in. Returns + * nsIScriptSecurityManager::NO_APP_ID if the docshell is not in an app. + */ + readonly attribute unsigned long appId; };