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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/singleton.h" | 10 #include "base/singleton.h" |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 notification_registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, | 348 notification_registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, |
349 NotificationService::AllSources()); | 349 NotificationService::AllSources()); |
350 notification_registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED, | 350 notification_registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED, |
351 NotificationService::AllSources()); | 351 NotificationService::AllSources()); |
352 notification_registrar_.Add(this, NotificationType::PAGE_TRANSLATED, | 352 notification_registrar_.Add(this, NotificationType::PAGE_TRANSLATED, |
353 NotificationService::AllSources()); | 353 NotificationService::AllSources()); |
354 } | 354 } |
355 | 355 |
356 void TranslateManager::InitiateTranslation(TabContents* tab, | 356 void TranslateManager::InitiateTranslation(TabContents* tab, |
357 const std::string& page_lang) { | 357 const std::string& page_lang) { |
358 PrefService* prefs = tab->profile()->GetPrefs(); | 358 PrefService* prefs = tab->profile()->GetOriginalProfile()->GetPrefs(); |
359 if (!prefs->GetBoolean(prefs::kEnableTranslate)) | 359 if (!prefs->GetBoolean(prefs::kEnableTranslate)) |
360 return; | 360 return; |
361 | 361 |
362 pref_change_registrar_.Init(prefs); | 362 pref_change_registrar_.Init(prefs); |
363 | 363 |
364 // Allow disabling of translate from the command line to assist with | 364 // Allow disabling of translate from the command line to assist with |
365 // automated browser testing. | 365 // automated browser testing. |
366 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableTranslate)) | 366 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableTranslate)) |
367 return; | 367 return; |
368 | 368 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 } else { | 541 } else { |
542 infobar = TranslateInfoBarDelegate::CreateDelegate( | 542 infobar = TranslateInfoBarDelegate::CreateDelegate( |
543 TranslateInfoBarDelegate::AFTER_TRANSLATE, tab, | 543 TranslateInfoBarDelegate::AFTER_TRANSLATE, tab, |
544 details->source_language, details->target_language); | 544 details->source_language, details->target_language); |
545 } | 545 } |
546 ShowInfoBar(tab, infobar); | 546 ShowInfoBar(tab, infobar); |
547 } | 547 } |
548 | 548 |
549 bool TranslateManager::IsAcceptLanguage(TabContents* tab, | 549 bool TranslateManager::IsAcceptLanguage(TabContents* tab, |
550 const std::string& language) { | 550 const std::string& language) { |
551 PrefService* pref_service = tab->profile()->GetPrefs(); | 551 PrefService* pref_service = tab->profile()->GetOriginalProfile()->GetPrefs(); |
552 PrefServiceLanguagesMap::const_iterator iter = | 552 PrefServiceLanguagesMap::const_iterator iter = |
553 accept_languages_.find(pref_service); | 553 accept_languages_.find(pref_service); |
554 if (iter == accept_languages_.end()) { | 554 if (iter == accept_languages_.end()) { |
555 InitAcceptLanguages(pref_service); | 555 InitAcceptLanguages(pref_service); |
556 // Listen for this profile going away, in which case we would need to clear | 556 // Listen for this profile going away, in which case we would need to clear |
557 // the accepted languages for the profile. | 557 // the accepted languages for the profile. |
558 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | 558 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, |
559 Source<Profile>(tab->profile())); | 559 Source<Profile>(tab->profile())); |
560 // Also start listening for changes in the accept languages. | 560 // Also start listening for changes in the accept languages. |
561 pref_change_registrar_.Add(prefs::kAcceptLanguages, this); | 561 pref_change_registrar_.Add(prefs::kAcceptLanguages, this); |
(...skipping 70 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 |