From 989babd09065477a36f4567200d17e574f08a034 Mon Sep 17 00:00:00 2001 From: Christoph Kerschbaumer Date: Fri, 14 Nov 2014 08:55:59 -0800 Subject: [PATCH] Bug 1083422 - Add triggering Principal to nsILoadInfo - loadinfo changes (r=bz) --- docshell/base/LoadInfo.cpp | 29 +++++++++++++++++++++++------ docshell/base/LoadInfo.h | 8 +++++--- docshell/base/nsILoadInfo.idl | 21 ++++++++++++++++++++- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/docshell/base/LoadInfo.cpp b/docshell/base/LoadInfo.cpp index 841dc895bb5..79ac48e51aa 100644 --- a/docshell/base/LoadInfo.cpp +++ b/docshell/base/LoadInfo.cpp @@ -14,18 +14,22 @@ namespace mozilla { -LoadInfo::LoadInfo(nsIPrincipal* aPrincipal, +LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal, + nsIPrincipal* aTriggeringPrincipal, nsINode* aLoadingContext, nsSecurityFlags aSecurityFlags, nsContentPolicyType aContentPolicyType, nsIURI* aBaseURI) - : mPrincipal(aPrincipal) + : mLoadingPrincipal(aLoadingPrincipal) + , mTriggeringPrincipal(aTriggeringPrincipal ? + aTriggeringPrincipal : aLoadingPrincipal) , mLoadingContext(do_GetWeakReference(aLoadingContext)) , mSecurityFlags(aSecurityFlags) , mContentPolicyType(aContentPolicyType) , mBaseURI(aBaseURI) { - MOZ_ASSERT(aPrincipal); + MOZ_ASSERT(aLoadingPrincipal); + MOZ_ASSERT(mTriggeringPrincipal); // if the load is sandboxed, we can not also inherit the principal if (mSecurityFlags & nsILoadInfo::SEC_SANDBOXED) { mSecurityFlags ^= nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL; @@ -39,16 +43,29 @@ LoadInfo::~LoadInfo() NS_IMPL_ISUPPORTS(LoadInfo, nsILoadInfo) NS_IMETHODIMP -LoadInfo::GetLoadingPrincipal(nsIPrincipal** aPrincipal) +LoadInfo::GetLoadingPrincipal(nsIPrincipal** aLoadingPrincipal) { - NS_ADDREF(*aPrincipal = mPrincipal); + NS_ADDREF(*aLoadingPrincipal = mLoadingPrincipal); return NS_OK; } nsIPrincipal* LoadInfo::LoadingPrincipal() { - return mPrincipal; + return mLoadingPrincipal; +} + +NS_IMETHODIMP +LoadInfo::GetTriggeringPrincipal(nsIPrincipal** aTriggeringPrincipal) +{ + NS_ADDREF(*aTriggeringPrincipal = mTriggeringPrincipal); + return NS_OK; +} + +nsIPrincipal* +LoadInfo::TriggeringPrincipal() +{ + return mTriggeringPrincipal; } NS_IMETHODIMP diff --git a/docshell/base/LoadInfo.h b/docshell/base/LoadInfo.h index 7daf725241a..974cc1fd35d 100644 --- a/docshell/base/LoadInfo.h +++ b/docshell/base/LoadInfo.h @@ -26,8 +26,9 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSILOADINFO - // aPrincipal MUST NOT BE NULL. - LoadInfo(nsIPrincipal* aPrincipal, + // aLoadingPrincipal MUST NOT BE NULL. + LoadInfo(nsIPrincipal* aLoadingPrincipal, + nsIPrincipal* aTriggeringPrincipal, nsINode* aLoadingContext, nsSecurityFlags aSecurityFlags, nsContentPolicyType aContentPolicyType, @@ -36,7 +37,8 @@ public: private: ~LoadInfo(); - nsCOMPtr mPrincipal; + nsCOMPtr mLoadingPrincipal; + nsCOMPtr mTriggeringPrincipal; nsWeakPtr mLoadingContext; nsSecurityFlags mSecurityFlags; nsContentPolicyType mContentPolicyType; diff --git a/docshell/base/nsILoadInfo.idl b/docshell/base/nsILoadInfo.idl index da0808351cf..4ca48c2b195 100644 --- a/docshell/base/nsILoadInfo.idl +++ b/docshell/base/nsILoadInfo.idl @@ -17,7 +17,7 @@ typedef unsigned long nsSecurityFlags; /** * An nsILoadOwner represents per-load information about who started the load. */ -[scriptable, builtinclass, uuid(b22b8ee7-047a-4351-a749-13c6d39f6b17)] +[scriptable, builtinclass, uuid(da363267-236d-49bf-83a2-33da8d892728)] interface nsILoadInfo : nsISupports { /** @@ -72,6 +72,25 @@ interface nsILoadInfo : nsISupports [noscript, notxpcom, nostdcall, binaryname(LoadingPrincipal)] nsIPrincipal binaryLoadingPrincipal(); + /** + * The triggeringPrincipal is the principal that triggerd the load. + * Most likely the triggeringPrincipal and the loadingPrincipal are the same, + * in which case triggeringPrincipal returns the loadingPrincipal. + * In some cases the loadingPrincipal and the triggeringPrincipal are different + * however, e.g. a stylesheet may import a subresource. In that case the + * stylesheet principal is the triggeringPrincipal and the document that loads + * the stylesheet provides a loadingContext and hence the loadingPrincipal. + * + * If triggeringPrincipal and loadingPrincipal are the same, then + * triggeringPrincipal returns loadingPrincipal. + */ + readonly attribute nsIPrincipal triggeringPrincipal; + + /** + * A C++-friendly version of triggeringPrincipal. + */ + [noscript, notxpcom, nostdcall, binaryname(TriggeringPrincipal)] + nsIPrincipal binaryTriggeringPrincipal(); /** * The loadingDocument of the channel.