Bug 1403024 part 1 - Add nsContentUtils::SchemeIs helper function. r?bholley draft
authorXidorn Quan <me@upsuper.org>
Tue, 26 Sep 2017 10:21:01 +1000
changeset 670175 f6e0e80c069914e32ac1bc0c4d6c6ababe928b54
parent 670174 843a6354a5b238cfc2a05e4a29fb91acc17d3646
child 670176 6082c31e1010cf8eb09381ef1cbae50d76654a8d
child 670177 324591edee1ebb3d03a670c7a70476a0cc137073
child 670178 7c1de0fb77a1fe2f20f36834619cf50be996cd53
child 670407 2c4f805ec97cf4c36d690a602dde99afc6dfa3ba
child 671448 fe7821ba122a8c5ebfa7f422493126089a2d3daa
push id81547
push userxquan@mozilla.com
push dateTue, 26 Sep 2017 00:32:10 +0000
reviewersbholley
bugs1403024
milestone58.0a1
Bug 1403024 part 1 - Add nsContentUtils::SchemeIs helper function. r?bholley MozReview-Commit-ID: 2NVc5QJSjl
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
dom/security/nsContentSecurityManager.cpp
--- 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;