| 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/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "components/translate/core/common/translate_pref_names.h" | 36 #include "components/translate/core/common/translate_pref_names.h" |
| 37 #include "components/translate/core/common/translate_switches.h" | 37 #include "components/translate/core/common/translate_switches.h" |
| 38 #include "content/public/browser/navigation_controller.h" | 38 #include "content/public/browser/navigation_controller.h" |
| 39 #include "content/public/browser/navigation_entry.h" | 39 #include "content/public/browser/navigation_entry.h" |
| 40 #include "content/public/browser/render_process_host.h" | 40 #include "content/public/browser/render_process_host.h" |
| 41 #include "content/public/browser/render_view_host.h" | 41 #include "content/public/browser/render_view_host.h" |
| 42 #include "content/public/browser/web_contents.h" | 42 #include "content/public/browser/web_contents.h" |
| 43 #include "net/base/url_util.h" | 43 #include "net/base/url_util.h" |
| 44 #include "net/http/http_status_code.h" | 44 #include "net/http/http_status_code.h" |
| 45 | 45 |
| 46 #if defined(OS_CHROMEOS) | |
| 47 #include "chrome/browser/chromeos/file_manager/app_id.h" | |
| 48 #include "extensions/common/constants.h" | |
| 49 #endif | |
| 50 | |
| 51 using content::NavigationController; | 46 using content::NavigationController; |
| 52 using content::NavigationEntry; | 47 using content::NavigationEntry; |
| 53 using content::WebContents; | 48 using content::WebContents; |
| 54 | 49 |
| 55 namespace { | 50 namespace { |
| 56 | 51 |
| 57 // Callbacks for translate errors. | 52 // Callbacks for translate errors. |
| 58 TranslateManager::TranslateErrorCallbackList* g_callback_list_ = NULL; | 53 TranslateManager::TranslateErrorCallbackList* g_callback_list_ = NULL; |
| 59 | 54 |
| 60 const char kReportLanguageDetectionErrorURL[] = | 55 const char kReportLanguageDetectionErrorURL[] = |
| (...skipping 12 matching lines...) Expand all Loading... |
| 73 return; | 68 return; |
| 74 | 69 |
| 75 g_callback_list_->Notify(details); | 70 g_callback_list_->Notify(details); |
| 76 } | 71 } |
| 77 | 72 |
| 78 } // namespace | 73 } // namespace |
| 79 | 74 |
| 80 TranslateManager::~TranslateManager() {} | 75 TranslateManager::~TranslateManager() {} |
| 81 | 76 |
| 82 // static | 77 // static |
| 83 bool TranslateManager::IsTranslatableURL(const GURL& url) { | |
| 84 // A URLs is translatable unless it is one of the following: | |
| 85 // - empty (can happen for popups created with window.open("")) | |
| 86 // - an internal URL (chrome:// and others) | |
| 87 // - the devtools (which is considered UI) | |
| 88 // - Chrome OS file manager extension | |
| 89 // - an FTP page (as FTP pages tend to have long lists of filenames that may | |
| 90 // confuse the CLD) | |
| 91 return !url.is_empty() && | |
| 92 !url.SchemeIs(content::kChromeUIScheme) && | |
| 93 !url.SchemeIs(content::kChromeDevToolsScheme) && | |
| 94 #if defined(OS_CHROMEOS) | |
| 95 !(url.SchemeIs(extensions::kExtensionScheme) && | |
| 96 url.DomainIs(file_manager::kFileManagerAppId)) && | |
| 97 #endif | |
| 98 !url.SchemeIs(content::kFtpScheme); | |
| 99 } | |
| 100 | |
| 101 // static | |
| 102 scoped_ptr<TranslateManager::TranslateErrorCallbackList::Subscription> | 78 scoped_ptr<TranslateManager::TranslateErrorCallbackList::Subscription> |
| 103 TranslateManager::RegisterTranslateErrorCallback( | 79 TranslateManager::RegisterTranslateErrorCallback( |
| 104 const TranslateManager::TranslateErrorCallback& callback) { | 80 const TranslateManager::TranslateErrorCallback& callback) { |
| 105 if (!g_callback_list_) | 81 if (!g_callback_list_) |
| 106 g_callback_list_ = new TranslateErrorCallbackList; | 82 g_callback_list_ = new TranslateErrorCallbackList; |
| 107 return g_callback_list_->Add(callback); | 83 return g_callback_list_->Add(callback); |
| 108 } | 84 } |
| 109 | 85 |
| 110 TranslateManager::TranslateManager( | 86 TranslateManager::TranslateManager( |
| 111 TranslateTabHelper* helper, | 87 TranslateTabHelper* helper, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 WebContents* web_contents = translate_tab_helper_->GetWebContents(); | 127 WebContents* web_contents = translate_tab_helper_->GetWebContents(); |
| 152 if (web_contents->GetContentsMimeType() == "multipart/related") { | 128 if (web_contents->GetContentsMimeType() == "multipart/related") { |
| 153 TranslateBrowserMetrics::ReportInitiationStatus( | 129 TranslateBrowserMetrics::ReportInitiationStatus( |
| 154 TranslateBrowserMetrics::INITIATION_STATUS_MIME_TYPE_IS_NOT_SUPPORTED); | 130 TranslateBrowserMetrics::INITIATION_STATUS_MIME_TYPE_IS_NOT_SUPPORTED); |
| 155 return; | 131 return; |
| 156 } | 132 } |
| 157 | 133 |
| 158 // Don't translate any Chrome specific page, e.g., New Tab Page, Download, | 134 // Don't translate any Chrome specific page, e.g., New Tab Page, Download, |
| 159 // History, and so on. | 135 // History, and so on. |
| 160 GURL page_url = web_contents->GetURL(); | 136 GURL page_url = web_contents->GetURL(); |
| 161 if (!IsTranslatableURL(page_url)) { | 137 if (!translate_client_->IsTranslatableURL(page_url)) { |
| 162 TranslateBrowserMetrics::ReportInitiationStatus( | 138 TranslateBrowserMetrics::ReportInitiationStatus( |
| 163 TranslateBrowserMetrics::INITIATION_STATUS_URL_IS_NOT_SUPPORTED); | 139 TranslateBrowserMetrics::INITIATION_STATUS_URL_IS_NOT_SUPPORTED); |
| 164 return; | 140 return; |
| 165 } | 141 } |
| 166 | 142 |
| 167 // Get the accepted languages list. | 143 // Get the accepted languages list. |
| 168 std::vector<std::string> accept_languages_list; | 144 std::vector<std::string> accept_languages_list; |
| 169 base::SplitString(prefs->GetString(accept_languages_pref_name_.c_str()), ',', | 145 base::SplitString(prefs->GetString(accept_languages_pref_name_.c_str()), ',', |
| 170 &accept_languages_list); | 146 &accept_languages_list); |
| 171 | 147 |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 &auto_target_lang)) { | 409 &auto_target_lang)) { |
| 434 // We need to confirm that the saved target language is still supported. | 410 // We need to confirm that the saved target language is still supported. |
| 435 // Also, GetLanguageCode will take care of removing country code if any. | 411 // Also, GetLanguageCode will take care of removing country code if any. |
| 436 auto_target_lang = | 412 auto_target_lang = |
| 437 TranslateDownloadManager::GetLanguageCode(auto_target_lang); | 413 TranslateDownloadManager::GetLanguageCode(auto_target_lang); |
| 438 if (TranslateDownloadManager::IsSupportedLanguage(auto_target_lang)) | 414 if (TranslateDownloadManager::IsSupportedLanguage(auto_target_lang)) |
| 439 return auto_target_lang; | 415 return auto_target_lang; |
| 440 } | 416 } |
| 441 return std::string(); | 417 return std::string(); |
| 442 } | 418 } |
| OLD | NEW |