| OLD | NEW |
| 1 // Copyright (c) 2012 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/bind.h" | 7 #include "base/bind.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/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 const char* const kTranslateScriptURL = | 131 const char* const kTranslateScriptURL = |
| 132 "http://translate.google.com/translate_a/element.js?" | 132 "http://translate.google.com/translate_a/element.js?" |
| 133 "cb=cr.googleTranslate.onTranslateElementLoad"; | 133 "cb=cr.googleTranslate.onTranslateElementLoad"; |
| 134 const char* const kTranslateScriptHeader = | 134 const char* const kTranslateScriptHeader = |
| 135 "Google-Translate-Element-Mode: library"; | 135 "Google-Translate-Element-Mode: library"; |
| 136 const char* const kReportLanguageDetectionErrorURL = | 136 const char* const kReportLanguageDetectionErrorURL = |
| 137 "http://translate.google.com/translate_error"; | 137 "http://translate.google.com/translate_error"; |
| 138 const char* const kLanguageListFetchURL = | 138 const char* const kLanguageListFetchURL = |
| 139 "http://translate.googleapis.com/translate_a/l?client=chrome&cb=sl"; | 139 "http://translate.googleapis.com/translate_a/l?client=chrome&cb=sl"; |
| 140 const int kMaxRetryLanguageListFetch = 5; | 140 const int kMaxRetryLanguageListFetch = 5; |
| 141 const int kTranslateScriptExpirationDelayDays = 1; | 141 const int kTranslateScriptExpirationDelayMS = 24 * 60 * 60 * 1000; // 1 day. |
| 142 | 142 |
| 143 } // namespace | 143 } // namespace |
| 144 | 144 |
| 145 // This must be kept in sync with the &cb= value in the kLanguageListFetchURL. | 145 // This must be kept in sync with the &cb= value in the kLanguageListFetchURL. |
| 146 const char* const TranslateManager::kLanguageListCallbackName = "sl("; | 146 const char* const TranslateManager::kLanguageListCallbackName = "sl("; |
| 147 const char* const TranslateManager::kTargetLanguagesKey = "tl"; | 147 const char* const TranslateManager::kTargetLanguagesKey = "tl"; |
| 148 | 148 |
| 149 // static | 149 // static |
| 150 base::LazyInstance<std::set<std::string> > | 150 base::LazyInstance<std::set<std::string> > |
| 151 TranslateManager::supported_languages_ = LAZY_INSTANCE_INITIALIZER; | 151 TranslateManager::supported_languages_ = LAZY_INSTANCE_INITIALIZER; |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 } | 443 } |
| 444 } | 444 } |
| 445 | 445 |
| 446 // static | 446 // static |
| 447 bool TranslateManager::IsShowingTranslateInfobar(WebContents* tab) { | 447 bool TranslateManager::IsShowingTranslateInfobar(WebContents* tab) { |
| 448 return GetTranslateInfoBarDelegate(tab) != NULL; | 448 return GetTranslateInfoBarDelegate(tab) != NULL; |
| 449 } | 449 } |
| 450 | 450 |
| 451 TranslateManager::TranslateManager() | 451 TranslateManager::TranslateManager() |
| 452 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_method_factory_(this)), | 452 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_method_factory_(this)), |
| 453 translate_script_expiration_delay_( | 453 translate_script_expiration_delay_(kTranslateScriptExpirationDelayMS) { |
| 454 base::TimeDelta::FromDays(kTranslateScriptExpirationDelayDays)) { | |
| 455 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 454 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 456 content::NotificationService::AllSources()); | 455 content::NotificationService::AllSources()); |
| 457 notification_registrar_.Add(this, | 456 notification_registrar_.Add(this, |
| 458 chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, | 457 chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, |
| 459 content::NotificationService::AllSources()); | 458 content::NotificationService::AllSources()); |
| 460 notification_registrar_.Add(this, chrome::NOTIFICATION_PAGE_TRANSLATED, | 459 notification_registrar_.Add(this, chrome::NOTIFICATION_PAGE_TRANSLATED, |
| 461 content::NotificationService::AllSources()); | 460 content::NotificationService::AllSources()); |
| 462 } | 461 } |
| 463 | 462 |
| 464 void TranslateManager::InitiateTranslation(WebContents* tab, | 463 void TranslateManager::InitiateTranslation(WebContents* tab, |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 InfoBarTabHelper* infobar_helper = wrapper->infobar_tab_helper(); | 835 InfoBarTabHelper* infobar_helper = wrapper->infobar_tab_helper(); |
| 837 | 836 |
| 838 for (size_t i = 0; i < infobar_helper->infobar_count(); ++i) { | 837 for (size_t i = 0; i < infobar_helper->infobar_count(); ++i) { |
| 839 TranslateInfoBarDelegate* delegate = | 838 TranslateInfoBarDelegate* delegate = |
| 840 infobar_helper->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); | 839 infobar_helper->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); |
| 841 if (delegate) | 840 if (delegate) |
| 842 return delegate; | 841 return delegate; |
| 843 } | 842 } |
| 844 return NULL; | 843 return NULL; |
| 845 } | 844 } |
| OLD | NEW |