Bug 965413 part 4. Teach the security manager about nsILoadInfo. r=smaug

This commit is contained in:
Boris Zbarsky 2014-07-10 02:56:36 -04:00
parent e8aa2f7514
commit b3d20bffbc

View File

@ -64,6 +64,7 @@
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "nsCxPusher.h" #include "nsCxPusher.h"
#include "nsJSUtils.h" #include "nsJSUtils.h"
#include "nsILoadInfo.h"
// This should be probably defined on some other place... but I couldn't find it // This should be probably defined on some other place... but I couldn't find it
#define WEBAPPS_PERM_NAME "webapps-manage" #define WEBAPPS_PERM_NAME "webapps-manage"
@ -265,6 +266,20 @@ nsScriptSecurityManager::GetChannelPrincipal(nsIChannel* aChannel,
} }
} }
// Check whether we have an nsILoadInfo that says what we should do.
nsCOMPtr<nsILoadInfo> loadInfo;
aChannel->GetLoadInfo(getter_AddRefs(loadInfo));
if (loadInfo) {
if (loadInfo->GetLoadingSandboxed()) {
return CallCreateInstance(NS_NULLPRINCIPAL_CONTRACTID, aPrincipal);
}
if (loadInfo->GetForceInheritPrincipal()) {
NS_ADDREF(*aPrincipal = loadInfo->LoadingPrincipal());
return NS_OK;
}
}
// OK, get the principal from the URI. Make sure this does the same thing // OK, get the principal from the URI. Make sure this does the same thing
// as nsDocument::Reset and XULDocument::StartDocumentLoad. // as nsDocument::Reset and XULDocument::StartDocumentLoad.
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri;