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

Side by Side Diff: chrome/browser/translate/translate_infobar_delegate.cc

Issue 159883002: Move TranslatePrefs to the Translate component (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@acceptLanguages
Patch Set: Fix ChromeOS browsertests Created 6 years, 10 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/browser/translate/translate_infobar_delegate.h" 5 #include "chrome/browser/translate/translate_infobar_delegate.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/i18n/string_compare.h" 9 #include "base/i18n/string_compare.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/infobars/infobar.h" 13 #include "chrome/browser/infobars/infobar.h"
14 #include "chrome/browser/infobars/infobar_service.h" 14 #include "chrome/browser/infobars/infobar_service.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/translate/translate_manager.h" 16 #include "chrome/browser/translate/translate_manager.h"
17 #include "chrome/browser/translate/translate_tab_helper.h" 17 #include "chrome/browser/translate/translate_tab_helper.h"
18 #include "components/translate/core/browser/translate_accept_languages.h"
18 #include "components/translate/core/browser/translate_download_manager.h" 19 #include "components/translate/core/browser/translate_download_manager.h"
19 #include "components/translate/core/common/translate_constants.h" 20 #include "components/translate/core/common/translate_constants.h"
20 #include "content/public/browser/navigation_details.h" 21 #include "content/public/browser/navigation_details.h"
21 #include "content/public/browser/navigation_entry.h" 22 #include "content/public/browser/navigation_entry.h"
22 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
23 #include "grit/generated_resources.h" 24 #include "grit/generated_resources.h"
24 #include "grit/theme_resources.h" 25 #include "grit/theme_resources.h"
25 #include "third_party/icu/source/i18n/unicode/coll.h" 26 #include "third_party/icu/source/i18n/unicode/coll.h"
26 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
27 28
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 } 135 }
135 136
136 void TranslateInfoBarDelegate::TranslationDeclined() { 137 void TranslateInfoBarDelegate::TranslationDeclined() {
137 ui_delegate_.TranslationDeclined(false); 138 ui_delegate_.TranslationDeclined(false);
138 } 139 }
139 140
140 bool TranslateInfoBarDelegate::IsTranslatableLanguageByPrefs() { 141 bool TranslateInfoBarDelegate::IsTranslatableLanguageByPrefs() {
141 Profile* profile = 142 Profile* profile =
142 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 143 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
143 Profile* original_profile = profile->GetOriginalProfile(); 144 Profile* original_profile = profile->GetOriginalProfile();
144 return TranslatePrefs::CanTranslateLanguage(original_profile, 145 scoped_ptr<TranslatePrefs> translate_prefs(
145 original_language_code()); 146 TranslateTabHelper::CreateTranslatePrefs(original_profile->GetPrefs()));
147 TranslateAcceptLanguages* accept_languages =
148 TranslateTabHelper::GetTranslateAcceptLanguages(original_profile);
149 return translate_prefs->CanTranslateLanguage(accept_languages,
150 original_language_code());
146 } 151 }
147 152
148 void TranslateInfoBarDelegate::ToggleTranslatableLanguageByPrefs() { 153 void TranslateInfoBarDelegate::ToggleTranslatableLanguageByPrefs() {
149 if (ui_delegate_.IsLanguageBlocked()) { 154 if (ui_delegate_.IsLanguageBlocked()) {
150 ui_delegate_.SetLanguageBlocked(false); 155 ui_delegate_.SetLanguageBlocked(false);
151 } else { 156 } else {
152 ui_delegate_.SetLanguageBlocked(true); 157 ui_delegate_.SetLanguageBlocked(true);
153 infobar()->RemoveSelf(); 158 infobar()->RemoveSelf();
154 } 159 }
155 } 160 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 web_contents(), original_language_code(), target_language_code()); 253 web_contents(), original_language_code(), target_language_code());
249 } 254 }
250 255
251 bool TranslateInfoBarDelegate::ShouldShowMessageInfoBarButton() { 256 bool TranslateInfoBarDelegate::ShouldShowMessageInfoBarButton() {
252 return !GetMessageInfoBarButtonText().empty(); 257 return !GetMessageInfoBarButtonText().empty();
253 } 258 }
254 259
255 bool TranslateInfoBarDelegate::ShouldShowNeverTranslateShortcut() { 260 bool TranslateInfoBarDelegate::ShouldShowNeverTranslateShortcut() {
256 DCHECK_EQ(BEFORE_TRANSLATE, infobar_type_); 261 DCHECK_EQ(BEFORE_TRANSLATE, infobar_type_);
257 return !web_contents()->GetBrowserContext()->IsOffTheRecord() && 262 return !web_contents()->GetBrowserContext()->IsOffTheRecord() &&
258 (prefs_.GetTranslationDeniedCount(original_language_code()) >= 263 (prefs_->GetTranslationDeniedCount(original_language_code()) >=
259 kNeverTranslateMinCount); 264 kNeverTranslateMinCount);
260 } 265 }
261 266
262 bool TranslateInfoBarDelegate::ShouldShowAlwaysTranslateShortcut() { 267 bool TranslateInfoBarDelegate::ShouldShowAlwaysTranslateShortcut() {
263 DCHECK_EQ(BEFORE_TRANSLATE, infobar_type_); 268 DCHECK_EQ(BEFORE_TRANSLATE, infobar_type_);
264 return !web_contents()->GetBrowserContext()->IsOffTheRecord() && 269 return !web_contents()->GetBrowserContext()->IsOffTheRecord() &&
265 (prefs_.GetTranslationAcceptedCount(original_language_code()) >= 270 (prefs_->GetTranslationAcceptedCount(original_language_code()) >=
266 kAlwaysTranslateMinCount); 271 kAlwaysTranslateMinCount);
267 } 272 }
268 273
269 // static 274 // static
270 base::string16 TranslateInfoBarDelegate::GetLanguageDisplayableName( 275 base::string16 TranslateInfoBarDelegate::GetLanguageDisplayableName(
271 const std::string& language_code) { 276 const std::string& language_code) {
272 return l10n_util::GetDisplayNameForLocale( 277 return l10n_util::GetDisplayNameForLocale(
273 language_code, g_browser_process->GetApplicationLocale(), true); 278 language_code, g_browser_process->GetApplicationLocale(), true);
274 } 279 }
275 280
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 TranslateInfoBarDelegate* old_delegate, 319 TranslateInfoBarDelegate* old_delegate,
315 const std::string& original_language, 320 const std::string& original_language,
316 const std::string& target_language, 321 const std::string& target_language,
317 TranslateErrors::Type error_type, 322 TranslateErrors::Type error_type,
318 PrefService* prefs) 323 PrefService* prefs)
319 : InfoBarDelegate(), 324 : InfoBarDelegate(),
320 infobar_type_(infobar_type), 325 infobar_type_(infobar_type),
321 background_animation_(NONE), 326 background_animation_(NONE),
322 ui_delegate_(web_contents, original_language, target_language), 327 ui_delegate_(web_contents, original_language, target_language),
323 error_type_(error_type), 328 error_type_(error_type),
324 prefs_(prefs) { 329 prefs_(TranslateTabHelper::CreateTranslatePrefs(prefs)) {
325 DCHECK_NE((infobar_type_ == TRANSLATION_ERROR), 330 DCHECK_NE((infobar_type_ == TRANSLATION_ERROR),
326 (error_type_ == TranslateErrors::NONE)); 331 (error_type_ == TranslateErrors::NONE));
327 332
328 if (old_delegate && (old_delegate->is_error() != is_error())) 333 if (old_delegate && (old_delegate->is_error() != is_error()))
329 background_animation_ = is_error() ? NORMAL_TO_ERROR : ERROR_TO_NORMAL; 334 background_animation_ = is_error() ? NORMAL_TO_ERROR : ERROR_TO_NORMAL;
330 } 335 }
331 336
332 // TranslateInfoBarDelegate::CreateInfoBar() is implemented in platform-specific 337 // TranslateInfoBarDelegate::CreateInfoBar() is implemented in platform-specific
333 // files. 338 // files.
334 339
(...skipping 21 matching lines...) Expand all
356 if (!details.is_navigation_to_different_page() && !details.is_main_frame) 361 if (!details.is_navigation_to_different_page() && !details.is_main_frame)
357 return false; 362 return false;
358 363
359 return InfoBarDelegate::ShouldExpireInternal(details); 364 return InfoBarDelegate::ShouldExpireInternal(details);
360 } 365 }
361 366
362 TranslateInfoBarDelegate* 367 TranslateInfoBarDelegate*
363 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { 368 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() {
364 return this; 369 return this;
365 } 370 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698