OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_service.h" | 5 #include "chrome/browser/translate/translate_service.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 TranslateService::~TranslateService() {} | 33 TranslateService::~TranslateService() {} |
34 | 34 |
35 // static | 35 // static |
36 void TranslateService::Initialize() { | 36 void TranslateService::Initialize() { |
37 if (g_translate_service) | 37 if (g_translate_service) |
38 return; | 38 return; |
39 | 39 |
40 g_translate_service = new TranslateService; | 40 g_translate_service = new TranslateService; |
41 // Initialize the allowed state for resource requests. | 41 // Initialize the allowed state for resource requests. |
42 g_translate_service->OnResourceRequestsAllowed(); | 42 g_translate_service->OnResourceRequestsAllowed(); |
43 TranslateDownloadManager* download_manager = | 43 translate::TranslateDownloadManager* download_manager = |
44 TranslateDownloadManager::GetInstance(); | 44 translate::TranslateDownloadManager::GetInstance(); |
45 download_manager->set_request_context( | 45 download_manager->set_request_context( |
46 g_browser_process->system_request_context()); | 46 g_browser_process->system_request_context()); |
47 download_manager->set_application_locale( | 47 download_manager->set_application_locale( |
48 g_browser_process->GetApplicationLocale()); | 48 g_browser_process->GetApplicationLocale()); |
49 } | 49 } |
50 | 50 |
51 // static | 51 // static |
52 void TranslateService::Shutdown(bool cleanup_pending_fetcher) { | 52 void TranslateService::Shutdown(bool cleanup_pending_fetcher) { |
53 TranslateDownloadManager* download_manager = | 53 translate::TranslateDownloadManager* download_manager = |
54 TranslateDownloadManager::GetInstance(); | 54 translate::TranslateDownloadManager::GetInstance(); |
55 if (cleanup_pending_fetcher) { | 55 if (cleanup_pending_fetcher) { |
56 download_manager->Shutdown(); | 56 download_manager->Shutdown(); |
57 } else { | 57 } else { |
58 // This path is only used by browser tests. | 58 // This path is only used by browser tests. |
59 download_manager->set_request_context(NULL); | 59 download_manager->set_request_context(NULL); |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 // static | 63 // static |
64 void TranslateService::InitializeForTesting() { | 64 void TranslateService::InitializeForTesting() { |
65 if (!g_translate_service) { | 65 if (!g_translate_service) { |
66 TranslateService::Initialize(); | 66 TranslateService::Initialize(); |
67 } else { | 67 } else { |
68 TranslateDownloadManager::GetInstance()->ResetForTesting(); | 68 translate::TranslateDownloadManager::GetInstance()->ResetForTesting(); |
69 g_translate_service->OnResourceRequestsAllowed(); | 69 g_translate_service->OnResourceRequestsAllowed(); |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 // static | 73 // static |
74 void TranslateService::ShutdownForTesting() { | 74 void TranslateService::ShutdownForTesting() { |
75 TranslateDownloadManager::GetInstance()->Shutdown(); | 75 translate::TranslateDownloadManager::GetInstance()->Shutdown(); |
76 } | 76 } |
77 | 77 |
78 void TranslateService::OnResourceRequestsAllowed() { | 78 void TranslateService::OnResourceRequestsAllowed() { |
79 TranslateLanguageList* language_list = | 79 translate::TranslateLanguageList* language_list = |
80 TranslateDownloadManager::GetInstance()->language_list(); | 80 translate::TranslateDownloadManager::GetInstance()->language_list(); |
81 if (!language_list) { | 81 if (!language_list) { |
82 NOTREACHED(); | 82 NOTREACHED(); |
83 return; | 83 return; |
84 } | 84 } |
85 | 85 |
86 language_list->SetResourceRequestsAllowed( | 86 language_list->SetResourceRequestsAllowed( |
87 resource_request_allowed_notifier_.ResourceRequestsAllowed()); | 87 resource_request_allowed_notifier_.ResourceRequestsAllowed()); |
88 } | 88 } |
89 | 89 |
90 // static | 90 // static |
91 bool TranslateService::IsTranslateBubbleEnabled() { | 91 bool TranslateService::IsTranslateBubbleEnabled() { |
92 #if defined(USE_AURA) | 92 #if defined(USE_AURA) |
93 return true; | 93 return true; |
94 #elif defined(OS_MACOSX) | 94 #elif defined(OS_MACOSX) |
95 // The bubble UX is experimental on Mac OS X. | 95 // The bubble UX is experimental on Mac OS X. |
96 return CommandLine::ForCurrentProcess()->HasSwitch( | 96 return CommandLine::ForCurrentProcess()->HasSwitch( |
97 switches::kEnableTranslateNewUX); | 97 switches::kEnableTranslateNewUX); |
98 #else | 98 #else |
99 // The bubble UX is not implemented on other platforms. | 99 // The bubble UX is not implemented on other platforms. |
100 return false; | 100 return false; |
101 #endif | 101 #endif |
102 } | 102 } |
103 | 103 |
104 // static | 104 // static |
105 std::string TranslateService::GetTargetLanguage(PrefService* prefs) { | 105 std::string TranslateService::GetTargetLanguage(PrefService* prefs) { |
106 std::vector<std::string> accept_languages_list; | 106 std::vector<std::string> accept_languages_list; |
107 base::SplitString(prefs->GetString(prefs::kAcceptLanguages), ',', | 107 base::SplitString(prefs->GetString(prefs::kAcceptLanguages), ',', |
108 &accept_languages_list); | 108 &accept_languages_list); |
109 return TranslateManager::GetTargetLanguage(accept_languages_list); | 109 return translate::TranslateManager::GetTargetLanguage(accept_languages_list); |
110 } | 110 } |
111 | 111 |
112 // static | 112 // static |
113 bool TranslateService::IsTranslatableURL(const GURL& url) { | 113 bool TranslateService::IsTranslatableURL(const GURL& url) { |
114 // A URLs is translatable unless it is one of the following: | 114 // A URLs is translatable unless it is one of the following: |
115 // - empty (can happen for popups created with window.open("")) | 115 // - empty (can happen for popups created with window.open("")) |
116 // - an internal URL (chrome:// and others) | 116 // - an internal URL (chrome:// and others) |
117 // - the devtools (which is considered UI) | 117 // - the devtools (which is considered UI) |
118 // - Chrome OS file manager extension | 118 // - Chrome OS file manager extension |
119 // - an FTP page (as FTP pages tend to have long lists of filenames that may | 119 // - an FTP page (as FTP pages tend to have long lists of filenames that may |
120 // confuse the CLD) | 120 // confuse the CLD) |
121 return !url.is_empty() && !url.SchemeIs(content::kChromeUIScheme) && | 121 return !url.is_empty() && !url.SchemeIs(content::kChromeUIScheme) && |
122 !url.SchemeIs(content::kChromeDevToolsScheme) && | 122 !url.SchemeIs(content::kChromeDevToolsScheme) && |
123 #if defined(OS_CHROMEOS) | 123 #if defined(OS_CHROMEOS) |
124 !(url.SchemeIs(extensions::kExtensionScheme) && | 124 !(url.SchemeIs(extensions::kExtensionScheme) && |
125 url.DomainIs(file_manager::kFileManagerAppId)) && | 125 url.DomainIs(file_manager::kFileManagerAppId)) && |
126 #endif | 126 #endif |
127 !url.SchemeIs(url::kFtpScheme); | 127 !url.SchemeIs(url::kFtpScheme); |
128 } | 128 } |
OLD | NEW |