Bug 790911 - part 1 - add a flag to suppress error reporting when using checkLoadURIWithPrincipal(); r=bz

This commit is contained in:
Tim Taubert 2012-09-13 16:16:17 +02:00
parent db6b7ff7c4
commit e2a74939dd
2 changed files with 17 additions and 5 deletions

View File

@ -10,7 +10,7 @@ interface nsIURI;
interface nsIChannel;
interface nsIDocShell;
[scriptable, uuid(75a7afe3-d7c9-46fe-b305-ae686457bc7f)]
[scriptable, uuid(51289544-fd8a-11e1-8017-5abf937d8bec)]
interface nsIScriptSecurityManager : nsIXPCSecurityManager
{
///////////////// Security Checks //////////////////
@ -71,6 +71,10 @@ interface nsIScriptSecurityManager : nsIXPCSecurityManager
// DISALLOW_INHERIT_PRINCIPAL
const unsigned long DISALLOW_SCRIPT = 1 << 3;
// Do not report errors if we just want to check if a principal can load
// a URI to not unnecessarily spam the error console.
const unsigned long DONT_REPORT_ERRORS = 1 << 4;
/**
* Check that content with principal aPrincipal can load "uri".
*

View File

@ -1306,7 +1306,8 @@ nsScriptSecurityManager::CheckLoadURIWithPrincipal(nsIPrincipal* aPrincipal,
NS_ENSURE_FALSE(aFlags & ~(nsIScriptSecurityManager::LOAD_IS_AUTOMATIC_DOCUMENT_REPLACEMENT |
nsIScriptSecurityManager::ALLOW_CHROME |
nsIScriptSecurityManager::DISALLOW_SCRIPT |
nsIScriptSecurityManager::DISALLOW_INHERIT_PRINCIPAL),
nsIScriptSecurityManager::DISALLOW_INHERIT_PRINCIPAL |
nsIScriptSecurityManager::DONT_REPORT_ERRORS),
NS_ERROR_UNEXPECTED);
NS_ENSURE_ARG_POINTER(aPrincipal);
NS_ENSURE_ARG_POINTER(aTargetURI);
@ -1374,6 +1375,7 @@ nsScriptSecurityManager::CheckLoadURIWithPrincipal(nsIPrincipal* aPrincipal,
}
NS_NAMED_LITERAL_STRING(errorTag, "CheckLoadURIError");
bool reportErrors = !(aFlags & nsIScriptSecurityManager::DONT_REPORT_ERRORS);
// Check for uris that are only loadable by principals that subsume them
bool hasFlags;
@ -1417,7 +1419,9 @@ nsScriptSecurityManager::CheckLoadURIWithPrincipal(nsIPrincipal* aPrincipal,
nsIProtocolHandler::URI_DANGEROUS_TO_LOAD);
if (NS_FAILED(rv)) {
// Deny access, since the origin principal is not system
ReportError(nullptr, errorTag, sourceURI, aTargetURI);
if (reportErrors) {
ReportError(nullptr, errorTag, sourceURI, aTargetURI);
}
return rv;
}
@ -1456,7 +1460,9 @@ nsScriptSecurityManager::CheckLoadURIWithPrincipal(nsIPrincipal* aPrincipal,
if (sourceIsChrome) {
return NS_OK;
}
ReportError(nullptr, errorTag, sourceURI, aTargetURI);
if (reportErrors) {
ReportError(nullptr, errorTag, sourceURI, aTargetURI);
}
return NS_ERROR_DOM_BAD_URI;
}
@ -1492,7 +1498,9 @@ nsScriptSecurityManager::CheckLoadURIWithPrincipal(nsIPrincipal* aPrincipal,
return NS_OK;
}
ReportError(nullptr, errorTag, sourceURI, aTargetURI);
if (reportErrors) {
ReportError(nullptr, errorTag, sourceURI, aTargetURI);
}
return NS_ERROR_DOM_BAD_URI;
}