OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_SPELLCHECK_HOST_H_ | 5 #ifndef CHROME_BROWSER_SPELLCHECK_HOST_H_ |
6 #define CHROME_BROWSER_SPELLCHECK_HOST_H_ | 6 #define CHROME_BROWSER_SPELLCHECK_HOST_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/platform_file.h" | 12 #include "base/platform_file.h" |
13 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
14 #include "chrome/browser/chrome_thread.h" | 14 #include "chrome/browser/chrome_thread.h" |
15 #include "chrome/browser/net/url_fetcher.h" | 15 #include "chrome/browser/net/url_fetcher.h" |
16 #include "chrome/browser/net/url_request_context_getter.h" | 16 #include "chrome/browser/net/url_request_context_getter.h" |
17 | 17 |
| 18 class Profile; |
| 19 |
18 class SpellCheckHost : public base::RefCountedThreadSafe<SpellCheckHost, | 20 class SpellCheckHost : public base::RefCountedThreadSafe<SpellCheckHost, |
19 ChromeThread::DeleteOnFileThread>, | 21 ChromeThread::DeleteOnFileThread>, |
20 public URLFetcher::Delegate { | 22 public URLFetcher::Delegate { |
21 public: | 23 public: |
22 class Observer { | 24 class Observer { |
23 public: | 25 public: |
24 virtual void SpellCheckHostInitialized() = 0; | 26 virtual void SpellCheckHostInitialized() = 0; |
25 }; | 27 }; |
26 | 28 |
27 SpellCheckHost(Observer* observer, | 29 SpellCheckHost(Observer* observer, |
28 const std::string& language, | 30 const std::string& language, |
29 URLRequestContextGetter* request_context_getter); | 31 URLRequestContextGetter* request_context_getter); |
30 | 32 |
31 void Initialize(); | 33 void Initialize(); |
32 | 34 |
33 // Clear |observer_|. Used to prevent calling back to a deleted object. | 35 // Clear |observer_|. Used to prevent calling back to a deleted object. |
34 void UnsetObserver(); | 36 void UnsetObserver(); |
35 | 37 |
36 // Add the given word to the custom words list and inform renderer of the | 38 // Add the given word to the custom words list and inform renderer of the |
37 // update. | 39 // update. |
38 void AddWord(const std::string& word); | 40 void AddWord(const std::string& word); |
39 | 41 |
| 42 // This function computes a vector of strings which are to be displayed in |
| 43 // the context menu over a text area for changing spell check languages. It |
| 44 // returns the index of the current spell check language in the vector. |
| 45 // TODO(port): this should take a vector of string16, but the implementation |
| 46 // has some dependencies in l10n util that need porting first. |
| 47 static int GetSpellCheckLanguages(Profile* profile, |
| 48 std::vector<std::string>* languages); |
| 49 |
40 const base::PlatformFile& bdict_file() const { return file_; } | 50 const base::PlatformFile& bdict_file() const { return file_; } |
41 | 51 |
42 const std::vector<std::string>& custom_words() const { return custom_words_; } | 52 const std::vector<std::string>& custom_words() const { return custom_words_; } |
43 | 53 |
44 const std::string& last_added_word() const { return custom_words_.back(); } | 54 const std::string& last_added_word() const { return custom_words_.back(); } |
45 | 55 |
46 const std::string& language() const { return language_; } | 56 const std::string& language() const { return language_; } |
47 | 57 |
| 58 bool use_platform_spellchecker() const { return use_platform_spellchecker_; } |
| 59 |
48 private: | 60 private: |
49 // These two classes can destruct us. | 61 // These two classes can destruct us. |
50 friend class ChromeThread; | 62 friend class ChromeThread; |
51 friend class DeleteTask<SpellCheckHost>; | 63 friend class DeleteTask<SpellCheckHost>; |
52 | 64 |
53 virtual ~SpellCheckHost(); | 65 virtual ~SpellCheckHost(); |
54 | 66 |
55 // Figure out the location for the dictionary. This is only non-trivial for | 67 // Figure out the location for the dictionary. This is only non-trivial for |
56 // Windows: | 68 // Windows: |
57 // The default place whether the spellcheck dictionary can reside is | 69 // The default place whether the spellcheck dictionary can reside is |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 // The file descriptor/handle for the dictionary file. | 114 // The file descriptor/handle for the dictionary file. |
103 base::PlatformFile file_; | 115 base::PlatformFile file_; |
104 | 116 |
105 // In-memory cache of the custom words file. | 117 // In-memory cache of the custom words file. |
106 std::vector<std::string> custom_words_; | 118 std::vector<std::string> custom_words_; |
107 | 119 |
108 // We don't want to attempt to download a missing dictionary file more than | 120 // We don't want to attempt to download a missing dictionary file more than |
109 // once. | 121 // once. |
110 bool tried_to_download_; | 122 bool tried_to_download_; |
111 | 123 |
| 124 // Whether we should use the platform spellchecker instead of Hunspell. |
| 125 bool use_platform_spellchecker_; |
| 126 |
112 // Data received from the dictionary download. | 127 // Data received from the dictionary download. |
113 std::string data_; | 128 std::string data_; |
114 | 129 |
115 // Used for downloading the dictionary file. We don't hold a reference, and | 130 // Used for downloading the dictionary file. We don't hold a reference, and |
116 // it is only valid to use it on the UI thread. | 131 // it is only valid to use it on the UI thread. |
117 URLRequestContextGetter* request_context_getter_; | 132 URLRequestContextGetter* request_context_getter_; |
118 | 133 |
119 // Used for downloading the dictionary file. | 134 // Used for downloading the dictionary file. |
120 scoped_ptr<URLFetcher> fetcher_; | 135 scoped_ptr<URLFetcher> fetcher_; |
121 }; | 136 }; |
122 | 137 |
123 #endif // CHROME_BROWSER_SPELLCHECK_HOST_H_ | 138 #endif // CHROME_BROWSER_SPELLCHECK_HOST_H_ |
OLD | NEW |