| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/profile.h" | 9 #include "chrome/browser/profile.h" |
| 10 #include "chrome/browser/renderer_host/translation_service.h" | 10 #include "chrome/browser/renderer_host/translation_service.h" |
| 11 #include "chrome/browser/tab_contents/language_state.h" | 11 #include "chrome/browser/tab_contents/language_state.h" |
| 12 #include "chrome/browser/tab_contents/navigation_controller.h" | 12 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 13 #include "chrome/browser/tab_contents/navigation_entry.h" | 13 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 14 #include "chrome/browser/tab_contents/tab_contents.h" | 14 #include "chrome/browser/tab_contents/tab_contents.h" |
| 15 #include "chrome/browser/translate/translate_infobars_delegates.h" | 15 #include "chrome/browser/translate/translate_infobars_delegates.h" |
| 16 #include "chrome/browser/translate/translate_prefs.h" | 16 #include "chrome/browser/translate/translate_prefs.h" |
| 17 #include "chrome/common/notification_details.h" | 17 #include "chrome/common/notification_details.h" |
| 18 #include "chrome/common/notification_service.h" | 18 #include "chrome/common/notification_service.h" |
| 19 #include "chrome/common/notification_source.h" | 19 #include "chrome/common/notification_source.h" |
| 20 #include "chrome/common/notification_type.h" | 20 #include "chrome/common/notification_type.h" |
| 21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 22 #include "chrome/common/pref_service.h" | 22 #include "chrome/common/pref_service.h" |
| 23 | 23 |
| 24 // static |
| 25 bool TranslateManager::test_enabled_ = false; |
| 26 |
| 24 TranslateManager::~TranslateManager() { | 27 TranslateManager::~TranslateManager() { |
| 25 } | 28 } |
| 26 | 29 |
| 27 void TranslateManager::Observe(NotificationType type, | 30 void TranslateManager::Observe(NotificationType type, |
| 28 const NotificationSource& source, | 31 const NotificationSource& source, |
| 29 const NotificationDetails& details) { | 32 const NotificationDetails& details) { |
| 30 switch (type.value) { | 33 switch (type.value) { |
| 31 case NotificationType::TAB_LANGUAGE_DETERMINED: { | 34 case NotificationType::TAB_LANGUAGE_DETERMINED: { |
| 32 TabContents* tab = Source<TabContents>(source).ptr(); | 35 TabContents* tab = Source<TabContents>(source).ptr(); |
| 33 std::string language = *(Details<std::string>(details).ptr()); | 36 std::string language = *(Details<std::string>(details).ptr()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 PrefService* prefs = Source<PrefService>(source).ptr(); | 79 PrefService* prefs = Source<PrefService>(source).ptr(); |
| 77 InitAcceptLanguages(prefs); | 80 InitAcceptLanguages(prefs); |
| 78 break; | 81 break; |
| 79 } | 82 } |
| 80 default: | 83 default: |
| 81 NOTREACHED(); | 84 NOTREACHED(); |
| 82 } | 85 } |
| 83 } | 86 } |
| 84 | 87 |
| 85 TranslateManager::TranslateManager() { | 88 TranslateManager::TranslateManager() { |
| 86 if (TestEnabled() && !TranslationService::IsTranslationEnabled()) | 89 if (!test_enabled_ && !TranslationService::IsTranslationEnabled()) |
| 87 return; | 90 return; |
| 88 | 91 |
| 89 notification_registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED, | 92 notification_registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED, |
| 90 NotificationService::AllSources()); | 93 NotificationService::AllSources()); |
| 91 notification_registrar_.Add(this, NotificationType::PAGE_TRANSLATED, | 94 notification_registrar_.Add(this, NotificationType::PAGE_TRANSLATED, |
| 92 NotificationService::AllSources()); | 95 NotificationService::AllSources()); |
| 93 } | 96 } |
| 94 | 97 |
| 95 void TranslateManager::InitiateTranslation(TabContents* tab, | 98 void TranslateManager::InitiateTranslation(TabContents* tab, |
| 96 const std::string& page_lang) { | 99 const std::string& page_lang) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 // Get rid of the locale extension if any (ex: en-US -> en), but for Chinese | 172 // Get rid of the locale extension if any (ex: en-US -> en), but for Chinese |
| 170 // for which the CLD reports zh-CN and zh-TW. | 173 // for which the CLD reports zh-CN and zh-TW. |
| 171 std::string accept_lang(*iter); | 174 std::string accept_lang(*iter); |
| 172 size_t index = iter->find("-"); | 175 size_t index = iter->find("-"); |
| 173 if (index != std::string::npos && *iter != "zh-CN" && *iter != "zh-TW") | 176 if (index != std::string::npos && *iter != "zh-CN" && *iter != "zh-TW") |
| 174 accept_lang = iter->substr(0, iter->length() - index - 1); | 177 accept_lang = iter->substr(0, iter->length() - index - 1); |
| 175 accept_langs_set.insert(accept_lang); | 178 accept_langs_set.insert(accept_lang); |
| 176 } | 179 } |
| 177 accept_languages_[prefs] = accept_langs_set; | 180 accept_languages_[prefs] = accept_langs_set; |
| 178 } | 181 } |
| OLD | NEW |