Fixing bug 337755. Make IsCallerSecure() deal with jar: URIs. r=enndeakin@sympatico.ca, sr=bugmail@sicking.cc, a=mtschrep@gmail.com

git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_8_BRANCH@202181 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
jst%mozilla.jstenback.com
2006-07-14 21:41:08 +00:00
parent 2d9d4cde7c
commit 3f1d0fd7a4
2 changed files with 23 additions and 6 deletions

View File

@@ -49,6 +49,7 @@
#include "nsIURI.h"
#include "nsReadableUtils.h"
#include "nsIObserverService.h"
#include "nsIJARURI.h"
//
// Helper that tells us whether the caller is secure or not.
@@ -57,21 +58,36 @@
static PRBool
IsCallerSecure()
{
nsCOMPtr<nsIDocument> callerDoc =
do_QueryInterface(nsContentUtils::GetDocumentFromCaller());
nsCOMPtr<nsIPrincipal> subjectPrincipal;
nsContentUtils::GetSecurityManager()->
GetSubjectPrincipal(getter_AddRefs(subjectPrincipal));
if (!subjectPrincipal) {
// No subject principal means no code is running. Default to not
// being secure in that case.
if (!callerDoc) {
return PR_FALSE;
}
nsIURI *uri = callerDoc->GetDocumentURI();
nsCOMPtr<nsIURI> codebase;
subjectPrincipal->GetURI(getter_AddRefs(codebase));
if (!uri) {
if (!codebase) {
return PR_FALSE;
}
nsCOMPtr<nsIJARURI> jarURI;
nsCOMPtr<nsIURI> innerUri(codebase);
while((jarURI = do_QueryInterface(innerUri))) {
jarURI->GetJARFile(getter_AddRefs(innerUri));
}
if (!innerUri) {
return PR_FALSE;
}
PRBool isHttps = PR_FALSE;
nsresult rv = uri->SchemeIs("https", &isHttps);
nsresult rv = innerUri->SchemeIs("https", &isHttps);
return NS_SUCCEEDED(rv) && isHttps;
}