Bug 1518964 - Add SchemeIs convenience functions; r=valentin
authorKyle Machulis <kyle@nonpolynomial.com>
Fri, 11 Jan 2019 08:08:19 +0000
changeset 510689 d288304b11fa701f20c691e8e5f5f2f9f6520b31
parent 510688 8583d9d483877e7e70bbf1514aca63068e6d9c77
child 510690 44ff151d71114915f645e2722aebc05071a3ad3d
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1518964
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1518964 - Add SchemeIs convenience functions; r=valentin Create convenience functions for common protocols used in SchemeIs queries. Differential Revision: https://phabricator.services.mozilla.com/D16231
netwerk/base/nsNetUtil.cpp
netwerk/base/nsNetUtil.h
--- a/netwerk/base/nsNetUtil.cpp
+++ b/netwerk/base/nsNetUtil.cpp
@@ -2819,10 +2819,70 @@ bool InScriptableRange(int64_t val) {
 bool InScriptableRange(uint64_t val) { return val <= kJS_MAX_SAFE_UINTEGER; }
 
 nsresult GetParameterHTTP(const nsACString &aHeaderVal, const char *aParamName,
                           nsAString &aResult) {
   return nsMIMEHeaderParamImpl::GetParameterHTTP(aHeaderVal, aParamName,
                                                  aResult);
 }
 
+bool SchemeIsHTTP(nsIURI *aURI) {
+  MOZ_ASSERT(aURI);
+  return aURI->SchemeIs("http");
+}
+
+bool SchemeIsHTTPS(nsIURI *aURI) {
+  MOZ_ASSERT(aURI);
+  return aURI->SchemeIs("https");
+}
+
+bool SchemeIsJavascript(nsIURI *aURI) {
+  MOZ_ASSERT(aURI);
+  return aURI->SchemeIs("javascript");
+}
+
+bool SchemeIsChrome(nsIURI *aURI) {
+  MOZ_ASSERT(aURI);
+  return aURI->SchemeIs("chrome");
+}
+
+bool SchemeIsAbout(nsIURI *aURI) {
+  MOZ_ASSERT(aURI);
+  return aURI->SchemeIs("about");
+}
+
+bool SchemeIsBlob(nsIURI *aURI) {
+  MOZ_ASSERT(aURI);
+  return aURI->SchemeIs("blob");
+}
+
+bool SchemeIsFile(nsIURI *aURI) {
+  MOZ_ASSERT(aURI);
+  return aURI->SchemeIs("file");
+}
+
+bool SchemeIsData(nsIURI *aURI) {
+  MOZ_ASSERT(aURI);
+  return aURI->SchemeIs("data");
+}
+
+bool SchemeIsWYCIWYG(nsIURI *aURI) {
+  MOZ_ASSERT(aURI);
+  return aURI->SchemeIs("wyciwyg");
+}
+
+bool SchemeIsViewSource(nsIURI *aURI) {
+  MOZ_ASSERT(aURI);
+  return aURI->SchemeIs("view-source");
+}
+
+bool SchemeIsResource(nsIURI *aURI) {
+  MOZ_ASSERT(aURI);
+  return aURI->SchemeIs("resource");
+}
+
+bool SchemeIsFTP(nsIURI *aURI) {
+  MOZ_ASSERT(aURI);
+  return aURI->SchemeIs("ftp");
+}
+
 }  // namespace net
 }  // namespace mozilla
--- a/netwerk/base/nsNetUtil.h
+++ b/netwerk/base/nsNetUtil.h
@@ -893,12 +893,29 @@ bool InScriptableRange(uint64_t val);
  * @param  aParamName        the name of a MIME header parameter (e.g.
  *                           filename, name, charset). If empty or nullptr,
  *                           returns the first (possibly) _unnamed_ 'parameter'.
  * @return the value of <code>aParamName</code> in Unichar(UTF-16).
  */
 nsresult GetParameterHTTP(const nsACString &aHeaderVal, const char *aParamName,
                           nsAString &aResult);
 
+/**
+ * Convenience functions for verifying nsIURI schemes. These functions simply
+ * wrap aURI->SchemeIs(), but specify the protocol as part of the function name.
+ */
+
+bool SchemeIsHTTP(nsIURI *aURI);
+bool SchemeIsHTTPS(nsIURI *aURI);
+bool SchemeIsJavascript(nsIURI *aURI);
+bool SchemeIsChrome(nsIURI *aURI);
+bool SchemeIsAbout(nsIURI *aURI);
+bool SchemeIsBlob(nsIURI *aURI);
+bool SchemeIsFile(nsIURI *aURI);
+bool SchemeIsData(nsIURI *aURI);
+bool SchemeIsWYCIWYG(nsIURI *aURI);
+bool SchemeIsViewSource(nsIURI *aURI);
+bool SchemeIsResource(nsIURI *aURI);
+bool SchemeIsFTP(nsIURI *aURI);
 }  // namespace net
 }  // namespace mozilla
 
 #endif  // !nsNetUtil_h__