Bug 1016875 - Part10: GetPrincipal for imports. r=mrbkap

This commit is contained in:
Gabor Krizsanits 2014-07-17 10:51:11 +02:00
parent 523e316e7f
commit 52ba548df3
2 changed files with 15 additions and 7 deletions

View File

@ -190,14 +190,23 @@ void ImportLoader::ReleaseResources()
mImportParent = nullptr;
}
nsIPrincipal*
ImportLoader::Principal()
{
MOZ_ASSERT(mImportParent);
nsCOMPtr<nsIDocument> master = mImportParent->MasterDocument();
nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(master);
MOZ_ASSERT(sop);
return sop->GetPrincipal();
}
void
ImportLoader::Open()
{
AutoError ae(this, false);
// Imports should obey to the master documents CSP.
nsCOMPtr<nsIDocument> master = mImportParent->MasterDocument();
nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(master);
nsCOMPtr<nsIPrincipal> principal = sop->GetPrincipal();
nsIPrincipal* principal = Principal();
int16_t shouldLoad = nsIContentPolicy::ACCEPT;
nsresult rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_SCRIPT,
@ -324,11 +333,7 @@ NS_IMETHODIMP
ImportLoader::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
{
AutoError ae(this);
nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(mImportParent);
nsCOMPtr<nsIPrincipal> principal = sop->GetPrincipal();
if (!sop) {
return NS_ERROR_DOM_ABORT_ERR;
}
nsIPrincipal* principal = Principal();
nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
if (!channel) {

View File

@ -49,6 +49,7 @@
class nsIDocument;
class nsIChannel;
class nsIPrincipal;
class nsINode;
class AutoError;
@ -115,6 +116,8 @@ private:
void BlockScripts();
void UnblockScripts();
nsIPrincipal* Principal();
nsCOMPtr<nsIDocument> mDocument;
nsCOMPtr<nsIURI> mURI;
nsCOMPtr<nsIStreamListener> mParserStreamListener;