Changed UpdatePrincipal to AddPrincipal; it takes an input parameter now instead of an inout parameter; this is clearer. r=norris

This commit is contained in:
mstoltz%netscape.com 2000-03-23 04:53:16 +00:00
Родитель e5f86d1226
Коммит 319b923a3a
12 изменённых файлов: 58 добавлений и 84 удалений

Просмотреть файл

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

Просмотреть файл

@ -927,35 +927,30 @@ nsDocument::GetPrincipal(nsIPrincipal **aPrincipal)
&mPrincipal)))
return rv;
}
*aPrincipal = mPrincipal;
NS_ADDREF(*aPrincipal);
if(aPrincipal)
{
*aPrincipal = mPrincipal;
NS_ADDREF(*aPrincipal);
}
return NS_OK;
}
NS_IMETHODIMP
nsDocument::UpdatePrincipal(nsIPrincipal **aNewPrincipal)
nsDocument::AddPrincipal(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;
}
if (!mPrincipal)
GetPrincipal(nsnull);
nsCOMPtr<nsIAggregatePrincipal> agg =
do_QueryInterface(mPrincipal, &rv);
if (NS_SUCCEEDED(rv))
{
rv = agg->Intersect(*aNewPrincipal);
rv = agg->Intersect(aNewPrincipal);
if (NS_FAILED(rv)) return rv;
}
*aNewPrincipal = mPrincipal;
NS_ADDREF(*aNewPrincipal);
return NS_OK;
}

Просмотреть файл

