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

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

Issue 2177023002: Remove spellchecker feedback. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile Created 4 years, 4 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/renderer/spellchecker/spellcheck.h" 10 #include "chrome/renderer/spellchecker/spellcheck.h"
11 #include "chrome/renderer/spellchecker/spellcheck_language.h" 11 #include "chrome/renderer/spellchecker/spellcheck_language.h"
12 #include "components/spellcheck/common/spellcheck_marker.h"
13 #include "components/spellcheck/common/spellcheck_messages.h" 12 #include "components/spellcheck/common/spellcheck_messages.h"
14 #include "components/spellcheck/common/spellcheck_result.h" 13 #include "components/spellcheck/common/spellcheck_result.h"
15 #include "content/public/renderer/render_view.h" 14 #include "content/public/renderer/render_view.h"
16 #include "third_party/WebKit/public/platform/WebVector.h" 15 #include "third_party/WebKit/public/platform/WebVector.h"
17 #include "third_party/WebKit/public/web/WebDocument.h" 16 #include "third_party/WebKit/public/web/WebDocument.h"
18 #include "third_party/WebKit/public/web/WebElement.h" 17 #include "third_party/WebKit/public/web/WebElement.h"
19 #include "third_party/WebKit/public/web/WebLocalFrame.h" 18 #include "third_party/WebKit/public/web/WebLocalFrame.h"
20 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h" 19 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h"
21 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" 20 #include "third_party/WebKit/public/web/WebTextCheckingResult.h"
22 #include "third_party/WebKit/public/web/WebTextDecorationType.h" 21 #include "third_party/WebKit/public/web/WebTextDecorationType.h"
23 #include "third_party/WebKit/public/web/WebView.h" 22 #include "third_party/WebKit/public/web/WebView.h"
24 23
25 using blink::WebElement; 24 using blink::WebElement;
26 using blink::WebLocalFrame; 25 using blink::WebLocalFrame;
27 using blink::WebString; 26 using blink::WebString;
28 using blink::WebTextCheckingCompletion; 27 using blink::WebTextCheckingCompletion;
29 using blink::WebTextCheckingResult; 28 using blink::WebTextCheckingResult;
30 using blink::WebTextDecorationType; 29 using blink::WebTextDecorationType;
31 using blink::WebVector; 30 using blink::WebVector;
32 31
33 static_assert(int(blink::WebTextDecorationTypeSpelling) == 32 static_assert(int(blink::WebTextDecorationTypeSpelling) ==
34 int(SpellCheckResult::SPELLING), "mismatching enums"); 33 int(SpellCheckResult::SPELLING), "mismatching enums");
35 static_assert(int(blink::WebTextDecorationTypeGrammar) == 34 static_assert(int(blink::WebTextDecorationTypeGrammar) ==
36 int(SpellCheckResult::GRAMMAR), "mismatching enums"); 35 int(SpellCheckResult::GRAMMAR), "mismatching enums");
37 static_assert(int(blink::WebTextDecorationTypeInvisibleSpellcheck) ==
38 int(SpellCheckResult::INVISIBLE), "mismatching enums");
39 36
40 SpellCheckProvider::SpellCheckProvider( 37 SpellCheckProvider::SpellCheckProvider(
41 content::RenderView* render_view, 38 content::RenderView* render_view,
42 SpellCheck* spellcheck) 39 SpellCheck* spellcheck)
43 : content::RenderViewObserver(render_view), 40 : content::RenderViewObserver(render_view),
44 content::RenderViewObserverTracker<SpellCheckProvider>(render_view), 41 content::RenderViewObserverTracker<SpellCheckProvider>(render_view),
45 spelling_panel_visible_(false), 42 spelling_panel_visible_(false),
46 spellcheck_(spellcheck) { 43 spellcheck_(spellcheck) {
47 DCHECK(spellcheck_); 44 DCHECK(spellcheck_);
48 if (render_view) { // NULL in unit tests. 45 if (render_view) { // NULL in unit tests.
49 render_view->GetWebView()->setSpellCheckClient(this); 46 render_view->GetWebView()->setSpellCheckClient(this);
50 EnableSpellcheck(spellcheck_->IsSpellcheckEnabled()); 47 EnableSpellcheck(spellcheck_->IsSpellcheckEnabled());
51 } 48 }
52 } 49 }
53 50
54 SpellCheckProvider::~SpellCheckProvider() { 51 SpellCheckProvider::~SpellCheckProvider() {
55 } 52 }
56 53
57 void SpellCheckProvider::RequestTextChecking( 54 void SpellCheckProvider::RequestTextChecking(
58 const base::string16& text, 55 const base::string16& text,
59 WebTextCheckingCompletion* completion, 56 WebTextCheckingCompletion* completion) {
60 const std::vector<SpellCheckMarker>& markers) {
61 // Ignore invalid requests. 57 // Ignore invalid requests.
62 if (text.empty() || !HasWordCharacters(text, 0)) { 58 if (text.empty() || !HasWordCharacters(text, 0)) {
63 completion->didCancelCheckingText(); 59 completion->didCancelCheckingText();
64 return; 60 return;
65 } 61 }
66 62
67 // Try to satisfy check from cache. 63 // Try to satisfy check from cache.
68 if (SatisfyRequestFromCache(text, completion)) 64 if (SatisfyRequestFromCache(text, completion))
69 return; 65 return;
70 66
71 // Send this text to a browser. A browser checks the user profile and send 67 // Send this text to a browser. A browser checks the user profile and send
72 // this text to the Spelling service only if a user enables this feature. 68 // this text to the Spelling service only if a user enables this feature.
73 last_request_.clear(); 69 last_request_.clear();
74 last_results_.assign(blink::WebVector<blink::WebTextCheckingResult>()); 70 last_results_.assign(blink::WebVector<blink::WebTextCheckingResult>());
75 71
76 #if defined(USE_BROWSER_SPELLCHECKER) 72 #if defined(USE_BROWSER_SPELLCHECKER)
77 // Text check (unified request for grammar and spell check) is only 73 // Text check (unified request for grammar and spell check) is only
78 // available for browser process, so we ask the system spellchecker 74 // available for browser process, so we ask the system spellchecker
79 // over IPC or return an empty result if the checker is not 75 // over IPC or return an empty result if the checker is not
80 // available. 76 // available.
81 Send(new SpellCheckHostMsg_RequestTextCheck( 77 Send(new SpellCheckHostMsg_RequestTextCheck(
82 routing_id(), 78 routing_id(),
83 text_check_completions_.Add(completion), 79 text_check_completions_.Add(completion),
84 text, 80 text));
85 markers));
86 #else 81 #else
87 Send(new SpellCheckHostMsg_CallSpellingService( 82 Send(new SpellCheckHostMsg_CallSpellingService(
88 routing_id(), 83 routing_id(),
89 text_check_completions_.Add(completion), 84 text_check_completions_.Add(completion),
90 base::string16(text), 85 base::string16(text)));
91 markers));
92 #endif // !USE_BROWSER_SPELLCHECKER 86 #endif // !USE_BROWSER_SPELLCHECKER
93 } 87 }
94 88
95 bool SpellCheckProvider::OnMessageReceived(const IPC::Message& message) { 89 bool SpellCheckProvider::OnMessageReceived(const IPC::Message& message) {
96 bool handled = true; 90 bool handled = true;
97 IPC_BEGIN_MESSAGE_MAP(SpellCheckProvider, message) 91 IPC_BEGIN_MESSAGE_MAP(SpellCheckProvider, message)
98 #if !defined(USE_BROWSER_SPELLCHECKER) 92 #if !defined(USE_BROWSER_SPELLCHECKER)
99 IPC_MESSAGE_HANDLER(SpellCheckMsg_RespondSpellingService, 93 IPC_MESSAGE_HANDLER(SpellCheckMsg_RespondSpellingService,
100 OnRespondSpellingService) 94 OnRespondSpellingService)
101 #endif 95 #endif
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 150
157 // TODO(groby): As far as I can tell, this method is never invoked. 151 // TODO(groby): As far as I can tell, this method is never invoked.
158 // UMA results seem to support that. Investigate, clean up if true. 152 // UMA results seem to support that. Investigate, clean up if true.
159 NOTREACHED(); 153 NOTREACHED();
160 spellcheck_->SpellCheckParagraph(text, results); 154 spellcheck_->SpellCheckParagraph(text, results);
161 UMA_HISTOGRAM_COUNTS("SpellCheck.api.paragraph", text.length()); 155 UMA_HISTOGRAM_COUNTS("SpellCheck.api.paragraph", text.length());
162 } 156 }
163 157
164 void SpellCheckProvider::requestCheckingOfText( 158 void SpellCheckProvider::requestCheckingOfText(
165 const WebString& text, 159 const WebString& text,
166 const WebVector<uint32_t>& markers,
167 const WebVector<unsigned>& marker_offsets,
168 WebTextCheckingCompletion* completion) { 160 WebTextCheckingCompletion* completion) {
169 std::vector<SpellCheckMarker> spellcheck_markers; 161 RequestTextChecking(text, completion);
170 for (size_t i = 0; i < markers.size(); ++i) {
171 spellcheck_markers.push_back(
172 SpellCheckMarker(markers[i], marker_offsets[i]));
173 }
174 RequestTextChecking(text, completion, spellcheck_markers);
175 UMA_HISTOGRAM_COUNTS("SpellCheck.api.async", text.length()); 162 UMA_HISTOGRAM_COUNTS("SpellCheck.api.async", text.length());
176 } 163 }
177 164
178 void SpellCheckProvider::showSpellingUI(bool show) { 165 void SpellCheckProvider::showSpellingUI(bool show) {
179 #if defined(USE_BROWSER_SPELLCHECKER) 166 #if defined(USE_BROWSER_SPELLCHECKER)
180 UMA_HISTOGRAM_BOOLEAN("SpellCheck.api.showUI", show); 167 UMA_HISTOGRAM_BOOLEAN("SpellCheck.api.showUI", show);
181 Send(new SpellCheckHostMsg_ShowSpellingPanel(routing_id(), show)); 168 Send(new SpellCheckHostMsg_ShowSpellingPanel(routing_id(), show));
182 #endif 169 #endif
183 } 170 }
184 171
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 return true; 338 return true;
352 } 339 }
353 } 340 }
354 341
355 return false; 342 return false;
356 } 343 }
357 344
358 void SpellCheckProvider::OnDestruct() { 345 void SpellCheckProvider::OnDestruct() {
359 delete this; 346 delete this;
360 } 347 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698