Bug 1524688: Part 11 - Convert search service to static registration. r=mikedeboer
☠☠ backed out by 3b1b94e39795 ☠ ☠
authorKris Maglione <maglione.k@gmail.com>
Tue, 29 Jan 2019 20:00:19 -0800
changeset 458984 9895239d8ac6
parent 458983 25f982fd53bd
child 458985 6dcacead1746
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)
reviewersmikedeboer
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 11 - Convert search service to static registration. r=mikedeboer
browser/installer/package-manifest.in
mobile/android/installer/package-manifest.in
toolkit/components/search/SearchService.jsm
toolkit/components/search/SearchSuggestions.jsm
toolkit/components/search/Sidebar.jsm
toolkit/components/search/components.conf
toolkit/components/search/moz.build
toolkit/components/search/nsSearchService.js
toolkit/components/search/nsSearchSuggestions.js
toolkit/components/search/nsSidebar.js
toolkit/components/search/toolkitsearch.manifest
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -192,19 +192,16 @@
 @RESPATH@/browser/components/EnterprisePoliciesContent.js
 @RESPATH@/browser/components/EnterprisePolicies.manifest
 @RESPATH@/components/Downloads.manifest
 @RESPATH@/components/DownloadLegacy.js
 @RESPATH@/components/PageThumbsComponents.manifest
 @RESPATH@/components/crashmonitor.manifest
 @RESPATH@/components/nsCrashMonitor.js
 @RESPATH@/components/toolkitsearch.manifest
-@RESPATH@/components/nsSearchService.js
-@RESPATH@/components/nsSearchSuggestions.js
-@RESPATH@/components/nsSidebar.js
 #ifdef NIGHTLY_BUILD
 @RESPATH@/browser/components/payments.manifest
 @RESPATH@/browser/components/paymentUIService.js
 #endif
 @RESPATH@/components/TooltipTextProvider.js
 @RESPATH@/components/TooltipTextProvider.manifest
 @RESPATH@/components/WebVTT.manifest
 @RESPATH@/components/WebVTTParserWrapper.js
--- a/mobile/android/installer/package-manifest.in
+++ b/mobile/android/installer/package-manifest.in
@@ -118,18 +118,16 @@
 @BINPATH@/components/WellKnownOpportunisticUtils.manifest
 @BINPATH@/components/mozProtocolHandler.js
 @BINPATH@/components/mozProtocolHandler.manifest
 #ifndef MOZ_GECKOVIEW_JAR
 @BINPATH@/components/nsDNSServiceDiscovery.manifest
 @BINPATH@/components/nsDNSServiceDiscovery.js
 #endif
 @BINPATH@/components/toolkitsearch.manifest
-@BINPATH@/components/nsSearchService.js
-@BINPATH@/components/nsSidebar.js
 @BINPATH@/components/TooltipTextProvider.js
 @BINPATH@/components/TooltipTextProvider.manifest
 @BINPATH@/components/NetworkGeolocationProvider.manifest
 @BINPATH@/components/NetworkGeolocationProvider.js
 
 @BINPATH@/components/extensions.manifest
 
 #ifndef MOZ_GECKOVIEW_JAR
rename from toolkit/components/search/nsSearchService.js
rename to toolkit/components/search/SearchService.jsm
--- a/toolkit/components/search/nsSearchService.js
+++ b/toolkit/components/search/SearchService.jsm
@@ -3,25 +3,21 @@
  * 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");
 const {PromiseUtils} = ChromeUtils.import("resource://gre/modules/PromiseUtils.jsm");
 const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 
 XPCOMUtils.defineLazyModuleGetters(this, {
-  AsyncShutdown: "resource://gre/modules/AsyncShutdown.jsm",
   DeferredTask: "resource://gre/modules/DeferredTask.jsm",
   OS: "resource://gre/modules/osfile.jsm",
-  Deprecated: "resource://gre/modules/Deprecated.jsm",
   SearchStaticData: "resource://gre/modules/SearchStaticData.jsm",
   setTimeout: "resource://gre/modules/Timer.jsm",
   clearTimeout: "resource://gre/modules/Timer.jsm",
-  Lz4: "resource://gre/modules/lz4.js",
-  NetUtil: "resource://gre/modules/NetUtil.jsm",
   ExtensionParent: "resource://gre/modules/ExtensionParent.jsm",
 });
 
 XPCOMUtils.defineLazyServiceGetters(this, {
   gEnvironment: ["@mozilla.org/process/environment;1", "nsIEnvironment"],
   gChromeReg: ["@mozilla.org/chrome/chrome-registry;1", "nsIChromeRegistry"],
 });
 
