| 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 "components/spellcheck/renderer/spellcheck_provider.h" | 5 #include "components/spellcheck/renderer/spellcheck_provider.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "components/spellcheck/common/spellcheck_marker.h" | 9 #include "components/spellcheck/common/spellcheck_marker.h" |
| 10 #include "components/spellcheck/common/spellcheck_messages.h" | 10 #include "components/spellcheck/common/spellcheck_messages.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 120 |
| 121 Send(new SpellCheckHostMsg_ToggleSpellCheck(routing_id(), enabled, checked)); | 121 Send(new SpellCheckHostMsg_ToggleSpellCheck(routing_id(), enabled, checked)); |
| 122 #endif // USE_BROWSER_SPELLCHECKER | 122 #endif // USE_BROWSER_SPELLCHECKER |
| 123 } | 123 } |
| 124 | 124 |
| 125 void SpellCheckProvider::checkSpelling( | 125 void SpellCheckProvider::checkSpelling( |
| 126 const WebString& text, | 126 const WebString& text, |
| 127 int& offset, | 127 int& offset, |
| 128 int& length, | 128 int& length, |
| 129 WebVector<WebString>* optional_suggestions) { | 129 WebVector<WebString>* optional_suggestions) { |
| 130 base::string16 word(text); | 130 base::string16 word = text.utf16(); |
| 131 std::vector<base::string16> suggestions; | 131 std::vector<base::string16> suggestions; |
| 132 const int kWordStart = 0; | 132 const int kWordStart = 0; |
| 133 spellcheck_->SpellCheckWord( | 133 spellcheck_->SpellCheckWord( |
| 134 word.c_str(), kWordStart, word.size(), routing_id(), | 134 word.c_str(), kWordStart, word.size(), routing_id(), |
| 135 &offset, &length, optional_suggestions ? & suggestions : NULL); | 135 &offset, &length, optional_suggestions ? & suggestions : NULL); |
| 136 if (optional_suggestions) { | 136 if (optional_suggestions) { |
| 137 *optional_suggestions = suggestions; | 137 WebVector<WebString> web_suggestions(suggestions.size()); |
| 138 std::transform( |
| 139 suggestions.begin(), suggestions.end(), web_suggestions.begin(), |
| 140 [](const base::string16& s) { return WebString::fromUTF16(s); }); |
| 141 *optional_suggestions = web_suggestions; |
| 138 UMA_HISTOGRAM_COUNTS("SpellCheck.api.check.suggestions", word.size()); | 142 UMA_HISTOGRAM_COUNTS("SpellCheck.api.check.suggestions", word.size()); |
| 139 } else { | 143 } else { |
| 140 UMA_HISTOGRAM_COUNTS("SpellCheck.api.check", word.size()); | 144 UMA_HISTOGRAM_COUNTS("SpellCheck.api.check", word.size()); |
| 141 // If optional_suggestions is not requested, the API is called | 145 // If optional_suggestions is not requested, the API is called |
| 142 // for marking. So we use this for counting markable words. | 146 // for marking. So we use this for counting markable words. |
| 143 Send(new SpellCheckHostMsg_NotifyChecked(routing_id(), word, 0 < length)); | 147 Send(new SpellCheckHostMsg_NotifyChecked(routing_id(), word, 0 < length)); |
| 144 } | 148 } |
| 145 } | 149 } |
| 146 | 150 |
| 147 void SpellCheckProvider::requestCheckingOfText( | 151 void SpellCheckProvider::requestCheckingOfText( |
| 148 const WebString& text, | 152 const WebString& text, |
| 149 const WebVector<uint32_t>& markers, | 153 const WebVector<uint32_t>& markers, |
| 150 const WebVector<unsigned>& marker_offsets, | 154 const WebVector<unsigned>& marker_offsets, |
| 151 WebTextCheckingCompletion* completion) { | 155 WebTextCheckingCompletion* completion) { |
| 152 std::vector<SpellCheckMarker> spellcheck_markers; | 156 std::vector<SpellCheckMarker> spellcheck_markers; |
| 153 for (size_t i = 0; i < markers.size(); ++i) { | 157 for (size_t i = 0; i < markers.size(); ++i) { |
| 154 spellcheck_markers.push_back( | 158 spellcheck_markers.push_back( |
| 155 SpellCheckMarker(markers[i], marker_offsets[i])); | 159 SpellCheckMarker(markers[i], marker_offsets[i])); |
| 156 } | 160 } |
| 157 RequestTextChecking(text, completion, spellcheck_markers); | 161 RequestTextChecking(text.utf16(), completion, spellcheck_markers); |
| 158 UMA_HISTOGRAM_COUNTS("SpellCheck.api.async", text.length()); | 162 UMA_HISTOGRAM_COUNTS("SpellCheck.api.async", text.length()); |
| 159 } | 163 } |
| 160 | 164 |
| 161 void SpellCheckProvider::cancelAllPendingRequests() { | 165 void SpellCheckProvider::cancelAllPendingRequests() { |
| 162 for (WebTextCheckCompletions::iterator iter(&text_check_completions_); | 166 for (WebTextCheckCompletions::iterator iter(&text_check_completions_); |
| 163 !iter.IsAtEnd(); iter.Advance()) { | 167 !iter.IsAtEnd(); iter.Advance()) { |
| 164 iter.GetCurrentValue()->didCancelCheckingText(); | 168 iter.GetCurrentValue()->didCancelCheckingText(); |
| 165 } | 169 } |
| 166 text_check_completions_.Clear(); | 170 text_check_completions_.Clear(); |
| 167 } | 171 } |
| 168 | 172 |
| 169 void SpellCheckProvider::showSpellingUI(bool show) { | 173 void SpellCheckProvider::showSpellingUI(bool show) { |
| 170 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) | 174 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| 171 UMA_HISTOGRAM_BOOLEAN("SpellCheck.api.showUI", show); | 175 UMA_HISTOGRAM_BOOLEAN("SpellCheck.api.showUI", show); |
| 172 Send(new SpellCheckHostMsg_ShowSpellingPanel(routing_id(), show)); | 176 Send(new SpellCheckHostMsg_ShowSpellingPanel(routing_id(), show)); |
| 173 #endif | 177 #endif |
| 174 } | 178 } |
| 175 | 179 |
| 176 bool SpellCheckProvider::isShowingSpellingUI() { | 180 bool SpellCheckProvider::isShowingSpellingUI() { |
| 177 return spelling_panel_visible_; | 181 return spelling_panel_visible_; |
| 178 } | 182 } |
| 179 | 183 |
| 180 void SpellCheckProvider::updateSpellingUIWithMisspelledWord( | 184 void SpellCheckProvider::updateSpellingUIWithMisspelledWord( |
| 181 const WebString& word) { | 185 const WebString& word) { |
| 182 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) | 186 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| 183 Send(new SpellCheckHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id(), | 187 Send(new SpellCheckHostMsg_UpdateSpellingPanelWithMisspelledWord( |
| 184 word)); | 188 routing_id(), word.utf16())); |
| 185 #endif | 189 #endif |
| 186 } | 190 } |
| 187 | 191 |
| 188 #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER) | 192 #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| 189 void SpellCheckProvider::OnRespondSpellingService( | 193 void SpellCheckProvider::OnRespondSpellingService( |
| 190 int identifier, | 194 int identifier, |
| 191 bool succeeded, | 195 bool succeeded, |
| 192 const base::string16& line, | 196 const base::string16& line, |
| 193 const std::vector<SpellCheckResult>& results) { | 197 const std::vector<SpellCheckResult>& results) { |
| 194 WebTextCheckingCompletion* completion = | 198 WebTextCheckingCompletion* completion = |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 completion->didFinishCheckingText(results); | 339 completion->didFinishCheckingText(results); |
| 336 return true; | 340 return true; |
| 337 } | 341 } |
| 338 | 342 |
| 339 return false; | 343 return false; |
| 340 } | 344 } |
| 341 | 345 |
| 342 void SpellCheckProvider::OnDestruct() { | 346 void SpellCheckProvider::OnDestruct() { |
| 343 delete this; | 347 delete this; |
| 344 } | 348 } |
| OLD | NEW |