Files
tubestation/browser/components/dirprovider/DirectoryProvider.cpp
Gabriele Svelto eeb9bfc398 Bug 1600545 - Remove useless inclusions of header files generated from IDL files in accessible/, browser/, caps/, chrome/, devtools/, docshell/, editor/, extensions/, gfx/, hal/, image/, intl/, ipc/, js/, layout/, and media/ r=Ehsan
The inclusions were removed with the following very crude script and the
resulting breakage was fixed up by hand. The manual fixups did either
revert the changes done by the script, replace a generic header with a more
specific one or replace a header with a forward declaration.

find . -name "*.idl" | grep -v web-platform | grep -v third_party | while read path; do
    interfaces=$(grep "^\(class\|interface\).*:.*" "$path" | cut -d' ' -f2)
    if [ -n "$interfaces" ]; then
        if [[ "$interfaces" == *$'\n'* ]]; then
          regexp="\("
          for i in $interfaces; do regexp="$regexp$i\|"; done
          regexp="${regexp%%\\\|}\)"
        else
          regexp="$interfaces"
        fi
        interface=$(basename "$path")
        rg -l "#include.*${interface%%.idl}.h" . | while read path2; do
            hits=$(grep -v "#include.*${interface%%.idl}.h" "$path2" | grep -c "$regexp" )
            if [ $hits -eq 0 ]; then
                echo "Removing ${interface} from ${path2}"
                grep -v "#include.*${interface%%.idl}.h" "$path2" > "$path2".tmp
                mv -f "$path2".tmp "$path2"
            fi
        done
    fi
done

Differential Revision: https://phabricator.services.mozilla.com/D55443
2019-12-06 09:16:44 +00:00

169 lines
4.9 KiB
C++

/* 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/
// |- <locale 1>/
// ...
// \- <locale N>/
// 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<nsIFile>& array) {
nsCOMPtr<nsIFile> searchPlugins;
nsresult rv = aDirSvc->Get(XRE_APP_DISTRIBUTION_DIR, NS_GET_IID(nsIFile),
getter_AddRefs(searchPlugins));
if (NS_FAILED(rv)) return;
searchPlugins->AppendNative(NS_LITERAL_CSTRING("searchplugins"));
nsCOMPtr<nsIFile> commonPlugins;
rv = searchPlugins->Clone(getter_AddRefs(commonPlugins));
if (NS_SUCCEEDED(rv)) {
commonPlugins->AppendNative(NS_LITERAL_CSTRING("common"));
array.AppendObject(commonPlugins);
}
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (prefs) {
nsCOMPtr<nsIFile> localePlugins;
rv = searchPlugins->Clone(getter_AddRefs(localePlugins));
if (NS_FAILED(rv)) return;
localePlugins->AppendNative(NS_LITERAL_CSTRING("locale"));
nsAutoCString defLocale;
rv = prefs->GetCharPref("distribution.searchplugins.defaultLocale",
defLocale);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIFile> 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()->GetAppLocaleAsLangTag(locale);
nsCOMPtr<nsIFile> 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<nsIProperties> dirSvc(
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));
if (!dirSvc) return NS_ERROR_FAILURE;
nsCOMArray<nsIFile> 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<nsISupports> nextbasesupp;
mBase->GetNext(getter_AddRefs(nextbasesupp));
nsCOMPtr<nsIFile> 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