OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_manager.h" | 5 #include "chrome/browser/translate/translate_manager.h" |
6 | 6 |
7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 notification_registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, | 347 notification_registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, |
348 NotificationService::AllSources()); | 348 NotificationService::AllSources()); |
349 notification_registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED, | 349 notification_registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED, |
350 NotificationService::AllSources()); | 350 NotificationService::AllSources()); |
351 notification_registrar_.Add(this, NotificationType::PAGE_TRANSLATED, | 351 notification_registrar_.Add(this, NotificationType::PAGE_TRANSLATED, |
352 NotificationService::AllSources()); | 352 NotificationService::AllSources()); |
353 } | 353 } |
354 | 354 |
355 void TranslateManager::InitiateTranslation(TabContents* tab, | 355 void TranslateManager::InitiateTranslation(TabContents* tab, |
356 const std::string& page_lang) { | 356 const std::string& page_lang) { |
357 PrefService* prefs = tab->profile()->GetPrefs(); | 357 PrefService* prefs = tab->profile()->GetOriginalProfile()->GetPrefs(); |
358 if (!prefs->GetBoolean(prefs::kEnableTranslate)) | 358 if (!prefs->GetBoolean(prefs::kEnableTranslate)) |
359 return; | 359 return; |
360 | 360 |
361 pref_change_registrar_.Init(prefs); | 361 pref_change_registrar_.Init(prefs); |
362 | 362 |
363 // Allow disabling of translate from the command line to assist with | 363 // Allow disabling of translate from the command line to assist with |
364 // automated browser testing. | 364 // automated browser testing. |
365 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableTranslate)) | 365 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableTranslate)) |
366 return; | 366 return; |
367 | 367 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 } else { | 539 } else { |
540 infobar = TranslateInfoBarDelegate::CreateDelegate( | 540 infobar = TranslateInfoBarDelegate::CreateDelegate( |
541 TranslateInfoBarDelegate::AFTER_TRANSLATE, tab, | 541 TranslateInfoBarDelegate::AFTER_TRANSLATE, tab, |
542 details->source_language, details->target_language); | 542 details->source_language, details->target_language); |
543 } | 543 } |
544 ShowInfoBar(tab, infobar); | 544 ShowInfoBar(tab, infobar); |
545 } | 545 } |
546 | 546 |
547 bool TranslateManager::IsAcceptLanguage(TabContents* tab, | 547 bool TranslateManager::IsAcceptLanguage(TabContents* tab, |
548 const std::string& language) { | 548 const std::string& language) { |
549 PrefService* pref_service = tab->profile()->GetPrefs(); | 549 PrefService* pref_service = tab->profile()->GetOriginalProfile()->GetPrefs(); |
550 PrefServiceLanguagesMap::const_iterator iter = | 550 PrefServiceLanguagesMap::const_iterator iter = |
551 accept_languages_.find(pref_service); | 551 accept_languages_.find(pref_service); |
552 if (iter == accept_languages_.end()) { | 552 if (iter == accept_languages_.end()) { |
553 InitAcceptLanguages(pref_service); | 553 InitAcceptLanguages(pref_service); |
554 // Listen for this profile going away, in which case we would need to clear | 554 // Listen for this profile going away, in which case we would need to clear |
555 // the accepted languages for the profile. | 555 // the accepted languages for the profile. |
556 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | 556 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, |
557 Source<Profile>(tab->profile())); | 557 Source<Profile>(tab->profile())); |
558 // Also start listening for changes in the accept languages. | 558 // Also start listening for changes in the accept languages. |
559 pref_change_registrar_.Add(prefs::kAcceptLanguages, this); | 559 pref_change_registrar_.Add(prefs::kAcceptLanguages, this); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 TranslateInfoBarDelegate* TranslateManager::GetTranslateInfoBarDelegate( | 632 TranslateInfoBarDelegate* TranslateManager::GetTranslateInfoBarDelegate( |
633 TabContents* tab) { | 633 TabContents* tab) { |
634 for (int i = 0; i < tab->infobar_delegate_count(); ++i) { | 634 for (int i = 0; i < tab->infobar_delegate_count(); ++i) { |
635 TranslateInfoBarDelegate* delegate = | 635 TranslateInfoBarDelegate* delegate = |
636 tab->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); | 636 tab->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); |
637 if (delegate) | 637 if (delegate) |
638 return delegate; | 638 return delegate; |
639 } | 639 } |
640 return NULL; | 640 return NULL; |
641 } | 641 } |
OLD | NEW |