1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/security_interstitials/content/https_only_mode_blocking_page.h"
#include "base/logging.h"
#include "base/notreached.h"
#include "base/strings/string_number_conversions.h"
#include "base/values.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/security_interstitials/content/security_interstitial_controller_client.h"
#include "components/security_interstitials/core/common_string_util.h"
#include "components/security_interstitials/core/controller_client.h"
#include "components/security_interstitials/core/https_only_mode_ui_util.h"
#include "components/security_interstitials/core/metrics_helper.h"
#include "components/security_interstitials/core/pref_names.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"
namespace security_interstitials {
// static
const SecurityInterstitialPage::TypeID
HttpsOnlyModeBlockingPage::kTypeForTesting =
&HttpsOnlyModeBlockingPage::kTypeForTesting;
// static
const char HttpsOnlyModeBlockingPage::kLearnMoreLink[] =
"https://support.google.com/chrome?p=first_mode";
HttpsOnlyModeBlockingPage::HttpsOnlyModeBlockingPage(
content::WebContents* web_contents,
const GURL& request_url,
std::unique_ptr<SecurityInterstitialControllerClient> controller_client,
const security_interstitials::https_only_mode::HttpInterstitialState&
interstitial_state,
MetricsCallback metrics_callback)
: SecurityInterstitialPage(web_contents,
request_url,
std::move(controller_client)),
interstitial_state_(interstitial_state),
metrics_callback_(std::move(metrics_callback)) {
controller()->metrics_helper()->RecordUserDecision(MetricsHelper::SHOW);
controller()->metrics_helper()->RecordUserInteraction(
MetricsHelper::TOTAL_VISITS);
}
HttpsOnlyModeBlockingPage::~HttpsOnlyModeBlockingPage() = default;
void HttpsOnlyModeBlockingPage::OnInterstitialClosing() {
// If the page is closing without an explicit decision, record it as not
// proceeding.
if (!user_made_decision_) {
if (metrics_callback_ && !ukm_recorded_) {
std::move(metrics_callback_)
.Run(https_only_mode::BlockingResult::kInterstitialDontProceed);
ukm_recorded_ = true;
}
controller()->metrics_helper()->RecordUserDecision(
MetricsHelper::DONT_PROCEED);
}
}
SecurityInterstitialPage::TypeID
HttpsOnlyModeBlockingPage::GetTypeForTesting() {
return HttpsOnlyModeBlockingPage::kTypeForTesting;
}
void HttpsOnlyModeBlockingPage::CommandReceived(const std::string& command) {
if (command == "\"pageLoadComplete\"") {
// content::WaitForRenderFrameReady sends this message when the page
// load completes. Ignore it.
return;
}
int cmd = 0;
bool retval = base::StringToInt(command, &cmd);
DCHECK(retval);
switch (cmd) {
case security_interstitials::CMD_DONT_PROCEED:
if (metrics_callback_ && !ukm_recorded_) {
std::move(metrics_callback_)
.Run(https_only_mode::BlockingResult::kInterstitialDontProceed);
ukm_recorded_ = true;
}
user_made_decision_ = true;
controller()->metrics_helper()->RecordUserDecision(
MetricsHelper::DONT_PROCEED);
controller()->GoBack();
break;
case security_interstitials::CMD_PROCEED:
if (metrics_callback_ && !ukm_recorded_) {
std::move(metrics_callback_)
.Run(https_only_mode::BlockingResult::kInterstitialProceed);
ukm_recorded_ = true;
}
user_made_decision_ = true;
controller()->metrics_helper()->RecordUserDecision(
MetricsHelper::PROCEED);
controller()->Proceed();
break;
case security_interstitials::CMD_OPEN_HELP_CENTER: {
controller()->metrics_helper()->RecordUserInteraction(
security_interstitials::MetricsHelper::SHOW_LEARN_MORE);
controller()->OpenUrlInNewForegroundTab(GURL(kLearnMoreLink));
break;
}
case security_interstitials::CMD_OPEN_ANDROID_ADVANCED_PROTECTION_SETTINGS:
#if BUILDFLAG(IS_ANDROID)
controller()->metrics_helper()->RecordUserInteraction(
security_interstitials::MetricsHelper::
OPEN_ADVANCED_PROTECTION_SETTINGS);
controller()->OpenAdvancedProtectionSettings();
#endif // BUILDFLAG(IS_ANDROID)
break;
case security_interstitials::CMD_DO_REPORT:
case security_interstitials::CMD_DONT_REPORT:
case security_interstitials::CMD_SHOW_MORE_SECTION:
case security_interstitials::CMD_OPEN_DATE_SETTINGS:
case security_interstitials::CMD_OPEN_REPORTING_PRIVACY:
case security_interstitials::CMD_OPEN_WHITEPAPER:
case security_interstitials::CMD_RELOAD:
case security_interstitials::CMD_OPEN_DIAGNOSTIC:
case security_interstitials::CMD_OPEN_LOGIN:
case security_interstitials::CMD_REPORT_PHISHING_ERROR:
// Not supported by the HTTPS-only mode blocking page.
NOTREACHED() << "Unsupported command: " << command;
case security_interstitials::CMD_ERROR:
case security_interstitials::CMD_TEXT_FOUND:
case security_interstitials::CMD_TEXT_NOT_FOUND:
// Commands are for testing.
break;
}
}
void HttpsOnlyModeBlockingPage::PopulateInterstitialStrings(
base::Value::Dict& load_time_data) {
PopulateHttpsOnlyModeStringsForSharedHTML(
load_time_data, /*august2024_refresh_enabled=*/true);
PopulateHttpsOnlyModeStringsForBlockingPage(
load_time_data, request_url(), interstitial_state_,
/*august2024_refresh_enabled=*/true);
}
} // namespace security_interstitials
|