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

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

Issue 15317007: Translate: split supporting language list handling to TranslateLanguageList (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: for review 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 | Annotate | Revision Log
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 "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/infobars/infobar_service.h" 12 #include "chrome/browser/infobars/infobar_service.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/translate/translate_language_list.h"
14 #include "chrome/browser/translate/translate_manager.h" 15 #include "chrome/browser/translate/translate_manager.h"
15 #include "chrome/browser/translate/translate_tab_helper.h" 16 #include "chrome/browser/translate/translate_tab_helper.h"
16 #include "content/public/browser/navigation_details.h" 17 #include "content/public/browser/navigation_details.h"
17 #include "content/public/browser/navigation_entry.h" 18 #include "content/public/browser/navigation_entry.h"
18 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
19 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
20 #include "grit/theme_resources.h" 21 #include "grit/theme_resources.h"
21 #include "third_party/icu/public/i18n/unicode/coll.h" 22 #include "third_party/icu/public/i18n/unicode/coll.h"
22 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
23 24
24 using content::NavigationEntry; 25 using content::NavigationEntry;
25 26
26 // static 27 // static
27 const size_t TranslateInfoBarDelegate::kNoIndex = static_cast<size_t>(-1); 28 const size_t TranslateInfoBarDelegate::kNoIndex = static_cast<size_t>(-1);
28 29
29 TranslateInfoBarDelegate::~TranslateInfoBarDelegate() { 30 TranslateInfoBarDelegate::~TranslateInfoBarDelegate() {
30 } 31 }
31 32
32 // static 33 // static
33 void TranslateInfoBarDelegate::Create( 34 void TranslateInfoBarDelegate::Create(
34 InfoBarService* infobar_service, bool replace_existing_infobar, 35 InfoBarService* infobar_service, bool replace_existing_infobar,
35 Type infobar_type, TranslateErrors::Type error_type, PrefService* prefs, 36 Type infobar_type, TranslateErrors::Type error_type, PrefService* prefs,
36 const ShortcutConfiguration& shortcut_config, 37 const ShortcutConfiguration& shortcut_config,
37 const std::string& original_language, const std::string& target_language) { 38 const std::string& original_language, const std::string& target_language) {
38 // Check preconditions. 39 // Check preconditions.
39 if (infobar_type != TRANSLATION_ERROR) { 40 if (infobar_type != TRANSLATION_ERROR) {
40 DCHECK(TranslateManager::IsSupportedLanguage(target_language)); 41 DCHECK(TranslateLanguageList::IsSupportedLanguage(target_language));
41 if (!TranslateManager::IsSupportedLanguage(original_language)) { 42 if (!TranslateLanguageList::IsSupportedLanguage(original_language)) {
42 // The original language can only be "unknown" for the "translating" 43 // The original language can only be "unknown" for the "translating"
43 // infobar, which is the case when the user started a translation from the 44 // infobar, which is the case when the user started a translation from the
44 // context menu. 45 // context menu.
45 DCHECK_EQ(TRANSLATING, infobar_type); 46 DCHECK_EQ(TRANSLATING, infobar_type);
46 DCHECK_EQ(chrome::kUnknownLanguageCode, original_language); 47 DCHECK_EQ(chrome::kUnknownLanguageCode, original_language);
47 } 48 }
48 } 49 }
49 50
50 // Find any existing translate infobar delegate. 51 // Find any existing translate infobar delegate.
51 TranslateInfoBarDelegate* old_delegate = NULL; 52 TranslateInfoBarDelegate* old_delegate = NULL;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 original_language_index_(kNoIndex), 305 original_language_index_(kNoIndex),
305 initial_original_language_index_(kNoIndex), 306 initial_original_language_index_(kNoIndex),
306 target_language_index_(kNoIndex), 307 target_language_index_(kNoIndex),
307 error_type_(error_type), 308 error_type_(error_type),
308 prefs_(prefs), 309 prefs_(prefs),
309 shortcut_config_(shortcut_config) { 310 shortcut_config_(shortcut_config) {
310 DCHECK_NE((infobar_type == TRANSLATION_ERROR), 311 DCHECK_NE((infobar_type == TRANSLATION_ERROR),
311 (error_type_ == TranslateErrors::NONE)); 312 (error_type_ == TranslateErrors::NONE));
312 313
313 std::vector<std::string> language_codes; 314 std::vector<std::string> language_codes;
314 TranslateManager::GetSupportedLanguages(&language_codes); 315 TranslateLanguageList::GetSupportedLanguages(&language_codes);
315 316
316 // Preparing for the alphabetical order in the locale. 317 // Preparing for the alphabetical order in the locale.
317 UErrorCode error = U_ZERO_ERROR; 318 UErrorCode error = U_ZERO_ERROR;
318 std::string locale = g_browser_process->GetApplicationLocale(); 319 std::string locale = g_browser_process->GetApplicationLocale();
319 icu::Locale loc(locale.c_str()); 320 icu::Locale loc(locale.c_str());
320 scoped_ptr<icu::Collator> collator(icu::Collator::createInstance(loc, error)); 321 scoped_ptr<icu::Collator> collator(icu::Collator::createInstance(loc, error));
321 collator->setStrength(icu::Collator::PRIMARY); 322 collator->setStrength(icu::Collator::PRIMARY);
322 323
323 languages_.reserve(language_codes.size()); 324 languages_.reserve(language_codes.size());
324 for (std::vector<std::string>::const_iterator iter = language_codes.begin(); 325 for (std::vector<std::string>::const_iterator iter = language_codes.begin();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 379
379 TranslateInfoBarDelegate* 380 TranslateInfoBarDelegate*
380 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { 381 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() {
381 return this; 382 return this;
382 } 383 }
383 384
384 std::string TranslateInfoBarDelegate::GetPageHost() { 385 std::string TranslateInfoBarDelegate::GetPageHost() {
385 NavigationEntry* entry = web_contents()->GetController().GetActiveEntry(); 386 NavigationEntry* entry = web_contents()->GetController().GetActiveEntry();
386 return entry ? entry->GetURL().HostNoBrackets() : std::string(); 387 return entry ? entry->GetURL().HostNoBrackets() : std::string();
387 } 388 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698