OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/spellcheck.h" | 5 #include "chrome/renderer/spellchecker/spellcheck.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/common/render_messages.h" | 11 #include "chrome/common/render_messages.h" |
12 #include "chrome/common/spellcheck_common.h" | 12 #include "chrome/common/spellcheck_common.h" |
13 #include "chrome/common/spellcheck_messages.h" | 13 #include "chrome/common/spellcheck_messages.h" |
14 #include "chrome/renderer/chrome_content_renderer_client.h" | |
14 #include "third_party/hunspell/src/hunspell/hunspell.hxx" | 15 #include "third_party/hunspell/src/hunspell/hunspell.hxx" |
15 | 16 |
16 using base::TimeTicks; | 17 using base::TimeTicks; |
17 | 18 |
18 SpellCheck::SpellCheck() | 19 SpellCheck::SpellCheck(chrome::ChromeContentRendererClient* renderer_client) |
19 : file_(base::kInvalidPlatformFileValue), | 20 : file_(base::kInvalidPlatformFileValue), |
20 auto_spell_correct_turned_on_(false), | 21 auto_spell_correct_turned_on_(false), |
21 is_using_platform_spelling_engine_(false), | 22 is_using_platform_spelling_engine_(false), |
22 initialized_(false) { | 23 initialized_(false), |
24 renderer_client_(renderer_client) { | |
23 // Wait till we check the first word before doing any initializing. | 25 // Wait till we check the first word before doing any initializing. |
24 } | 26 } |
25 | 27 |
26 SpellCheck::~SpellCheck() { | 28 SpellCheck::~SpellCheck() { |
27 } | 29 } |
28 | 30 |
29 bool SpellCheck::OnControlMessageReceived(const IPC::Message& message) { | 31 bool SpellCheck::OnControlMessageReceived(const IPC::Message& message) { |
30 bool handled = true; | 32 bool handled = true; |
31 IPC_BEGIN_MESSAGE_MAP(SpellCheck, message) | 33 IPC_BEGIN_MESSAGE_MAP(SpellCheck, message) |
32 IPC_MESSAGE_HANDLER(SpellCheckMsg_Init, OnInit) | 34 IPC_MESSAGE_HANDLER(SpellCheckMsg_Init, OnInit) |
33 IPC_MESSAGE_HANDLER(SpellCheckMsg_WordAdded, OnWordAdded) | 35 IPC_MESSAGE_HANDLER(SpellCheckMsg_WordAdded, OnWordAdded) |
34 IPC_MESSAGE_HANDLER(SpellCheckMsg_EnableAutoSpellCorrect, | 36 IPC_MESSAGE_HANDLER(SpellCheckMsg_EnableAutoSpellCorrect, |
35 OnEnableAutoSpellCorrect) | 37 OnEnableAutoSpellCorrect) |
36 IPC_MESSAGE_UNHANDLED(handled = false) | 38 IPC_MESSAGE_UNHANDLED(handled = false) |
37 IPC_END_MESSAGE_MAP() | 39 IPC_END_MESSAGE_MAP() |
38 | 40 |
39 if (message.type() == ViewMsg_PurgeMemory::ID) { | 41 if (message.type() == ViewMsg_PurgeMemory::ID) { |
40 delete this; | 42 if (renderer_client_) { |
jam
2011/06/21 22:59:39
ditto
Greg Billock
2011/06/22 15:58:35
Done.
| |
41 new SpellCheck(); | 43 renderer_client_->ResetSpellCheck(); |
44 } | |
42 } | 45 } |
43 | 46 |
44 return handled; | 47 return handled; |
45 } | 48 } |
46 | 49 |
47 void SpellCheck::OnInit(IPC::PlatformFileForTransit bdict_file, | 50 void SpellCheck::OnInit(IPC::PlatformFileForTransit bdict_file, |
48 const std::vector<std::string>& custom_words, | 51 const std::vector<std::string>& custom_words, |
49 const std::string& language, | 52 const std::string& language, |
50 bool auto_spell_correct) { | 53 bool auto_spell_correct) { |
51 Init(IPC::PlatformFileForTransitToPlatformFile(bdict_file), | 54 Init(IPC::PlatformFileForTransitToPlatformFile(bdict_file), |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 | 306 |
304 string16 word; | 307 string16 word; |
305 int word_start; | 308 int word_start; |
306 int word_length; | 309 int word_length; |
307 while (word_iterator.GetNextWord(&word, &word_start, &word_length)) { | 310 while (word_iterator.GetNextWord(&word, &word_start, &word_length)) { |
308 if (!CheckSpelling(word, tag)) | 311 if (!CheckSpelling(word, tag)) |
309 return false; | 312 return false; |
310 } | 313 } |
311 return true; | 314 return true; |
312 } | 315 } |
OLD | NEW |