Bug 1522265 - Moving malware, phishing and blocked URIs to features - part 1 - feature no channel, r=dimi
☠☠ backed out by 98040e23391e ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 29 Jan 2019 10:11:33 +0100
changeset 455941 e6a0832f3b1192a550136835d25550783afcbf04
parent 455940 55a7c08b3b67c472266f383b14cc4ca3803849c9
child 455942 6085d51681f8c763132973f65f305f1f15058135
push id35463
push usershindli@mozilla.com
push dateTue, 29 Jan 2019 21:38:17 +0000
treeherdermozilla-central@4440fbf71c72 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdimi
bugs1522265
milestone67.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 1522265 - Moving malware, phishing and blocked URIs to features - part 1 - feature no channel, r=dimi
modules/libpref/init/StaticPrefList.h
modules/libpref/init/all.js
netwerk/url-classifier/UrlClassifierFeatureFactory.cpp
netwerk/url-classifier/UrlClassifierFeatureNoChannel.cpp
netwerk/url-classifier/UrlClassifierFeatureNoChannel.h
netwerk/url-classifier/moz.build
--- a/modules/libpref/init/StaticPrefList.h
+++ b/modules/libpref/init/StaticPrefList.h
@@ -1936,16 +1936,37 @@ VARCACHE_PREF(
 
 // Password protection
 VARCACHE_PREF(
   "browser.safebrowsing.passwords.enabled",
    browser_safebrowsing_passwords_enabled,
   bool, false
 )
 
+// Malware protection
+VARCACHE_PREF(
+  "browser.safebrowsing.malware.enabled",
+   browser_safebrowsing_malware_enabled,
+  bool, true
+)
+
+// Phishing protection
+VARCACHE_PREF(
+  "browser.safebrowsing.phishing.enabled",
+   browser_safebrowsing_phishing_enabled,
+  bool, true
+)
+
+// Blocked plugin content
+VARCACHE_PREF(
+  "browser.safebrowsing.blockedURIs.enabled",
+   browser_safebrowsing_blockedURIs_enabled,
+  bool, true
+)
+
 //---------------------------------------------------------------------------
 // ChannelClassifier prefs
 //---------------------------------------------------------------------------
 
 VARCACHE_PREF(
   "channelclassifier.allowlist_example",
    channelclassifier_allowlist_example,
   bool, false
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -5582,19 +5582,17 @@ pref("urlclassifier.gethash.timeout_ms",
 // Update server response timeout for Safe Browsing
 pref("urlclassifier.update.response_timeout_ms", 30000);
 // Download update timeout for Safe Browsing
 pref("urlclassifier.update.timeout_ms", 90000);
 
 // Name of the about: page to display Safe Browsing warnings (bug 399233)
 pref("urlclassifier.alternate_error_page", "blocked");
 
-// Enable phishing & malware protection.
-pref("browser.safebrowsing.phishing.enabled", true);
-pref("browser.safebrowsing.malware.enabled", true);
+// Enable safe-browsing debugging
 pref("browser.safebrowsing.debug", false);
 
 // Allow users to ignore Safe Browsing warnings.
 pref("browser.safebrowsing.allowOverride", true);
 
 // These names are approved by the Google Safe Browsing team.
 // Any changes must be coordinated with them.
 #ifdef MOZILLA_OFFICIAL
@@ -5647,17 +5645,16 @@ pref("browser.safebrowsing.provider.mozi
 // Set to a date in the past to force immediate download in new profiles.
 pref("browser.safebrowsing.provider.mozilla.nextupdatetime", "1");
 // Block lists for tracking protection. The name values will be used as the keys
 // to lookup the localized name in preferences.properties.
 pref("browser.safebrowsing.provider.mozilla.lists.base", "moz-std");
 pref("browser.safebrowsing.provider.mozilla.lists.content", "moz-full");
 
 // The table and global pref for blocking plugin content
-pref("browser.safebrowsing.blockedURIs.enabled", true);
 pref("urlclassifier.blockedTable", "test-block-simple,mozplugin-block-digest256");
 
 // Flash blocking tables
 pref("urlclassifier.flashAllowTable", "allow-flashallow-digest256");
 pref("urlclassifier.flashAllowExceptTable", "except-flashallow-digest256");
 pref("urlclassifier.flashTable", "block-flash-digest256");
 pref("urlclassifier.flashExceptTable", "except-flash-digest256");
 pref("urlclassifier.flashSubDocTable", "block-flashsubdoc-digest256");
--- a/netwerk/url-classifier/UrlClassifierFeatureFactory.cpp
+++ b/netwerk/url-classifier/UrlClassifierFeatureFactory.cpp
@@ -6,16 +6,17 @@
 
 #include "mozilla/net/UrlClassifierFeatureFactory.h"
 
 // List of Features
 #include "UrlClassifierFeatureCryptomining.h"
 #include "UrlClassifierFeatureFingerprinting.h"
 #include "UrlClassifierFeatureFlash.h"
 #include "UrlClassifierFeatureLoginReputation.h"
+#include "UrlClassifierFeatureNoChannel.h"
 #include "UrlClassifierFeatureTrackingProtection.h"
 #include "UrlClassifierFeatureTrackingAnnotation.h"
 #include "UrlClassifierFeatureCustomTables.h"
 
 #include "nsAppRunner.h"
 
 namespace mozilla {
 namespace net {
@@ -25,16 +26,17 @@ namespace net {
   if (!XRE_IsParentProcess()) {
     return;
   }
 
   UrlClassifierFeatureCryptomining::MaybeShutdown();
   UrlClassifierFeatureFingerprinting::MaybeShutdown();
   UrlClassifierFeatureFlash::MaybeShutdown();
   UrlClassifierFeatureLoginReputation::MaybeShutdown();
+  UrlClassifierFeatureNoChannel::MaybeShutdown();
   UrlClassifierFeatureTrackingAnnotation::MaybeShutdown();
   UrlClassifierFeatureTrackingProtection::MaybeShutdown();
 }
 
 /* static */ void UrlClassifierFeatureFactory::GetFeaturesFromChannel(
     nsIChannel* aChannel,
     nsTArray<nsCOMPtr<nsIUrlClassifierFeature>>& aFeatures) {
   MOZ_ASSERT(XRE_IsParentProcess());
@@ -122,16 +124,22 @@ UrlClassifierFeatureFactory::GetFeatureB
   }
 
   // We use Flash feature just for document loading.
   feature = UrlClassifierFeatureFlash::GetIfNameMatches(aName);
   if (feature) {
     return feature.forget();
   }
 
+  // NoChannel features
+  feature = UrlClassifierFeatureNoChannel::GetIfNameMatches(aName);
+  if (feature) {
+    return feature.forget();
+  }
+
   return nullptr;
 }
 
 /* static */ void UrlClassifierFeatureFactory::GetFeatureNames(
     nsTArray<nsCString>& aArray) {
   if (!XRE_IsParentProcess()) {
     return;
   }
@@ -163,19 +171,28 @@ UrlClassifierFeatureFactory::GetFeatureB
 
   // Login reputation
   name.Assign(UrlClassifierFeatureLoginReputation::Name());
   if (!name.IsEmpty()) {
     aArray.AppendElement(name);
   }
 
   // Flash features
-  nsTArray<nsCString> features;
-  UrlClassifierFeatureFlash::GetFeatureNames(features);
-  aArray.AppendElements(features);
+  {
+    nsTArray<nsCString> features;
+    UrlClassifierFeatureFlash::GetFeatureNames(features);
+    aArray.AppendElements(features);
+  }
+
+  // NoChannel features
+  {
+    nsTArray<nsCString> features;
+    UrlClassifierFeatureNoChannel::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,
new file mode 100644
--- /dev/null
+++ b/netwerk/url-classifier/UrlClassifierFeatureNoChannel.cpp
@@ -0,0 +1,104 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "UrlClassifierFeatureNoChannel.h"
+
+namespace mozilla {
+namespace net {
+
+struct UrlClassifierFeatureNoChannel::NoChannelFeature {
+  const char* mName;
+  const char* mBlacklistPrefTables;
+  bool (*mPref)();
+
+  RefPtr<UrlClassifierFeatureNoChannel> mFeature;
+};
+
+namespace {
+
+struct UrlClassifierFeatureNoChannel::NoChannelFeature sNoChannelFeaturesMap[] =
+    {
+        {"malware", "urlclassifier.malwareTable",
+         StaticPrefs::browser_safebrowsing_malware_enabled},
+        {"phishing", "urlclassifier.phishTable",
+         StaticPrefs::browser_safebrowsing_phishing_enabled},
+        {"blockedURIs", "urlclassifier.blockedTable",
+         StaticPrefs::browser_safebrowsing_blockedURIs_enabled},
+};
+
+}  // namespace
+
+UrlClassifierFeatureNoChannel::UrlClassifierFeatureNoChannel(
+    const UrlClassifierFeatureNoChannel::NoChannelFeature& aFeature)
+    : UrlClassifierFeatureBase(
+          nsDependentCString(aFeature.mName),
+          nsDependentCString(aFeature.mBlacklistPrefTables),
+          EmptyCString(),    // aPrefWhitelistPrefTbles,
+          EmptyCString(),    // aPrefBlacklistHosts
+          EmptyCString(),    // aPrefWhitelistHosts
+          EmptyCString(),    // aPrefBlacklistTableName
+          EmptyCString(),    // aPrefWhitelistTableName
+          EmptyCString()) {  // aPrefSkipHosts
+}
+
+/* static */ void UrlClassifierFeatureNoChannel::GetFeatureNames(
+    nsTArray<nsCString>& aArray) {
+  for (const NoChannelFeature& feature : sNoChannelFeaturesMap) {
+    if (feature.mPref()) {
+      aArray.AppendElement(nsDependentCString(feature.mName));
+    }
+  }
+}
+
+/* static */ void UrlClassifierFeatureNoChannel::MaybeInitialize() {
+  for (NoChannelFeature& feature : sNoChannelFeaturesMap) {
+    if (!feature.mFeature && feature.mPref()) {
+      feature.mFeature = new UrlClassifierFeatureNoChannel(feature);
+      feature.mFeature->InitializePreferences();
+    }
+  }
+}
+
+/* static */ void UrlClassifierFeatureNoChannel::MaybeShutdown() {
+  for (NoChannelFeature& feature : sNoChannelFeaturesMap) {
+    if (feature.mFeature) {
+      feature.mFeature->ShutdownPreferences();
+      feature.mFeature = nullptr;
+    }
+  }
+}
+
+/* static */ already_AddRefed<nsIUrlClassifierFeature>
+UrlClassifierFeatureNoChannel::GetIfNameMatches(const nsACString& aName) {
+  MaybeInitialize();
+
+  for (const NoChannelFeature& feature : sNoChannelFeaturesMap) {
+    if (feature.mPref() && aName.Equals(feature.mName)) {
+      MOZ_ASSERT(feature.mFeature);
+      nsCOMPtr<nsIUrlClassifierFeature> self = feature.mFeature.get();
+      return self.forget();
+    }
+  }
+
+  return nullptr;
+}
+
+NS_IMETHODIMP
+UrlClassifierFeatureNoChannel::ProcessChannel(nsIChannel* aChannel,
+                                              const nsACString& aList,
+                                              bool* aShouldContinue) {
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
+UrlClassifierFeatureNoChannel::GetURIByListType(
+    nsIChannel* aChannel, nsIUrlClassifierFeature::listType aListType,
+    nsIURI** aURI) {
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+}  // namespace net
+}  // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/netwerk/url-classifier/UrlClassifierFeatureNoChannel.h
@@ -0,0 +1,43 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_UrlClassifierFeatureNoChannel_h
+#define mozilla_UrlClassifierFeatureNoChannel_h
+
+#include "UrlClassifierFeatureBase.h"
+
+namespace mozilla {
+namespace net {
+
+class UrlClassifierFeatureNoChannel final : public UrlClassifierFeatureBase {
+ public:
+  struct NoChannelFeature;
+
+  static void GetFeatureNames(nsTArray<nsCString>& aNames);
+
+  static void MaybeShutdown();
+
+  static already_AddRefed<nsIUrlClassifierFeature> GetIfNameMatches(
+      const nsACString& aName);
+
+  NS_IMETHOD
+  ProcessChannel(nsIChannel* aChannel, const nsACString& aList,
+                 bool* aShouldContinue) override;
+
+  NS_IMETHOD GetURIByListType(nsIChannel* aChannel,
+                              nsIUrlClassifierFeature::listType aListType,
+                              nsIURI** aURI) override;
+
+ private:
+  explicit UrlClassifierFeatureNoChannel(const NoChannelFeature& aFeature);
+
+  static void MaybeInitialize();
+};
+
+}  // namespace net
+}  // namespace mozilla
+
+#endif  // mozilla_UrlClassifierFeatureNoChannel_h
--- a/netwerk/url-classifier/moz.build
+++ b/netwerk/url-classifier/moz.build
@@ -23,16 +23,17 @@ UNIFIED_SOURCES += [
     'UrlClassifierCommon.cpp',
     'UrlClassifierFeatureBase.cpp',
     'UrlClassifierFeatureCryptomining.cpp',
     'UrlClassifierFeatureCustomTables.cpp',
     'UrlClassifierFeatureFactory.cpp',
     'UrlClassifierFeatureFingerprinting.cpp',
     'UrlClassifierFeatureFlash.cpp',
     'UrlClassifierFeatureLoginReputation.cpp',
+    'UrlClassifierFeatureNoChannel.cpp',
     'UrlClassifierFeatureResult.cpp',
     'UrlClassifierFeatureTrackingAnnotation.cpp',
     'UrlClassifierFeatureTrackingProtection.cpp',
 ]
 
 EXPORTS.mozilla.net += [
     'AsyncUrlChannelClassifier.h',
     'UrlClassifierCommon.h',