Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(619)

Side by Side Diff: chrome/renderer/spellchecker/spellcheck_provider.cc

Issue 15318004: Store feedback for spellcheck results from spelling service (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Move typedefs to feedback.h Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 #include "chrome/common/spellcheck_marker.h"
10 #include "chrome/common/spellcheck_messages.h" 11 #include "chrome/common/spellcheck_messages.h"
11 #include "chrome/common/spellcheck_result.h" 12 #include "chrome/common/spellcheck_result.h"
12 #include "chrome/renderer/spellchecker/spellcheck.h" 13 #include "chrome/renderer/spellchecker/spellcheck.h"
13 #include "content/public/renderer/render_view.h" 14 #include "content/public/renderer/render_view.h"
14 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingComple tion.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingComple tion.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult .h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult .h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingType.h " 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingType.h "
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
(...skipping 22 matching lines...) Expand all
42 render_view->GetWebView()->setSpellCheckClient(this); 43 render_view->GetWebView()->setSpellCheckClient(this);
43 EnableSpellcheck(spellcheck_->is_spellcheck_enabled()); 44 EnableSpellcheck(spellcheck_->is_spellcheck_enabled());
44 } 45 }
45 } 46 }
46 47
47 SpellCheckProvider::~SpellCheckProvider() { 48 SpellCheckProvider::~SpellCheckProvider() {
48 } 49 }
49 50
50 void SpellCheckProvider::RequestTextChecking( 51 void SpellCheckProvider::RequestTextChecking(
51 const WebString& text, 52 const WebString& text,
52 WebTextCheckingCompletion* completion) { 53 WebTextCheckingCompletion* completion,
54 const std::vector<SpellCheckMarker>& markers) {
53 // Ignore invalid requests. 55 // Ignore invalid requests.
54 if (text.isEmpty() || !HasWordCharacters(text, 0)) { 56 if (text.isEmpty() || !HasWordCharacters(text, 0)) {
55 completion->didCancelCheckingText(); 57 completion->didCancelCheckingText();
56 return; 58 return;
57 } 59 }
58 60
59 // Try to satisfy check from cache. 61 // Try to satisfy check from cache.
60 if (SatisfyRequestFromCache(text, completion)) 62 if (SatisfyRequestFromCache(text, completion))
61 return; 63 return;
62 64
63 // Send this text to a browser. A browser checks the user profile and send 65 // Send this text to a browser. A browser checks the user profile and send
64 // this text to the Spelling service only if a user enables this feature. 66 // this text to the Spelling service only if a user enables this feature.
65 last_request_.clear(); 67 last_request_.clear();
66 last_results_.assign(WebKit::WebVector<WebKit::WebTextCheckingResult>()); 68 last_results_.assign(WebKit::WebVector<WebKit::WebTextCheckingResult>());
67 69
68 #if defined(OS_MACOSX) 70 #if defined(OS_MACOSX)
69 // Text check (unified request for grammar and spell check) is only 71 // Text check (unified request for grammar and spell check) is only
70 // available for browser process, so we ask the system spellchecker 72 // available for browser process, so we ask the system spellchecker
71 // over IPC or return an empty result if the checker is not 73 // over IPC or return an empty result if the checker is not
72 // available. 74 // available.
73 Send(new SpellCheckHostMsg_RequestTextCheck( 75 Send(new SpellCheckHostMsg_RequestTextCheck(
74 routing_id(), 76 routing_id(),
75 text_check_completions_.Add(completion), 77 text_check_completions_.Add(completion),
76 text)); 78 text));
77 #else 79 #else
78 Send(new SpellCheckHostMsg_CallSpellingService( 80 Send(new SpellCheckHostMsg_CallSpellingService(
79 routing_id(), 81 routing_id(),
80 text_check_completions_.Add(completion), 82 text_check_completions_.Add(completion),
81 string16(text))); 83 string16(text),
84 markers));
82 #endif // !OS_MACOSX 85 #endif // !OS_MACOSX
83 } 86 }
84 87
85 bool SpellCheckProvider::OnMessageReceived(const IPC::Message& message) { 88 bool SpellCheckProvider::OnMessageReceived(const IPC::Message& message) {
86 bool handled = true; 89 bool handled = true;
87 IPC_BEGIN_MESSAGE_MAP(SpellCheckProvider, message) 90 IPC_BEGIN_MESSAGE_MAP(SpellCheckProvider, message)
88 #if !defined(OS_MACOSX) 91 #if !defined(OS_MACOSX)
89 IPC_MESSAGE_HANDLER(SpellCheckMsg_RespondSpellingService, 92 IPC_MESSAGE_HANDLER(SpellCheckMsg_RespondSpellingService,
90 OnRespondSpellingService) 93 OnRespondSpellingService)
91 #endif 94 #endif
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 NOTREACHED(); 157 NOTREACHED();
155 spellcheck_->SpellCheckParagraph(string16(text), results); 158 spellcheck_->SpellCheckParagraph(string16(text), results);
156 UMA_HISTOGRAM_COUNTS("SpellCheck.api.paragraph", text.length()); 159 UMA_HISTOGRAM_COUNTS("SpellCheck.api.paragraph", text.length());
157 } 160 }
158 161
159 void SpellCheckProvider::requestCheckingOfText( 162 void SpellCheckProvider::requestCheckingOfText(
160 const WebString& text, 163 const WebString& text,
161 const WebVector<uint32>& markers, 164 const WebVector<uint32>& markers,
162 const WebVector<unsigned>& marker_offsets, 165 const WebVector<unsigned>& marker_offsets,
163 WebTextCheckingCompletion* completion) { 166 WebTextCheckingCompletion* completion) {
164 RequestTextChecking(text, completion); 167 std::vector<SpellCheckMarker> spellcheck_markers;
168 for (size_t i = 0; i < markers.size(); ++i) {
169 spellcheck_markers.push_back(
170 SpellCheckMarker(markers[i], marker_offsets[i]));
171 }
172 RequestTextChecking(text, completion, spellcheck_markers);
165 UMA_HISTOGRAM_COUNTS("SpellCheck.api.async", text.length()); 173 UMA_HISTOGRAM_COUNTS("SpellCheck.api.async", text.length());
166 } 174 }
167 175
168 WebString SpellCheckProvider::autoCorrectWord(const WebString& word) { 176 WebString SpellCheckProvider::autoCorrectWord(const WebString& word) {
169 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 177 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
170 if (command_line.HasSwitch(switches::kEnableSpellingAutoCorrect)) { 178 if (command_line.HasSwitch(switches::kEnableSpellingAutoCorrect)) {
171 UMA_HISTOGRAM_COUNTS("SpellCheck.api.autocorrect", word.length()); 179 UMA_HISTOGRAM_COUNTS("SpellCheck.api.autocorrect", word.length());
172 return spellcheck_->GetAutoCorrectionWord(word, routing_id()); 180 return spellcheck_->GetAutoCorrectionWord(word, routing_id());
173 } 181 }
174 return string16(); 182 return string16();
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 results[i].length = last_results_[i].length; 348 results[i].length = last_results_[i].length;
341 results[i].replacement = last_results_[i].replacement; 349 results[i].replacement = last_results_[i].replacement;
342 } 350 }
343 completion->didFinishCheckingText(results); 351 completion->didFinishCheckingText(results);
344 return true; 352 return true;
345 } 353 }
346 } 354 }
347 355
348 return false; 356 return false;
349 } 357 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698