| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/renderer_context_menu/spelling_menu_observer.h" | 5 #include "chrome/browser/renderer_context_menu/spelling_menu_observer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" | 14 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
| 15 #include "chrome/browser/renderer_context_menu/spelling_bubble_model.h" | 15 #include "chrome/browser/renderer_context_menu/spelling_bubble_model.h" |
| 16 #include "chrome/browser/spellchecker/feedback_sender.h" | 16 #include "chrome/browser/spellchecker/feedback_sender.h" |
| 17 #include "chrome/browser/spellchecker/spellcheck_factory.h" | 17 #include "chrome/browser/spellchecker/spellcheck_factory.h" |
| 18 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" | 18 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" |
| 19 #include "chrome/browser/spellchecker/spellcheck_platform_mac.h" | 19 #include "chrome/browser/spellchecker/spellcheck_platform_mac.h" |
| 20 #include "chrome/browser/spellchecker/spellcheck_service.h" | 20 #include "chrome/browser/spellchecker/spellcheck_service.h" |
| 21 #include "chrome/browser/spellchecker/spelling_service_client.h" | 21 #include "chrome/browser/spellchecker/spelling_service_client.h" |
| 22 #include "chrome/browser/ui/confirm_bubble.h" | 22 #include "chrome/browser/ui/confirm_bubble.h" |
| 23 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 25 #include "chrome/common/spellcheck_common.h" |
| 25 #include "chrome/common/spellcheck_result.h" | 26 #include "chrome/common/spellcheck_result.h" |
| 26 #include "chrome/grit/generated_resources.h" | 27 #include "chrome/grit/generated_resources.h" |
| 27 #include "content/public/browser/render_view_host.h" | 28 #include "content/public/browser/render_view_host.h" |
| 28 #include "content/public/browser/render_widget_host_view.h" | 29 #include "content/public/browser/render_widget_host_view.h" |
| 29 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
| 30 #include "content/public/common/context_menu_params.h" | 31 #include "content/public/common/context_menu_params.h" |
| 31 #include "extensions/browser/view_type_utils.h" | 32 #include "extensions/browser/view_type_utils.h" |
| 32 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 33 #include "ui/gfx/geometry/rect.h" | 34 #include "ui/gfx/geometry/rect.h" |
| 34 | 35 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 proxy_->AddSeparator(); | 158 proxy_->AddSeparator(); |
| 158 | 159 |
| 159 // |spellcheck_service| can be null when the suggested word is | 160 // |spellcheck_service| can be null when the suggested word is |
| 160 // provided by Web SpellCheck API. | 161 // provided by Web SpellCheck API. |
| 161 SpellcheckService* spellcheck_service = | 162 SpellcheckService* spellcheck_service = |
| 162 SpellcheckServiceFactory::GetForContext(browser_context); | 163 SpellcheckServiceFactory::GetForContext(browser_context); |
| 163 if (spellcheck_service && spellcheck_service->GetMetrics()) | 164 if (spellcheck_service && spellcheck_service->GetMetrics()) |
| 164 spellcheck_service->GetMetrics()->RecordSuggestionStats(1); | 165 spellcheck_service->GetMetrics()->RecordSuggestionStats(1); |
| 165 } | 166 } |
| 166 | 167 |
| 167 // If word is misspelled, give option for "Add to dictionary" and a check item | 168 // If word is misspelled, give option for "Add to dictionary" and, if |
| 168 // "Ask Google for suggestions". | 169 // multilingual spellchecking is not enabled, a check item "Ask Google for |
| 170 // suggestions". |
| 169 proxy_->AddMenuItem(IDC_SPELLCHECK_ADD_TO_DICTIONARY, | 171 proxy_->AddMenuItem(IDC_SPELLCHECK_ADD_TO_DICTIONARY, |
| 170 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY)); | 172 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY)); |
| 171 | 173 |
| 172 proxy_->AddCheckItem(IDC_CONTENT_CONTEXT_SPELLING_TOGGLE, | 174 if (!chrome::spellcheck_common::IsMultilingualSpellcheckEnabled()) { |
| 173 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLING_ASK_GOOGLE)); | 175 proxy_->AddCheckItem(IDC_CONTENT_CONTEXT_SPELLING_TOGGLE, |
| 176 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLING_ASK_GOOGLE)); |
| 177 } |
| 174 | 178 |
| 175 const base::CommandLine* command_line = | 179 const base::CommandLine* command_line = |
| 176 base::CommandLine::ForCurrentProcess(); | 180 base::CommandLine::ForCurrentProcess(); |
| 177 if (command_line->HasSwitch(switches::kEnableSpellingAutoCorrect)) { | 181 if (command_line->HasSwitch(switches::kEnableSpellingAutoCorrect)) { |
| 178 proxy_->AddCheckItem(IDC_CONTENT_CONTEXT_AUTOCORRECT_SPELLING_TOGGLE, | 182 proxy_->AddCheckItem(IDC_CONTENT_CONTEXT_AUTOCORRECT_SPELLING_TOGGLE, |
| 179 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLING_AUTOCORRECT)); | 183 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLING_AUTOCORRECT)); |
| 180 } | 184 } |
| 181 | 185 |
| 182 proxy_->AddSeparator(); | 186 proxy_->AddSeparator(); |
| 183 } | 187 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 198 default: | 202 default: |
| 199 return false; | 203 return false; |
| 200 } | 204 } |
| 201 } | 205 } |
| 202 | 206 |
| 203 bool SpellingMenuObserver::IsCommandIdChecked(int command_id) { | 207 bool SpellingMenuObserver::IsCommandIdChecked(int command_id) { |
| 204 DCHECK(IsCommandIdSupported(command_id)); | 208 DCHECK(IsCommandIdSupported(command_id)); |
| 205 Profile* profile = Profile::FromBrowserContext(proxy_->GetBrowserContext()); | 209 Profile* profile = Profile::FromBrowserContext(proxy_->GetBrowserContext()); |
| 206 | 210 |
| 207 if (command_id == IDC_CONTENT_CONTEXT_SPELLING_TOGGLE) | 211 if (command_id == IDC_CONTENT_CONTEXT_SPELLING_TOGGLE) |
| 208 return integrate_spelling_service_.GetValue() && !profile->IsOffTheRecord(); | 212 return integrate_spelling_service_.GetValue() && |
| 213 !profile->IsOffTheRecord() && |
| 214 !chrome::spellcheck_common::IsMultilingualSpellcheckEnabled(); |
| 209 if (command_id == IDC_CONTENT_CONTEXT_AUTOCORRECT_SPELLING_TOGGLE) | 215 if (command_id == IDC_CONTENT_CONTEXT_AUTOCORRECT_SPELLING_TOGGLE) |
| 210 return autocorrect_spelling_.GetValue() && !profile->IsOffTheRecord(); | 216 return autocorrect_spelling_.GetValue() && !profile->IsOffTheRecord(); |
| 211 return false; | 217 return false; |
| 212 } | 218 } |
| 213 | 219 |
| 214 bool SpellingMenuObserver::IsCommandIdEnabled(int command_id) { | 220 bool SpellingMenuObserver::IsCommandIdEnabled(int command_id) { |
| 215 DCHECK(IsCommandIdSupported(command_id)); | 221 DCHECK(IsCommandIdSupported(command_id)); |
| 216 | 222 |
| 217 if (command_id >= IDC_SPELLCHECK_SUGGESTION_0 && | 223 if (command_id >= IDC_SPELLCHECK_SUGGESTION_0 && |
| 218 command_id <= IDC_SPELLCHECK_SUGGESTION_LAST) | 224 command_id <= IDC_SPELLCHECK_SUGGESTION_LAST) |
| 219 return true; | 225 return true; |
| 220 | 226 |
| 221 Profile* profile = Profile::FromBrowserContext(proxy_->GetBrowserContext()); | 227 Profile* profile = Profile::FromBrowserContext(proxy_->GetBrowserContext()); |
| 222 switch (command_id) { | 228 switch (command_id) { |
| 223 case IDC_SPELLCHECK_ADD_TO_DICTIONARY: | 229 case IDC_SPELLCHECK_ADD_TO_DICTIONARY: |
| 224 return !misspelled_word_.empty(); | 230 return !misspelled_word_.empty(); |
| 225 | 231 |
| 226 case IDC_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS: | 232 case IDC_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS: |
| 227 return false; | 233 return false; |
| 228 | 234 |
| 229 case IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION: | 235 case IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION: |
| 230 return succeeded_; | 236 return succeeded_; |
| 231 | 237 |
| 232 case IDC_CONTENT_CONTEXT_SPELLING_TOGGLE: | 238 case IDC_CONTENT_CONTEXT_SPELLING_TOGGLE: |
| 233 return integrate_spelling_service_.IsUserModifiable() && | 239 return integrate_spelling_service_.IsUserModifiable() && |
| 234 !profile->IsOffTheRecord(); | 240 !profile->IsOffTheRecord() && |
| 241 !chrome::spellcheck_common::IsMultilingualSpellcheckEnabled(); |
| 235 | 242 |
| 236 case IDC_CONTENT_CONTEXT_AUTOCORRECT_SPELLING_TOGGLE: | 243 case IDC_CONTENT_CONTEXT_AUTOCORRECT_SPELLING_TOGGLE: |
| 237 return integrate_spelling_service_.IsUserModifiable() && | 244 return integrate_spelling_service_.IsUserModifiable() && |
| 238 !profile->IsOffTheRecord(); | 245 !profile->IsOffTheRecord(); |
| 239 | 246 |
| 240 default: | 247 default: |
| 241 return false; | 248 return false; |
| 242 } | 249 } |
| 243 } | 250 } |
| 244 | 251 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 // Append '.' characters to the end of "Checking". | 412 // Append '.' characters to the end of "Checking". |
| 406 loading_frame_ = (loading_frame_ + 1) & 3; | 413 loading_frame_ = (loading_frame_ + 1) & 3; |
| 407 base::string16 loading_message = | 414 base::string16 loading_message = |
| 408 loading_message_ + base::string16(loading_frame_,'.'); | 415 loading_message_ + base::string16(loading_frame_,'.'); |
| 409 | 416 |
| 410 // Update the menu item with the text. We disable this item to prevent users | 417 // Update the menu item with the text. We disable this item to prevent users |
| 411 // from selecting it. | 418 // from selecting it. |
| 412 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false, | 419 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false, |
| 413 loading_message); | 420 loading_message); |
| 414 } | 421 } |
| OLD | NEW |