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

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

Issue 7810002: Move infobar handling to a tab helper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update Created 9 years, 3 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) 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/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/string_split.h" 12 #include "base/string_split.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/autofill/autofill_manager.h" 15 #include "chrome/browser/autofill/autofill_manager.h"
16 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/infobars/infobar_tab_helper.h"
17 #include "chrome/browser/prefs/pref_service.h" 18 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/tab_contents/language_state.h" 20 #include "chrome/browser/tab_contents/language_state.h"
20 #include "chrome/browser/tab_contents/tab_util.h" 21 #include "chrome/browser/tab_contents/tab_util.h"
21 #include "chrome/browser/tabs/tab_strip_model.h" 22 #include "chrome/browser/tabs/tab_strip_model.h"
22 #include "chrome/browser/translate/page_translated_details.h" 23 #include "chrome/browser/translate/page_translated_details.h"
23 #include "chrome/browser/translate/translate_infobar_delegate.h" 24 #include "chrome/browser/translate/translate_infobar_delegate.h"
24 #include "chrome/browser/translate/translate_tab_helper.h" 25 #include "chrome/browser/translate/translate_tab_helper.h"
25 #include "chrome/browser/translate/translate_prefs.h" 26 #include "chrome/browser/translate/translate_prefs.h"
26 #include "chrome/browser/ui/browser.h" 27 #include "chrome/browser/ui/browser.h"
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 506
506 TranslateTabHelper* helper = wrapper->translate_tab_helper(); 507 TranslateTabHelper* helper = wrapper->translate_tab_helper();
507 std::string auto_translate_to = helper->language_state().AutoTranslateTo(); 508 std::string auto_translate_to = helper->language_state().AutoTranslateTo();
508 if (!auto_translate_to.empty()) { 509 if (!auto_translate_to.empty()) {
509 // This page was navigated through a click from a translated page. 510 // This page was navigated through a click from a translated page.
510 TranslatePage(tab, language_code, auto_translate_to); 511 TranslatePage(tab, language_code, auto_translate_to);
511 return; 512 return;
512 } 513 }
513 514
514 // Prompts the user if he/she wants the page translated. 515 // Prompts the user if he/she wants the page translated.
515 wrapper->AddInfoBar(TranslateInfoBarDelegate::CreateDelegate( 516 wrapper->infobar_tab_helper()->AddInfoBar(
516 TranslateInfoBarDelegate::BEFORE_TRANSLATE, tab, language_code, 517 TranslateInfoBarDelegate::CreateDelegate(
517 target_lang)); 518 TranslateInfoBarDelegate::BEFORE_TRANSLATE, tab, language_code,
519 target_lang));
518 } 520 }
519 521
520 void TranslateManager::InitiateTranslationPosted( 522 void TranslateManager::InitiateTranslationPosted(
521 int process_id, int render_id, const std::string& page_lang) { 523 int process_id, int render_id, const std::string& page_lang) {
522 // The tab might have been closed. 524 // The tab might have been closed.
523 TabContents* tab = tab_util::GetTabContentsByID(process_id, render_id); 525 TabContents* tab = tab_util::GetTabContentsByID(process_id, render_id);
524 if (!tab) 526 if (!tab)
525 return; 527 return;
526 528
527 TranslateTabHelper* helper = TabContentsWrapper::GetCurrentWrapperForContents( 529 TranslateTabHelper* helper = TabContentsWrapper::GetCurrentWrapperForContents(
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 TranslateInfoBarDelegate* infobar) { 758 TranslateInfoBarDelegate* infobar) {
757 DCHECK(infobar != NULL); 759 DCHECK(infobar != NULL);
758 TranslateInfoBarDelegate* old_infobar = GetTranslateInfoBarDelegate(tab); 760 TranslateInfoBarDelegate* old_infobar = GetTranslateInfoBarDelegate(tab);
759 infobar->UpdateBackgroundAnimation(old_infobar); 761 infobar->UpdateBackgroundAnimation(old_infobar);
760 TabContentsWrapper* wrapper = 762 TabContentsWrapper* wrapper =
761 TabContentsWrapper::GetCurrentWrapperForContents(tab); 763 TabContentsWrapper::GetCurrentWrapperForContents(tab);
762 if (!wrapper) 764 if (!wrapper)
763 return; 765 return;
764 if (old_infobar) { 766 if (old_infobar) {
765 // There already is a translate infobar, simply replace it. 767 // There already is a translate infobar, simply replace it.
766 wrapper->ReplaceInfoBar(old_infobar, infobar); 768 wrapper->infobar_tab_helper()->ReplaceInfoBar(old_infobar, infobar);
767 } else { 769 } else {
768 wrapper->AddInfoBar(infobar); 770 wrapper->infobar_tab_helper()->AddInfoBar(infobar);
769 } 771 }
770 } 772 }
771 773
772 // static 774 // static
773 std::string TranslateManager::GetTargetLanguage(PrefService* prefs) { 775 std::string TranslateManager::GetTargetLanguage(PrefService* prefs) {
774 std::string ui_lang = 776 std::string ui_lang =
775 GetLanguageCode(g_browser_process->GetApplicationLocale()); 777 GetLanguageCode(g_browser_process->GetApplicationLocale());
776 if (IsSupportedLanguage(ui_lang)) 778 if (IsSupportedLanguage(ui_lang))
777 return ui_lang; 779 return ui_lang;
778 780
(...skipping 16 matching lines...) Expand all
795 } 797 }
796 798
797 // static 799 // static
798 TranslateInfoBarDelegate* TranslateManager::GetTranslateInfoBarDelegate( 800 TranslateInfoBarDelegate* TranslateManager::GetTranslateInfoBarDelegate(
799 TabContents* tab) { 801 TabContents* tab) {
800 TabContentsWrapper* wrapper = 802 TabContentsWrapper* wrapper =
801 TabContentsWrapper::GetCurrentWrapperForContents(tab); 803 TabContentsWrapper::GetCurrentWrapperForContents(tab);
802 if (!wrapper) 804 if (!wrapper)
803 return NULL; 805 return NULL;
804 806
805 for (size_t i = 0; i < wrapper->infobar_count(); ++i) { 807 for (size_t i = 0; i < wrapper->infobar_tab_helper()->infobar_count(); ++i) {
Peter Kasting 2011/08/31 18:47:32 Nit: Factor this infobar_tab_helper() out to a tem
806 TranslateInfoBarDelegate* delegate = 808 TranslateInfoBarDelegate* delegate =
807 wrapper->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); 809 wrapper->infobar_tab_helper()->GetInfoBarDelegateAt(i)->
810 AsTranslateInfoBarDelegate();
808 if (delegate) 811 if (delegate)
809 return delegate; 812 return delegate;
810 } 813 }
811 return NULL; 814 return NULL;
812 } 815 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698