File: ssl_blocking_page_base.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (96 lines) | stat: -rw-r--r-- 3,414 bytes parent folder | download | duplicates (10)
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
// Copyright 2017 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/ssl_blocking_page_base.h"

#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/security_interstitials/content/security_interstitial_controller_client.h"
#include "components/security_interstitials/core/controller_client.h"
#include "components/security_interstitials/core/metrics_helper.h"
#include "components/strings/grit/components_strings.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/web_contents.h"
#include "ui/base/l10n/l10n_util.h"

namespace {
PrefService* GetPrefs(content::WebContents* web_contents) {
  return user_prefs::UserPrefs::Get(web_contents->GetBrowserContext());
}
}  // namespace

SSLBlockingPageBase::SSLBlockingPageBase(
    content::WebContents* web_contents,
    const net::SSLInfo& ssl_info,
    const GURL& request_url,
    bool overridable,
    const base::Time& time_triggered,
    bool can_show_enhanced_protection_message,
    std::unique_ptr<
        security_interstitials::SecurityInterstitialControllerClient>
        controller_client)
    : security_interstitials::SecurityInterstitialPage(
          web_contents,
          request_url,
          std::move(controller_client)),
      can_show_enhanced_protection_message_(
          can_show_enhanced_protection_message) {}

SSLBlockingPageBase::~SSLBlockingPageBase() = default;

void SSLBlockingPageBase::OnInterstitialClosing() {}

bool SSLBlockingPageBase::ShouldShowEnhancedProtectionMessage() {
  // Only show the enhanced protection message if all the following are true:
  // |can_show_enhanced_protection_message_| is set to true AND
  // the window is not incognito AND
  // Safe Browsing is not managed by policy AND
  // the user is not already in enhanced protection mode.
  if (!can_show_enhanced_protection_message_) {
    return false;
  }

  const bool in_incognito =
      web_contents()->GetBrowserContext()->IsOffTheRecord();
  const PrefService* pref_service = GetPrefs(web_contents());
  bool is_enhanced_protection_enabled =
      safe_browsing::IsEnhancedProtectionEnabled(*pref_service);
  bool is_safe_browsing_managed =
      safe_browsing::IsSafeBrowsingPolicyManaged(*pref_service);

  if (in_incognito) {
    return false;
  }
  if (is_enhanced_protection_enabled) {
    return false;
  }
  if (is_safe_browsing_managed) {
    return false;
  }
  return true;
}

void SSLBlockingPageBase::PopulateEnhancedProtectionMessage(
    base::Value::Dict& load_time_data) {
  const bool show = ShouldShowEnhancedProtectionMessage();

  load_time_data.Set(security_interstitials::kDisplayEnhancedProtectionMessage,
                     show);
  // This needs to be set even if it's not shown.
  load_time_data.Set(
      security_interstitials::kEnhancedProtectionMessage,
      l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_ENHANCED_PROTECTION_MESSAGE));

  // Disable Extended Reporting checkbox.
  load_time_data.Set(security_interstitials::kDisplayCheckBox, false);

  if (!show) {
    return;
  }

  if (controller()->metrics_helper()) {
    controller()->metrics_helper()->RecordUserInteraction(
        security_interstitials::MetricsHelper::SHOW_ENHANCED_PROTECTION);
  }
}