Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: chrome/browser/translate/translate_manager.cc

Issue 19857005: Do not show translate bar for MHTML files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add and use GURL::ExtractFileExtension() Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | url/gurl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 const char kUrlQueryName[] = "u"; 74 const char kUrlQueryName[] = "u";
75 75
76 // The delay in ms that we'll wait to check if a page has finished loading 76 // The delay in ms that we'll wait to check if a page has finished loading
77 // before attempting a translation. 77 // before attempting a translation.
78 const int kTranslateLoadCheckDelayMs = 150; 78 const int kTranslateLoadCheckDelayMs = 150;
79 79
80 // The maximum number of attempts we'll do to see if the page has finshed 80 // The maximum number of attempts we'll do to see if the page has finshed
81 // loading before giving up the translation 81 // loading before giving up the translation
82 const int kMaxTranslateLoadCheckAttempts = 20; 82 const int kMaxTranslateLoadCheckAttempts = 20;
83 83
84 // file extensions tested for in IsTranslatableURL()
85 const char kFileExtMHTMLShort[] = "mht";
86 const char kFileExtMHTMLLong[] = "mhtml";
87
84 } // namespace 88 } // namespace
85 89
86 TranslateManager::~TranslateManager() { 90 TranslateManager::~TranslateManager() {
87 weak_method_factory_.InvalidateWeakPtrs(); 91 weak_method_factory_.InvalidateWeakPtrs();
88 } 92 }
89 93
90 // static 94 // static
91 TranslateManager* TranslateManager::GetInstance() { 95 TranslateManager* TranslateManager::GetInstance() {
92 return Singleton<TranslateManager>::get(); 96 return Singleton<TranslateManager>::get();
93 } 97 }
94 98
95 // static 99 // static
96 bool TranslateManager::IsTranslatableURL(const GURL& url) { 100 bool TranslateManager::IsTranslatableURL(const GURL& url) {
97 // A URLs is translatable unless it is one of the following: 101 // A URLs is translatable unless it is one of the following:
98 // - empty (can happen for popups created with window.open("")) 102 // - empty (can happen for popups created with window.open(""))
99 // - an internal URL (chrome:// and others) 103 // - an internal URL (chrome:// and others)
100 // - the devtools (which is considered UI) 104 // - the devtools (which is considered UI)
101 // - Chrome OS file manager extension 105 // - Chrome OS file manager extension
102 // - an FTP page (as FTP pages tend to have long lists of filenames that may 106 // - an FTP page (as FTP pages tend to have long lists of filenames that may
103 // confuse the CLD) 107 // confuse the CLD)
108 // - an MHTML page (Chrome does not load external resources when displaying
109 // MHTML pages, see bug 262953)
110
111 // extract file extension (empty if URL does not reference a file)
112 std::string file_extension = url.ExtractFileExtension();
113
104 return !url.is_empty() && 114 return !url.is_empty() &&
105 !url.SchemeIs(chrome::kChromeUIScheme) && 115 !url.SchemeIs(chrome::kChromeUIScheme) &&
106 !url.SchemeIs(chrome::kChromeDevToolsScheme) && 116 !url.SchemeIs(chrome::kChromeDevToolsScheme) &&
107 #ifdef FILE_MANAGER_EXTENSION 117 #ifdef FILE_MANAGER_EXTENSION
108 !(url.SchemeIs(extensions::kExtensionScheme) && 118 !(url.SchemeIs(extensions::kExtensionScheme) &&
109 url.DomainIs(kFileBrowserDomain)) && 119 url.DomainIs(kFileBrowserDomain)) &&
110 #endif 120 #endif
111 !url.SchemeIs(chrome::kFtpScheme); 121 !url.SchemeIs(chrome::kFtpScheme) &&
122 !(file_extension.compare(kFileExtMHTMLShort) == 0 ||
MAD 2013/07/29 20:39:17 Shouldn't we do a case insensitive compare?
123 file_extension.compare(kFileExtMHTMLLong) == 0);
112 } 124 }
113 125
114 // static 126 // static
115 void TranslateManager::GetSupportedLanguages( 127 void TranslateManager::GetSupportedLanguages(
116 std::vector<std::string>* languages) { 128 std::vector<std::string>* languages) {
117 if (GetInstance()->language_list_.get()) { 129 if (GetInstance()->language_list_.get()) {
118 GetInstance()->language_list_->GetSupportedLanguages(languages); 130 GetInstance()->language_list_->GetSupportedLanguages(languages);
119 return; 131 return;
120 } 132 }
121 NOTREACHED(); 133 NOTREACHED();
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 // so we are more aggressive about showing the shortcut to never translate. 729 // so we are more aggressive about showing the shortcut to never translate.
718 #if defined(OS_ANDROID) 730 #if defined(OS_ANDROID)
719 config.never_translate_min_count = 1; 731 config.never_translate_min_count = 1;
720 #else 732 #else
721 config.never_translate_min_count = 3; 733 config.never_translate_min_count = 3;
722 #endif // defined(OS_ANDROID) 734 #endif // defined(OS_ANDROID)
723 735
724 config.always_translate_min_count = 3; 736 config.always_translate_min_count = 3;
725 return config; 737 return config;
726 } 738 }
OLDNEW
« no previous file with comments | « no previous file | url/gurl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698