Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / extensions / spellcheck / hunspell / src / mozHunspellDirProvider.cpp
blob9853312d553386a92e809c802856c006b8a93280
1 /******* BEGIN LICENSE BLOCK *******
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Initial Developers of the Original Code are Kevin Hendricks (MySpell)
15 * and László Németh (Hunspell). Portions created by the Initial Developers
16 * are Copyright (C) 2002-2005 the Initial Developers. All Rights Reserved.
18 * Contributor(s): Benjamin Smedberg (benjamin@smedbergs.us) (Original Code)
19 * László Németh (nemethl@gyorsposta.hu)
20 * Ryan VanderMeulen (ryanvm@gmail.com)
22 * Alternatively, the contents of this file may be used under the terms of
23 * either the GNU General Public License Version 2 or later (the "GPL"), or
24 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
25 * in which case the provisions of the GPL or the LGPL are applicable instead
26 * of those above. If you wish to allow use of your version of this file only
27 * under the terms of either the GPL or the LGPL, and not to allow others to
28 * use your version of this file under the terms of the MPL, indicate your
29 * decision by deleting the provisions above and replace them with the notice
30 * and other provisions required by the GPL or the LGPL. If you do not delete
31 * the provisions above, a recipient may use your version of this file under
32 * the terms of any one of the MPL, the GPL or the LGPL.
34 ******* END LICENSE BLOCK *******/
36 #include "mozHunspellDirProvider.h"
37 #include "nsXULAppAPI.h"
38 #include "nsString.h"
40 #include "mozISpellCheckingEngine.h"
41 #include "nsICategoryManager.h"
43 NS_IMPL_ISUPPORTS2(mozHunspellDirProvider,
44 nsIDirectoryServiceProvider,
45 nsIDirectoryServiceProvider2)
47 NS_IMETHODIMP
48 mozHunspellDirProvider::GetFile(const char *aKey, PRBool *aPersist,
49 nsIFile* *aResult)
51 return NS_ERROR_FAILURE;
54 NS_IMETHODIMP
55 mozHunspellDirProvider::GetFiles(const char *aKey,
56 nsISimpleEnumerator* *aResult)
58 if (strcmp(aKey, DICTIONARY_SEARCH_DIRECTORY_LIST) != 0) {
59 return NS_ERROR_FAILURE;
62 nsCOMPtr<nsIProperties> dirSvc =
63 do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID);
64 if (!dirSvc)
65 return NS_ERROR_FAILURE;
67 nsCOMPtr<nsISimpleEnumerator> list;
68 nsresult rv = dirSvc->Get(XRE_EXTENSIONS_DIR_LIST,
69 NS_GET_IID(nsISimpleEnumerator),
70 getter_AddRefs(list));
71 if (NS_FAILED(rv))
72 return rv;
74 nsCOMPtr<nsISimpleEnumerator> e = new AppendingEnumerator(list);
75 if (!e)
76 return NS_ERROR_OUT_OF_MEMORY;
78 *aResult = nsnull;
79 e.swap(*aResult);
80 return NS_SUCCESS_AGGREGATE_RESULT;
83 NS_IMPL_ISUPPORTS1(mozHunspellDirProvider::AppendingEnumerator,
84 nsISimpleEnumerator)
86 NS_IMETHODIMP
87 mozHunspellDirProvider::AppendingEnumerator::HasMoreElements(PRBool *aResult)
89 *aResult = mNext ? PR_TRUE : PR_FALSE;
90 return NS_OK;
93 NS_IMETHODIMP
94 mozHunspellDirProvider::AppendingEnumerator::GetNext(nsISupports* *aResult)
96 if (aResult)
97 NS_ADDREF(*aResult = mNext);
99 mNext = nsnull;
101 nsresult rv;
103 // Ignore all errors
105 PRBool more;
106 while (NS_SUCCEEDED(mBase->HasMoreElements(&more)) && more) {
107 nsCOMPtr<nsISupports> nextbasesupp;
108 mBase->GetNext(getter_AddRefs(nextbasesupp));
110 nsCOMPtr<nsIFile> nextbase(do_QueryInterface(nextbasesupp));
111 if (!nextbase)
112 continue;
114 nextbase->Clone(getter_AddRefs(mNext));
115 if (!mNext)
116 continue;
118 mNext->AppendNative(NS_LITERAL_CSTRING("dictionaries"));
120 PRBool exists;
121 rv = mNext->Exists(&exists);
122 if (NS_SUCCEEDED(rv) && exists)
123 break;
125 mNext = nsnull;
128 return NS_OK;
131 mozHunspellDirProvider::AppendingEnumerator::AppendingEnumerator
132 (nsISimpleEnumerator* aBase) :
133 mBase(aBase)
135 // Initialize mNext to begin
136 GetNext(nsnull);
139 NS_METHOD
140 mozHunspellDirProvider::Register(nsIComponentManager* aCompMgr,
141 nsIFile* aPath, const char *aLoaderStr,
142 const char *aType,
143 const nsModuleComponentInfo *aInfo)
145 nsresult rv;
147 nsCOMPtr<nsICategoryManager> catMan =
148 do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
149 if (!catMan)
150 return NS_ERROR_FAILURE;
152 rv = catMan->AddCategoryEntry(XPCOM_DIRECTORY_PROVIDER_CATEGORY,
153 "spellcheck-directory-provider",
154 kContractID, PR_TRUE, PR_TRUE, nsnull);
155 return rv;
158 NS_METHOD
159 mozHunspellDirProvider::Unregister(nsIComponentManager* aCompMgr,
160 nsIFile* aPath,
161 const char *aLoaderStr,
162 const nsModuleComponentInfo *aInfo)
164 nsresult rv;
166 nsCOMPtr<nsICategoryManager> catMan =
167 do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
168 if (!catMan)
169 return NS_ERROR_FAILURE;
171 rv = catMan->DeleteCategoryEntry(XPCOM_DIRECTORY_PROVIDER_CATEGORY,
172 "spellcheck-directory-provider",
173 PR_TRUE);
174 return rv;
177 char const *const
178 mozHunspellDirProvider::kContractID = "@mozilla.org/spellcheck/dir-provider;1";