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