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" |
11 #include "components/spellcheck/common/spellcheck_result.h" | 11 #include "components/spellcheck/common/spellcheck_result.h" |
12 #include "components/spellcheck/renderer/spellcheck.h" | 12 #include "components/spellcheck/renderer/spellcheck.h" |
13 #include "components/spellcheck/renderer/spellcheck_language.h" | 13 #include "components/spellcheck/renderer/spellcheck_language.h" |
| 14 #include "components/spellcheck/spellcheck_build_features.h" |
14 #include "content/public/renderer/render_view.h" | 15 #include "content/public/renderer/render_view.h" |
15 #include "third_party/WebKit/public/platform/WebVector.h" | 16 #include "third_party/WebKit/public/platform/WebVector.h" |
16 #include "third_party/WebKit/public/web/WebDocument.h" | 17 #include "third_party/WebKit/public/web/WebDocument.h" |
17 #include "third_party/WebKit/public/web/WebElement.h" | 18 #include "third_party/WebKit/public/web/WebElement.h" |
18 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 19 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
19 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h" | 20 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h" |
20 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" | 21 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" |
21 #include "third_party/WebKit/public/web/WebTextDecorationType.h" | 22 #include "third_party/WebKit/public/web/WebTextDecorationType.h" |
22 #include "third_party/WebKit/public/web/WebView.h" | 23 #include "third_party/WebKit/public/web/WebView.h" |
23 | 24 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 66 |
66 // Try to satisfy check from cache. | 67 // Try to satisfy check from cache. |
67 if (SatisfyRequestFromCache(text, completion)) | 68 if (SatisfyRequestFromCache(text, completion)) |
68 return; | 69 return; |
69 | 70 |
70 // Send this text to a browser. A browser checks the user profile and send | 71 // Send this text to a browser. A browser checks the user profile and send |
71 // this text to the Spelling service only if a user enables this feature. | 72 // this text to the Spelling service only if a user enables this feature. |
72 last_request_.clear(); | 73 last_request_.clear(); |
73 last_results_.assign(blink::WebVector<blink::WebTextCheckingResult>()); | 74 last_results_.assign(blink::WebVector<blink::WebTextCheckingResult>()); |
74 | 75 |
75 #if defined(USE_BROWSER_SPELLCHECKER) | 76 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
76 // Text check (unified request for grammar and spell check) is only | 77 // Text check (unified request for grammar and spell check) is only |
77 // available for browser process, so we ask the system spellchecker | 78 // available for browser process, so we ask the system spellchecker |
78 // over IPC or return an empty result if the checker is not | 79 // over IPC or return an empty result if the checker is not |
79 // available. | 80 // available. |
80 Send(new SpellCheckHostMsg_RequestTextCheck( | 81 Send(new SpellCheckHostMsg_RequestTextCheck( |
81 routing_id(), | 82 routing_id(), |
82 text_check_completions_.Add(completion), | 83 text_check_completions_.Add(completion), |
83 text, | 84 text, |
84 markers)); | 85 markers)); |
85 #else | 86 #else |
86 Send(new SpellCheckHostMsg_CallSpellingService( | 87 Send(new SpellCheckHostMsg_CallSpellingService( |
87 routing_id(), | 88 routing_id(), |
88 text_check_completions_.Add(completion), | 89 text_check_completions_.Add(completion), |
89 base::string16(text), | 90 base::string16(text), |
90 markers)); | 91 markers)); |
91 #endif // !USE_BROWSER_SPELLCHECKER | 92 #endif // !USE_BROWSER_SPELLCHECKER |
92 } | 93 } |
93 | 94 |
94 bool SpellCheckProvider::OnMessageReceived(const IPC::Message& message) { | 95 bool SpellCheckProvider::OnMessageReceived(const IPC::Message& message) { |
95 bool handled = true; | 96 bool handled = true; |
96 IPC_BEGIN_MESSAGE_MAP(SpellCheckProvider, message) | 97 IPC_BEGIN_MESSAGE_MAP(SpellCheckProvider, message) |
97 #if !defined(USE_BROWSER_SPELLCHECKER) | 98 #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
98 IPC_MESSAGE_HANDLER(SpellCheckMsg_RespondSpellingService, | 99 IPC_MESSAGE_HANDLER(SpellCheckMsg_RespondSpellingService, |
99 OnRespondSpellingService) | 100 OnRespondSpellingService) |
100 #endif | 101 #endif |
101 #if defined(USE_BROWSER_SPELLCHECKER) | 102 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
102 IPC_MESSAGE_HANDLER(SpellCheckMsg_AdvanceToNextMisspelling, | 103 IPC_MESSAGE_HANDLER(SpellCheckMsg_AdvanceToNextMisspelling, |
103 OnAdvanceToNextMisspelling) | 104 OnAdvanceToNextMisspelling) |
104 IPC_MESSAGE_HANDLER(SpellCheckMsg_RespondTextCheck, OnRespondTextCheck) | 105 IPC_MESSAGE_HANDLER(SpellCheckMsg_RespondTextCheck, OnRespondTextCheck) |
105 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellPanel, OnToggleSpellPanel) | 106 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellPanel, OnToggleSpellPanel) |
106 #endif | 107 #endif |
107 IPC_MESSAGE_UNHANDLED(handled = false) | 108 IPC_MESSAGE_UNHANDLED(handled = false) |
108 IPC_END_MESSAGE_MAP() | 109 IPC_END_MESSAGE_MAP() |
109 return handled; | 110 return handled; |
110 } | 111 } |
111 | 112 |
112 void SpellCheckProvider::FocusedNodeChanged(const blink::WebNode& unused) { | 113 void SpellCheckProvider::FocusedNodeChanged(const blink::WebNode& unused) { |
113 #if defined(USE_BROWSER_SPELLCHECKER) | 114 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
114 WebLocalFrame* frame = render_view()->GetWebView()->focusedFrame(); | 115 WebLocalFrame* frame = render_view()->GetWebView()->focusedFrame(); |
115 WebElement element = frame->document().isNull() ? WebElement() : | 116 WebElement element = frame->document().isNull() ? WebElement() : |
116 frame->document().focusedElement(); | 117 frame->document().focusedElement(); |
117 bool enabled = !element.isNull() && element.isEditable(); | 118 bool enabled = !element.isNull() && element.isEditable(); |
118 bool checked = enabled && frame->isSpellCheckingEnabled(); | 119 bool checked = enabled && frame->isSpellCheckingEnabled(); |
119 | 120 |
120 Send(new SpellCheckHostMsg_ToggleSpellCheck(routing_id(), enabled, checked)); | 121 Send(new SpellCheckHostMsg_ToggleSpellCheck(routing_id(), enabled, checked)); |
121 #endif // USE_BROWSER_SPELLCHECKER | 122 #endif // USE_BROWSER_SPELLCHECKER |
122 } | 123 } |
123 | 124 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 160 |
160 void SpellCheckProvider::cancelAllPendingRequests() { | 161 void SpellCheckProvider::cancelAllPendingRequests() { |
161 for (WebTextCheckCompletions::iterator iter(&text_check_completions_); | 162 for (WebTextCheckCompletions::iterator iter(&text_check_completions_); |
162 !iter.IsAtEnd(); iter.Advance()) { | 163 !iter.IsAtEnd(); iter.Advance()) { |
163 iter.GetCurrentValue()->didCancelCheckingText(); | 164 iter.GetCurrentValue()->didCancelCheckingText(); |
164 } | 165 } |
165 text_check_completions_.Clear(); | 166 text_check_completions_.Clear(); |
166 } | 167 } |
167 | 168 |
168 void SpellCheckProvider::showSpellingUI(bool show) { | 169 void SpellCheckProvider::showSpellingUI(bool show) { |
169 #if defined(USE_BROWSER_SPELLCHECKER) | 170 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
170 UMA_HISTOGRAM_BOOLEAN("SpellCheck.api.showUI", show); | 171 UMA_HISTOGRAM_BOOLEAN("SpellCheck.api.showUI", show); |
171 Send(new SpellCheckHostMsg_ShowSpellingPanel(routing_id(), show)); | 172 Send(new SpellCheckHostMsg_ShowSpellingPanel(routing_id(), show)); |
172 #endif | 173 #endif |
173 } | 174 } |
174 | 175 |
175 bool SpellCheckProvider::isShowingSpellingUI() { | 176 bool SpellCheckProvider::isShowingSpellingUI() { |
176 return spelling_panel_visible_; | 177 return spelling_panel_visible_; |
177 } | 178 } |
178 | 179 |
179 void SpellCheckProvider::updateSpellingUIWithMisspelledWord( | 180 void SpellCheckProvider::updateSpellingUIWithMisspelledWord( |
180 const WebString& word) { | 181 const WebString& word) { |
181 #if defined(USE_BROWSER_SPELLCHECKER) | 182 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
182 Send(new SpellCheckHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id(), | 183 Send(new SpellCheckHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id(), |
183 word)); | 184 word)); |
184 #endif | 185 #endif |
185 } | 186 } |
186 | 187 |
187 #if !defined(USE_BROWSER_SPELLCHECKER) | 188 #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
188 void SpellCheckProvider::OnRespondSpellingService( | 189 void SpellCheckProvider::OnRespondSpellingService( |
189 int identifier, | 190 int identifier, |
190 bool succeeded, | 191 bool succeeded, |
191 const base::string16& line, | 192 const base::string16& line, |
192 const std::vector<SpellCheckResult>& results) { | 193 const std::vector<SpellCheckResult>& results) { |
193 WebTextCheckingCompletion* completion = | 194 WebTextCheckingCompletion* completion = |
194 text_check_completions_.Lookup(identifier); | 195 text_check_completions_.Lookup(identifier); |
195 if (!completion) | 196 if (!completion) |
196 return; | 197 return; |
197 text_check_completions_.Remove(identifier); | 198 text_check_completions_.Remove(identifier); |
(...skipping 28 matching lines...) Expand all Loading... |
226 while (index < length) { | 227 while (index < length) { |
227 uint32_t code = 0; | 228 uint32_t code = 0; |
228 U16_NEXT(data, index, length, code); | 229 U16_NEXT(data, index, length, code); |
229 UErrorCode error = U_ZERO_ERROR; | 230 UErrorCode error = U_ZERO_ERROR; |
230 if (uscript_getScript(code, &error) != USCRIPT_COMMON) | 231 if (uscript_getScript(code, &error) != USCRIPT_COMMON) |
231 return true; | 232 return true; |
232 } | 233 } |
233 return false; | 234 return false; |
234 } | 235 } |
235 | 236 |
236 #if defined(USE_BROWSER_SPELLCHECKER) | 237 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
237 void SpellCheckProvider::OnAdvanceToNextMisspelling() { | 238 void SpellCheckProvider::OnAdvanceToNextMisspelling() { |
238 if (!render_view()->GetWebView()) | 239 if (!render_view()->GetWebView()) |
239 return; | 240 return; |
240 render_view()->GetWebView()->focusedFrame()->executeCommand( | 241 render_view()->GetWebView()->focusedFrame()->executeCommand( |
241 WebString::fromUTF8("AdvanceToNextMisspelling")); | 242 WebString::fromUTF8("AdvanceToNextMisspelling")); |
242 } | 243 } |
243 | 244 |
244 void SpellCheckProvider::OnRespondTextCheck( | 245 void SpellCheckProvider::OnRespondTextCheck( |
245 int identifier, | 246 int identifier, |
246 const base::string16& line, | 247 const base::string16& line, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 return true; | 342 return true; |
342 } | 343 } |
343 } | 344 } |
344 | 345 |
345 return false; | 346 return false; |
346 } | 347 } |
347 | 348 |
348 void SpellCheckProvider::OnDestruct() { | 349 void SpellCheckProvider::OnDestruct() { |
349 delete this; | 350 delete this; |
350 } | 351 } |
OLD | NEW |