@ -147,7 +147,7 @@ public:
* 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);
NS_IMETHOD AddPrincipal(nsIPrincipal *aPrincipal);
/**
* Return the content (mime) type of this document.

Просмотреть файл

@ -371,8 +371,7 @@ public:
nsresult EvaluateScript(nsString& aScript,
nsIURI *aScriptURI,
PRInt32 aLineNo,
const char* aVersion,
nsIPrincipal* aPrincipal);
const char* aVersion);
const char* mScriptLanguageVersion;
void UpdateAllContexts();
@ -4121,11 +4120,9 @@ nsresult
HTMLContentSink::EvaluateScript(nsString& aScript,
nsIURI *aScriptURI,
PRInt32 aLineNo,
const char* aVersion,
nsIPrincipal* aPrincipal)
const char* aVersion)
{
nsresult rv = NS_OK;
NS_ASSERTION(aPrincipal, "principal required for document");
if (aScript.Length() > 0) {
nsCOMPtr<nsIScriptGlobalObject> globalObject;
@ -4136,6 +4133,10 @@ HTMLContentSink::EvaluateScript(nsString& aScript,
NS_ENSURE_SUCCESS(globalObject->GetContext(getter_AddRefs(context)),
NS_ERROR_FAILURE);
nsCOMPtr<nsIPrincipal> principal;
mDocument->GetPrincipal(getter_AddRefs(principal));
NS_ASSERTION(principal, "principal required for document");
nsAutoString ret;
char* url = nsnull;
@ -4144,7 +4145,7 @@ HTMLContentSink::EvaluateScript(nsString& aScript,
}
PRBool isUndefined;
context->EvaluateString(aScript, nsnull, aPrincipal, url,
context->EvaluateString(aScript, nsnull, principal, url,
aLineNo, aVersion, ret, &isUndefined);
if (url) {
@ -4168,24 +4169,18 @@ HTMLContentSink::OnStreamComplete(nsIStreamLoader* aLoader,
if (NS_OK == aStatus) {
PRBool bodyPresent = PreEvaluateScript();
nsISupports* owner;
aLoader->GetOwner(&owner);
nsIPrincipal* prin = nsnull;
//-- Merge the principal of the script file with that of the document
nsCOMPtr<nsISupports> owner;
aLoader->GetOwner(getter_AddRefs(owner));
if (owner)
{
rv = owner->QueryInterface(NS_GET_IID(nsIPrincipal),
(void**)&prin);
NS_RELEASE(owner);
nsCOMPtr<nsIPrincipal> prin = do_QueryInterface(owner, &rv);
if (NS_FAILED(rv)) return rv;
rv = mDocument->AddPrincipal(prin);
if (NS_FAILED(rv)) return rv;
}
rv = mDocument->UpdatePrincipal(&prin);
if (NS_FAILED(rv)) {
NS_IF_RELEASE(prin);
return rv;
}
rv = EvaluateScript(aData, mScriptURI, 1, mScriptLanguageVersion, prin);
NS_IF_RELEASE(prin);
rv = EvaluateScript(aData, mScriptURI, 1, mScriptLanguageVersion);
if (NS_FAILED(rv)) return rv;
PostEvaluateScript(bodyPresent);
@ -4350,15 +4345,12 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode)
}
}
else {
nsCOMPtr<nsIPrincipal> prin;
mDocument->GetPrincipal(getter_AddRefs(prin));
PRBool bodyPresent = PreEvaluateScript();
PRUint32 lineNo = (PRUint32)aNode.GetSourceLineNumber();
nsIURI *docURI = mDocument->GetDocumentURL();
EvaluateScript(script, docURI, lineNo, jsVersionString, prin);
EvaluateScript(script, docURI, lineNo, jsVersionString);
NS_IF_RELEASE(docURI);
PostEvaluateScript(bodyPresent);

Просмотреть файл

@ -779,7 +779,7 @@ nsXULDocument::GetPrincipal(nsIPrincipal **aPrincipal)
}
NS_IMETHODIMP
nsXULDocument::UpdatePrincipal(nsIPrincipal **aPrincipal)
nsXULDocument::AddPrincipal(nsIPrincipal *aPrincipal)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

Просмотреть файл

@ -120,7 +120,7 @@ public:
NS_IMETHOD GetPrincipal(nsIPrincipal **aPrincipal);
NS_IMETHOD UpdatePrincipal(nsIPrincipal **aPrincipal);
NS_IMETHOD AddPrincipal(nsIPrincipal *aPrincipal);
NS_IMETHOD GetDocumentLoadGroup(nsILoadGroup **aGroup) const;

Просмотреть файл

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

Просмотреть файл

@ -927,35 +927,30 @@ nsDocument::GetPrincipal(nsIPrincipal **aPrincipal)
&mPrincipal)))
return rv;
}
*aPrincipal = mPrincipal;
NS_ADDREF(*aPrincipal);
if(aPrincipal)
{
*aPrincipal = mPrincipal;
NS_ADDREF(*aPrincipal);
}
return NS_OK;
}
NS_IMETHODIMP
nsDocument::UpdatePrincipal(nsIPrincipal **aNewPrincipal)
nsDocument::AddPrincipal(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;
}
if (!mPrincipal)
GetPrincipal(nsnull);
nsCOMPtr<nsIAggregatePrincipal> agg =
do_QueryInterface(mPrincipal, &rv);
if (NS_SUCCEEDED(rv))
{
rv = agg->Intersect(*aNewPrincipal);
rv = agg->Intersect(aNewPrincipal);
if (NS_FAILED(rv)) return rv;
}
*aNewPrincipal = mPrincipal;
NS_ADDREF(*aNewPrincipal);
return NS_OK;
}

Просмотреть файл

@ -147,7 +147,7 @@ public:
* 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);
NS_IMETHOD AddPrincipal(nsIPrincipal *aPrincipal);
/**
* Return the content (mime) type of this document.

Просмотреть файл

@ -371,8 +371,7 @@ public:
nsresult EvaluateScript(nsString& aScript,
nsIURI *aScriptURI,
PRInt32 aLineNo,
const char* aVersion,
nsIPrincipal* aPrincipal);
const char* aVersion);
const char* mScriptLanguageVersion;
void UpdateAllContexts();
@ -4121,11 +4120,9 @@ nsresult
HTMLContentSink::EvaluateScript(nsString& aScript,
nsIURI *aScriptURI,
PRInt32 aLineNo,
const char* aVersion,
nsIPrincipal* aPrincipal)
const char* aVersion)
{
nsresult rv = NS_OK;
NS_ASSERTION(aPrincipal, "principal required for document");
if (aScript.Length() > 0) {
nsCOMPtr<nsIScriptGlobalObject> globalObject;
@ -4136,6 +4133,10 @@ HTMLContentSink::EvaluateScript(nsString& aScript,
NS_ENSURE_SUCCESS(globalObject->GetContext(getter_AddRefs(context)),
NS_ERROR_FAILURE);
nsCOMPtr<nsIPrincipal> principal;
mDocument->GetPrincipal(getter_AddRefs(principal));
NS_ASSERTION(principal, "principal required for document");
nsAutoString ret;
char* url = nsnull;
@ -4144,7 +4145,7 @@ HTMLContentSink::EvaluateScript(nsString& aScript,
}
PRBool isUndefined;
context->EvaluateString(aScript, nsnull, aPrincipal, url,
context->EvaluateString(aScript, nsnull, principal, url,
aLineNo, aVersion, ret, &isUndefined);
if (url) {
@ -4168,24 +4169,18 @@ HTMLContentSink::OnStreamComplete(nsIStreamLoader* aLoader,
if (NS_OK == aStatus) {
PRBool bodyPresent = PreEvaluateScript();
nsISupports* owner;
aLoader->GetOwner(&owner);
nsIPrincipal* prin = nsnull;
//-- Merge the principal of the script file with that of the document
nsCOMPtr<nsISupports> owner;
aLoader->GetOwner(getter_AddRefs(owner));
if (owner)
{
rv = owner->QueryInterface(NS_GET_IID(nsIPrincipal),
(void**)&prin);
NS_RELEASE(owner);
nsCOMPtr<nsIPrincipal> prin = do_QueryInterface(owner, &rv);
if (NS_FAILED(rv)) return rv;
rv = mDocument->AddPrincipal(prin);
if (NS_FAILED(rv)) return rv;
}
rv = mDocument->UpdatePrincipal(&prin);
if (NS_FAILED(rv)) {
NS_IF_RELEASE(prin);
return rv;
}
rv = EvaluateScript(aData, mScriptURI, 1, mScriptLanguageVersion, prin);
NS_IF_RELEASE(prin);
rv = EvaluateScript(aData, mScriptURI, 1, mScriptLanguageVersion);
if (NS_FAILED(rv)) return rv;
PostEvaluateScript(bodyPresent);
@ -4350,15 +4345,12 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode)
}
}
else {
nsCOMPtr<nsIPrincipal> prin;
mDocument->GetPrincipal(getter_AddRefs(prin));
PRBool bodyPresent = PreEvaluateScript();
PRUint32 lineNo = (PRUint32)aNode.GetSourceLineNumber();
nsIURI *docURI = mDocument->GetDocumentURL();
EvaluateScript(script, docURI, lineNo, jsVersionString, prin);
EvaluateScript(script, docURI, lineNo, jsVersionString);
NS_IF_RELEASE(docURI);
PostEvaluateScript(bodyPresent);

Просмотреть файл

@ -779,7 +779,7 @@ nsXULDocument::GetPrincipal(nsIPrincipal **aPrincipal)
}
NS_IMETHODIMP
nsXULDocument::UpdatePrincipal(nsIPrincipal **aPrincipal)
nsXULDocument::AddPrincipal(nsIPrincipal *aPrincipal)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

Просмотреть файл

@ -120,7 +120,7 @@ public:
NS_IMETHOD GetPrincipal(nsIPrincipal **aPrincipal);
NS_IMETHOD UpdatePrincipal(nsIPrincipal **aPrincipal);
NS_IMETHOD AddPrincipal(nsIPrincipal *aPrincipal);
NS_IMETHOD GetDocumentLoadGroup(nsILoadGroup **aGroup) const;