From 0c73d9a3c9eac3e5c8aa0a321d628c95d6d0d6ea Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Tue, 29 Jan 2019 20:00:19 -0800 Subject: [PATCH] Bug 1524688: Part 11 - Convert search service to static registration. r=mikedeboer --HG-- rename : toolkit/components/search/nsSearchService.js => toolkit/components/search/SearchService.jsm rename : toolkit/components/search/nsSearchSuggestions.js => toolkit/components/search/SearchSuggestions.jsm rename : toolkit/components/search/nsSidebar.js => toolkit/components/search/Sidebar.jsm extra : source : 9895239d8ac64bef30e5f6390f18456ffe209e4e --- browser/installer/package-manifest.in | 3 -- mobile/android/installer/package-manifest.in | 2 - .../{nsSearchService.js => SearchService.jsm} | 42 +------------------ ...chSuggestions.js => SearchSuggestions.jsm} | 4 +- .../search/{nsSidebar.js => Sidebar.jsm} | 3 +- toolkit/components/search/components.conf | 33 +++++++++++++++ toolkit/components/search/moz.build | 16 +++---- .../components/search/toolkitsearch.manifest | 8 ---- 8 files changed, 44 insertions(+), 67 deletions(-) rename toolkit/components/search/{nsSearchService.js => SearchService.jsm} (99%) rename toolkit/components/search/{nsSearchSuggestions.js => SearchSuggestions.jsm} (97%) rename toolkit/components/search/{nsSidebar.js => Sidebar.jsm} (90%) create mode 100644 toolkit/components/search/components.conf diff --git a/browser/installer/package-manifest.in b/browser/installer/package-manifest.in index f51100fea970..6f65bed845fa 100644 --- a/browser/installer/package-manifest.in +++ b/browser/installer/package-manifest.in @@ -197,9 +197,6 @@ @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 diff --git a/mobile/android/installer/package-manifest.in b/mobile/android/installer/package-manifest.in index 8d517c21e88c..0db47e570c89 100644 --- a/mobile/android/installer/package-manifest.in +++ b/mobile/android/installer/package-manifest.in @@ -123,8 +123,6 @@ @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 diff --git a/toolkit/components/search/nsSearchService.js b/toolkit/components/search/SearchService.jsm similarity index 99% rename from toolkit/components/search/nsSearchService.js rename to toolkit/components/search/SearchService.jsm index bb19d89a7256..cf1ba32cd0a3 100644 --- a/toolkit/components/search/nsSearchService.js +++ b/toolkit/components/search/SearchService.jsm @@ -8,15 +8,11 @@ const {PromiseUtils} = ChromeUtils.import("resource://gre/modules/PromiseUtils.j 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", }); @@ -51,21 +47,12 @@ XPCOMUtils.defineLazyGetter(this, "gEncoder", }); -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"; @@ -92,9 +79,6 @@ const SEARCH_SERVICE_TOPIC = "browser-search-service"; */ 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; @@ -104,8 +88,6 @@ 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; @@ -148,7 +130,6 @@ 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"; @@ -189,7 +170,6 @@ const SEARCH_DEFAULT_UPDATE_INTERVAL = 7; // 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. */ @@ -732,21 +712,6 @@ function getVerificationHash(aName) { 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 @@ -868,11 +833,6 @@ function notifyAction(aEngine, 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. */ @@ -4532,4 +4492,4 @@ var engineUpdateService = { }, }; -this.NSGetFactory = XPCOMUtils.generateNSGetFactory([SearchService]); +var EXPORTED_SYMBOLS = ["SearchService"]; diff --git a/toolkit/components/search/nsSearchSuggestions.js b/toolkit/components/search/SearchSuggestions.jsm similarity index 97% rename from toolkit/components/search/nsSearchSuggestions.js rename to toolkit/components/search/SearchSuggestions.jsm index cc793e684e1d..40d8f8d5981e 100644 --- a/toolkit/components/search/nsSearchSuggestions.js +++ b/toolkit/components/search/SearchSuggestions.jsm @@ -2,7 +2,6 @@ * 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", @@ -179,5 +178,4 @@ SearchSuggestAutoComplete.prototype = { serviceURL: "", }; -var component = [SearchSuggestAutoComplete]; -this.NSGetFactory = XPCOMUtils.generateNSGetFactory(component); +var EXPORTED_SYMBOLS = ["SearchSuggestAutoComplete"]; diff --git a/toolkit/components/search/nsSidebar.js b/toolkit/components/search/Sidebar.jsm similarity index 90% rename from toolkit/components/search/nsSidebar.js rename to toolkit/components/search/Sidebar.jsm index 9672e4a1964f..381fb938f2b4 100644 --- a/toolkit/components/search/nsSidebar.js +++ b/toolkit/components/search/Sidebar.jsm @@ -3,7 +3,6 @@ * 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() { @@ -43,4 +42,4 @@ nsSidebar.prototype = { QueryInterface: ChromeUtils.generateQI([Ci.nsIDOMGlobalPropertyInitializer]), }; -this.NSGetFactory = XPCOMUtils.generateNSGetFactory([nsSidebar]); +var EXPORTED_SYMBOLS = ["nsSidebar"]; diff --git a/toolkit/components/search/components.conf b/toolkit/components/search/components.conf new file mode 100644 index 000000000000..8182d3661d23 --- /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', + }, + ] diff --git a/toolkit/components/search/moz.build b/toolkit/components/search/moz.build index 8864aafe6358..651cd75ef8e8 100644 --- a/toolkit/components/search/moz.build +++ b/toolkit/components/search/moz.build @@ -14,26 +14,26 @@ if CONFIG['MOZ_TOOLKIT_SEARCH']: 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('**'): diff --git a/toolkit/components/search/toolkitsearch.manifest b/toolkit/components/search/toolkitsearch.manifest index b7c55da0e966..c69934e2d3a9 100644 --- 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