OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/renderer/spellchecker/hunspell_engine.h" | 5 #include "chrome/renderer/spellchecker/hunspell_engine.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <iterator> | 9 #include <iterator> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/files/memory_mapped_file.h" | 12 #include "base/files/memory_mapped_file.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "chrome/common/spellcheck_common.h" | 14 #include "components/spellcheck/common/spellcheck_common.h" |
15 #include "chrome/common/spellcheck_messages.h" | 15 #include "components/spellcheck/common/spellcheck_messages.h" |
16 #include "content/public/renderer/render_thread.h" | 16 #include "content/public/renderer/render_thread.h" |
17 #include "third_party/hunspell/src/hunspell/hunspell.hxx" | 17 #include "third_party/hunspell/src/hunspell/hunspell.hxx" |
18 | 18 |
19 using content::RenderThread; | 19 using content::RenderThread; |
20 | 20 |
21 namespace { | 21 namespace { |
22 // Maximum length of words we actually check. | 22 // Maximum length of words we actually check. |
23 // 64 is the observed limits for OSX system checker. | 23 // 64 is the observed limits for OSX system checker. |
24 const size_t kMaxCheckedLen = 64; | 24 const size_t kMaxCheckedLen = 64; |
25 | 25 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 // TODO(groby): Technically, it's not. We should track down the issue. | 104 // TODO(groby): Technically, it's not. We should track down the issue. |
105 if (!hunspell_.get()) | 105 if (!hunspell_.get()) |
106 return; | 106 return; |
107 | 107 |
108 char** suggestions = NULL; | 108 char** suggestions = NULL; |
109 int number_of_suggestions = | 109 int number_of_suggestions = |
110 hunspell_->suggest(&suggestions, wrong_word_utf8.c_str()); | 110 hunspell_->suggest(&suggestions, wrong_word_utf8.c_str()); |
111 | 111 |
112 // Populate the vector of WideStrings. | 112 // Populate the vector of WideStrings. |
113 for (int i = 0; i < number_of_suggestions; ++i) { | 113 for (int i = 0; i < number_of_suggestions; ++i) { |
114 if (i < chrome::spellcheck_common::kMaxSuggestions) | 114 if (i < spellcheck::kMaxSuggestions) |
115 optional_suggestions->push_back(base::UTF8ToUTF16(suggestions[i])); | 115 optional_suggestions->push_back(base::UTF8ToUTF16(suggestions[i])); |
116 free(suggestions[i]); | 116 free(suggestions[i]); |
117 } | 117 } |
118 if (suggestions != NULL) | 118 if (suggestions != NULL) |
119 free(suggestions); | 119 free(suggestions); |
120 } | 120 } |
121 | 121 |
122 bool HunspellEngine::InitializeIfNeeded() { | 122 bool HunspellEngine::InitializeIfNeeded() { |
123 if (!initialized_ && !dictionary_requested_) { | 123 if (!initialized_ && !dictionary_requested_) { |
124 // RenderThread will not exist in test. | 124 // RenderThread will not exist in test. |
125 if (RenderThread::Get()) | 125 if (RenderThread::Get()) |
126 RenderThread::Get()->Send(new SpellCheckHostMsg_RequestDictionary); | 126 RenderThread::Get()->Send(new SpellCheckHostMsg_RequestDictionary); |
127 dictionary_requested_ = true; | 127 dictionary_requested_ = true; |
128 return true; | 128 return true; |
129 } | 129 } |
130 | 130 |
131 // Don't initialize if hunspell is disabled. | 131 // Don't initialize if hunspell is disabled. |
132 if (file_.IsValid()) | 132 if (file_.IsValid()) |
133 InitializeHunspell(); | 133 InitializeHunspell(); |
134 | 134 |
135 return !initialized_; | 135 return !initialized_; |
136 } | 136 } |
137 | 137 |
138 bool HunspellEngine::IsEnabled() { | 138 bool HunspellEngine::IsEnabled() { |
139 return hunspell_enabled_; | 139 return hunspell_enabled_; |
140 } | 140 } |
OLD | NEW |