@@ -46,31 +42,22 @@ XPCOMUtils.defineLazyGlobalGetters(this,
 
 // A text encoder to UTF8, used whenever we commit the cache to disk.
 XPCOMUtils.defineLazyGetter(this, "gEncoder",
                             function() {
                               return new TextEncoder();
                             });
 
 
-const MODE_RDONLY   = 0x01;
-const MODE_WRONLY   = 0x02;
-const MODE_CREATE   = 0x08;
-const MODE_APPEND   = 0x10;
-const MODE_TRUNCATE = 0x20;
-const PERMS_FILE    = 0o644;
-
 // Directory service keys
 const NS_APP_DISTRIBUTION_SEARCH_DIR_LIST = "SrchPluginsDistDL";
-const NS_APP_USER_PROFILE_50_DIR = "ProfD";
 
 // We load plugins from APP_SEARCH_PREFIX, where a list.json
 // file needs to exist to list available engines.
 const APP_SEARCH_PREFIX = "resource://search-plugins/";
-const EXT_SEARCH_PREFIX = "resource://search-extensions/";
 
 // See documentation in nsISearchService.idl.
 const SEARCH_ENGINE_TOPIC        = "browser-search-engine-modified";
 const TOPIC_LOCALES_CHANGE       = "intl:app-locales-changed";
 const QUIT_APPLICATION_TOPIC     = "quit-application";
 
 const SEARCH_ENGINE_REMOVED      = "engine-removed";
 const SEARCH_ENGINE_ADDED        = "engine-added";
@@ -87,30 +74,25 @@ const SEARCH_ENGINE_DEFAULT      = "engi
  */
 const SEARCH_SERVICE_TOPIC       = "browser-search-service";
 
 /**
  * Sent whenever the cache is fully written to disk.
  */
 const SEARCH_SERVICE_CACHE_WRITTEN  = "write-cache-to-disk-complete";
 
-// Delay for lazy serialization (ms)
-const LAZY_SERIALIZE_DELAY = 100;
-
 // Delay for batching invalidation of the JSON cache (ms)
 const CACHE_INVALIDATION_DELAY = 1000;
 
 // Current cache version. This should be incremented if the format of the cache
 // file is modified.
 const CACHE_VERSION = 1;
 
 const CACHE_FILENAME = "search.json.mozlz4";
 
-const NEW_LINES = /(\r\n|\r|\n)/;
-
 // Set an arbitrary cap on the maximum icon size. Without this, large icons can
 // cause big delays when loading them at startup.
 const MAX_ICON_SIZE   = 20000;
 
 // Default charset to use for sending search parameters. ISO-8859-1 is used to
 // match previous nsInternetSearchService behavior as a URL parameter. Label
 // resolution causes windows-1252 to be actually used.
 const DEFAULT_QUERY_CHARSET = "ISO-8859-1";
@@ -143,17 +125,16 @@ const USER_DEFINED = "searchTerms";
 
 // Custom search parameters
 const MOZ_PARAM_LOCALE         = "moz:locale";
 const MOZ_PARAM_DIST_ID        = "moz:distributionID";
 const MOZ_PARAM_OFFICIAL       = "moz:official";
 
 // Supported OpenSearch parameters
 // See http://opensearch.a9.com/spec/1.1/querysyntax/#core
-const OS_PARAM_USER_DEFINED    = "searchTerms";
 const OS_PARAM_INPUT_ENCODING  = "inputEncoding";
 const OS_PARAM_LANGUAGE        = "language";
 const OS_PARAM_OUTPUT_ENCODING = "outputEncoding";
 
 // Default values
 const OS_PARAM_LANGUAGE_DEF         = "*";
 const OS_PARAM_OUTPUT_ENCODING_DEF  = "UTF-8";
 const OS_PARAM_INPUT_ENCODING_DEF   = "UTF-8";
@@ -184,17 +165,16 @@ var OS_UNSUPPORTED_PARAMS = [
 // specifies an updateURL, but not an updateInterval.
 const SEARCH_DEFAULT_UPDATE_INTERVAL = 7;
 
 // The default interval before checking again for the name of the
 // default engine for the region, in seconds. Only used if the response
 // from the server doesn't specify an interval.
 const SEARCH_GEO_DEFAULT_UPDATE_INTERVAL = 2592000; // 30 days.
 
-const SEARCH_COUNTS_HISTOGRAM_KEY = "SEARCH_COUNTS";
 /**
  * Prefixed to all search debug output.
  */
 const SEARCH_LOG_PREFIX = "*** Search: ";
 
 /**
  * Outputs aText to the JavaScript console as well as to stdout.
  */
@@ -728,31 +708,16 @@ function getVerificationHash(aName) {
                  .createInstance(Ci.nsICryptoHash);
   hasher.init(hasher.SHA256);
   hasher.update(data, data.length);
 
   return hasher.finish(true);
 }
 
 /**
- * Safely close a nsISafeOutputStream.
- * @param aFOS
- *        The file output stream to close.
- */
-function closeSafeOutputStream(aFOS) {
-  if (aFOS instanceof Ci.nsISafeOutputStream) {
-    try {
-      aFOS.finish();
-      return;
-    } catch (e) { }
-  }
-  aFOS.close();
-}
-
-/**
  * Wrapper function for nsIIOService::newURI.
  * @param aURLSpec
  *        The URL string from which to create an nsIURI.
  * @returns an nsIURI object, or null if the creation of the URI failed.
  */
 function makeURI(aURLSpec, aCharset) {
   try {
     return Services.io.newURI(aURLSpec, aCharset);
@@ -863,21 +828,16 @@ var gInitialized = false;
 var gReinitializing = false;
 function notifyAction(aEngine, aVerb) {
   if (gInitialized) {
     LOG("NOTIFY: Engine: \"" + aEngine.name + "\"; Verb: \"" + aVerb + "\"");
     Services.obs.notifyObservers(aEngine, SEARCH_ENGINE_TOPIC, aVerb);
   }
 }
 
-function parseJsonFromStream(aInputStream) {
-  let bytes = NetUtil.readInputStream(aInputStream, aInputStream.available());
-  return JSON.parse(new TextDecoder().decode(bytes));
-}
-
 /**
  * Simple object representing a name/value pair.
  */
 function QueryParameter(aName, aValue, aPurpose) {
   if (!aName || (aValue == null))
     FAIL("missing name or value for QueryParameter!");
 
   this.name = aName;
@@ -4527,9 +4487,9 @@ var engineUpdateService = {
     if (engine._iconUpdateURL) {
       // If we're updating the engine too, use the new engine object,
       // otherwise use the existing engine object.
       (testEngine || engine)._setIcon(engine._iconUpdateURL, true);
     }
   },
 };
 
-this.NSGetFactory = XPCOMUtils.generateNSGetFactory([SearchService]);
+var EXPORTED_SYMBOLS = ["SearchService"];
rename from toolkit/components/search/nsSearchSuggestions.js
rename to toolkit/components/search/SearchSuggestions.jsm
--- a/toolkit/components/search/nsSearchSuggestions.js
+++ b/toolkit/components/search/SearchSuggestions.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 {FormAutoCompleteResult} = ChromeUtils.import("resource://gre/modules/nsFormAutoCompleteResult.jsm");
 const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.defineModuleGetter(this, "SearchSuggestionController",
                                "resource://gre/modules/SearchSuggestionController.jsm");
 
 /**
  * SuggestAutoComplete is a base class that implements nsIAutoCompleteSearch
  * and can collect results for a given search by using this._suggestionController.
@@ -174,10 +173,9 @@ function SearchSuggestAutoComplete() {
   this._init();
 }
 SearchSuggestAutoComplete.prototype = {
   classID: Components.ID("{aa892eb4-ffbf-477d-9f9a-06c995ae9f27}"),
   __proto__: SuggestAutoComplete.prototype,
   serviceURL: "",
 };
 
-var component = [SearchSuggestAutoComplete];
-this.NSGetFactory = XPCOMUtils.generateNSGetFactory(component);
+var EXPORTED_SYMBOLS = ["SearchSuggestAutoComplete"];
rename from toolkit/components/search/nsSidebar.js
rename to toolkit/components/search/Sidebar.jsm
--- a/toolkit/components/search/nsSidebar.js
+++ b/toolkit/components/search/Sidebar.jsm
@@ -1,14 +1,13 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- */
 /* 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");
 
 function nsSidebar() {
 }
 
 nsSidebar.prototype = {
   init(window) {
     this.window = window;
@@ -38,9 +37,9 @@ nsSidebar.prototype = {
   // for compatibility with other browsers.  The function has been deprecated
   // and so will not be implemented.
   IsSearchProviderInstalled() {},
 
   classID: Components.ID("{22117140-9c6e-11d3-aaf1-00805f8a4905}"),
   QueryInterface: ChromeUtils.generateQI([Ci.nsIDOMGlobalPropertyInitializer]),
 };
 
-this.NSGetFactory = XPCOMUtils.generateNSGetFactory([nsSidebar]);
+var EXPORTED_SYMBOLS = ["nsSidebar"];
new file mode 100644
--- /dev/null
+++ b/toolkit/components/search/components.conf
@@ -0,0 +1,33 @@
+# -*- 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/.
+
+HAVE_SIDEBAR = buildconfig.substs['MOZ_BUILD_APP'] in ('browser', 'mobile/android', 'xulrunner')
+
+Classes = [
+    {
+        'cid': '{7319788a-fe93-4db3-9f39-818cf08f4256}',
+        'contract_ids': ['@mozilla.org/browser/search-service;1'],
+        'jsm': 'resource://gre/modules/SearchService.jsm',
+        'constructor': 'SearchService',
+        'processes': ProcessSelector.MAIN_PROCESS_ONLY,
+    },
+    {
+        'cid': '{aa892eb4-ffbf-477d-9f9a-06c995ae9f27}',
+        'contract_ids': ['@mozilla.org/autocomplete/search;1?name=search-autocomplete'],
+        'jsm': 'resource://gre/modules/SearchSuggestions.jsm',
+        'constructor': 'SearchSuggestAutoComplete',
+    },
+]
+
+if HAVE_SIDEBAR:
+    Classes += [
+        {
+            'cid': '{22117140-9c6e-11d3-aaf1-00805f8a4905}',
+            'contract_ids': ['@mozilla.org/sidebar;1'],
+            'jsm': 'resource://gre/modules/Sidebar.jsm',
+            'constructor': 'nsSidebar',
+        },
+    ]
--- a/toolkit/components/search/moz.build
+++ b/toolkit/components/search/moz.build
@@ -9,32 +9,32 @@ XPCSHELL_TESTS_MANIFESTS += ['tests/xpcs
 if CONFIG['MOZ_TOOLKIT_SEARCH']:
     XPIDL_SOURCES += [
         'nsISearchService.idl',
     ]
 
 XPIDL_MODULE = 'toolkit_search'
 
 EXTRA_COMPONENTS += [
-    'nsSearchService.js',
-    'nsSearchSuggestions.js',
 ]
 
 if CONFIG['MOZ_BUILD_APP'] in ['browser', 'mobile/android', 'xulrunner']:
-    DEFINES['HAVE_SIDEBAR'] = True
-    EXTRA_COMPONENTS += [
-    'nsSidebar.js',
+    EXTRA_JS_MODULES += [
+        'Sidebar.jsm',
     ]
 
 EXTRA_JS_MODULES += [
+    'SearchService.jsm',
+    'SearchStaticData.jsm',
     'SearchSuggestionController.jsm',
+    'SearchSuggestions.jsm',
 ]
 
-EXTRA_PP_COMPONENTS += [
+EXTRA_COMPONENTS += [
     'toolkitsearch.manifest',
 ]
 
-EXTRA_JS_MODULES += [
-    'SearchStaticData.jsm',
+XPCOM_MANIFESTS += [
+    'components.conf',
 ]
 
 with Files('**'):
     BUG_COMPONENT = ('Firefox', 'Search')
--- a/toolkit/components/search/toolkitsearch.manifest
+++ b/toolkit/components/search/toolkitsearch.manifest
@@ -1,10 +1,2 @@
-component {7319788a-fe93-4db3-9f39-818cf08f4256} nsSearchService.js process=main
-contract @mozilla.org/browser/search-service;1 {7319788a-fe93-4db3-9f39-818cf08f4256} process=main
 # 21600 == 6 hours
 category update-timer nsSearchService @mozilla.org/browser/search-service;1,getService,search-engine-update-timer,browser.search.update.interval,21600
-component {aa892eb4-ffbf-477d-9f9a-06c995ae9f27} nsSearchSuggestions.js
-contract @mozilla.org/autocomplete/search;1?name=search-autocomplete {aa892eb4-ffbf-477d-9f9a-06c995ae9f27}
-#ifdef HAVE_SIDEBAR
-component {22117140-9c6e-11d3-aaf1-00805f8a4905} nsSidebar.js
-contract @mozilla.org/sidebar;1 {22117140-9c6e-11d3-aaf1-00805f8a4905}
-#endif