From 5a80757288f70d0278f3c3124d2abc0029baafab Mon Sep 17 00:00:00 2001 From: Mark Banner Date: Tue, 1 Sep 2020 18:08:22 +0000 Subject: [PATCH] Bug 1619926 - Remove distribution search directory provider definitions. r=daleharvey Also remove DirectoryProvider as it is now unused. Depends on D88018 Differential Revision: https://phabricator.services.mozilla.com/D88019 --- browser/components/build/components.conf | 10 +- browser/components/build/moz.build | 1 - browser/components/build/nsBrowserCompsCID.h | 8 - .../dirprovider/DirectoryProvider.cpp | 168 ------------------ .../dirprovider/DirectoryProvider.h | 47 ----- browser/components/dirprovider/moz.build | 22 --- browser/components/moz.build | 1 - .../tests/unit/data/engine-de-DE.xml | 8 - .../tests/unit/test_distribution.js | 78 +------- browser/components/tests/unit/xpcshell.ini | 1 - xpcom/io/nsAppDirectoryServiceDefs.h | 1 - xpcom/io/nsAppFileLocationProvider.cpp | 3 - 12 files changed, 3 insertions(+), 345 deletions(-) delete mode 100644 browser/components/dirprovider/DirectoryProvider.cpp delete mode 100644 browser/components/dirprovider/DirectoryProvider.h delete mode 100644 browser/components/dirprovider/moz.build delete mode 100644 browser/components/tests/unit/data/engine-de-DE.xml diff --git a/browser/components/build/components.conf b/browser/components/build/components.conf index ae4169e85174..d9079491aade 100644 --- a/browser/components/build/components.conf +++ b/browser/components/build/components.conf @@ -4,15 +4,7 @@ # 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': '{6deb193c-f87d-4078-bc78-5e64655b4d62}', - 'contract_ids': ['@mozilla.org/browser/directory-provider;1'], - 'type': 'mozilla::browser::DirectoryProvider', - 'headers': ['mozilla/browser/DirectoryProvider.h'], - 'categories': {'xpcom-directory-providers': 'browser-directory-provider'}, - }, -] +Classes = [] TOOLKIT = buildconfig.substs['MOZ_WIDGET_TOOLKIT'] diff --git a/browser/components/build/moz.build b/browser/components/build/moz.build index 50b3b9e61e1a..170f181bf871 100644 --- a/browser/components/build/moz.build +++ b/browser/components/build/moz.build @@ -16,7 +16,6 @@ FINAL_LIBRARY = 'xul' LOCAL_INCLUDES += [ '../about', - '../dirprovider', '../migration', '../sessionstore', '../shell', diff --git a/browser/components/build/nsBrowserCompsCID.h b/browser/components/build/nsBrowserCompsCID.h index 7a95285ae5e1..a9ce3f47effb 100644 --- a/browser/components/build/nsBrowserCompsCID.h +++ b/browser/components/build/nsBrowserCompsCID.h @@ -39,11 +39,3 @@ 0xb1, 0x31, 0xd9, 0x3d, 0x7d, 0x70, 0x4f, 0x64 \ } \ } - -// {6DEB193C-F87D-4078-BC78-5E64655B4D62} -#define NS_BROWSERDIRECTORYPROVIDER_CID \ - { \ - 0x6deb193c, 0xf87d, 0x4078, { \ - 0xbc, 0x78, 0x5e, 0x64, 0x65, 0x5b, 0x4d, 0x62 \ - } \ - } diff --git a/browser/components/dirprovider/DirectoryProvider.cpp b/browser/components/dirprovider/DirectoryProvider.cpp deleted file mode 100644 index b16b721cd38c..000000000000 --- a/browser/components/dirprovider/DirectoryProvider.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* 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 "DirectoryProvider.h" - -#include "nsIFile.h" -#include "nsISimpleEnumerator.h" -#include "nsIPrefService.h" -#include "nsIPrefBranch.h" - -#include "nsArrayEnumerator.h" -#include "nsEnumeratorUtils.h" -#include "nsAppDirectoryServiceDefs.h" -#include "nsDirectoryServiceDefs.h" -#include "nsCategoryManagerUtils.h" -#include "nsComponentManagerUtils.h" -#include "nsCOMArray.h" -#include "nsDirectoryServiceUtils.h" -#include "mozilla/ModuleUtils.h" -#include "mozilla/intl/LocaleService.h" -#include "nsServiceManagerUtils.h" -#include "nsString.h" -#include "nsXULAppAPI.h" - -using mozilla::intl::LocaleService; - -namespace mozilla { -namespace browser { - -NS_IMPL_ISUPPORTS(DirectoryProvider, nsIDirectoryServiceProvider, - nsIDirectoryServiceProvider2) - -NS_IMETHODIMP -DirectoryProvider::GetFile(const char* aKey, bool* aPersist, - nsIFile** aResult) { - return NS_ERROR_FAILURE; -} - -// Appends the distribution-specific search engine directories to the -// array. The directory structure is as follows: - -// appdir/ -// \- distribution/ -// \- searchplugins/ -// |- common/ -// \- locale/ -// |- / -// ... -// \- / - -// common engines are loaded for all locales. If there is no locale -// directory for the current locale, there is a pref: -// "distribution.searchplugins.defaultLocale" -// which specifies a default locale to use. - -static void AppendDistroSearchDirs(nsIProperties* aDirSvc, - nsCOMArray& array) { - nsCOMPtr searchPlugins; - nsresult rv = aDirSvc->Get(XRE_APP_DISTRIBUTION_DIR, NS_GET_IID(nsIFile), - getter_AddRefs(searchPlugins)); - if (NS_FAILED(rv)) return; - searchPlugins->AppendNative("searchplugins"_ns); - - nsCOMPtr commonPlugins; - rv = searchPlugins->Clone(getter_AddRefs(commonPlugins)); - if (NS_SUCCEEDED(rv)) { - commonPlugins->AppendNative("common"_ns); - array.AppendObject(commonPlugins); - } - - nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefs) { - nsCOMPtr localePlugins; - rv = searchPlugins->Clone(getter_AddRefs(localePlugins)); - if (NS_FAILED(rv)) return; - - localePlugins->AppendNative("locale"_ns); - - nsAutoCString defLocale; - rv = prefs->GetCharPref("distribution.searchplugins.defaultLocale", - defLocale); - if (NS_SUCCEEDED(rv)) { - nsCOMPtr defLocalePlugins; - rv = localePlugins->Clone(getter_AddRefs(defLocalePlugins)); - if (NS_SUCCEEDED(rv)) { - defLocalePlugins->AppendNative(defLocale); - array.AppendObject(defLocalePlugins); - return; // all done - } - } - - // we didn't have a defaultLocale, use the user agent locale - nsAutoCString locale; - LocaleService::GetInstance()->GetAppLocaleAsBCP47(locale); - - nsCOMPtr curLocalePlugins; - rv = localePlugins->Clone(getter_AddRefs(curLocalePlugins)); - if (NS_SUCCEEDED(rv)) { - curLocalePlugins->AppendNative(locale); - array.AppendObject(curLocalePlugins); - return; // all done - } - } -} - -NS_IMETHODIMP -DirectoryProvider::GetFiles(const char* aKey, nsISimpleEnumerator** aResult) { - if (!strcmp(aKey, NS_APP_DISTRIBUTION_SEARCH_DIR_LIST)) { - nsCOMPtr dirSvc( - do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID)); - if (!dirSvc) return NS_ERROR_FAILURE; - - nsCOMArray distroFiles; - AppendDistroSearchDirs(dirSvc, distroFiles); - - return NS_NewArrayEnumerator(aResult, distroFiles, NS_GET_IID(nsIFile)); - } - - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -DirectoryProvider::AppendingEnumerator::HasMoreElements(bool* aResult) { - *aResult = mNext ? true : false; - return NS_OK; -} - -NS_IMETHODIMP -DirectoryProvider::AppendingEnumerator::GetNext(nsISupports** aResult) { - if (aResult) NS_ADDREF(*aResult = mNext); - - mNext = nullptr; - - // Ignore all errors - - bool more; - while (NS_SUCCEEDED(mBase->HasMoreElements(&more)) && more) { - nsCOMPtr nextbasesupp; - mBase->GetNext(getter_AddRefs(nextbasesupp)); - - nsCOMPtr nextbase(do_QueryInterface(nextbasesupp)); - if (!nextbase) continue; - - nextbase->Clone(getter_AddRefs(mNext)); - if (!mNext) continue; - - char const* const* i = mAppendList; - while (*i) { - mNext->AppendNative(nsDependentCString(*i)); - ++i; - } - - mNext = nullptr; - } - - return NS_OK; -} - -DirectoryProvider::AppendingEnumerator::AppendingEnumerator( - nsISimpleEnumerator* aBase, char const* const* aAppendList) - : mBase(aBase), mAppendList(aAppendList) { - // Initialize mNext to begin. - GetNext(nullptr); -} - -} // namespace browser -} // namespace mozilla diff --git a/browser/components/dirprovider/DirectoryProvider.h b/browser/components/dirprovider/DirectoryProvider.h deleted file mode 100644 index 78682e940727..000000000000 --- a/browser/components/dirprovider/DirectoryProvider.h +++ /dev/null @@ -1,47 +0,0 @@ -/* 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 DirectoryProvider_h__ -#define DirectoryProvider_h__ - -#include "nsIDirectoryService.h" -#include "nsComponentManagerUtils.h" -#include "nsSimpleEnumerator.h" -#include "mozilla/Attributes.h" - -#define NS_BROWSERDIRECTORYPROVIDER_CONTRACTID \ - "@mozilla.org/browser/directory-provider;1" - -namespace mozilla { -namespace browser { - -class DirectoryProvider final : public nsIDirectoryServiceProvider2 { - public: - NS_DECL_ISUPPORTS - NS_DECL_NSIDIRECTORYSERVICEPROVIDER - NS_DECL_NSIDIRECTORYSERVICEPROVIDER2 - - private: - ~DirectoryProvider() {} - - class AppendingEnumerator final : public nsSimpleEnumerator { - public: - NS_DECL_NSISIMPLEENUMERATOR - - AppendingEnumerator(nsISimpleEnumerator* aBase, - char const* const* aAppendList); - - private: - ~AppendingEnumerator() override = default; - - nsCOMPtr mBase; - char const* const* const mAppendList; - nsCOMPtr mNext; - }; -}; - -} // namespace browser -} // namespace mozilla - -#endif // DirectoryProvider_h__ diff --git a/browser/components/dirprovider/moz.build b/browser/components/dirprovider/moz.build deleted file mode 100644 index 5656f4139566..000000000000 --- a/browser/components/dirprovider/moz.build +++ /dev/null @@ -1,22 +0,0 @@ -# -*- 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/. - -with Files("**"): - BUG_COMPONENT = ("Firefox", "General") - -EXPORTS.mozilla.browser += [ - 'DirectoryProvider.h', -] - -SOURCES += [ - 'DirectoryProvider.cpp', -] - -FINAL_LIBRARY = 'browsercomps' - -LOCAL_INCLUDES += [ - '../build' -] diff --git a/browser/components/moz.build b/browser/components/moz.build index c75c10b0c92d..12f001ebc278 100644 --- a/browser/components/moz.build +++ b/browser/components/moz.build @@ -33,7 +33,6 @@ DIRS += [ 'attribution', 'contextualidentity', 'customizableui', - 'dirprovider', 'doh', 'downloads', 'enterprisepolicies', diff --git a/browser/components/tests/unit/data/engine-de-DE.xml b/browser/components/tests/unit/data/engine-de-DE.xml deleted file mode 100644 index b9fa0a46445b..000000000000 --- a/browser/components/tests/unit/data/engine-de-DE.xml +++ /dev/null @@ -1,8 +0,0 @@ - -Google -override-de-DE -UTF-8 - - - - diff --git a/browser/components/tests/unit/test_distribution.js b/browser/components/tests/unit/test_distribution.js index 99b55fa5554f..a0a046bd7da7 100644 --- a/browser/components/tests/unit/test_distribution.js +++ b/browser/components/tests/unit/test_distribution.js @@ -5,37 +5,12 @@ * Tests that preferences are properly set by distribution.ini */ -// Import common head. -var commonFile = do_get_file( - "../../../../toolkit/components/places/tests/head_common.js", - false -); -/* import-globals-from ../../../../toolkit/components/places/tests/head_common.js */ -if (commonFile) { - let uri = Services.io.newFileURI(commonFile); - Services.scriptloader.loadSubScript(uri.spec, this); -} +const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm"); -const { AddonTestUtils } = ChromeUtils.import( - "resource://testing-common/AddonTestUtils.jsm" -); const { PromiseTestUtils } = ChromeUtils.import( "resource://testing-common/PromiseTestUtils.jsm" ); -AddonTestUtils.init(this); -AddonTestUtils.createAppInfo( - "xpcshell@tests.mozilla.org", - "XPCShell", - "42", - "42" -); - -add_task(async function setup() { - Services.prefs.setBoolPref("browser.search.modernConfig", false); - await AddonTestUtils.promiseStartupManager(); -}); - // This test causes BrowserGlue to start but not fully initialise, when the // AddonManager shuts down BrowserGlue will then try to uninit which will // cause AutoComplete.jsm to throw an error. @@ -48,44 +23,6 @@ PromiseTestUtils.allowMatchingRejectionsGlobally( const TOPICDATA_DISTRIBUTION_CUSTOMIZATION = "force-distribution-customization"; const TOPIC_BROWSERGLUE_TEST = "browser-glue-test"; -/** - * Copy the engine-distribution.xml engine to a fake distribution - * created in the profile, and registered with the directory service. - * Create an empty en-US directory to make sure it isn't used. - */ -function installDistributionEngine() { - const XRE_APP_DISTRIBUTION_DIR = "XREAppDist"; - - let dir = gProfD.clone(); - dir.append("distribution"); - let distDir = dir.clone(); - - dir.append("searchplugins"); - dir.create(dir.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY); - - dir.append("locale"); - dir.create(dir.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY); - let localeDir = dir.clone(); - - dir.append("en-US"); - dir.create(dir.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY); - - localeDir.append("de-DE"); - localeDir.create(dir.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY); - - do_get_file("data/engine-de-DE.xml").copyTo(localeDir, "engine-de-DE.xml"); - - Services.dirsvc.registerProvider({ - getFile(aProp, aPersistent) { - aPersistent.value = true; - if (aProp == XRE_APP_DISTRIBUTION_DIR) { - return distDir.clone(); - } - return null; - }, - }); -} - registerCleanupFunction(async function() { // Remove the distribution dir, even if the test failed, otherwise all // next tests will use it. @@ -109,12 +46,10 @@ add_task(async function() { print("distribution.ini already exists, did some test forget to cleanup?"); } - let testDistributionFile = gTestDir.clone(); + let testDistributionFile = do_get_cwd().clone(); testDistributionFile.append("distribution.ini"); testDistributionFile.copyTo(distroDir, "distribution.ini"); Assert.ok(testDistributionFile.exists()); - - installDistributionEngine(); }); add_task(async function() { @@ -278,13 +213,4 @@ add_task(async function() { ).data, "Language Set" ); - - Services.prefs.setCharPref( - "distribution.searchplugins.defaultLocale", - "de-DE" - ); - - await Services.search.init(); - var engine = Services.search.getEngineByName("Google"); - Assert.equal(engine.description, "override-de-DE"); }); diff --git a/browser/components/tests/unit/xpcshell.ini b/browser/components/tests/unit/xpcshell.ini index 6d421f63524a..cdf8c4f30273 100644 --- a/browser/components/tests/unit/xpcshell.ini +++ b/browser/components/tests/unit/xpcshell.ini @@ -4,7 +4,6 @@ firefox-appdir = browser skip-if = toolkit == 'android' support-files = distribution.ini - data/engine-de-DE.xml [test_distribution.js] [test_distribution_cachedexistence.js] diff --git a/xpcom/io/nsAppDirectoryServiceDefs.h b/xpcom/io/nsAppDirectoryServiceDefs.h index ced213759736..5fad3e3badbb 100644 --- a/xpcom/io/nsAppDirectoryServiceDefs.h +++ b/xpcom/io/nsAppDirectoryServiceDefs.h @@ -41,7 +41,6 @@ #define NS_APP_CHROME_DIR_LIST "AChromDL" #define NS_APP_PLUGINS_DIR_LIST "APluginsDL" -#define NS_APP_DISTRIBUTION_SEARCH_DIR_LIST "SrchPluginsDistDL" // -------------------------------------------------------------------------------------- // Files and directories which exist on a per-profile basis diff --git a/xpcom/io/nsAppFileLocationProvider.cpp b/xpcom/io/nsAppFileLocationProvider.cpp index b8699fecc4b7..942894901607 100644 --- a/xpcom/io/nsAppFileLocationProvider.cpp +++ b/xpcom/io/nsAppFileLocationProvider.cpp @@ -427,8 +427,5 @@ nsAppFileLocationProvider::GetFiles(const char* aProp, NS_ADDREF(*aResult); rv = NS_OK; } - if (!strcmp(aProp, NS_APP_DISTRIBUTION_SEARCH_DIR_LIST)) { - return NS_NewEmptyEnumerator(aResult); - } return rv; }