| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/renderer/spellchecker/spellcheck_provider.h" |
| 6 |
| 7 #include "chrome/common/render_messages.h" |
| 8 #include "chrome/renderer/render_thread.h" |
| 9 #include "chrome/renderer/spellchecker/spellcheck.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingComple
tion.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult
.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" |
| 13 |
| 14 using WebKit::WebString; |
| 15 using WebKit::WebTextCheckingCompletion; |
| 16 using WebKit::WebTextCheckingResult; |
| 17 |
| 18 SpellCheckProvider::SpellCheckProvider(RenderView* render_view, |
| 19 SpellCheck* spellcheck) |
| 20 : RenderViewObserver(render_view), |
| 21 spellcheck_(spellcheck) { |
| 22 } |
| 23 |
| 24 SpellCheckProvider::~SpellCheckProvider() { |
| 25 } |
| 26 |
| 27 void SpellCheckProvider::RequestTextChecking( |
| 28 const WebString& text, |
| 29 int document_tag, |
| 30 WebTextCheckingCompletion* completion) { |
| 31 // Text check (unified request for grammar and spell check) is only |
| 32 // available for browser process, so we ask the system sellchecker |
| 33 // over IPC or return an empty result if the checker is not |
| 34 // available. |
| 35 if (!is_using_platform_spelling_engine()) { |
| 36 completion->didFinishCheckingText |
| 37 (std::vector<WebTextCheckingResult>()); |
| 38 return; |
| 39 } |
| 40 |
| 41 Send(new ViewHostMsg_SpellChecker_PlatformRequestTextCheck( |
| 42 routing_id(), |
| 43 text_check_completions_.Add(completion), |
| 44 document_tag, |
| 45 text)); |
| 46 } |
| 47 |
| 48 void SpellCheckProvider::OnSpellCheckerRespondTextCheck( |
| 49 int identifier, |
| 50 int tag, |
| 51 const std::vector<WebTextCheckingResult>& results) { |
| 52 WebKit::WebTextCheckingCompletion* completion = |
| 53 text_check_completions_.Lookup(identifier); |
| 54 if (!completion) |
| 55 return; |
| 56 text_check_completions_.Remove(identifier); |
| 57 completion->didFinishCheckingText(results); |
| 58 } |
| 59 |
| 60 bool SpellCheckProvider::OnMessageReceived(const IPC::Message& message) { |
| 61 bool handled = true; |
| 62 IPC_BEGIN_MESSAGE_MAP(SpellCheckProvider, message) |
| 63 IPC_MESSAGE_HANDLER(ViewMsg_SpellChecker_RespondTextCheck, |
| 64 OnSpellCheckerRespondTextCheck) |
| 65 IPC_MESSAGE_UNHANDLED(handled = false) |
| 66 IPC_END_MESSAGE_MAP() |
| 67 return handled; |
| 68 } |
| 69 |
| 70 bool SpellCheckProvider::is_using_platform_spelling_engine() const { |
| 71 return spellcheck_ && spellcheck_->is_using_platform_spelling_engine(); |
| 72 } |
| OLD | NEW |