| 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/browser/spellchecker/spellcheck_message_filter.h" | 5 #include "chrome/browser/spellchecker/spellcheck_message_filter.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/spellchecker/spellcheck_factory.h" | 10 #include "chrome/browser/spellchecker/spellcheck_factory.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 int route_id, | 100 int route_id, |
| 101 int identifier, | 101 int identifier, |
| 102 int document_tag, | 102 int document_tag, |
| 103 const string16& text) { | 103 const string16& text) { |
| 104 DCHECK(!text.empty()); | 104 DCHECK(!text.empty()); |
| 105 if (!CallSpellingService(route_id, identifier, document_tag, text)) { | 105 if (!CallSpellingService(route_id, identifier, document_tag, text)) { |
| 106 std::vector<SpellCheckResult> results; | 106 std::vector<SpellCheckResult> results; |
| 107 Send(new SpellCheckMsg_RespondSpellingService(route_id, | 107 Send(new SpellCheckMsg_RespondSpellingService(route_id, |
| 108 identifier, | 108 identifier, |
| 109 document_tag, | 109 document_tag, |
| 110 false, |
| 111 text, |
| 110 results)); | 112 results)); |
| 111 return; | 113 return; |
| 112 } | 114 } |
| 113 route_id_ = route_id; | 115 route_id_ = route_id; |
| 114 identifier_ = identifier; | 116 identifier_ = identifier; |
| 115 } | 117 } |
| 116 | 118 |
| 117 void SpellCheckMessageFilter::OnTextCheckComplete( | 119 void SpellCheckMessageFilter::OnTextCheckComplete( |
| 118 int tag, | 120 int tag, |
| 119 const std::vector<SpellCheckResult>& results) { | 121 const std::vector<SpellCheckResult>& results) { |
| 120 Send(new SpellCheckMsg_RespondSpellingService(route_id_, | 122 Send(new SpellCheckMsg_RespondSpellingService(route_id_, |
| 121 identifier_, | 123 identifier_, |
| 122 tag, | 124 tag, |
| 125 true, |
| 126 string16(), |
| 123 results)); | 127 results)); |
| 124 client_.reset(); | 128 client_.reset(); |
| 125 } | 129 } |
| 126 | 130 |
| 127 bool SpellCheckMessageFilter::CallSpellingService( | 131 bool SpellCheckMessageFilter::CallSpellingService( |
| 128 int route_id, | 132 int route_id, |
| 129 int identifier, | 133 int identifier, |
| 130 int document_tag, | 134 int document_tag, |
| 131 const string16& text) { | 135 const string16& text) { |
| 132 content::RenderProcessHost* host = | 136 content::RenderProcessHost* host = |
| 133 content::RenderProcessHost::FromID(render_process_id_); | 137 content::RenderProcessHost::FromID(render_process_id_); |
| 134 if (!host) | 138 if (!host) |
| 135 return false; | 139 return false; |
| 136 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); | 140 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); |
| 137 if (!profile->GetPrefs()->GetBoolean(prefs::kSpellCheckUseSpellingService)) | 141 if (!profile->GetPrefs()->GetBoolean(prefs::kSpellCheckUseSpellingService)) |
| 138 return false; | 142 return false; |
| 139 client_.reset(new SpellingServiceClient); | 143 client_.reset(new SpellingServiceClient); |
| 140 return client_->RequestTextCheck( | 144 return client_->RequestTextCheck( |
| 141 profile, document_tag, SpellingServiceClient::SPELLCHECK, text, | 145 profile, document_tag, SpellingServiceClient::SPELLCHECK, text, |
| 142 base::Bind(&SpellCheckMessageFilter::OnTextCheckComplete, | 146 base::Bind(&SpellCheckMessageFilter::OnTextCheckComplete, |
| 143 base::Unretained(this))); | 147 base::Unretained(this))); |
| 144 } | 148 } |
| 145 #endif | 149 #endif |
| OLD | NEW |