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" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/translate/translate_manager.h" | 12 #include "chrome/browser/translate/translate_manager.h" |
13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
14 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
15 #include "components/translate/core/browser/translate_download_manager.h" | 15 #include "components/translate/core/browser/translate_download_manager.h" |
| 16 #include "content/public/common/url_constants.h" |
| 17 #include "url/gurl.h" |
| 18 |
| 19 #if defined(OS_CHROMEOS) |
| 20 #include "chrome/browser/chromeos/file_manager/app_id.h" |
| 21 #include "extensions/common/constants.h" |
| 22 #endif |
16 | 23 |
17 namespace { | 24 namespace { |
18 // The singleton instance of TranslateService. | 25 // The singleton instance of TranslateService. |
19 TranslateService* g_translate_service = NULL; | 26 TranslateService* g_translate_service = NULL; |
20 } | 27 } |
21 | 28 |
22 TranslateService::TranslateService() : use_infobar_(false) { | 29 TranslateService::TranslateService() : use_infobar_(false) { |
23 resource_request_allowed_notifier_.Init(this); | 30 resource_request_allowed_notifier_.Init(this); |
24 } | 31 } |
25 | 32 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 g_translate_service->use_infobar_ = value; | 108 g_translate_service->use_infobar_ = value; |
102 } | 109 } |
103 | 110 |
104 // static | 111 // static |
105 std::string TranslateService::GetTargetLanguage(PrefService* prefs) { | 112 std::string TranslateService::GetTargetLanguage(PrefService* prefs) { |
106 std::vector<std::string> accept_languages_list; | 113 std::vector<std::string> accept_languages_list; |
107 base::SplitString(prefs->GetString(prefs::kAcceptLanguages), ',', | 114 base::SplitString(prefs->GetString(prefs::kAcceptLanguages), ',', |
108 &accept_languages_list); | 115 &accept_languages_list); |
109 return TranslateManager::GetTargetLanguage(accept_languages_list); | 116 return TranslateManager::GetTargetLanguage(accept_languages_list); |
110 } | 117 } |
| 118 |
| 119 // static |
| 120 bool TranslateService::IsTranslatableURL(const GURL& url) { |
| 121 // A URLs is translatable unless it is one of the following: |
| 122 // - empty (can happen for popups created with window.open("")) |
| 123 // - an internal URL (chrome:// and others) |
| 124 // - the devtools (which is considered UI) |
| 125 // - Chrome OS file manager extension |
| 126 // - an FTP page (as FTP pages tend to have long lists of filenames that may |
| 127 // confuse the CLD) |
| 128 return !url.is_empty() && !url.SchemeIs(content::kChromeUIScheme) && |
| 129 !url.SchemeIs(content::kChromeDevToolsScheme) && |
| 130 #if defined(OS_CHROMEOS) |
| 131 !(url.SchemeIs(extensions::kExtensionScheme) && |
| 132 url.DomainIs(file_manager::kFileManagerAppId)) && |
| 133 #endif |
| 134 !url.SchemeIs(content::kFtpScheme); |
| 135 } |
OLD | NEW |