| 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 "components/translate/core/browser/translate_ui_delegate.h" | 5 #include "components/translate/core/browser/translate_ui_delegate.h" |
| 6 | 6 |
| 7 #include "base/i18n/string_compare.h" | 7 #include "base/i18n/string_compare.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "components/translate/core/browser/language_state.h" | 10 #include "components/translate/core/browser/language_state.h" |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 } | 249 } |
| 250 } | 250 } |
| 251 | 251 |
| 252 bool TranslateUIDelegate::IsLanguageBlocked() { | 252 bool TranslateUIDelegate::IsLanguageBlocked() { |
| 253 return prefs_->IsBlockedLanguage(GetOriginalLanguageCode()); | 253 return prefs_->IsBlockedLanguage(GetOriginalLanguageCode()); |
| 254 } | 254 } |
| 255 | 255 |
| 256 void TranslateUIDelegate::SetLanguageBlocked(bool value) { | 256 void TranslateUIDelegate::SetLanguageBlocked(bool value) { |
| 257 if (value) { | 257 if (value) { |
| 258 prefs_->BlockLanguage(GetOriginalLanguageCode()); | 258 prefs_->BlockLanguage(GetOriginalLanguageCode()); |
| 259 // In the new UI, we will keep showing the translate omnibar icon | 259 if (translate_manager_) { |
| 260 // even if the language is blocked so in case the user just wants to | |
| 261 // translate that page the user can invoke the translate bubble from | |
| 262 // the omnibar icon. | |
| 263 if (!base::FeatureList::IsEnabled(kTranslateUI2016Q2) && | |
| 264 translate_manager_) { | |
| 265 translate_manager_->GetLanguageState().SetTranslateEnabled(false); | 260 translate_manager_->GetLanguageState().SetTranslateEnabled(false); |
| 266 } | 261 } |
| 267 } else { | 262 } else { |
| 268 prefs_->UnblockLanguage(GetOriginalLanguageCode()); | 263 prefs_->UnblockLanguage(GetOriginalLanguageCode()); |
| 269 } | 264 } |
| 270 | 265 |
| 271 UMA_HISTOGRAM_BOOLEAN(kNeverTranslateLang, value); | 266 UMA_HISTOGRAM_BOOLEAN(kNeverTranslateLang, value); |
| 272 } | 267 } |
| 273 | 268 |
| 274 bool TranslateUIDelegate::IsSiteBlacklisted() { | 269 bool TranslateUIDelegate::IsSiteBlacklisted() { |
| 275 std::string host = GetPageHost(); | 270 std::string host = GetPageHost(); |
| 276 return !host.empty() && prefs_->IsSiteBlacklisted(host); | 271 return !host.empty() && prefs_->IsSiteBlacklisted(host); |
| 277 } | 272 } |
| 278 | 273 |
| 279 void TranslateUIDelegate::SetSiteBlacklist(bool value) { | 274 void TranslateUIDelegate::SetSiteBlacklist(bool value) { |
| 280 std::string host = GetPageHost(); | 275 std::string host = GetPageHost(); |
| 281 if (host.empty()) | 276 if (host.empty()) |
| 282 return; | 277 return; |
| 283 | 278 |
| 284 if (value) { | 279 if (value) { |
| 285 prefs_->BlacklistSite(host); | 280 prefs_->BlacklistSite(host); |
| 286 // In the new UI, we will keep showing the translate omnibar icon | 281 if (translate_manager_) { |
| 287 // even if the site is blocked so in case the user just wants to | |
| 288 // translate that page the user can invoke the translate bubble from | |
| 289 // the omnibar icon. | |
| 290 if (!base::FeatureList::IsEnabled(kTranslateUI2016Q2) && | |
| 291 translate_manager_) { | |
| 292 translate_manager_->GetLanguageState().SetTranslateEnabled(false); | 282 translate_manager_->GetLanguageState().SetTranslateEnabled(false); |
| 293 } | 283 } |
| 294 } else { | 284 } else { |
| 295 prefs_->RemoveSiteFromBlacklist(host); | 285 prefs_->RemoveSiteFromBlacklist(host); |
| 296 } | 286 } |
| 297 | 287 |
| 298 UMA_HISTOGRAM_BOOLEAN(kNeverTranslateSite, value); | 288 UMA_HISTOGRAM_BOOLEAN(kNeverTranslateSite, value); |
| 299 } | 289 } |
| 300 | 290 |
| 301 bool TranslateUIDelegate::ShouldAlwaysTranslate() { | 291 bool TranslateUIDelegate::ShouldAlwaysTranslate() { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 UMA_HISTOGRAM_BOOLEAN(kAlwaysTranslateLang, value); | 328 UMA_HISTOGRAM_BOOLEAN(kAlwaysTranslateLang, value); |
| 339 } | 329 } |
| 340 | 330 |
| 341 std::string TranslateUIDelegate::GetPageHost() { | 331 std::string TranslateUIDelegate::GetPageHost() { |
| 342 if (!translate_driver_->HasCurrentPage()) | 332 if (!translate_driver_->HasCurrentPage()) |
| 343 return std::string(); | 333 return std::string(); |
| 344 return translate_driver_->GetLastCommittedURL().HostNoBrackets(); | 334 return translate_driver_->GetLastCommittedURL().HostNoBrackets(); |
| 345 } | 335 } |
| 346 | 336 |
| 347 } // namespace translate | 337 } // namespace translate |
| OLD | NEW |