Chromium Code Reviews| 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/spellcheck_provider.h" | 5 #include "chrome/renderer/spellchecker/spellcheck_provider.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/common/chrome_switches.h" | 8 #include "chrome/common/chrome_switches.h" |
| 9 #include "chrome/common/spellcheck_messages.h" | 9 #include "chrome/common/spellcheck_messages.h" |
| 10 #include "chrome/renderer/chrome_content_renderer_client.h" | 10 #include "chrome/renderer/chrome_content_renderer_client.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 Send(new SpellCheckHostMsg_DocumentWithTagClosed( | 44 Send(new SpellCheckHostMsg_DocumentWithTagClosed( |
| 45 routing_id(), document_tag_)); | 45 routing_id(), document_tag_)); |
| 46 } | 46 } |
| 47 #endif | 47 #endif |
| 48 } | 48 } |
| 49 | 49 |
| 50 void SpellCheckProvider::RequestTextChecking( | 50 void SpellCheckProvider::RequestTextChecking( |
| 51 const WebString& text, | 51 const WebString& text, |
| 52 int document_tag, | 52 int document_tag, |
| 53 WebTextCheckingCompletion* completion) { | 53 WebTextCheckingCompletion* completion) { |
| 54 DCHECK(completion); | |
| 55 if (!completion) | |
| 56 return; | |
| 57 | |
| 58 if (text.isEmpty()) { | |
| 59 completion->didFinishCheckingText(WebVector<WebTextCheckingResult>()); | |
| 60 return; | |
| 61 } | |
| 62 | |
| 54 #if defined(OS_MACOSX) | 63 #if defined(OS_MACOSX) |
| 55 // Text check (unified request for grammar and spell check) is only | 64 // SpellChecker on Mac is only available for browser process, so we ask the |
| 56 // available for browser process, so we ask the system spellchecker | 65 // system spellchecker over IPC. |
| 57 // over IPC or return an empty result if the checker is not | |
| 58 // available. | |
| 59 Send(new SpellCheckHostMsg_RequestTextCheck( | 66 Send(new SpellCheckHostMsg_RequestTextCheck( |
| 60 routing_id(), | 67 routing_id(), |
|
Hironori Bono
2012/01/27 06:17:41
nit: I do not think we need these space characters
shinyak
2012/01/30 06:53:05
Done. Sorry.
| |
| 61 text_check_completions_.Add(completion), | 68 text_check_completions_.Add(completion), |
| 62 document_tag, | 69 document_tag, |
| 63 text)); | 70 text)); |
| 64 #else | 71 #else |
| 65 completion->didFinishCheckingText( | 72 // On the other platforms, currently we don't have a system spellchecker. |
| 66 std::vector<WebTextCheckingResult>()); | 73 // So we post a task to spellcheck. |
| 67 #endif // !OS_MACOSX | 74 |
| 75 // |chrome_content_renderer_client| may be NULL in unit tests. | |
| 76 if (chrome_content_renderer_client_) { | |
| 77 chrome_content_renderer_client_->spellcheck()->RequestTextChecking( | |
| 78 text, document_tag, completion); | |
| 79 return; | |
| 80 } | |
| 81 | |
| 82 completion->didFinishCheckingText(WebVector<WebTextCheckingResult>()); | |
| 83 #endif | |
| 68 } | 84 } |
| 69 | 85 |
| 70 bool SpellCheckProvider::OnMessageReceived(const IPC::Message& message) { | 86 bool SpellCheckProvider::OnMessageReceived(const IPC::Message& message) { |
| 71 bool handled = true; | 87 bool handled = true; |
| 72 IPC_BEGIN_MESSAGE_MAP(SpellCheckProvider, message) | 88 IPC_BEGIN_MESSAGE_MAP(SpellCheckProvider, message) |
| 73 IPC_MESSAGE_HANDLER(SpellCheckMsg_AdvanceToNextMisspelling, | 89 IPC_MESSAGE_HANDLER(SpellCheckMsg_AdvanceToNextMisspelling, |
| 74 OnAdvanceToNextMisspelling) | 90 OnAdvanceToNextMisspelling) |
| 75 IPC_MESSAGE_HANDLER(SpellCheckMsg_RespondTextCheck, OnRespondTextCheck) | 91 IPC_MESSAGE_HANDLER(SpellCheckMsg_RespondTextCheck, OnRespondTextCheck) |
| 76 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellPanel, OnToggleSpellPanel) | 92 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellPanel, OnToggleSpellPanel) |
| 77 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellCheck, OnToggleSpellCheck) | 93 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellCheck, OnToggleSpellCheck) |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 // TODO(darin): There's actually no reason for this to be here. We should | 245 // TODO(darin): There's actually no reason for this to be here. We should |
| 230 // have the browser side manage the document tag. | 246 // have the browser side manage the document tag. |
| 231 #if defined(OS_MACOSX) | 247 #if defined(OS_MACOSX) |
| 232 if (!has_document_tag_) { | 248 if (!has_document_tag_) { |
| 233 // Make the call to get the tag. | 249 // Make the call to get the tag. |
| 234 Send(new SpellCheckHostMsg_GetDocumentTag(routing_id(), &document_tag_)); | 250 Send(new SpellCheckHostMsg_GetDocumentTag(routing_id(), &document_tag_)); |
| 235 has_document_tag_ = true; | 251 has_document_tag_ = true; |
| 236 } | 252 } |
| 237 #endif | 253 #endif |
| 238 } | 254 } |
| OLD | NEW |