Bug 776824 - Add isInBrowserElement to nsIPrincipal. r=mrbkap sr=sicking

This commit is contained in:
Mounir Lamouri 2012-07-31 17:47:20 +02:00
parent 0e427a3628
commit fcaf100669
6 changed files with 42 additions and 1 deletions

View File

@ -21,7 +21,7 @@ interface nsIContentSecurityPolicy;
[ptr] native JSPrincipals(JSPrincipals);
[ptr] native PrincipalArray(nsTArray<nsCOMPtr<nsIPrincipal> >);
[scriptable, uuid(fbb93cc7-9a94-4743-8e89-9e6939cac083)]
[scriptable, uuid(8a74b011-667d-4cfa-b2a2-b27582ba5f38)]
interface nsIPrincipal : nsISerializable
{
/**
@ -245,6 +245,11 @@ interface nsIPrincipal : nsISerializable
* Returns nsIAppsService::NO_APP_ID if this principal isn't part of an app.
*/
readonly attribute unsigned long appId;
/**
* Returns true iif the principal is inside a browser element.
*/
readonly attribute boolean isInBrowserElement;
};
/**

View File

@ -127,6 +127,7 @@ public:
NS_IMETHOD GetExtendedOrigin(nsACString& aExtendedOrigin);
NS_IMETHOD GetAppStatus(PRUint16* aAppStatus);
NS_IMETHOD GetAppId(PRUint32* aAppStatus);
NS_IMETHOD GetIsInBrowserElement(bool* aIsInBrowserElement);
#ifdef DEBUG
virtual void dumpImpl();
#endif
@ -205,6 +206,7 @@ public:
NS_IMETHOD GetExtendedOrigin(nsACString& aExtendedOrigin);
NS_IMETHOD GetAppStatus(PRUint16* aAppStatus);
NS_IMETHOD GetAppId(PRUint32* aAppStatus);
NS_IMETHOD GetIsInBrowserElement(bool* aIsInBrowserElement);
#ifdef DEBUG
virtual void dumpImpl();
#endif

View File

@ -335,6 +335,13 @@ nsNullPrincipal::GetAppId(PRUint32* aAppId)
return NS_OK;
}
NS_IMETHODIMP
nsNullPrincipal::GetIsInBrowserElement(bool* aIsInBrowserElement)
{
*aIsInBrowserElement = false;
return NS_OK;
}
/**
* nsISerializable implementation
*/

View File

@ -1093,6 +1093,13 @@ nsPrincipal::GetAppId(PRUint32* aAppId)
return NS_OK;
}
NS_IMETHODIMP
nsPrincipal::GetIsInBrowserElement(bool* aIsInBrowserElement)
{
*aIsInBrowserElement = mInMozBrowser;
return NS_OK;
}
NS_IMETHODIMP
nsPrincipal::Read(nsIObjectInputStream* aStream)
{
@ -1476,6 +1483,12 @@ nsExpandedPrincipal::GetAppId(PRUint32* aAppId)
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP
nsExpandedPrincipal::GetIsInBrowserElement(bool* aIsInBrowserElement)
{
return NS_ERROR_NOT_AVAILABLE;
}
void
nsExpandedPrincipal::GetScriptLocation(nsACString& aStr)
{

View File

@ -258,6 +258,13 @@ nsSystemPrincipal::GetAppId(PRUint32* aAppId)
return NS_OK;
}
NS_IMETHODIMP
nsSystemPrincipal::GetIsInBrowserElement(bool* aIsInBrowserElement)
{
*aIsInBrowserElement = false;
return NS_OK;
}
//////////////////////////////////////////
// Methods implementing nsISerializable //
//////////////////////////////////////////

View File

@ -251,6 +251,7 @@ var gData = [
child: {
src: "http://example.org/chrome/",
isapp: false,
inBrowser: true,
},
test: [ "child-has-same-eo" ],
},
@ -310,6 +311,9 @@ function checkIFrame(aFrame, data) {
"extendedOrigin should be the same as the last inserted one");
}
is(principal.isInBrowserElement, !!data.browser,
"check principal.isInBrowserElement");
if (data.child) {
let childPrincipal = aFrame.contentWindow.frames[0].document.nodePrincipal;
@ -318,6 +322,9 @@ function checkIFrame(aFrame, data) {
"child should be an installed app");
}
is(childPrincipal.isInBrowserElement, !!data.child.browser || !!data.child.inBrowser,
"check childPrincipal.isInBrowserElement");
if (data.test.indexOf("child-has-same-eo") != -1) {
is(childPrincipal.extendedOrigin, principal.extendedOrigin,
"child should have the same extendedOrigin as parent");