Bug 1524688: Part 8 - Convert URL classifier to static registration r=Ehsan
☠☠ backed out by 3b1b94e39795 ☠ ☠
authorKris Maglione <maglione.k@gmail.com>
Tue, 29 Jan 2019 18:41:19 -0800
changeset 458981 fdc6c4ed241a
parent 458980 5ce5986068f0
child 458982 4fb0f0a59fe2
push id111909
push usermaglione.k@gmail.com
push dateThu, 14 Feb 2019 02:30:40 +0000
treeherdermozilla-inbound@81dc12cc9257 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1524688
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 1524688: Part 8 - Convert URL classifier to static registration r=Ehsan
browser/installer/package-manifest.in
mobile/android/installer/package-manifest.in
toolkit/components/url-classifier/UrlClassifierHashCompleter.jsm
toolkit/components/url-classifier/UrlClassifierLib.jsm
toolkit/components/url-classifier/UrlClassifierListManager.jsm
toolkit/components/url-classifier/components.conf
toolkit/components/url-classifier/moz.build
toolkit/components/url-classifier/nsURLClassifier.manifest
toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js
toolkit/components/url-classifier/nsUrlClassifierLib.js
toolkit/components/url-classifier/nsUrlClassifierListManager.js
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -339,22 +339,16 @@
 @RESPATH@/browser/components/pdfjs.js
 
 ; Modules
 @RESPATH@/browser/modules/*
 @RESPATH@/modules/*
 @RESPATH@/browser/actors/*
 @RESPATH@/actors/*
 
-; Safe Browsing
-@RESPATH@/components/nsURLClassifier.manifest
-@RESPATH@/components/nsUrlClassifierHashCompleter.js
-@RESPATH@/components/nsUrlClassifierListManager.js
-@RESPATH@/components/nsUrlClassifierLib.js
-
 ; Security Reports
 @RESPATH@/components/SecurityReporter.manifest
 @RESPATH@/components/SecurityReporter.js
 
 ; ANGLE GLES-on-D3D rendering library
 #ifdef MOZ_ANGLE_RENDERER
 @BINPATH@/libEGL.dll
 @BINPATH@/libGLESv2.dll
--- a/mobile/android/installer/package-manifest.in
+++ b/mobile/android/installer/package-manifest.in
@@ -222,22 +222,16 @@
 
 @BINPATH@/components/mozIntl.manifest
 @BINPATH@/components/mozIntl.js
 
 ; Modules
 @BINPATH@/modules/*
 @BINPATH@/actors/*
 
-; Safe Browsing
-@BINPATH@/components/nsURLClassifier.manifest
-@BINPATH@/components/nsUrlClassifierHashCompleter.js
-@BINPATH@/components/nsUrlClassifierListManager.js
-@BINPATH@/components/nsUrlClassifierLib.js
-
 ; Security Reports
 @BINPATH@/components/SecurityReporter.manifest
 @BINPATH@/components/SecurityReporter.js
 
 ; [Browser Chrome Files]
 @BINPATH@/chrome/toolkit@JAREXT@
 @BINPATH@/chrome/toolkit.manifest
 
rename from toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js
rename to toolkit/components/url-classifier/UrlClassifierHashCompleter.jsm
--- a/toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js
+++ b/toolkit/components/url-classifier/UrlClassifierHashCompleter.jsm
@@ -840,23 +840,15 @@ HashCompleterRequest.prototype = {
         this.telemetryClockStart = 0;
       }
 
       Services.obs.removeObserver(this, "quit-application");
     }
   },
 };
 
-// Converts a URL safe base64 string to a normal base64 string. Will not change
-// normal base64 strings. This is modelled after the same function in
-// nsUrlClassifierUtils.h.
-function unUrlsafeBase64(aStr) {
-  return !aStr ? "" : aStr.replace(/-/g, "+")
-                          .replace(/_/g, "/");
-}
-
 function errorWithStack() {
   let err = new Error();
   err.value = Cr.NS_ERROR_FAILURE;
   return err;
 }
 
-this.NSGetFactory = XPCOMUtils.generateNSGetFactory([HashCompleter]);
+var EXPORTED_SYMBOLS = ["HashCompleter"];
rename from toolkit/components/url-classifier/nsUrlClassifierLib.js
rename to toolkit/components/url-classifier/UrlClassifierLib.jsm
--- a/toolkit/components/url-classifier/nsUrlClassifierLib.js
+++ b/toolkit/components/url-classifier/UrlClassifierLib.jsm
@@ -1,19 +1,16 @@
 /* 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/. */
 
 // We wastefully reload the same JS files across components.  This puts all
 // the common JS files used by safebrowsing and url-classifier into a
 // single component.
 
