controller_client.cc 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/security_interstitials/core/controller_client.h"
  5. #include <utility>
  6. #include "components/google/core/common/google_util.h"
  7. #include "components/prefs/pref_service.h"
  8. #include "components/security_interstitials/core/metrics_helper.h"
  9. #include "components/security_interstitials/core/urls.h"
  10. #include "components/strings/grit/components_strings.h"
  11. #include "ui/base/l10n/l10n_util.h"
  12. namespace security_interstitials {
  13. const char kBoxChecked[] = "boxchecked";
  14. const char kDisplayCheckBox[] = "displaycheckbox";
  15. const char kDisplayEnhancedProtectionMessage[] =
  16. "displayEnhancedProtectionMessage";
  17. const char kOptInLink[] = "optInLink";
  18. const char kEnhancedProtectionMessage[] = "enhancedProtectionMessage";
  19. const char kHelpCenterUrl[] = "https://support.google.com/chrome/";
  20. ControllerClient::ControllerClient(
  21. std::unique_ptr<MetricsHelper> metrics_helper)
  22. : metrics_helper_(std::move(metrics_helper)),
  23. help_center_url_(kHelpCenterUrl) {}
  24. ControllerClient::~ControllerClient() {}
  25. MetricsHelper* ControllerClient::metrics_helper() const {
  26. return metrics_helper_.get();
  27. }
  28. void ControllerClient::SetReportingPreference(bool report) {
  29. DCHECK(GetPrefService());
  30. GetPrefService()->SetBoolean(GetExtendedReportingPrefName(), report);
  31. metrics_helper_->RecordUserInteraction(
  32. report ? MetricsHelper::SET_EXTENDED_REPORTING_ENABLED
  33. : MetricsHelper::SET_EXTENDED_REPORTING_DISABLED);
  34. }
  35. void ControllerClient::OpenExtendedReportingPrivacyPolicy(
  36. bool open_links_in_new_tab) {
  37. metrics_helper_->RecordUserInteraction(MetricsHelper::SHOW_PRIVACY_POLICY);
  38. GURL privacy_url(kSafeBrowsingPrivacyPolicyUrl);
  39. privacy_url =
  40. google_util::AppendGoogleLocaleParam(privacy_url, GetApplicationLocale());
  41. OpenURL(open_links_in_new_tab, privacy_url);
  42. }
  43. void ControllerClient::OpenExtendedReportingWhitepaper(
  44. bool open_links_in_new_tab) {
  45. metrics_helper_->RecordUserInteraction(MetricsHelper::SHOW_WHITEPAPER);
  46. GURL whitepaper_url(kSafeBrowsingWhitePaperUrl);
  47. whitepaper_url = google_util::AppendGoogleLocaleParam(whitepaper_url,
  48. GetApplicationLocale());
  49. OpenURL(open_links_in_new_tab, whitepaper_url);
  50. }
  51. void ControllerClient::OpenURL(bool open_links_in_new_tab, const GURL& url) {
  52. if (open_links_in_new_tab) {
  53. OpenUrlInNewForegroundTab(url);
  54. } else {
  55. OpenUrlInCurrentTab(url);
  56. }
  57. }
  58. bool ControllerClient::HasSeenRecurrentError() {
  59. return false;
  60. }
  61. GURL ControllerClient::GetBaseHelpCenterUrl() const {
  62. return help_center_url_;
  63. }
  64. void ControllerClient::SetBaseHelpCenterUrlForTesting(const GURL& test_url) {
  65. help_center_url_ = test_url;
  66. }
  67. } // namespace security_interstitials