File: safe_browsing_blocking_page.h

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 (188 lines) | stat: -rw-r--r-- 8,131 bytes parent folder | download | duplicates (6)
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Classes for managing the SafeBrowsing interstitial pages.
//
// When a user is about to visit a page the SafeBrowsing system has deemed to
// be malicious, either as malware or a phishing page, we show an interstitial
// page with some options (go back, continue) to give the user a chance to avoid
// the harmful page.
//
// The SafeBrowsingBlockingPage is created by the SafeBrowsingUIManager on the
// UI thread when we've determined that a page is malicious. The operation of
// the blocking page occurs on the UI thread, where it waits for the user to
// make a decision about what to do: either go back or continue on.
//
// The blocking page forwards the result of the user's choice back to the
// SafeBrowsingUIManager so that we can cancel the request for the new page,
// or allow it to continue.
//
// A web page may contain several resources flagged as malware/phishing.  This
// results into more than one interstitial being shown.  On the first unsafe
// resource received we show an interstitial.  Any subsequent unsafe resource
// notifications while the first interstitial is showing is queued.  If the user
// decides to proceed in the first interstitial, we display all queued unsafe
// resources in a new interstitial.

#ifndef COMPONENTS_SAFE_BROWSING_CONTENT_BROWSER_SAFE_BROWSING_BLOCKING_PAGE_H_
#define COMPONENTS_SAFE_BROWSING_CONTENT_BROWSER_SAFE_BROWSING_BLOCKING_PAGE_H_

#include <map>

#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "components/safe_browsing/content/browser/base_blocking_page.h"
#include "components/safe_browsing/content/browser/base_ui_manager.h"

namespace history {
class HistoryService;
}

namespace network {
class SharedURLLoaderFactory;
}

namespace weblayer {
class WebLayerSafeBrowsingBlockingPageFactory;
}

namespace safe_browsing {

class SafeBrowsingNavigationObserverManager;
class SafeBrowsingMetricsCollector;
class ThreatDetails;
class TriggerManager;

class SafeBrowsingBlockingPage : public BaseBlockingPage {
 public:
  typedef security_interstitials::BaseSafeBrowsingErrorUI
      BaseSafeBrowsingErrorUI;
  // Interstitial type, used in tests.
  static const security_interstitials::SecurityInterstitialPage::TypeID
      kTypeForTesting;

  SafeBrowsingBlockingPage(const SafeBrowsingBlockingPage&) = delete;
  SafeBrowsingBlockingPage& operator=(const SafeBrowsingBlockingPage&) = delete;

  ~SafeBrowsingBlockingPage() override;

  // SecurityInterstitialPage method:
  security_interstitials::SecurityInterstitialPage::TypeID GetTypeForTesting()
      override;

