| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/security_interstitials/core/controller_client.h" | 5 #include "components/security_interstitials/core/controller_client.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "components/google/core/browser/google_util.h" | 9 #include "components/google/core/browser/google_util.h" |
| 10 #include "components/prefs/pref_service.h" | 10 #include "components/prefs/pref_service.h" |
| 11 #include "components/security_interstitials/core/metrics_helper.h" | 11 #include "components/security_interstitials/core/metrics_helper.h" |
| 12 #include "grit/components_strings.h" | 12 #include "grit/components_strings.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 15 | 15 |
| 16 namespace security_interstitials { | 16 namespace security_interstitials { |
| 17 | 17 |
| 18 const char kBoxChecked[] = "boxchecked"; | 18 const char kBoxChecked[] = "boxchecked"; |
| 19 const char kDisplayCheckBox[] = "displaycheckbox"; | 19 const char kDisplayCheckBox[] = "displaycheckbox"; |
| 20 const char kOptInLink[] = "optInLink"; | 20 const char kOptInLink[] = "optInLink"; |
| 21 const char kPrivacyLinkHtml[] = | 21 const char kPrivacyLinkHtml[] = |
| 22 "<a id=\"privacy-link\" href=\"\" onclick=\"sendCommand(%d); " | 22 "<a id=\"privacy-link\" href=\"\" onclick=\"sendCommand(%d); " |
| 23 "return false;\" onmousedown=\"return false;\">%s</a>"; | 23 "return false;\" onmousedown=\"return false;\">%s</a>"; |
| 24 | 24 |
| 25 ControllerClient::ControllerClient() {} | 25 ControllerClient::ControllerClient( |
| 26 std::unique_ptr<MetricsHelper> metrics_helper) |
| 27 : metrics_helper_(std::move(metrics_helper)) {} |
| 28 |
| 26 ControllerClient::~ControllerClient() {} | 29 ControllerClient::~ControllerClient() {} |
| 27 | 30 |
| 28 MetricsHelper* ControllerClient::metrics_helper() const { | 31 MetricsHelper* ControllerClient::metrics_helper() const { |
| 29 return metrics_helper_.get(); | 32 return metrics_helper_.get(); |
| 30 } | 33 } |
| 31 | 34 |
| 32 void ControllerClient::set_metrics_helper( | |
| 33 std::unique_ptr<MetricsHelper> metrics_helper) { | |
| 34 metrics_helper_ = std::move(metrics_helper); | |
| 35 } | |
| 36 | |
| 37 void ControllerClient::SetReportingPreference(bool report) { | 35 void ControllerClient::SetReportingPreference(bool report) { |
| 38 GetPrefService()->SetBoolean(GetExtendedReportingPrefName(), report); | 36 GetPrefService()->SetBoolean(GetExtendedReportingPrefName(), report); |
| 39 metrics_helper_->RecordUserInteraction( | 37 metrics_helper_->RecordUserInteraction( |
| 40 report ? MetricsHelper::SET_EXTENDED_REPORTING_ENABLED | 38 report ? MetricsHelper::SET_EXTENDED_REPORTING_ENABLED |
| 41 : MetricsHelper::SET_EXTENDED_REPORTING_DISABLED); | 39 : MetricsHelper::SET_EXTENDED_REPORTING_DISABLED); |
| 42 } | 40 } |
| 43 | 41 |
| 44 void ControllerClient::OpenExtendedReportingPrivacyPolicy() { | 42 void ControllerClient::OpenExtendedReportingPrivacyPolicy() { |
| 45 metrics_helper_->RecordUserInteraction(MetricsHelper::SHOW_PRIVACY_POLICY); | 43 metrics_helper_->RecordUserInteraction(MetricsHelper::SHOW_PRIVACY_POLICY); |
| 46 GURL privacy_url( | 44 GURL privacy_url( |
| 47 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_URL)); | 45 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_URL)); |
| 48 privacy_url = | 46 privacy_url = |
| 49 google_util::AppendGoogleLocaleParam(privacy_url, GetApplicationLocale()); | 47 google_util::AppendGoogleLocaleParam(privacy_url, GetApplicationLocale()); |
| 50 OpenUrlInCurrentTab(privacy_url); | 48 OpenUrlInCurrentTab(privacy_url); |
| 51 } | 49 } |
| 52 | 50 |
| 53 void ControllerClient::OpenExtendedReportingWhitepaper() { | 51 void ControllerClient::OpenExtendedReportingWhitepaper() { |
| 54 metrics_helper_->RecordUserInteraction(MetricsHelper::SHOW_WHITEPAPER); | 52 metrics_helper_->RecordUserInteraction(MetricsHelper::SHOW_WHITEPAPER); |
| 55 GURL whitepaper_url( | 53 GURL whitepaper_url( |
| 56 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_WHITEPAPER_URL)); | 54 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_WHITEPAPER_URL)); |
| 57 whitepaper_url = google_util::AppendGoogleLocaleParam(whitepaper_url, | 55 whitepaper_url = google_util::AppendGoogleLocaleParam(whitepaper_url, |
| 58 GetApplicationLocale()); | 56 GetApplicationLocale()); |
| 59 OpenUrlInCurrentTab(whitepaper_url); | 57 OpenUrlInCurrentTab(whitepaper_url); |
| 60 } | 58 } |
| 61 | 59 |
| 62 } // namespace security_interstitials | 60 } // namespace security_interstitials |
| OLD | NEW |