OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "chrome/browser/translate/translate_infobar_delegate.h" | 26 #include "chrome/browser/translate/translate_infobar_delegate.h" |
27 #include "chrome/browser/translate/translate_language_list.h" | 27 #include "chrome/browser/translate/translate_language_list.h" |
28 #include "chrome/browser/translate/translate_prefs.h" | 28 #include "chrome/browser/translate/translate_prefs.h" |
29 #include "chrome/browser/translate/translate_script.h" | 29 #include "chrome/browser/translate/translate_script.h" |
30 #include "chrome/browser/translate/translate_tab_helper.h" | 30 #include "chrome/browser/translate/translate_tab_helper.h" |
31 #include "chrome/browser/translate/translate_url_util.h" | 31 #include "chrome/browser/translate/translate_url_util.h" |
32 #include "chrome/browser/ui/browser.h" | 32 #include "chrome/browser/ui/browser.h" |
33 #include "chrome/browser/ui/browser_finder.h" | 33 #include "chrome/browser/ui/browser_finder.h" |
34 #include "chrome/browser/ui/browser_tabstrip.h" | 34 #include "chrome/browser/ui/browser_tabstrip.h" |
35 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 35 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
36 #include "chrome/common/chrome_constants.h" | |
37 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
38 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
39 #include "chrome/common/render_messages.h" | 38 #include "chrome/common/render_messages.h" |
40 #include "chrome/common/translate/language_detection_details.h" | 39 #include "chrome/common/translate/language_detection_details.h" |
41 #include "chrome/common/url_constants.h" | 40 #include "chrome/common/url_constants.h" |
| 41 #include "components/translate/common/translate_constants.h" |
42 #include "content/public/browser/navigation_controller.h" | 42 #include "content/public/browser/navigation_controller.h" |
43 #include "content/public/browser/navigation_details.h" | 43 #include "content/public/browser/navigation_details.h" |
44 #include "content/public/browser/navigation_entry.h" | 44 #include "content/public/browser/navigation_entry.h" |
45 #include "content/public/browser/notification_details.h" | 45 #include "content/public/browser/notification_details.h" |
46 #include "content/public/browser/notification_service.h" | 46 #include "content/public/browser/notification_service.h" |
47 #include "content/public/browser/notification_source.h" | 47 #include "content/public/browser/notification_source.h" |
48 #include "content/public/browser/notification_types.h" | 48 #include "content/public/browser/notification_types.h" |
49 #include "content/public/browser/render_process_host.h" | 49 #include "content/public/browser/render_process_host.h" |
50 #include "content/public/browser/render_view_host.h" | 50 #include "content/public/browser/render_view_host.h" |
51 #include "content/public/browser/web_contents.h" | 51 #include "content/public/browser/web_contents.h" |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 NOTREACHED(); | 459 NOTREACHED(); |
460 return; | 460 return; |
461 } | 461 } |
462 | 462 |
463 // Translation can be kicked by context menu against unsupported languages. | 463 // Translation can be kicked by context menu against unsupported languages. |
464 // Unsupported language strings should be replaced with | 464 // Unsupported language strings should be replaced with |
465 // kUnknownLanguageCode in order to send a translation request with enabling | 465 // kUnknownLanguageCode in order to send a translation request with enabling |
466 // server side auto language detection. | 466 // server side auto language detection. |
467 std::string source_lang(original_source_lang); | 467 std::string source_lang(original_source_lang); |
468 if (!IsSupportedLanguage(source_lang)) | 468 if (!IsSupportedLanguage(source_lang)) |
469 source_lang = std::string(chrome::kUnknownLanguageCode); | 469 source_lang = std::string(translate::kUnknownLanguageCode); |
470 | 470 |
471 Profile* profile = | 471 Profile* profile = |
472 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 472 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
473 TranslateInfoBarDelegate::Create( | 473 TranslateInfoBarDelegate::Create( |
474 true, InfoBarService::FromWebContents(web_contents), | 474 true, InfoBarService::FromWebContents(web_contents), |
475 TranslateInfoBarDelegate::TRANSLATING, source_lang, target_lang, | 475 TranslateInfoBarDelegate::TRANSLATING, source_lang, target_lang, |
476 TranslateErrors::NONE, profile->GetPrefs(), ShortcutConfig()); | 476 TranslateErrors::NONE, profile->GetPrefs(), ShortcutConfig()); |
477 | 477 |
478 DCHECK(script_.get() != NULL); | 478 DCHECK(script_.get() != NULL); |
479 | 479 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 | 573 |
574 translate_tab_helper->language_state().set_translation_pending(true); | 574 translate_tab_helper->language_state().set_translation_pending(true); |
575 web_contents->GetRenderViewHost()->Send(new ChromeViewMsg_TranslatePage( | 575 web_contents->GetRenderViewHost()->Send(new ChromeViewMsg_TranslatePage( |
576 web_contents->GetRenderViewHost()->GetRoutingID(), entry->GetPageID(), | 576 web_contents->GetRenderViewHost()->GetRoutingID(), entry->GetPageID(), |
577 translate_script, source_lang, target_lang)); | 577 translate_script, source_lang, target_lang)); |
578 } | 578 } |
579 | 579 |
580 void TranslateManager::PageTranslated(WebContents* web_contents, | 580 void TranslateManager::PageTranslated(WebContents* web_contents, |
581 PageTranslatedDetails* details) { | 581 PageTranslatedDetails* details) { |
582 if ((details->error_type == TranslateErrors::NONE) && | 582 if ((details->error_type == TranslateErrors::NONE) && |
583 details->source_language != chrome::kUnknownLanguageCode && | 583 details->source_language != translate::kUnknownLanguageCode && |
584 !IsSupportedLanguage(details->source_language)) { | 584 !IsSupportedLanguage(details->source_language)) { |
585 details->error_type = TranslateErrors::UNSUPPORTED_LANGUAGE; | 585 details->error_type = TranslateErrors::UNSUPPORTED_LANGUAGE; |
586 } | 586 } |
587 | 587 |
588 PrefService* prefs = Profile::FromBrowserContext( | 588 PrefService* prefs = Profile::FromBrowserContext( |
589 web_contents->GetBrowserContext())->GetPrefs(); | 589 web_contents->GetBrowserContext())->GetPrefs(); |
590 TranslateInfoBarDelegate::Create( | 590 TranslateInfoBarDelegate::Create( |
591 true, InfoBarService::FromWebContents(web_contents), | 591 true, InfoBarService::FromWebContents(web_contents), |
592 (details->error_type == TranslateErrors::NONE) ? | 592 (details->error_type == TranslateErrors::NONE) ? |
593 TranslateInfoBarDelegate::AFTER_TRANSLATE : | 593 TranslateInfoBarDelegate::AFTER_TRANSLATE : |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 // so we are more aggressive about showing the shortcut to never translate. | 704 // so we are more aggressive about showing the shortcut to never translate. |
705 #if defined(OS_ANDROID) | 705 #if defined(OS_ANDROID) |
706 config.never_translate_min_count = 1; | 706 config.never_translate_min_count = 1; |
707 #else | 707 #else |
708 config.never_translate_min_count = 3; | 708 config.never_translate_min_count = 3; |
709 #endif // defined(OS_ANDROID) | 709 #endif // defined(OS_ANDROID) |
710 | 710 |
711 config.always_translate_min_count = 3; | 711 config.always_translate_min_count = 3; |
712 return config; | 712 return config; |
713 } | 713 } |
OLD | NEW |