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/browser/spellcheck_message_filter.h" | 5 #include "chrome/browser/spellcheck_message_filter.h" |
6 | 6 |
| 7 #include "chrome/browser/prefs/pref_service.h" |
| 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/spellcheck_host.h" |
7 #include "chrome/browser/spellchecker_platform_engine.h" | 10 #include "chrome/browser/spellchecker_platform_engine.h" |
8 #include "chrome/common/spellcheck_messages.h" | 11 #include "chrome/common/spellcheck_messages.h" |
| 12 #include "content/browser/renderer_host/render_process_host.h" |
9 | 13 |
10 SpellCheckMessageFilter::SpellCheckMessageFilter() { | 14 SpellCheckMessageFilter::SpellCheckMessageFilter(int render_process_id) |
| 15 : render_process_id_(render_process_id) { |
11 } | 16 } |
12 | 17 |
13 SpellCheckMessageFilter::~SpellCheckMessageFilter() { | 18 SpellCheckMessageFilter::~SpellCheckMessageFilter() { |
14 } | 19 } |
15 | 20 |
| 21 void SpellCheckMessageFilter::OverrideThreadForMessage( |
| 22 const IPC::Message& message, BrowserThread::ID* thread) { |
| 23 if (message.type() == SpellCheckHostMsg_RequestDictionary::ID) |
| 24 *thread = BrowserThread::UI; |
| 25 } |
| 26 |
16 bool SpellCheckMessageFilter::OnMessageReceived(const IPC::Message& message, | 27 bool SpellCheckMessageFilter::OnMessageReceived(const IPC::Message& message, |
17 bool* message_was_ok) { | 28 bool* message_was_ok) { |
18 bool handled = true; | 29 bool handled = true; |
19 IPC_BEGIN_MESSAGE_MAP_EX(SpellCheckMessageFilter, message, *message_was_ok) | 30 IPC_BEGIN_MESSAGE_MAP_EX(SpellCheckMessageFilter, message, *message_was_ok) |
20 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_PlatformCheckSpelling, | 31 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_PlatformCheckSpelling, |
21 OnPlatformCheckSpelling) | 32 OnPlatformCheckSpelling) |
22 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_PlatformFillSuggestionList, | 33 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_PlatformFillSuggestionList, |
23 OnPlatformFillSuggestionList) | 34 OnPlatformFillSuggestionList) |
24 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_GetDocumentTag, OnGetDocumentTag) | 35 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_GetDocumentTag, OnGetDocumentTag) |
25 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_DocumentWithTagClosed, | 36 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_DocumentWithTagClosed, |
26 OnDocumentWithTagClosed) | 37 OnDocumentWithTagClosed) |
27 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_ShowSpellingPanel, | 38 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_ShowSpellingPanel, |
28 OnShowSpellingPanel) | 39 OnShowSpellingPanel) |
29 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_UpdateSpellingPanelWithMisspelledWord, | 40 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_UpdateSpellingPanelWithMisspelledWord, |
30 OnUpdateSpellingPanelWithMisspelledWord) | 41 OnUpdateSpellingPanelWithMisspelledWord) |
31 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_PlatformRequestTextCheck, | 42 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_PlatformRequestTextCheck, |
32 OnPlatformRequestTextCheck) | 43 OnPlatformRequestTextCheck) |
| 44 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_RequestDictionary, |
| 45 OnSpellCheckerRequestDictionary) |
33 IPC_MESSAGE_UNHANDLED(handled = false) | 46 IPC_MESSAGE_UNHANDLED(handled = false) |
34 IPC_END_MESSAGE_MAP() | 47 IPC_END_MESSAGE_MAP() |
35 return handled; | 48 return handled; |
36 } | 49 } |
37 | 50 |
38 void SpellCheckMessageFilter::OnPlatformCheckSpelling(const string16& word, | 51 void SpellCheckMessageFilter::OnPlatformCheckSpelling(const string16& word, |
39 int tag, | 52 int tag, |
40 bool* correct) { | 53 bool* correct) { |
41 *correct = SpellCheckerPlatform::CheckSpelling(word, tag); | 54 *correct = SpellCheckerPlatform::CheckSpelling(word, tag); |
42 } | 55 } |
(...skipping 22 matching lines...) Expand all Loading... |
65 } | 78 } |
66 | 79 |
67 void SpellCheckMessageFilter::OnPlatformRequestTextCheck( | 80 void SpellCheckMessageFilter::OnPlatformRequestTextCheck( |
68 int route_id, | 81 int route_id, |
69 int identifier, | 82 int identifier, |
70 int document_tag, | 83 int document_tag, |
71 const string16& text) { | 84 const string16& text) { |
72 SpellCheckerPlatform::RequestTextCheck( | 85 SpellCheckerPlatform::RequestTextCheck( |
73 route_id, identifier, document_tag, text, this); | 86 route_id, identifier, document_tag, text, this); |
74 } | 87 } |
| 88 |
| 89 void SpellCheckMessageFilter::OnSpellCheckerRequestDictionary() { |
| 90 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id_); |
| 91 if (!host) |
| 92 return; // Teardown. |
| 93 Profile* profile = host->profile(); |
| 94 // The renderer has requested that we initialize its spellchecker. This should |
| 95 // generally only be called once per session, as after the first call, all |
| 96 // future renderers will be passed the initialization information on startup |
| 97 // (or when the dictionary changes in some way). |
| 98 if (profile->GetSpellCheckHost()) { |
| 99 // The spellchecker initialization already started and finished; just send |
| 100 // it to the renderer. |
| 101 profile->GetSpellCheckHost()->InitForRenderer(host); |
| 102 } else { |
| 103 // We may have gotten multiple requests from different renderers. We don't |
| 104 // want to initialize multiple times in this case, so we set |force| to |
| 105 // false. |
| 106 profile->ReinitializeSpellCheckHost(false); |
| 107 } |
| 108 } |
OLD | NEW |