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" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 | 94 |
95 // static | 95 // static |
96 bool TranslateManager::IsTranslatableURL(const GURL& url) { | 96 bool TranslateManager::IsTranslatableURL(const GURL& url) { |
97 // A URLs is translatable unless it is one of the following: | 97 // A URLs is translatable unless it is one of the following: |
98 // - empty (can happen for popups created with window.open("")) | 98 // - empty (can happen for popups created with window.open("")) |
99 // - an internal URL (chrome:// and others) | 99 // - an internal URL (chrome:// and others) |
100 // - the devtools (which is considered UI) | 100 // - the devtools (which is considered UI) |
101 // - Chrome OS file manager extension | 101 // - Chrome OS file manager extension |
102 // - an FTP page (as FTP pages tend to have long lists of filenames that may | 102 // - an FTP page (as FTP pages tend to have long lists of filenames that may |
103 // confuse the CLD) | 103 // confuse the CLD) |
104 // - an MHTML page (Chrome does not load external resources when displaying | |
105 // MHTML pages, see bug 262953) | |
106 | |
107 // get file extension (empty if URL does not reference a file) | |
Miguel Garcia
2013/07/22 17:42:00
I'd move this to a method and add a unittest for i
| |
108 std::string file_name, file_extension; | |
109 size_t path_delim = url.path().rfind('/'); | |
110 if (path_delim != std::string::npos) { | |
111 file_name = url.path().substr(path_delim+1); | |
112 size_t file_delim = file_name.rfind('.'); | |
113 if (file_delim != std::string::npos) { | |
114 file_extension = file_name.substr(file_delim+1); | |
115 } | |
116 } | |
117 | |
104 return !url.is_empty() && | 118 return !url.is_empty() && |
105 !url.SchemeIs(chrome::kChromeUIScheme) && | 119 !url.SchemeIs(chrome::kChromeUIScheme) && |
106 !url.SchemeIs(chrome::kChromeDevToolsScheme) && | 120 !url.SchemeIs(chrome::kChromeDevToolsScheme) && |
107 #ifdef FILE_MANAGER_EXTENSION | 121 #ifdef FILE_MANAGER_EXTENSION |
108 !(url.SchemeIs(extensions::kExtensionScheme) && | 122 !(url.SchemeIs(extensions::kExtensionScheme) && |
109 url.DomainIs(kFileBrowserDomain)) && | 123 url.DomainIs(kFileBrowserDomain)) && |
110 #endif | 124 #endif |
111 !url.SchemeIs(chrome::kFtpScheme); | 125 !url.SchemeIs(chrome::kFtpScheme) && |
126 !(file_extension == "mht" || file_extension == "mhtml"); | |
Miguel Garcia
2013/07/22 17:42:00
create constants perhaps?
| |
112 } | 127 } |
113 | 128 |
114 // static | 129 // static |
115 void TranslateManager::GetSupportedLanguages( | 130 void TranslateManager::GetSupportedLanguages( |
116 std::vector<std::string>* languages) { | 131 std::vector<std::string>* languages) { |
117 if (GetInstance()->language_list_.get()) { | 132 if (GetInstance()->language_list_.get()) { |
118 GetInstance()->language_list_->GetSupportedLanguages(languages); | 133 GetInstance()->language_list_->GetSupportedLanguages(languages); |
119 return; | 134 return; |
120 } | 135 } |
121 NOTREACHED(); | 136 NOTREACHED(); |
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
717 // so we are more aggressive about showing the shortcut to never translate. | 732 // so we are more aggressive about showing the shortcut to never translate. |
718 #if defined(OS_ANDROID) | 733 #if defined(OS_ANDROID) |
719 config.never_translate_min_count = 1; | 734 config.never_translate_min_count = 1; |
720 #else | 735 #else |
721 config.never_translate_min_count = 3; | 736 config.never_translate_min_count = 3; |
722 #endif // defined(OS_ANDROID) | 737 #endif // defined(OS_ANDROID) |
723 | 738 |
724 config.always_translate_min_count = 3; | 739 config.always_translate_min_count = 3; |
725 return config; | 740 return config; |
726 } | 741 } |
OLD | NEW |