Bug 1517308 - Add a search field in about:url-classifier - part 1 - nsIUrlClassifier.getFeatureNames(), r=dimi
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 08 Jan 2019 23:05:40 +0100
changeset 510134 543e146f314a1cd3af05bd421067df15df862402
parent 510133 a4b8887afbc97edd031cd4ac4fd04317dd28650a
child 510135 0ab9267646168b00142468dd0d243bef4431455a
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)
reviewersdimi
bugs1517308
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 1517308 - Add a search field in about:url-classifier - part 1 - nsIUrlClassifier.getFeatureNames(), r=dimi
netwerk/url-classifier/UrlClassifierFeatureFactory.cpp
netwerk/url-classifier/UrlClassifierFeatureFactory.h
netwerk/url-classifier/UrlClassifierFeatureFlash.cpp
netwerk/url-classifier/UrlClassifierFeatureFlash.h
netwerk/url-classifier/UrlClassifierFeatureLoginReputation.cpp
netwerk/url-classifier/UrlClassifierFeatureLoginReputation.h
netwerk/url-classifier/UrlClassifierFeatureTrackingAnnotation.cpp
netwerk/url-classifier/UrlClassifierFeatureTrackingAnnotation.h
netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.cpp
netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.h
netwerk/url-classifier/nsIURIClassifier.idl
toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
--- a/netwerk/url-classifier/UrlClassifierFeatureFactory.cpp
+++ b/netwerk/url-classifier/UrlClassifierFeatureFactory.cpp
@@ -97,16 +97,47 @@ UrlClassifierFeatureFactory::GetFeatureB
   feature = UrlClassifierFeatureFlash::GetIfNameMatches(aName);
   if (feature) {
     return feature.forget();
   }
 
   return nullptr;
 }
 
+/* static */ void UrlClassifierFeatureFactory::GetFeatureNames(
+    nsTArray<nsCString>& aArray) {
+  if (!XRE_IsParentProcess()) {
+    return;
+  }
+
+  // Tracking Protection
+  nsAutoCString name;
+  name.Assign(UrlClassifierFeatureTrackingProtection::Name());
+  if (!name.IsEmpty()) {
+    aArray.AppendElement(name);
+  }
+
+  // Tracking Annotation
+  name.Assign(UrlClassifierFeatureTrackingAnnotation::Name());
+  if (!name.IsEmpty()) {
+    aArray.AppendElement(name);
+  }
+
+  // Login reputation
+  name.Assign(UrlClassifierFeatureLoginReputation::Name());
+  if (!name.IsEmpty()) {
+    aArray.AppendElement(name);
+  }
+
+  // Flash features
+  nsTArray<nsCString> features;
+  UrlClassifierFeatureFlash::GetFeatureNames(features);
+  aArray.AppendElements(features);
+}
+
 /* static */ already_AddRefed<nsIUrlClassifierFeature>
 UrlClassifierFeatureFactory::CreateFeatureWithTables(
     const nsACString& aName, const nsTArray<nsCString>& aBlacklistTables,
     const nsTArray<nsCString>& aWhitelistTables) {
   nsCOMPtr<nsIUrlClassifierFeature> feature =
       new UrlClassifierFeatureCustomTables(aName, aBlacklistTables,
                                            aWhitelistTables);
   return feature.forget();
--- a/netwerk/url-classifier/UrlClassifierFeatureFactory.h
+++ b/netwerk/url-classifier/UrlClassifierFeatureFactory.h
@@ -24,16 +24,18 @@ class UrlClassifierFeatureFactory final 
       nsIChannel* aChannel,
       nsTArray<nsCOMPtr<nsIUrlClassifierFeature>>& aFeatures);
 
   static nsIUrlClassifierFeature* GetFeatureLoginReputation();
 
   static already_AddRefed<nsIUrlClassifierFeature> GetFeatureByName(
       const nsACString& aFeatureName);
 
+  static void GetFeatureNames(nsTArray<nsCString>& aArray);
+
   static already_AddRefed<nsIUrlClassifierFeature> CreateFeatureWithTables(
       const nsACString& aName, const nsTArray<nsCString>& aBlacklistTables,
       const nsTArray<nsCString>& aWhitelistTables);
 };
 
 }  // namespace net
 }  // namespace mozilla
 
