| 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" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
| 17 #include "chrome/browser/infobars/infobar_service.h" | 17 #include "chrome/browser/infobars/infobar_service.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/tab_contents/language_state.h" | 19 #include "chrome/browser/tab_contents/language_state.h" |
| 20 #include "chrome/browser/tab_contents/tab_util.h" | 20 #include "chrome/browser/tab_contents/tab_util.h" |
| 21 #include "chrome/browser/translate/page_translated_details.h" | 21 #include "chrome/browser/translate/page_translated_details.h" |
| 22 #include "chrome/browser/translate/translate_accept_languages.h" | 22 #include "chrome/browser/translate/translate_accept_languages.h" |
| 23 #include "chrome/browser/translate/translate_browser_metrics.h" | 23 #include "chrome/browser/translate/translate_browser_metrics.h" |
| 24 #include "chrome/browser/translate/translate_bubble_showable.h" |
| 24 #include "chrome/browser/translate/translate_error_details.h" | 25 #include "chrome/browser/translate/translate_error_details.h" |
| 25 #include "chrome/browser/translate/translate_event_details.h" | 26 #include "chrome/browser/translate/translate_event_details.h" |
| 26 #include "chrome/browser/translate/translate_infobar_delegate.h" | 27 #include "chrome/browser/translate/translate_infobar_delegate.h" |
| 27 #include "chrome/browser/translate/translate_language_list.h" | 28 #include "chrome/browser/translate/translate_language_list.h" |
| 28 #include "chrome/browser/translate/translate_prefs.h" | 29 #include "chrome/browser/translate/translate_prefs.h" |
| 29 #include "chrome/browser/translate/translate_script.h" | 30 #include "chrome/browser/translate/translate_script.h" |
| 30 #include "chrome/browser/translate/translate_tab_helper.h" | 31 #include "chrome/browser/translate/translate_tab_helper.h" |
| 31 #include "chrome/browser/translate/translate_url_util.h" | 32 #include "chrome/browser/translate/translate_url_util.h" |
| 32 #include "chrome/browser/ui/browser.h" | 33 #include "chrome/browser/ui/browser.h" |
| 33 #include "chrome/browser/ui/browser_finder.h" | 34 #include "chrome/browser/ui/browser_finder.h" |
| 34 #include "chrome/browser/ui/browser_tabstrip.h" | 35 #include "chrome/browser/ui/browser_tabstrip.h" |
| 36 #include "chrome/browser/ui/browser_window.h" |
| 35 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 37 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 36 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
| 37 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
| 38 #include "chrome/common/render_messages.h" | 40 #include "chrome/common/render_messages.h" |
| 39 #include "chrome/common/translate/language_detection_details.h" | 41 #include "chrome/common/translate/language_detection_details.h" |
| 40 #include "chrome/common/url_constants.h" | 42 #include "chrome/common/url_constants.h" |
| 41 #include "components/translate/common/translate_constants.h" | 43 #include "components/translate/common/translate_constants.h" |
| 42 #include "content/public/browser/navigation_controller.h" | 44 #include "content/public/browser/navigation_controller.h" |
| 43 #include "content/public/browser/navigation_details.h" | 45 #include "content/public/browser/navigation_details.h" |
| 44 #include "content/public/browser/navigation_entry.h" | 46 #include "content/public/browser/navigation_entry.h" |
| 45 #include "content/public/browser/notification_details.h" | 47 #include "content/public/browser/notification_details.h" |
| 46 #include "content/public/browser/notification_service.h" | 48 #include "content/public/browser/notification_service.h" |
| 47 #include "content/public/browser/notification_source.h" | 49 #include "content/public/browser/notification_source.h" |
| 48 #include "content/public/browser/notification_types.h" | 50 #include "content/public/browser/notification_types.h" |
| 49 #include "content/public/browser/render_process_host.h" | 51 #include "content/public/browser/render_process_host.h" |
| 50 #include "content/public/browser/render_view_host.h" | 52 #include "content/public/browser/render_view_host.h" |
| 51 #include "content/public/browser/web_contents.h" | 53 #include "content/public/browser/web_contents.h" |
| 52 #include "net/base/url_util.h" | 54 #include "net/base/url_util.h" |
| 53 #include "net/http/http_status_code.h" | 55 #include "net/http/http_status_code.h" |
| 54 | 56 |
| 55 #ifdef FILE_MANAGER_EXTENSION | 57 #ifdef FILE_MANAGER_EXTENSION |
| 56 #include "chrome/browser/chromeos/file_manager/app_id.h" | 58 #include "chrome/browser/chromeos/file_manager/app_id.h" |
| 57 #include "extensions/common/constants.h" | 59 #include "extensions/common/constants.h" |
| 58 #endif | 60 #endif |
| 59 | 61 |
| 60 using content::NavigationController; | 62 using content::NavigationController; |
| 61 using content::NavigationEntry; | 63 using content::NavigationEntry; |
| 62 using content::WebContents; | 64 using content::WebContents; |
| 63 | 65 |
| 66 namespace { |
| 67 |
| 64 const char kReportLanguageDetectionErrorURL[] = | 68 const char kReportLanguageDetectionErrorURL[] = |
| 65 "https://translate.google.com/translate_error?client=cr&action=langidc"; | 69 "https://translate.google.com/translate_error?client=cr&action=langidc"; |
| 66 | 70 |
| 67 // Used in kReportLanguageDetectionErrorURL to specify the original page | 71 // Used in kReportLanguageDetectionErrorURL to specify the original page |
| 68 // language. | 72 // language. |
| 69 const char kSourceLanguageQueryName[] = "sl"; | 73 const char kSourceLanguageQueryName[] = "sl"; |
| 70 | 74 |
| 71 // Used in kReportLanguageDetectionErrorURL to specify the page URL. | 75 // Used in kReportLanguageDetectionErrorURL to specify the page URL. |
| 72 const char kUrlQueryName[] = "u"; | 76 const char kUrlQueryName[] = "u"; |
| 73 | 77 |
| 74 // The maximum number of attempts we'll do to see if the page has finshed | 78 // The maximum number of attempts we'll do to see if the page has finshed |
| 75 // loading before giving up the translation | 79 // loading before giving up the translation |
| 76 const int kMaxTranslateLoadCheckAttempts = 20; | 80 const int kMaxTranslateLoadCheckAttempts = 20; |
| 77 | 81 |
| 82 bool IsEnabledTranslateNewUX() { |
| 83 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 84 switches::kEnableTranslateNewUX); |
| 85 } |
| 86 |
| 87 class TranslateBubbleShowableImpl : public TranslateBubbleShowable { |
| 88 public: |
| 89 TranslateBubbleShowableImpl() { |
| 90 } |
| 91 |
| 92 virtual void Show(WebContents* web_contents, |
| 93 TranslateBubbleModel::ViewState view_state) OVERRIDE { |
| 94 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
| 95 if (!browser) |
| 96 return; |
| 97 |
| 98 BrowserWindow* window = browser->window(); |
| 99 if (!window) |
| 100 return; |
| 101 |
| 102 window->ShowTranslateBubble(web_contents, view_state); |
| 103 } |
| 104 |
| 105 private: |
| 106 DISALLOW_COPY_AND_ASSIGN(TranslateBubbleShowableImpl); |
| 107 }; |
| 108 |
| 109 } // namespace |
| 110 |
| 78 TranslateManager::~TranslateManager() { | 111 TranslateManager::~TranslateManager() { |
| 79 } | 112 } |
| 80 | 113 |
| 81 // static | 114 // static |
| 82 TranslateManager* TranslateManager::GetInstance() { | 115 TranslateManager* TranslateManager::GetInstance() { |
| 83 return Singleton<TranslateManager>::get(); | 116 return Singleton<TranslateManager>::get(); |
| 84 } | 117 } |
| 85 | 118 |
| 86 // static | 119 // static |
| 87 bool TranslateManager::IsTranslatableURL(const GURL& url) { | 120 bool TranslateManager::IsTranslatableURL(const GURL& url) { |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 324 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 292 content::NotificationService::AllSources()); | 325 content::NotificationService::AllSources()); |
| 293 notification_registrar_.Add(this, | 326 notification_registrar_.Add(this, |
| 294 chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, | 327 chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, |
| 295 content::NotificationService::AllSources()); | 328 content::NotificationService::AllSources()); |
| 296 notification_registrar_.Add(this, chrome::NOTIFICATION_PAGE_TRANSLATED, | 329 notification_registrar_.Add(this, chrome::NOTIFICATION_PAGE_TRANSLATED, |
| 297 content::NotificationService::AllSources()); | 330 content::NotificationService::AllSources()); |
| 298 language_list_.reset(new TranslateLanguageList); | 331 language_list_.reset(new TranslateLanguageList); |
| 299 accept_languages_.reset(new TranslateAcceptLanguages); | 332 accept_languages_.reset(new TranslateAcceptLanguages); |
| 300 script_.reset(new TranslateScript); | 333 script_.reset(new TranslateScript); |
| 334 bubble_showable_.reset(new TranslateBubbleShowableImpl); |
| 301 } | 335 } |
| 302 | 336 |
| 303 void TranslateManager::InitiateTranslation(WebContents* web_contents, | 337 void TranslateManager::InitiateTranslation(WebContents* web_contents, |
| 304 const std::string& page_lang) { | 338 const std::string& page_lang) { |
| 339 TranslateTabHelper* translate_tab_helper = |
| 340 TranslateTabHelper::FromWebContents(web_contents); |
| 341 if (!translate_tab_helper) |
| 342 return; |
| 343 |
| 305 Profile* profile = | 344 Profile* profile = |
| 306 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 345 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 307 Profile* original_profile = profile->GetOriginalProfile(); | 346 Profile* original_profile = profile->GetOriginalProfile(); |
| 308 PrefService* prefs = original_profile->GetPrefs(); | 347 PrefService* prefs = original_profile->GetPrefs(); |
| 309 if (!prefs->GetBoolean(prefs::kEnableTranslate)) { | 348 if (!prefs->GetBoolean(prefs::kEnableTranslate)) { |
| 310 TranslateBrowserMetrics::ReportInitiationStatus( | 349 TranslateBrowserMetrics::ReportInitiationStatus( |
| 311 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_PREFS); | 350 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_PREFS); |
| 312 const std::string& locale = g_browser_process->GetApplicationLocale(); | 351 const std::string& locale = g_browser_process->GetApplicationLocale(); |
| 313 TranslateBrowserMetrics::ReportLocalesOnDisabledByPrefs(locale); | 352 TranslateBrowserMetrics::ReportLocalesOnDisabledByPrefs(locale); |
| 314 return; | 353 return; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 // Also, GetLanguageCode will take care of removing country code if any. | 427 // Also, GetLanguageCode will take care of removing country code if any. |
| 389 auto_target_lang = GetLanguageCode(auto_target_lang); | 428 auto_target_lang = GetLanguageCode(auto_target_lang); |
| 390 if (IsSupportedLanguage(auto_target_lang)) { | 429 if (IsSupportedLanguage(auto_target_lang)) { |
| 391 TranslateBrowserMetrics::ReportInitiationStatus( | 430 TranslateBrowserMetrics::ReportInitiationStatus( |
| 392 TranslateBrowserMetrics::INITIATION_STATUS_AUTO_BY_CONFIG); | 431 TranslateBrowserMetrics::INITIATION_STATUS_AUTO_BY_CONFIG); |
| 393 TranslatePage(web_contents, language_code, auto_target_lang); | 432 TranslatePage(web_contents, language_code, auto_target_lang); |
| 394 return; | 433 return; |
| 395 } | 434 } |
| 396 } | 435 } |
| 397 | 436 |
| 398 TranslateTabHelper* translate_tab_helper = | 437 LanguageState& language_state = translate_tab_helper->language_state(); |
| 399 TranslateTabHelper::FromWebContents(web_contents); | 438 std::string auto_translate_to = language_state.AutoTranslateTo(); |
| 400 if (!translate_tab_helper) | |
| 401 return; | |
| 402 std::string auto_translate_to = | |
| 403 translate_tab_helper->language_state().AutoTranslateTo(); | |
| 404 if (!auto_translate_to.empty()) { | 439 if (!auto_translate_to.empty()) { |
| 405 // This page was navigated through a click from a translated page. | 440 // This page was navigated through a click from a translated page. |
| 406 TranslateBrowserMetrics::ReportInitiationStatus( | 441 TranslateBrowserMetrics::ReportInitiationStatus( |
| 407 TranslateBrowserMetrics::INITIATION_STATUS_AUTO_BY_LINK); | 442 TranslateBrowserMetrics::INITIATION_STATUS_AUTO_BY_LINK); |
| 408 TranslatePage(web_contents, language_code, auto_translate_to); | 443 TranslatePage(web_contents, language_code, auto_translate_to); |
| 409 return; | 444 return; |
| 410 } | 445 } |
| 411 | 446 |
| 412 // Prompts the user if he/she wants the page translated. | |
| 413 TranslateBrowserMetrics::ReportInitiationStatus( | 447 TranslateBrowserMetrics::ReportInitiationStatus( |
| 414 TranslateBrowserMetrics::INITIATION_STATUS_SHOW_INFOBAR); | 448 TranslateBrowserMetrics::INITIATION_STATUS_SHOW_INFOBAR); |
| 415 TranslateInfoBarDelegate::Create( | 449 |
| 416 false, InfoBarService::FromWebContents(web_contents), | 450 if (IsEnabledTranslateNewUX()) { |
| 417 TranslateInfoBarDelegate::BEFORE_TRANSLATE, language_code, target_lang, | 451 language_state.SetTranslateEnabled(true); |
| 418 TranslateErrors::NONE, profile->GetPrefs(), ShortcutConfig()); | 452 if (language_state.HasLanguageChanged()) |
| 453 ShowBubble(web_contents, |
| 454 TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE); |
| 455 } else { |
| 456 // Prompts the user if he/she wants the page translated. |
| 457 TranslateInfoBarDelegate::Create( |
| 458 false, InfoBarService::FromWebContents(web_contents), |
| 459 TranslateInfoBarDelegate::BEFORE_TRANSLATE, language_code, target_lang, |
| 460 TranslateErrors::NONE, profile->GetPrefs(), ShortcutConfig()); |
| 461 } |
| 419 } | 462 } |
| 420 | 463 |
| 421 void TranslateManager::InitiateTranslationPosted(int process_id, | 464 void TranslateManager::InitiateTranslationPosted(int process_id, |
| 422 int render_id, | 465 int render_id, |
| 423 const std::string& page_lang, | 466 const std::string& page_lang, |
| 424 int attempt) { | 467 int attempt) { |
| 425 // The tab might have been closed. | 468 // The tab might have been closed. |
| 426 WebContents* web_contents = | 469 WebContents* web_contents = |
| 427 tab_util::GetWebContentsByID(process_id, render_id); | 470 tab_util::GetWebContentsByID(process_id, render_id); |
| 428 if (!web_contents) | 471 if (!web_contents) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 } | 503 } |
| 461 | 504 |
| 462 // Translation can be kicked by context menu against unsupported languages. | 505 // Translation can be kicked by context menu against unsupported languages. |
| 463 // Unsupported language strings should be replaced with | 506 // Unsupported language strings should be replaced with |
| 464 // kUnknownLanguageCode in order to send a translation request with enabling | 507 // kUnknownLanguageCode in order to send a translation request with enabling |
| 465 // server side auto language detection. | 508 // server side auto language detection. |
| 466 std::string source_lang(original_source_lang); | 509 std::string source_lang(original_source_lang); |
| 467 if (!IsSupportedLanguage(source_lang)) | 510 if (!IsSupportedLanguage(source_lang)) |
| 468 source_lang = std::string(translate::kUnknownLanguageCode); | 511 source_lang = std::string(translate::kUnknownLanguageCode); |
| 469 | 512 |
| 470 Profile* profile = | 513 if (IsEnabledTranslateNewUX()) { |
| 471 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 514 ShowBubble(web_contents, TranslateBubbleModel::VIEW_STATE_TRANSLATING); |
| 472 TranslateInfoBarDelegate::Create( | 515 } else { |
| 473 true, InfoBarService::FromWebContents(web_contents), | 516 Profile* profile = |
| 474 TranslateInfoBarDelegate::TRANSLATING, source_lang, target_lang, | 517 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 475 TranslateErrors::NONE, profile->GetPrefs(), ShortcutConfig()); | 518 TranslateInfoBarDelegate::Create( |
| 519 true, InfoBarService::FromWebContents(web_contents), |
| 520 TranslateInfoBarDelegate::TRANSLATING, source_lang, target_lang, |
| 521 TranslateErrors::NONE, profile->GetPrefs(), ShortcutConfig()); |
| 522 } |
| 476 | 523 |
| 477 DCHECK(script_.get() != NULL); | 524 DCHECK(script_.get() != NULL); |
| 478 | 525 |
| 479 const std::string& translate_script = script_->data(); | 526 const std::string& translate_script = script_->data(); |
| 480 if (!translate_script.empty()) { | 527 if (!translate_script.empty()) { |
| 481 DoTranslatePage(web_contents, translate_script, source_lang, target_lang); | 528 DoTranslatePage(web_contents, translate_script, source_lang, target_lang); |
| 482 return; | 529 return; |
| 483 } | 530 } |
| 484 | 531 |
| 485 // The script is not available yet. Queue that request and query for the | 532 // The script is not available yet. Queue that request and query for the |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 } | 624 } |
| 578 | 625 |
| 579 void TranslateManager::PageTranslated(WebContents* web_contents, | 626 void TranslateManager::PageTranslated(WebContents* web_contents, |
| 580 PageTranslatedDetails* details) { | 627 PageTranslatedDetails* details) { |
| 581 if ((details->error_type == TranslateErrors::NONE) && | 628 if ((details->error_type == TranslateErrors::NONE) && |
| 582 details->source_language != translate::kUnknownLanguageCode && | 629 details->source_language != translate::kUnknownLanguageCode && |
| 583 !IsSupportedLanguage(details->source_language)) { | 630 !IsSupportedLanguage(details->source_language)) { |
| 584 details->error_type = TranslateErrors::UNSUPPORTED_LANGUAGE; | 631 details->error_type = TranslateErrors::UNSUPPORTED_LANGUAGE; |
| 585 } | 632 } |
| 586 | 633 |
| 587 PrefService* prefs = Profile::FromBrowserContext( | 634 if (IsEnabledTranslateNewUX()) { |
| 588 web_contents->GetBrowserContext())->GetPrefs(); | 635 TranslateBubbleModel::ViewState view_state = |
| 589 TranslateInfoBarDelegate::Create( | 636 (details->error_type == TranslateErrors::NONE) ? |
| 590 true, InfoBarService::FromWebContents(web_contents), | 637 TranslateBubbleModel::VIEW_STATE_AFTER_TRANSLATE : |
| 591 (details->error_type == TranslateErrors::NONE) ? | 638 TranslateBubbleModel::VIEW_STATE_ERROR; |
| 592 TranslateInfoBarDelegate::AFTER_TRANSLATE : | 639 ShowBubble(web_contents, view_state); |
| 593 TranslateInfoBarDelegate::TRANSLATION_ERROR, | 640 } else { |
| 594 details->source_language, details->target_language, details->error_type, | 641 PrefService* prefs = Profile::FromBrowserContext( |
| 595 prefs, ShortcutConfig()); | 642 web_contents->GetBrowserContext())->GetPrefs(); |
| 643 TranslateInfoBarDelegate::Create( |
| 644 true, InfoBarService::FromWebContents(web_contents), |
| 645 (details->error_type == TranslateErrors::NONE) ? |
| 646 TranslateInfoBarDelegate::AFTER_TRANSLATE : |
| 647 TranslateInfoBarDelegate::TRANSLATION_ERROR, |
| 648 details->source_language, details->target_language, details->error_type, |
| 649 prefs, ShortcutConfig()); |
| 650 } |
| 596 | 651 |
| 597 if (details->error_type != TranslateErrors::NONE && | 652 if (details->error_type != TranslateErrors::NONE && |
| 598 !web_contents->GetBrowserContext()->IsOffTheRecord()) { | 653 !web_contents->GetBrowserContext()->IsOffTheRecord()) { |
| 599 TranslateErrorDetails error_details; | 654 TranslateErrorDetails error_details; |
| 600 error_details.time = base::Time::Now(); | 655 error_details.time = base::Time::Now(); |
| 601 error_details.url = web_contents->GetLastCommittedURL(); | 656 error_details.url = web_contents->GetLastCommittedURL(); |
| 602 error_details.error = details->error_type; | 657 error_details.error = details->error_type; |
| 603 NotifyTranslateError(error_details); | 658 NotifyTranslateError(error_details); |
| 604 } | 659 } |
| 605 } | 660 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 // We navigated away from the page the translation was triggered on. | 698 // We navigated away from the page the translation was triggered on. |
| 644 continue; | 699 continue; |
| 645 } | 700 } |
| 646 | 701 |
| 647 if (success) { | 702 if (success) { |
| 648 // Translate the page. | 703 // Translate the page. |
| 649 const std::string& translate_script = script_->data(); | 704 const std::string& translate_script = script_->data(); |
| 650 DoTranslatePage(web_contents, translate_script, | 705 DoTranslatePage(web_contents, translate_script, |
| 651 request.source_lang, request.target_lang); | 706 request.source_lang, request.target_lang); |
| 652 } else { | 707 } else { |
| 653 Profile* profile = | 708 if (IsEnabledTranslateNewUX()) { |
| 654 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 709 ShowBubble(web_contents, TranslateBubbleModel::VIEW_STATE_ERROR); |
| 655 TranslateInfoBarDelegate::Create( | 710 } else { |
| 656 true, InfoBarService::FromWebContents(web_contents), | 711 Profile* profile = |
| 657 TranslateInfoBarDelegate::TRANSLATION_ERROR, request.source_lang, | 712 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 658 request.target_lang, TranslateErrors::NETWORK, profile->GetPrefs(), | 713 TranslateInfoBarDelegate::Create( |
| 659 ShortcutConfig()); | 714 true, InfoBarService::FromWebContents(web_contents), |
| 715 TranslateInfoBarDelegate::TRANSLATION_ERROR, request.source_lang, |
| 716 request.target_lang, TranslateErrors::NETWORK, profile->GetPrefs(), |
| 717 ShortcutConfig()); |
| 718 } |
| 660 | 719 |
| 661 if (!web_contents->GetBrowserContext()->IsOffTheRecord()) { | 720 if (!web_contents->GetBrowserContext()->IsOffTheRecord()) { |
| 662 TranslateErrorDetails error_details; | 721 TranslateErrorDetails error_details; |
| 663 error_details.time = base::Time::Now(); | 722 error_details.time = base::Time::Now(); |
| 664 error_details.url = entry->GetURL(); | 723 error_details.url = entry->GetURL(); |
| 665 error_details.error = TranslateErrors::NETWORK; | 724 error_details.error = TranslateErrors::NETWORK; |
| 666 NotifyTranslateError(error_details); | 725 NotifyTranslateError(error_details); |
| 667 } | 726 } |
| 668 } | 727 } |
| 669 } | 728 } |
| 670 pending_requests_.clear(); | 729 pending_requests_.clear(); |
| 671 } | 730 } |
| 672 | 731 |
| 732 void TranslateManager::ShowBubble(WebContents* web_contents, |
| 733 TranslateBubbleModel::ViewState view_state) { |
| 734 bubble_showable_->Show(web_contents, view_state); |
| 735 } |
| 736 |
| 737 void TranslateManager::SetTranslateBubbleShowable( |
| 738 scoped_ptr<TranslateBubbleShowable> translate_bubble_showable) { |
| 739 DCHECK(translate_bubble_showable.get()); |
| 740 bubble_showable_ = translate_bubble_showable.Pass(); |
| 741 } |
| 742 |
| 673 // static | 743 // static |
| 674 std::string TranslateManager::GetTargetLanguage(PrefService* prefs) { | 744 std::string TranslateManager::GetTargetLanguage(PrefService* prefs) { |
| 675 std::string ui_lang = | 745 std::string ui_lang = |
| 676 GetLanguageCode(g_browser_process->GetApplicationLocale()); | 746 GetLanguageCode(g_browser_process->GetApplicationLocale()); |
| 677 if (IsSupportedLanguage(ui_lang)) | 747 if (IsSupportedLanguage(ui_lang)) |
| 678 return ui_lang; | 748 return ui_lang; |
| 679 | 749 |
| 680 // Getting the accepted languages list | 750 // Getting the accepted languages list |
| 681 std::string accept_langs_str = prefs->GetString(prefs::kAcceptLanguages); | 751 std::string accept_langs_str = prefs->GetString(prefs::kAcceptLanguages); |
| 682 | 752 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 703 // so we are more aggressive about showing the shortcut to never translate. | 773 // so we are more aggressive about showing the shortcut to never translate. |
| 704 #if defined(OS_ANDROID) | 774 #if defined(OS_ANDROID) |
| 705 config.never_translate_min_count = 1; | 775 config.never_translate_min_count = 1; |
| 706 #else | 776 #else |
| 707 config.never_translate_min_count = 3; | 777 config.never_translate_min_count = 3; |
| 708 #endif // defined(OS_ANDROID) | 778 #endif // defined(OS_ANDROID) |
| 709 | 779 |
| 710 config.always_translate_min_count = 3; | 780 config.always_translate_min_count = 3; |
| 711 return config; | 781 return config; |
| 712 } | 782 } |
| OLD | NEW |