Bug 1403024 part 1 - Add nsContentUtils::SchemeIs helper function. r?bholley
MozReview-Commit-ID: 2NVc5QJSjl
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -5435,17 +5435,18 @@ nsContentUtils::IsInSameAnonymousTree(co
/* static */
void
nsContentUtils::NotifyInstalledMenuKeyboardListener(bool aInstalling)
{
IMEStateManager::OnInstalledMenuKeyboardListener(aInstalling);
}
-static bool SchemeIs(nsIURI* aURI, const char* aScheme)
+/* static */ bool
+nsContentUtils::SchemeIs(nsIURI* aURI, const char* aScheme)
{
nsCOMPtr<nsIURI> baseURI = NS_GetInnermostURI(aURI);
NS_ENSURE_TRUE(baseURI, false);
bool isScheme = false;
return NS_SUCCEEDED(baseURI->SchemeIs(aScheme, &isScheme)) && isScheme;
}
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -1697,16 +1697,24 @@ public:
/*
* Notify when the first XUL menu is opened and when the all XUL menus are
* closed. At opening, aInstalling should be TRUE, otherwise, it should be
* FALSE.
*/
static void NotifyInstalledMenuKeyboardListener(bool aInstalling);
/**
+ * Check whether the nsIURI uses the given scheme.
+ *
+ * Note that this will check the innermost URI rather than that of
+ * the nsIURI itself.
+ */
+ static bool SchemeIs(nsIURI* aURI, const char* aScheme);
+
+ /**
* Returns true if aPrincipal is the system principal.
*/
static bool IsSystemPrincipal(nsIPrincipal* aPrincipal);
/**
* Returns true if aPrincipal is an ExpandedPrincipal.
*/
static bool IsExpandedPrincipal(nsIPrincipal* aPrincipal);
--- a/dom/security/nsContentSecurityManager.cpp
+++ b/dom/security/nsContentSecurityManager.cpp
@@ -93,26 +93,16 @@ ValidateSecurityFlags(nsILoadInfo* aLoad
MOZ_ASSERT(false, "need one securityflag from nsILoadInfo to perform security checks");
return NS_ERROR_FAILURE;
}
// all good, found the right security flags
return NS_OK;
}
-static bool SchemeIs(nsIURI* aURI, const char* aScheme)
-{
- nsCOMPtr<nsIURI> baseURI = NS_GetInnermostURI(aURI);
- NS_ENSURE_TRUE(baseURI, false);
-
- bool isScheme = false;
- return NS_SUCCEEDED(baseURI->SchemeIs(aScheme, &isScheme)) && isScheme;
-}
-
-
static bool IsImageLoadInEditorAppType(nsILoadInfo* aLoadInfo)
{
// Editor apps get special treatment here, editors can load images
// from anywhere. This allows editor to insert images from file://
// into documents that are being edited.
nsContentPolicyType type = aLoadInfo->InternalContentPolicyType();
if (type != nsIContentPolicy::TYPE_INTERNAL_IMAGE &&
type != nsIContentPolicy::TYPE_INTERNAL_IMAGE_PRELOAD &&
@@ -185,17 +175,17 @@ URIHasFlags(nsIURI* aURI, uint32_t aURIF
return hasFlags;
}
static nsresult
DoSOPChecks(nsIURI* aURI, nsILoadInfo* aLoadInfo, nsIChannel* aChannel)
{
if (aLoadInfo->GetAllowChrome() &&
(URIHasFlags(aURI, nsIProtocolHandler::URI_IS_UI_RESOURCE) ||
- SchemeIs(aURI, "moz-safe-about"))) {
+ nsContentUtils::SchemeIs(aURI, "moz-safe-about"))) {
// UI resources are allowed.
return DoCheckLoadURIChecks(aURI, aLoadInfo);
}
NS_ENSURE_FALSE(NS_HasBeenCrossOrigin(aChannel, true),
NS_ERROR_DOM_BAD_URI);
return NS_OK;