Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /******* BEGIN LICENSE BLOCK ******* |
michael@0 | 2 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
michael@0 | 3 | * |
michael@0 | 4 | * The contents of this file are subject to the Mozilla Public License Version |
michael@0 | 5 | * 1.1 (the "License"); you may not use this file except in compliance with |
michael@0 | 6 | * the License. You may obtain a copy of the License at |
michael@0 | 7 | * http://www.mozilla.org/MPL/ |
michael@0 | 8 | * |
michael@0 | 9 | * Software distributed under the License is distributed on an "AS IS" basis, |
michael@0 | 10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
michael@0 | 11 | * for the specific language governing rights and limitations under the |
michael@0 | 12 | * License. |
michael@0 | 13 | * |
michael@0 | 14 | * The Initial Developers of the Original Code are Kevin Hendricks (MySpell) |
michael@0 | 15 | * and László Németh (Hunspell). Portions created by the Initial Developers |
michael@0 | 16 | * are Copyright (C) 2002-2005 the Initial Developers. All Rights Reserved. |
michael@0 | 17 | * |
michael@0 | 18 | * Contributor(s): Benjamin Smedberg (benjamin@smedbergs.us) (Original Code) |
michael@0 | 19 | * László Németh (nemethl@gyorsposta.hu) |
michael@0 | 20 | * Ryan VanderMeulen (ryanvm@gmail.com) |
michael@0 | 21 | * |
michael@0 | 22 | * Alternatively, the contents of this file may be used under the terms of |
michael@0 | 23 | * either the GNU General Public License Version 2 or later (the "GPL"), or |
michael@0 | 24 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
michael@0 | 25 | * in which case the provisions of the GPL or the LGPL are applicable instead |
michael@0 | 26 | * of those above. If you wish to allow use of your version of this file only |
michael@0 | 27 | * under the terms of either the GPL or the LGPL, and not to allow others to |
michael@0 | 28 | * use your version of this file under the terms of the MPL, indicate your |
michael@0 | 29 | * decision by deleting the provisions above and replace them with the notice |
michael@0 | 30 | * and other provisions required by the GPL or the LGPL. If you do not delete |
michael@0 | 31 | * the provisions above, a recipient may use your version of this file under |
michael@0 | 32 | * the terms of any one of the MPL, the GPL or the LGPL. |
michael@0 | 33 | * |
michael@0 | 34 | ******* END LICENSE BLOCK *******/ |
michael@0 | 35 | |
michael@0 | 36 | #include "mozHunspellDirProvider.h" |
michael@0 | 37 | #include "nsXULAppAPI.h" |
michael@0 | 38 | #include "nsString.h" |
michael@0 | 39 | |
michael@0 | 40 | #include "mozISpellCheckingEngine.h" |
michael@0 | 41 | #include "nsICategoryManager.h" |
michael@0 | 42 | |
michael@0 | 43 | NS_IMPL_ISUPPORTS(mozHunspellDirProvider, |
michael@0 | 44 | nsIDirectoryServiceProvider, |
michael@0 | 45 | nsIDirectoryServiceProvider2) |
michael@0 | 46 | |
michael@0 | 47 | NS_IMETHODIMP |
michael@0 | 48 | mozHunspellDirProvider::GetFile(const char *aKey, bool *aPersist, |
michael@0 | 49 | nsIFile* *aResult) |
michael@0 | 50 | { |
michael@0 | 51 | return NS_ERROR_FAILURE; |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | NS_IMETHODIMP |
michael@0 | 55 | mozHunspellDirProvider::GetFiles(const char *aKey, |
michael@0 | 56 | nsISimpleEnumerator* *aResult) |
michael@0 | 57 | { |
michael@0 | 58 | if (strcmp(aKey, DICTIONARY_SEARCH_DIRECTORY_LIST) != 0) { |
michael@0 | 59 | return NS_ERROR_FAILURE; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | nsCOMPtr<nsIProperties> dirSvc = |
michael@0 | 63 | do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID); |
michael@0 | 64 | if (!dirSvc) |
michael@0 | 65 | return NS_ERROR_FAILURE; |
michael@0 | 66 | |
michael@0 | 67 | nsCOMPtr<nsISimpleEnumerator> list; |
michael@0 | 68 | nsresult rv = dirSvc->Get(XRE_EXTENSIONS_DIR_LIST, |
michael@0 | 69 | NS_GET_IID(nsISimpleEnumerator), |
michael@0 | 70 | getter_AddRefs(list)); |
michael@0 | 71 | if (NS_FAILED(rv)) |
michael@0 | 72 | return rv; |
michael@0 | 73 | |
michael@0 | 74 | nsCOMPtr<nsISimpleEnumerator> e = new AppendingEnumerator(list); |
michael@0 | 75 | if (!e) |
michael@0 | 76 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 77 | |
michael@0 | 78 | *aResult = nullptr; |
michael@0 | 79 | e.swap(*aResult); |
michael@0 | 80 | return NS_SUCCESS_AGGREGATE_RESULT; |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | NS_IMPL_ISUPPORTS(mozHunspellDirProvider::AppendingEnumerator, |
michael@0 | 84 | nsISimpleEnumerator) |
michael@0 | 85 | |
michael@0 | 86 | NS_IMETHODIMP |
michael@0 | 87 | mozHunspellDirProvider::AppendingEnumerator::HasMoreElements(bool *aResult) |
michael@0 | 88 | { |
michael@0 | 89 | *aResult = mNext ? true : false; |
michael@0 | 90 | return NS_OK; |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | NS_IMETHODIMP |
michael@0 | 94 | mozHunspellDirProvider::AppendingEnumerator::GetNext(nsISupports* *aResult) |
michael@0 | 95 | { |
michael@0 | 96 | if (aResult) |
michael@0 | 97 | NS_ADDREF(*aResult = mNext); |
michael@0 | 98 | |
michael@0 | 99 | mNext = nullptr; |
michael@0 | 100 | |
michael@0 | 101 | nsresult rv; |
michael@0 | 102 | |
michael@0 | 103 | // Ignore all errors |
michael@0 | 104 | |
michael@0 | 105 | bool more; |
michael@0 | 106 | while (NS_SUCCEEDED(mBase->HasMoreElements(&more)) && more) { |
michael@0 | 107 | nsCOMPtr<nsISupports> nextbasesupp; |
michael@0 | 108 | mBase->GetNext(getter_AddRefs(nextbasesupp)); |
michael@0 | 109 | |
michael@0 | 110 | nsCOMPtr<nsIFile> nextbase(do_QueryInterface(nextbasesupp)); |
michael@0 | 111 | if (!nextbase) |
michael@0 | 112 | continue; |
michael@0 | 113 | |
michael@0 | 114 | nextbase->Clone(getter_AddRefs(mNext)); |
michael@0 | 115 | if (!mNext) |
michael@0 | 116 | continue; |
michael@0 | 117 | |
michael@0 | 118 | mNext->AppendNative(NS_LITERAL_CSTRING("dictionaries")); |
michael@0 | 119 | |
michael@0 | 120 | bool exists; |
michael@0 | 121 | rv = mNext->Exists(&exists); |
michael@0 | 122 | if (NS_SUCCEEDED(rv) && exists) |
michael@0 | 123 | break; |
michael@0 | 124 | |
michael@0 | 125 | mNext = nullptr; |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | return NS_OK; |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | mozHunspellDirProvider::AppendingEnumerator::AppendingEnumerator |
michael@0 | 132 | (nsISimpleEnumerator* aBase) : |
michael@0 | 133 | mBase(aBase) |
michael@0 | 134 | { |
michael@0 | 135 | // Initialize mNext to begin |
michael@0 | 136 | GetNext(nullptr); |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | char const *const |
michael@0 | 140 | mozHunspellDirProvider::kContractID = "@mozilla.org/spellcheck/dir-provider;1"; |