Eliminate more callers of CheckSameOriginPrincipal in favor of

Equals/Subsumes.  Bug 387212, r=mrbkap, sr=jst
This commit is contained in:
bzbarsky@mit.edu 2007-07-09 21:22:55 -07:00
Родитель ced8f1a4b0
Коммит 4d46bda6dc
3 изменённых файлов: 38 добавлений и 36 удалений

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

@ -628,14 +628,11 @@ CheckSameOrigin(nsINode* aNode1, nsINode* aNode2)
NS_PRECONDITION(aNode1, "Null node?");
NS_PRECONDITION(aNode2, "Null node?");
nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
if (!secMan) {
return PR_FALSE;
}
PRBool equal;
return
NS_SUCCEEDED(secMan->CheckSameOriginPrincipal(aNode1->NodePrincipal(),
aNode2->NodePrincipal()));
NS_SUCCEEDED(aNode1->NodePrincipal()->
Equals(aNode2->NodePrincipal(), &equal)) &&
equal;
}
PRBool
@ -2146,9 +2143,10 @@ nsHTMLDocument::OpenCommon(const nsACString& aContentType, PRBool aReplace)
// If callerPrincipal doesn't match our principal. make sure that
// SetNewDocument gives us a new inner window and clears our scope.
PRBool samePrincipal;
if (!callerPrincipal ||
NS_FAILED(nsContentUtils::GetSecurityManager()->
CheckSameOriginPrincipal(callerPrincipal, NodePrincipal()))) {
NS_FAILED(callerPrincipal->Equals(NodePrincipal(), &samePrincipal)) ||
!samePrincipal) {
SetIsInitialDocument(PR_FALSE);
}
@ -4018,8 +4016,11 @@ nsHTMLDocument::SetDesignMode(const nsAString & aDesignMode)
rv = secMan->GetSubjectPrincipal(getter_AddRefs(subject));
NS_ENSURE_SUCCESS(rv, rv);
if (subject) {
rv = secMan->CheckSameOriginPrincipal(subject, NodePrincipal());
PRBool subsumes;
rv = subject->Subsumes(NodePrincipal(), &subsumes);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(subsumes, NS_ERROR_DOM_PROP_ACCESS_DENIED);
}
}

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

@ -1025,10 +1025,11 @@ nsDocShell::ValidateOrigin(nsIDocShellTreeItem* aOriginTreeItem,
nsCOMPtr<nsIDocument> targetDocument(do_QueryInterface(targetDOMDocument));
NS_ENSURE_TRUE(targetDocument, PR_FALSE);
PRBool equal;
return
NS_SUCCEEDED(securityManager->
CheckSameOriginPrincipal(originDocument->NodePrincipal(),
targetDocument->NodePrincipal()));
NS_SUCCEEDED(originDocument->NodePrincipal()->
Equals(targetDocument->NodePrincipal(), &equal)) &&
equal;
}
NS_IMETHODIMP
@ -6209,12 +6210,16 @@ nsDocShell::CheckLoadingPermissions()
}
// Compare origins
sameOrigin =
securityManager->CheckSameOriginPrincipal(subjPrincipal, p);
PRBool equal;
sameOrigin = subjPrincipal->Equals(p, &equal);
if (NS_SUCCEEDED(sameOrigin)) {
// Same origin, permit load
if (equal) {
// Same origin, permit load
return sameOrigin;
return sameOrigin;
}
sameOrigin = NS_ERROR_DOM_PROP_ACCESS_DENIED;
}
nsCOMPtr<nsIDocShellTreeItem> tmp;

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

@ -992,10 +992,10 @@ nsGlobalWindow::WouldReuseInnerWindow(nsIDocument *aNewDocument)
return PR_TRUE;
}
if (nsContentUtils::GetSecurityManager() &&
NS_SUCCEEDED(nsContentUtils::GetSecurityManager()->
CheckSameOriginPrincipal(mDoc->NodePrincipal(),
aNewDocument->NodePrincipal()))) {
PRBool equal;
if (NS_SUCCEEDED(mDoc->NodePrincipal()->Equals(aNewDocument->NodePrincipal(),
&equal)) &&
equal) {
// The origin is the same.
return PR_TRUE;
}
@ -1329,10 +1329,10 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
// the existing inner window or the new document is from the same
// origin as the old document.
if (!reUseInnerWindow && mNavigator && oldPrincipal) {
rv = nsContentUtils::GetSecurityManager()->
CheckSameOriginPrincipal(oldPrincipal, aDocument->NodePrincipal());
PRBool equal;
rv = oldPrincipal->Equals(aDocument->NodePrincipal(), &equal);
if (NS_FAILED(rv)) {
if (NS_FAILED(rv) || !equal) {
// Different origins. Release the navigator object so it gets
// recreated for the new document. The plugins or mime types
// arrays may have changed. See bug 150087.
@ -6566,9 +6566,9 @@ nsGlobalWindow::SetTimeoutOrInterval(nsIScriptTimeoutHandler *aHandler,
timeout->mScriptHandler = aHandler;
// Get principal of currently executing code, save for execution of timeout.
// If either our principals subsume the subject principal, or we're from the
// same origin, then use the subject principal. Otherwise, use our principal
// to avoid running script in elevated principals.
// If our principals subsume the subject principal then use the subject
// principal. Otherwise, use our principal to avoid running script in
// elevated principals.
nsCOMPtr<nsIPrincipal> subjectPrincipal;
nsresult rv;
@ -6583,8 +6583,10 @@ nsGlobalWindow::SetTimeoutOrInterval(nsIScriptTimeoutHandler *aHandler,
PRBool subsumes = PR_FALSE;
nsCOMPtr<nsIPrincipal> ourPrincipal = GetPrincipal();
// Note the direction of this test: We don't allow chrome setTimeouts on
// content windows, but we do allow content setTimeouts on chrome windows.
// Note the direction of this test: We don't allow setTimeouts running with
// chrome privileges on content windows, but we do allow setTimeouts running
// with content privileges on chrome windows (where they can't do very much,
// of course).
rv = ourPrincipal->Subsumes(subjectPrincipal, &subsumes);
if (NS_FAILED(rv)) {
timeout->Release();
@ -6595,13 +6597,7 @@ nsGlobalWindow::SetTimeoutOrInterval(nsIScriptTimeoutHandler *aHandler,
if (subsumes) {
timeout->mPrincipal = subjectPrincipal;
} else {
// Subsumes does a very strict equality test. Allow sites of the same origin
// to set timeouts on each other.
rv = nsContentUtils::GetSecurityManager()->
CheckSameOriginPrincipal(subjectPrincipal, ourPrincipal);
timeout->mPrincipal = NS_SUCCEEDED(rv) ? subjectPrincipal : ourPrincipal;
rv = NS_OK;
timeout->mPrincipal = ourPrincipal;
}
PRTime delta = (PRTime)realInterval * PR_USEC_PER_MSEC;