| 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 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 | 408 |
| 409 std::string auto_translate_to = tab->language_state().AutoTranslateTo(); | 409 std::string auto_translate_to = tab->language_state().AutoTranslateTo(); |
| 410 if (!auto_translate_to.empty()) { | 410 if (!auto_translate_to.empty()) { |
| 411 // This page was navigated through a click from a translated page. | 411 // This page was navigated through a click from a translated page. |
| 412 TranslatePage(tab, page_lang, auto_translate_to); | 412 TranslatePage(tab, page_lang, auto_translate_to); |
| 413 return; | 413 return; |
| 414 } | 414 } |
| 415 | 415 |
| 416 // Prompts the user if he/she wants the page translated. | 416 // Prompts the user if he/she wants the page translated. |
| 417 tab->AddInfoBar(TranslateInfoBarDelegate::CreateDelegate( | 417 tab->AddInfoBar(TranslateInfoBarDelegate::CreateDelegate( |
| 418 TranslateInfoBarDelegate::BEFORE_TRANSLATE, tab, | 418 TranslateInfoBarDelegate::BEFORE_TRANSLATE, tab, page_lang, target_lang)); |
| 419 page_lang, target_lang)); | |
| 420 } | 419 } |
| 421 | 420 |
| 422 void TranslateManager::InitiateTranslationPosted( | 421 void TranslateManager::InitiateTranslationPosted( |
| 423 int process_id, int render_id, const std::string& page_lang) { | 422 int process_id, int render_id, const std::string& page_lang) { |
| 424 // The tab might have been closed. | 423 // The tab might have been closed. |
| 425 TabContents* tab = tab_util::GetTabContentsByID(process_id, render_id); | 424 TabContents* tab = tab_util::GetTabContentsByID(process_id, render_id); |
| 426 if (!tab || tab->language_state().translation_pending()) | 425 if (!tab || tab->language_state().translation_pending()) |
| 427 return; | 426 return; |
| 428 | 427 |
| 429 InitiateTranslation(tab, page_lang); | 428 InitiateTranslation(tab, page_lang); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 // current form and re-parse it in AutoFillManager first to get the new | 521 // current form and re-parse it in AutoFillManager first to get the new |
| 523 // labels. | 522 // labels. |
| 524 tab->autofill_manager()->Reset(); | 523 tab->autofill_manager()->Reset(); |
| 525 } | 524 } |
| 526 | 525 |
| 527 void TranslateManager::PageTranslated(TabContents* tab, | 526 void TranslateManager::PageTranslated(TabContents* tab, |
| 528 PageTranslatedDetails* details) { | 527 PageTranslatedDetails* details) { |
| 529 // Create the new infobar to display. | 528 // Create the new infobar to display. |
| 530 TranslateInfoBarDelegate* infobar; | 529 TranslateInfoBarDelegate* infobar; |
| 531 if (details->error_type != TranslateErrors::NONE) { | 530 if (details->error_type != TranslateErrors::NONE) { |
| 532 infobar = TranslateInfoBarDelegate::CreateErrorDelegate( | 531 infobar = TranslateInfoBarDelegate::CreateErrorDelegate(details->error_type, |
| 533 details->error_type, tab, | 532 tab, details->source_language, details->target_language); |
| 534 details->source_language, details->target_language); | |
| 535 } else if (!IsSupportedLanguage(details->source_language)) { | 533 } else if (!IsSupportedLanguage(details->source_language)) { |
| 536 // TODO(jcivelli): http://crbug.com/9390 We should change the "after | 534 // TODO(jcivelli): http://crbug.com/9390 We should change the "after |
| 537 // translate" infobar to support unknown as the original | 535 // translate" infobar to support unknown as the original |
| 538 // language. | 536 // language. |
| 539 UMA_HISTOGRAM_COUNTS("Translate.ServerReportedUnsupportedLanguage", 1); | 537 UMA_HISTOGRAM_COUNTS("Translate.ServerReportedUnsupportedLanguage", 1); |
| 540 infobar = TranslateInfoBarDelegate::CreateErrorDelegate( | 538 infobar = TranslateInfoBarDelegate::CreateErrorDelegate( |
| 541 TranslateErrors::UNSUPPORTED_LANGUAGE, tab, | 539 TranslateErrors::UNSUPPORTED_LANGUAGE, tab, |
| 542 details->source_language, details->target_language); | 540 details->source_language, details->target_language); |
| 543 } else { | 541 } else { |
| 544 infobar = TranslateInfoBarDelegate::CreateDelegate( | 542 infobar = TranslateInfoBarDelegate::CreateDelegate( |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 tab->ReplaceInfoBar(old_infobar, infobar); | 618 tab->ReplaceInfoBar(old_infobar, infobar); |
| 621 } else { | 619 } else { |
| 622 tab->AddInfoBar(infobar); | 620 tab->AddInfoBar(infobar); |
| 623 } | 621 } |
| 624 } | 622 } |
| 625 | 623 |
| 626 // static | 624 // static |
| 627 std::string TranslateManager::GetTargetLanguage() { | 625 std::string TranslateManager::GetTargetLanguage() { |
| 628 std::string target_lang = | 626 std::string target_lang = |
| 629 GetLanguageCode(g_browser_process->GetApplicationLocale()); | 627 GetLanguageCode(g_browser_process->GetApplicationLocale()); |
| 630 if (IsSupportedLanguage(target_lang)) | 628 return IsSupportedLanguage(target_lang) ? target_lang : std::string(); |
| 631 return target_lang; | |
| 632 return std::string(); | |
| 633 } | 629 } |
| 634 | 630 |
| 635 // static | 631 // static |
| 636 TranslateInfoBarDelegate* TranslateManager::GetTranslateInfoBarDelegate( | 632 TranslateInfoBarDelegate* TranslateManager::GetTranslateInfoBarDelegate( |
| 637 TabContents* tab) { | 633 TabContents* tab) { |
| 638 for (int i = 0; i < tab->infobar_delegate_count(); ++i) { | 634 for (int i = 0; i < tab->infobar_delegate_count(); ++i) { |
| 639 TranslateInfoBarDelegate* delegate = | 635 TranslateInfoBarDelegate* delegate = |
| 640 tab->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); | 636 tab->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); |
| 641 if (delegate) | 637 if (delegate) |
| 642 return delegate; | 638 return delegate; |
| 643 } | 639 } |
| 644 return NULL; | 640 return NULL; |
| 645 } | 641 } |
| OLD | NEW |