 protected:
  friend class ChromeSafeBrowsingBlockingPageFactory;
  friend class weblayer::WebLayerSafeBrowsingBlockingPageFactory;
  friend class SafeBrowsingBlockingPageTestBase;
  friend class SafeBrowsingBlockingPageBrowserTest;
  friend class SafeBrowsingBlockingQuietPageFactoryImpl;
  friend class SafeBrowsingBlockingQuietPageTest;
  FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest,
                           ProceedThenDontProceed);
  FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest,
                           MalwareReportsDisabled);
  FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest,
                           MalwareReportsToggling);
  FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest,
                           ExtendedReportingNotShownOnSecurePage);
  FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest,
                           MalwareReportsTransitionDisabled);
  FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageIncognitoTest,
                           ExtendedReportingNotShownInIncognito);
  FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest,
                           ExtendedReportingNotShownNotAllowExtendedReporting);
  FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest,
                           ExtendedReportingNotShownForEnhancedProtection);
  FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, BillingPage);

  void UpdateReportingPref();  // Used for the transition from old to new pref.

  // Don't instantiate this class directly, use CreateBlockingPage instead.
  // |trigger_manager| may be null, in which case reporting will not occur.
  SafeBrowsingBlockingPage(
      BaseUIManager* ui_manager,
      content::WebContents* web_contents,
      const GURL& main_frame_url,
      const UnsafeResourceList& unsafe_resources,
      std::unique_ptr<
          security_interstitials::SecurityInterstitialControllerClient>
          controller_client,
      const BaseSafeBrowsingErrorUI::SBErrorDisplayOptions& display_options,
      bool should_trigger_reporting,
      history::HistoryService* history_service,
      SafeBrowsingNavigationObserverManager* navigation_observer_manager,
      SafeBrowsingMetricsCollector* metrics_collector,
      TriggerManager* trigger_manager,
      bool is_proceed_anyway_disabled,
      bool is_safe_browsing_surveys_enabled,
      base::OnceCallback<void(bool, SBThreatType)>
          trust_safety_sentiment_service_trigger,
      base::OnceCallback<void(bool, SBThreatType)>
          ignore_auto_revocation_notifications_trigger,
      network::SharedURLLoaderFactory* url_loader_for_testing = nullptr);

  // Called when an interstitial is closed, either due to a click through or a
  // navigation elsewhere.
  void OnInterstitialClosing() override;

  // Called when the trigger manager can't send the report because the threat
  // details are unavailable. This typically happens when the user closes the
  // tab without using the interstitial UI.
  void SendFallbackReport(
      const security_interstitials::UnsafeResource resource,
      bool did_proceed,
      int num_visits,
      security_interstitials::InterstitialInteractionMap* interactions,
      bool is_hats_candidate);

  // Called when the interstitial is going away. If there is a
  // pending threat details object, we look at the user's
  // preferences, and if the option to send threat details is
  // enabled, the report is scheduled to be sent on the |ui_manager_|.
  void FinishThreatDetails(const base::TimeDelta& delay,
                           bool did_proceed,
                           int num_visits) override;

  // Log UKM for the user bypassing a safe browsing interstitial.
  void LogSafeBrowsingInterstitialBypassedUKM();

  // Log UKM for the safe browsing interstitial being shown to the user.
  void LogSafeBrowsingInterstitialShownUKM();

  // Whether ThreatDetails collection is in progress as part of this
  // interstitial.
  bool threat_details_in_progress_;

  // The threat source that triggers the blocking page.
  ThreatSource threat_source_;

  // The threat type of the resource that triggered the blocking page.
  SBThreatType threat_type_;

 private:
  raw_ptr<history::HistoryService> history_service_ = nullptr;
  raw_ptr<SafeBrowsingNavigationObserverManager> navigation_observer_manager_ =
      nullptr;
  raw_ptr<SafeBrowsingMetricsCollector> metrics_collector_ = nullptr;
  raw_ptr<TriggerManager> trigger_manager_ = nullptr;
  std::unique_ptr<security_interstitials::InterstitialInteractionMap>
      interstitial_interactions_;
  // Whether the user has SafeBrowsingProceedAnywayDisabled enabled.
  bool is_proceed_anyway_disabled_;
  // Whether the user has SafeBrowsingSurveysEnabled enabled.
  bool is_safe_browsing_surveys_enabled_;
  // Triggers trust and safety sentiment service when interstitial closes.
  base::OnceCallback<void(bool, SBThreatType)>
      trust_safety_sentiment_service_trigger_ = base::NullCallback();
  // Triggers callback for ignoring the url for future auto abusive notification
  // revocation.
  base::OnceCallback<void(bool, SBThreatType)>
      ignore_auto_revocation_notifications_trigger_ = base::NullCallback();
  // Timestamp of when the safe browsing blocking page was shown to the user.
  int64_t warning_shown_ts_;
};

}  // namespace safe_browsing

#endif  // COMPONENTS_SAFE_BROWSING_CONTENT_BROWSER_SAFE_BROWSING_BLOCKING_PAGE_H_