Added UpdatePrincipal function to support multiple signed scripts in a document. r=norris

This commit is contained in:
norris%netscape.com 2000-03-21 04:09:58 +00:00
parent d655019842
commit 0ac075877f
6 changed files with 80 additions and 0 deletions

View File

@ -121,6 +121,12 @@ public:
*/
NS_IMETHOD GetPrincipal(nsIPrincipal **aPrincipal) = 0;
/**
* Update principal responsible for this document to the intersection
* of its previous value and aPrincipal.
*/
NS_IMETHOD UpdatePrincipal(nsIPrincipal **aPrincipal) = 0;
/**
* Return the LoadGroup for the document. May return null.
*/

View File

@ -84,6 +84,7 @@
#include "nsLayoutUtils.h"
#include "nsIScriptSecurityManager.h"
#include "nsIAggregatePrincipal.h"
static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID);
static NS_DEFINE_IID(kIDOMCommentIID, NS_IDOMCOMMENT_IID);
@ -894,6 +895,33 @@ nsDocument::GetPrincipal(nsIPrincipal **aPrincipal)
return NS_OK;
}
NS_IMETHODIMP
nsDocument::UpdatePrincipal(nsIPrincipal **aNewPrincipal)
{
nsresult rv;
if (!mPrincipal) {
NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager,
NS_SCRIPTSECURITYMANAGER_PROGID, &rv);
if (NS_FAILED(rv))
return rv;
if (NS_FAILED(rv = securityManager->GetCodebasePrincipal(mDocumentURL,
&mPrincipal)))
return rv;
}
nsCOMPtr<nsIAggregatePrincipal> agg =
do_QueryInterface(mPrincipal, &rv);
if (NS_SUCCEEDED(rv))
{
rv = agg->Intersect(*aNewPrincipal);
if (NS_FAILED(rv)) return rv;
}
*aNewPrincipal = mPrincipal;
NS_ADDREF(*aNewPrincipal);
return NS_OK;
}
NS_IMETHODIMP
nsDocument::GetContentType(nsString& aContentType) const
{

View File

@ -143,6 +143,12 @@ public:
*/
NS_IMETHOD GetPrincipal(nsIPrincipal **aPrincipal);
/**
* Update principal responsible for this document to the intersection
* of its previous value and aPrincipal, and return its new value.
*/
NS_IMETHOD UpdatePrincipal(nsIPrincipal **aPrincipal);
/**
* Return the content (mime) type of this document.
*/

View File

@ -121,6 +121,12 @@ public:
*/
NS_IMETHOD GetPrincipal(nsIPrincipal **aPrincipal) = 0;
/**
* Update principal responsible for this document to the intersection
* of its previous value and aPrincipal.
*/
NS_IMETHOD UpdatePrincipal(nsIPrincipal **aPrincipal) = 0;
/**
* Return the LoadGroup for the document. May return null.
*/

View File

@ -84,6 +84,7 @@
#include "nsLayoutUtils.h"
#include "nsIScriptSecurityManager.h"
#include "nsIAggregatePrincipal.h"
static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID);
static NS_DEFINE_IID(kIDOMCommentIID, NS_IDOMCOMMENT_IID);
@ -894,6 +895,33 @@ nsDocument::GetPrincipal(nsIPrincipal **aPrincipal)
return NS_OK;
}
NS_IMETHODIMP
nsDocument::UpdatePrincipal(nsIPrincipal **aNewPrincipal)
{
nsresult rv;
if (!mPrincipal) {
NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager,
NS_SCRIPTSECURITYMANAGER_PROGID, &rv);
if (NS_FAILED(rv))
return rv;
if (NS_FAILED(rv = securityManager->GetCodebasePrincipal(mDocumentURL,
&mPrincipal)))
return rv;
}
nsCOMPtr<nsIAggregatePrincipal> agg =
do_QueryInterface(mPrincipal, &rv);
if (NS_SUCCEEDED(rv))
{
rv = agg->Intersect(*aNewPrincipal);
if (NS_FAILED(rv)) return rv;
}
*aNewPrincipal = mPrincipal;
NS_ADDREF(*aNewPrincipal);
return NS_OK;
}
NS_IMETHODIMP
nsDocument::GetContentType(nsString& aContentType) const
{

View File

@ -143,6 +143,12 @@ public:
*/
NS_IMETHOD GetPrincipal(nsIPrincipal **aPrincipal);
/**
* Update principal responsible for this document to the intersection
* of its previous value and aPrincipal, and return its new value.
*/
NS_IMETHOD UpdatePrincipal(nsIPrincipal **aPrincipal);
/**
* Return the content (mime) type of this document.
*/