From c73e96a53dcf2a338116c026412b0b7894853a0a Mon Sep 17 00:00:00 2001 From: Tanvi Vyas Date: Wed, 13 Apr 2016 16:30:22 -0700 Subject: [PATCH] Bug 1105556 - Call Create(originAttributes) when loadinfo->loadingPrincipal is null, instead of CreatePrincipalWithInheritedAttributes(). r=sicking --- caps/nsScriptSecurityManager.cpp | 16 +++++++++++++--- docshell/base/nsDocShell.cpp | 17 ++++++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/caps/nsScriptSecurityManager.cpp b/caps/nsScriptSecurityManager.cpp index dcb26b21a4cf..3e3d467c584d 100644 --- a/caps/nsScriptSecurityManager.cpp +++ b/caps/nsScriptSecurityManager.cpp @@ -344,9 +344,19 @@ nsScriptSecurityManager::GetChannelResultPrincipal(nsIChannel* aChannel, aChannel->GetLoadInfo(getter_AddRefs(loadInfo)); if (loadInfo) { if (loadInfo->GetLoadingSandboxed()) { - RefPtr prin = - nsNullPrincipal::CreateWithInheritedAttributes(loadInfo->LoadingPrincipal()); - NS_ENSURE_TRUE(prin, NS_ERROR_FAILURE); + RefPtr prin; + if (loadInfo->LoadingPrincipal()) { + prin = + nsNullPrincipal::CreateWithInheritedAttributes(loadInfo->LoadingPrincipal()); + NS_ENSURE_TRUE(prin, NS_ERROR_FAILURE); + } else { + NeckoOriginAttributes nAttrs; + loadInfo->GetOriginAttributes(&nAttrs); + PrincipalOriginAttributes pAttrs; + pAttrs.InheritFromNecko(nAttrs); + prin = nsNullPrincipal::Create(pAttrs); + NS_ENSURE_TRUE(prin, NS_ERROR_FAILURE); + } prin.forget(aPrincipal); return NS_OK; } diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index dd5c68fdd3a3..8c39b54ed409 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -12048,9 +12048,20 @@ nsDocShell::AddToSessionHistory(nsIURI* aURI, nsIChannel* aChannel, if (loadInfo) { // For now keep storing just the principal in the SHEntry. if (loadInfo->GetLoadingSandboxed()) { - owner = nsNullPrincipal::CreateWithInheritedAttributes( - loadInfo->LoadingPrincipal()); - NS_ENSURE_TRUE(owner, NS_ERROR_FAILURE); + if (loadInfo->LoadingPrincipal()) { + owner = nsNullPrincipal::CreateWithInheritedAttributes( + loadInfo->LoadingPrincipal()); + NS_ENSURE_TRUE(owner, NS_ERROR_FAILURE); + } else { + // get the OriginAttributes + NeckoOriginAttributes nAttrs; + loadInfo->GetOriginAttributes(&nAttrs); + PrincipalOriginAttributes pAttrs; + pAttrs.InheritFromNecko(nAttrs); + + owner = nsNullPrincipal::Create(pAttrs); + NS_ENSURE_TRUE(owner, NS_ERROR_FAILURE); + } } else if (loadInfo->GetForceInheritPrincipal()) { owner = loadInfo->TriggeringPrincipal(); }