--- a/netwerk/url-classifier/UrlClassifierFeatureFlash.cpp
+++ b/netwerk/url-classifier/UrlClassifierFeatureFlash.cpp
@@ -50,16 +50,25 @@ UrlClassifierFeatureFlash::UrlClassifier
           EmptyCString())  // aPrefSkipHosts
       ,
       mFlashPluginState(sFlashFeaturesMap[aId].mFlashPluginState) {
   static_assert(nsIHttpChannel::FlashPluginDeniedInSubdocuments ==
                     nsIHttpChannel::FlashPluginLastValue,
                 "nsIHttpChannel::FlashPluginLastValue is out-of-sync!");
 }
 
+/* static */ void UrlClassifierFeatureFlash::GetFeatureNames(
+    nsTArray<nsCString>& aArray) {
+  uint32_t numFeatures =
+      (sizeof(sFlashFeaturesMap) / sizeof(sFlashFeaturesMap[0]));
+  for (uint32_t i = 0; i < numFeatures; ++i) {
+    aArray.AppendElement(nsDependentCString(sFlashFeaturesMap[i].mName));
+  }
+}
+
 /* static */ void UrlClassifierFeatureFlash::MaybeInitialize() {
   MOZ_ASSERT(XRE_IsParentProcess());
 
   if (IsInitialized()) {
     return;
   }
 
   uint32_t numFeatures =
--- a/netwerk/url-classifier/UrlClassifierFeatureFlash.h
+++ b/netwerk/url-classifier/UrlClassifierFeatureFlash.h
@@ -9,16 +9,18 @@
 
 #include "UrlClassifierFeatureBase.h"
 
 namespace mozilla {
 namespace net {
 
 class UrlClassifierFeatureFlash final : public UrlClassifierFeatureBase {
  public:
+  static void GetFeatureNames(nsTArray<nsCString>& aNames);
+
   static void MaybeShutdown();
 
   static void MaybeCreate(
       nsIChannel* aChannel,
       nsTArray<nsCOMPtr<nsIUrlClassifierFeature>>& aFeatures);
 
   static already_AddRefed<nsIUrlClassifierFeature> GetIfNameMatches(
       const nsACString& aName);
--- a/netwerk/url-classifier/UrlClassifierFeatureLoginReputation.cpp
+++ b/netwerk/url-classifier/UrlClassifierFeatureLoginReputation.cpp
@@ -28,16 +28,22 @@ UrlClassifierFeatureLoginReputation::Url
           NS_LITERAL_CSTRING(PREF_PASSWORD_ALLOW_TABLE),
           EmptyCString(),  // blacklist pref
           EmptyCString(),  // whitelist pref
           EmptyCString(),  // blacklist pref table name
           EmptyCString(),  // whitelist pref table name
           EmptyCString())  // skip host pref
 {}
 
+/* static */ const char* UrlClassifierFeatureLoginReputation::Name() {
+  return StaticPrefs::browser_safebrowsing_passwords_enabled()
+             ? LOGIN_REPUTATION_FEATURE_NAME
+             : "";
+}
+
 /* static */ void UrlClassifierFeatureLoginReputation::MaybeShutdown() {
   UC_LOG(("UrlClassifierFeatureLoginReputation: MaybeShutdown"));
 
   if (gFeatureLoginReputation) {
     gFeatureLoginReputation->ShutdownPreferences();
     gFeatureLoginReputation = nullptr;
   }
 }
@@ -72,46 +78,16 @@ UrlClassifierFeatureLoginReputation::Pro
                                                     bool* aShouldContinue) {
   MOZ_CRASH(
       "UrlClassifierFeatureLoginReputation::ProcessChannel should never be "
       "called");
   return NS_OK;
 }
 
 NS_IMETHODIMP
-UrlClassifierFeatureLoginReputation::GetTables(
-    nsIUrlClassifierFeature::listType aListType, nsTArray<nsCString>& aTables) {
-  MOZ_ASSERT(aListType == nsIUrlClassifierFeature::whitelist,
-             "UrlClassifierFeatureLoginReputation is meant to be used just to "
-             "whitelist URLs");
-  return UrlClassifierFeatureBase::GetTables(aListType, aTables);
-}
-
-NS_IMETHODIMP
-UrlClassifierFeatureLoginReputation::HasTable(
-    const nsACString& aTable, nsIUrlClassifierFeature::listType aListType,
-    bool* aResult) {
-  MOZ_ASSERT(aListType == nsIUrlClassifierFeature::whitelist,
-             "UrlClassifierFeatureLoginReputation is meant to be used just to "
-             "whitelist URLs");
-  return UrlClassifierFeatureBase::HasTable(aTable, aListType, aResult);
-}
-
-NS_IMETHODIMP
-UrlClassifierFeatureLoginReputation::HasHostInPreferences(
-    const nsACString& aHost, nsIUrlClassifierFeature::listType aListType,
-    nsACString& aPrefTableName, bool* aResult) {
-  MOZ_ASSERT(aListType == nsIUrlClassifierFeature::whitelist,
-             "UrlClassifierFeatureLoginReputation is meant to be used just to "
-             "whitelist URLs");
-  return UrlClassifierFeatureBase::HasHostInPreferences(
-      aHost, aListType, aPrefTableName, aResult);
-}
-
-NS_IMETHODIMP
 UrlClassifierFeatureLoginReputation::GetURIByListType(
     nsIChannel* aChannel, nsIUrlClassifierFeature::listType aListType,
     nsIURI** aURI) {
   NS_ENSURE_ARG_POINTER(aChannel);
   NS_ENSURE_ARG_POINTER(aURI);
   MOZ_ASSERT(aListType == nsIUrlClassifierFeature::whitelist,
              "UrlClassifierFeatureLoginReputation is meant to be used just to "
              "whitelist URLs");
--- a/netwerk/url-classifier/UrlClassifierFeatureLoginReputation.h
+++ b/netwerk/url-classifier/UrlClassifierFeatureLoginReputation.h
@@ -12,36 +12,25 @@
 class nsIChannel;
 
 namespace mozilla {
 namespace net {
 
 class UrlClassifierFeatureLoginReputation final
     : public UrlClassifierFeatureBase {
  public:
+  static const char* Name();
+
   static void MaybeShutdown();
 
   static nsIUrlClassifierFeature* MaybeGetOrCreate();
 
   static already_AddRefed<nsIUrlClassifierFeature> GetIfNameMatches(
       const nsACString& aName);
 
-  NS_IMETHOD
-  GetTables(nsIUrlClassifierFeature::listType aListType,
-            nsTArray<nsCString>& aResult) override;
-
-  NS_IMETHOD
-  HasTable(const nsACString& aTable,
-           nsIUrlClassifierFeature::listType aListType, bool* aResult) override;
-
-  NS_IMETHOD
-  HasHostInPreferences(const nsACString& aHost,
-                       nsIUrlClassifierFeature::listType aListType,
-                       nsACString& aPrefTableName, bool* aResult) override;
-
   NS_IMETHOD ProcessChannel(nsIChannel* aChannel, const nsACString& aList,
                             bool* aShouldContinue) override;
 
   NS_IMETHOD GetURIByListType(nsIChannel* aChannel,
                               nsIUrlClassifierFeature::listType aListType,
                               nsIURI** aURI) override;
 
  private:
--- a/netwerk/url-classifier/UrlClassifierFeatureTrackingAnnotation.cpp
+++ b/netwerk/url-classifier/UrlClassifierFeatureTrackingAnnotation.cpp
@@ -115,16 +115,20 @@ UrlClassifierFeatureTrackingAnnotation::
           NS_LITERAL_CSTRING(URLCLASSIFIER_ANNOTATION_BLACKLIST),
           NS_LITERAL_CSTRING(URLCLASSIFIER_ANNOTATION_WHITELIST),
           NS_LITERAL_CSTRING(URLCLASSIFIER_ANNOTATION_BLACKLIST_TEST_ENTRIES),
           NS_LITERAL_CSTRING(URLCLASSIFIER_ANNOTATION_WHITELIST_TEST_ENTRIES),
           NS_LITERAL_CSTRING(TABLE_ANNOTATION_BLACKLIST_PREF),
           NS_LITERAL_CSTRING(TABLE_ANNOTATION_WHITELIST_PREF),
           NS_LITERAL_CSTRING(URLCLASSIFIER_TRACKING_ANNOTATION_SKIP_URLS)) {}
 
+/* static */ const char* UrlClassifierFeatureTrackingAnnotation::Name() {
+  return TRACKING_ANNOTATION_FEATURE_NAME;
+}
+
 /* static */ void UrlClassifierFeatureTrackingAnnotation::MaybeInitialize() {
   MOZ_ASSERT(XRE_IsParentProcess());
   UC_LOG(("UrlClassifierFeatureTrackingAnnotation: MaybeInitialize"));
 
   if (!gFeatureTrackingAnnotation) {
     gFeatureTrackingAnnotation = new UrlClassifierFeatureTrackingAnnotation();
     gFeatureTrackingAnnotation->InitializePreferences();
   }
--- a/netwerk/url-classifier/UrlClassifierFeatureTrackingAnnotation.h
+++ b/netwerk/url-classifier/UrlClassifierFeatureTrackingAnnotation.h
@@ -12,16 +12,18 @@
 class nsIChannel;
 
 namespace mozilla {
 namespace net {
 
 class UrlClassifierFeatureTrackingAnnotation final
     : public UrlClassifierFeatureBase {
  public:
+  static const char* Name();
+
   static void MaybeShutdown();
 
   static already_AddRefed<UrlClassifierFeatureTrackingAnnotation> MaybeCreate(
       nsIChannel* aChannel);
 
   static already_AddRefed<nsIUrlClassifierFeature> GetIfNameMatches(
       const nsACString& aName);
 
--- a/netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.cpp
+++ b/netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.cpp
@@ -37,16 +37,20 @@ UrlClassifierFeatureTrackingProtection::
           NS_LITERAL_CSTRING(TRACKING_PROTECTION_FEATURE_NAME),
           NS_LITERAL_CSTRING(URLCLASSIFIER_TRACKING_BLACKLIST),
           NS_LITERAL_CSTRING(URLCLASSIFIER_TRACKING_WHITELIST),
           NS_LITERAL_CSTRING(URLCLASSIFIER_TRACKING_BLACKLIST_TEST_ENTRIES),
           NS_LITERAL_CSTRING(URLCLASSIFIER_TRACKING_WHITELIST_TEST_ENTRIES),
           NS_LITERAL_CSTRING(TABLE_TRACKING_BLACKLIST_PREF),
           NS_LITERAL_CSTRING(TABLE_TRACKING_WHITELIST_PREF), EmptyCString()) {}
 
+/* static */ const char* UrlClassifierFeatureTrackingProtection::Name() {
+  return TRACKING_PROTECTION_FEATURE_NAME;
+}
+
 /* static */ void UrlClassifierFeatureTrackingProtection::MaybeInitialize() {
   MOZ_ASSERT(XRE_IsParentProcess());
   UC_LOG(("UrlClassifierFeatureTrackingProtection: MaybeInitialize"));
 
   if (!gFeatureTrackingProtection) {
     gFeatureTrackingProtection = new UrlClassifierFeatureTrackingProtection();
     gFeatureTrackingProtection->InitializePreferences();
   }
--- a/netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.h
+++ b/netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.h
@@ -12,16 +12,18 @@
 class nsIChannel;
 
 namespace mozilla {
 namespace net {
 
 class UrlClassifierFeatureTrackingProtection final
     : public UrlClassifierFeatureBase {
  public:
+  static const char* Name();
+
   static void MaybeShutdown();
 
   static already_AddRefed<UrlClassifierFeatureTrackingProtection> MaybeCreate(
       nsIChannel* aChannel);
 
   static already_AddRefed<nsIUrlClassifierFeature> GetIfNameMatches(
       const nsACString& aName);
 
--- a/netwerk/url-classifier/nsIURIClassifier.idl
+++ b/netwerk/url-classifier/nsIURIClassifier.idl
@@ -91,16 +91,21 @@ interface nsIURIClassifier : nsISupports
                                       in nsIUrlClassifierFeatureCallback aCallback);
 
   /**
    * Returns a feature named aFeatureName.
    */
   nsIUrlClassifierFeature getFeatureByName(in ACString aFeatureName);
 
   /**
+   * Returns all the feature names.
+   */
+  Array<ACString> getFeatureNames();
+
+  /**
    * Create a new feature with a list of tables. This method is just for
    * testing! Don't use it elsewhere.
    */
   nsIUrlClassifierFeature createFeatureWithTables(in ACString aName,
                                                   in Array<ACString> aBlacklistTables,
                                                   in Array<ACString> aWhitelistTables);
 
   /**
--- a/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
@@ -2695,16 +2695,22 @@ nsUrlClassifierDBService::GetFeatureByNa
     return NS_ERROR_FAILURE;
   }
 
   feature.forget(aFeature);
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsUrlClassifierDBService::GetFeatureNames(nsTArray<nsCString>& aArray) {
+  mozilla::net::UrlClassifierFeatureFactory::GetFeatureNames(aArray);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsUrlClassifierDBService::CreateFeatureWithTables(
     const nsACString& aName, const nsTArray<nsCString>& aBlacklistTables,
     const nsTArray<nsCString>& aWhitelistTables,
     nsIUrlClassifierFeature** aFeature) {
   NS_ENSURE_ARG_POINTER(aFeature);
   nsCOMPtr<nsIUrlClassifierFeature> feature =
       mozilla::net::UrlClassifierFeatureFactory::CreateFeatureWithTables(
           aName, aBlacklistTables, aWhitelistTables);