-const G_GDEBUG = false;
-
-const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 const PREF_DISABLE_TEST_BACKOFF = "browser.safebrowsing.provider.test.disableBackoff";
 /**
  * Partially applies a function to a particular "this object" and zero or
  * more arguments. The result is a new function with some arguments of the first
  * function pre-filled and the value of |this| "pre-specified".
  *
@@ -181,16 +178,17 @@ RequestBackoff.prototype.isErrorStatus =
           HTTP_SEE_OTHER == status ||
           HTTP_TEMPORARY_REDIRECT == status);
 };
 
 // Wrap a general-purpose |RequestBackoff| to a v4-specific one
 // since both listmanager and hashcompleter would use it.
 // Note that |maxRequests| and |requestPeriod| is still configurable
 // to throttle pending requests.
+/* exported RequestBackoffV4 */
 function RequestBackoffV4(maxRequests, requestPeriod,
                           provider = null) {
   let rand = Math.random();
   let retryInterval = Math.floor(15 * 60 * 1000 * (rand + 1)); // 15 ~ 30 min.
   let backoffInterval = Math.floor(30 * 60 * 1000 * (rand + 1)); // 30 ~ 60 min.
 
   return new RequestBackoff(2 /* max errors */,
                 retryInterval /* retry interval, 15~30 min */,
@@ -203,12 +201,11 @@ function RequestBackoffV4(maxRequests, r
 }
 
 // Expose this whole component.
 var lib = this;
 
 function UrlClassifierLib() {
   this.wrappedJSObject = lib;
 }
-UrlClassifierLib.prototype.classID = Components.ID("{26a4a019-2827-4a89-a85c-5931a678823a}");
 UrlClassifierLib.prototype.QueryInterface = ChromeUtils.generateQI([]);
 
-this.NSGetFactory = XPCOMUtils.generateNSGetFactory([UrlClassifierLib]);
+var EXPORTED_SYMBOLS = ["UrlClassifierLib"];
rename from toolkit/components/url-classifier/nsUrlClassifierListManager.js
rename to toolkit/components/url-classifier/UrlClassifierListManager.jsm
--- a/toolkit/components/url-classifier/nsUrlClassifierListManager.js
+++ b/toolkit/components/url-classifier/UrlClassifierListManager.jsm
@@ -1,13 +1,12 @@
 /* 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/. */
 
-const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 // This is the only implementation of nsIUrlListManager.
 // A class that manages lists, namely white and black lists for
 // phishing or malware protection. The ListManager knows how to fetch,
 // update, and store lists.
 //
 // There is a single listmanager for the whole application.
@@ -692,22 +691,13 @@ function Init() {
   modScope.BindToObject = jslib.BindToObject;
   modScope.RequestBackoffV4 = jslib.RequestBackoffV4;
 
   // We only need to call Init once.
   modScope.Init = function() {};
 }
 
 function RegistrationData() {
+  Init();
+  return new PROT_ListManager();
 }
-RegistrationData.prototype = {
-    classID: Components.ID("{ca168834-cc00-48f9-b83c-fd018e58cae3}"),
-    _xpcom_factory: {
-        createInstance(outer, iid) {
-            if (outer != null)
-                throw Cr.NS_ERROR_NO_AGGREGATION;
-            Init();
-            return (new PROT_ListManager()).QueryInterface(iid);
-        },
-    },
-};
 
-this.NSGetFactory = XPCOMUtils.generateNSGetFactory([RegistrationData]);
+var EXPORTED_SYMBOLS = ["RegistrationData"];
new file mode 100644
--- /dev/null
+++ b/toolkit/components/url-classifier/components.conf
@@ -0,0 +1,26 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+Classes = [
+    {
+        'cid': '{26a4a019-2827-4a89-a85c-5931a678823a}',
+        'contract_ids': ['@mozilla.org/url-classifier/jslib;1'],
+        'jsm': 'resource://gre/modules/UrlClassifierLib.jsm',
+        'constructor': 'UrlClassifierLib',
+    },
+    {
+        'cid': '{ca168834-cc00-48f9-b83c-fd018e58cae3}',
+        'contract_ids': ['@mozilla.org/url-classifier/listmanager;1'],
+        'jsm': 'resource://gre/modules/UrlClassifierListManager.jsm',
+        'constructor': 'RegistrationData',
+    },
+    {
+        'cid': '{9111de73-9322-4bfc-8b65-2b727f3e6ec8}',
+        'contract_ids': ['@mozilla.org/url-classifier/hashcompleter;1'],
+        'jsm': 'resource://gre/modules/UrlClassifierHashCompleter.jsm',
+        'constructor': 'HashCompleter',
+    },
+]
--- a/toolkit/components/url-classifier/moz.build
+++ b/toolkit/components/url-classifier/moz.build
@@ -48,25 +48,25 @@ SOURCES += [
     'VariableLengthPrefixSet.cpp',
 ]
 
 # contains variables that conflict with LookupCache.cpp
 SOURCES += [
     'HashStore.cpp',
 ]
 
-EXTRA_COMPONENTS += [
-    'nsURLClassifier.manifest',
-    'nsUrlClassifierHashCompleter.js',
-    'nsUrlClassifierLib.js',
-    'nsUrlClassifierListManager.js',
+EXTRA_JS_MODULES += [
+    'SafeBrowsing.jsm',
+    'UrlClassifierHashCompleter.jsm',
+    'UrlClassifierLib.jsm',
+    'UrlClassifierListManager.jsm',
 ]
 
-EXTRA_JS_MODULES += [
-    'SafeBrowsing.jsm',
+XPCOM_MANIFESTS += [
+    'components.conf',
 ]
 
 EXPORTS += [
     'chromium/safebrowsing.pb.h',
     'Entries.h',
     'LookupCache.h',
     'LookupCacheV4.h',
     'nsUrlClassifierPrefixSet.h',
deleted file mode 100644
--- a/toolkit/components/url-classifier/nsURLClassifier.manifest
+++ /dev/null
@@ -1,6 +0,0 @@
-component {26a4a019-2827-4a89-a85c-5931a678823a} nsUrlClassifierLib.js
-contract @mozilla.org/url-classifier/jslib;1 {26a4a019-2827-4a89-a85c-5931a678823a}
-component {ca168834-cc00-48f9-b83c-fd018e58cae3} nsUrlClassifierListManager.js
-contract @mozilla.org/url-classifier/listmanager;1 {ca168834-cc00-48f9-b83c-fd018e58cae3}
-component {9111de73-9322-4bfc-8b65-2b727f3e6ec8} nsUrlClassifierHashCompleter.js
-contract @mozilla.org/url-classifier/hashcompleter;1 {9111de73-9322-4bfc-8b65-2b727f3e6ec8}