File: data_protection_navigation_controller.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (90 lines) | stat: -rw-r--r-- 3,786 bytes parent folder | download | duplicates (3)
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
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ENTERPRISE_DATA_PROTECTION_DATA_PROTECTION_NAVIGATION_CONTROLLER_H_
#define CHROME_BROWSER_ENTERPRISE_DATA_PROTECTION_DATA_PROTECTION_NAVIGATION_CONTROLLER_H_

#include "base/callback_list.h"
#include "base/memory/weak_ptr.h"
#include "components/enterprise/buildflags/buildflags.h"
#include "content/public/browser/web_contents_observer.h"

namespace tabs {
class TabInterface;
}

namespace enterprise_data_protection {
struct UrlSettings;

// Observes navigations in order to correctly set that tab's Data Protection
// settings based on the SafeBrowsing verdict for said navigation.
// This class is unconditionally created, but will do nothing if data protection
// is disabled.
class DataProtectionNavigationController : public content::WebContentsObserver {
 public:
  explicit DataProtectionNavigationController(
      tabs::TabInterface* tab_interface);
  ~DataProtectionNavigationController() override;

  // Callback is invoked by ApplyDataProtectionSettingsOrDelayIfEmpty.
  void SetCallbackForTesting(base::OnceClosure closure);

 private:
  // TabInterface subscriber. Called when the associated tab enters the
  // foreground.
  void TabForegrounded(tabs::TabInterface* tab);

  // TabInterface subscriber. Called when the associated tab is going to be
  // discarded.
  void WillDiscardContents(tabs::TabInterface* tab,
                           content::WebContents* old_contents,
                           content::WebContents* new_contents);
  // Applies data protection settings if there are any to apply, otherwise
  // delay clearing the data protection settings until the page loads.
  //
  // This is called from a finish navigation event to handle the case where the
  // browser view is switching from a tab with data protections enabled to one
  // without.  At the end of the navigation, the existing page is still visible
  // to the user since the UI has not yet refreshed.  In this case the
  // protections should remain in place.  Once the document finishes loading,
  // `ApplyDataProtectionSettings()` will be called.  See
  // `DocumentOnLoadCompletedInPrimaryMainFrame()`.
  void ApplyDataProtectionSettingsOrDelayIfEmpty(
      base::WeakPtr<content::WebContents> expected_web_contents,
      const enterprise_data_protection::UrlSettings& settings);

  // Applies data protection settings based on the verdict received by
  // safe-browsing's realtime to `watermark_view_`.
  void ApplyDataProtectionSettings(
      base::WeakPtr<content::WebContents> expected_web_contents,
      const enterprise_data_protection::UrlSettings& settings);

  // content::WebContentsObserver
  void DidStartNavigation(
      content::NavigationHandle* navigation_handle) override;
  void DocumentOnLoadCompletedInPrimaryMainFrame() override;

  // Clear data protections once the page loads.
  // TODO(b/330960313): These bools can be removed once FCP is used as the
  // signal to set the data protections for the current tab.
  bool clear_watermark_text_on_page_load_ = false;
#if BUILDFLAG(ENTERPRISE_SCREENSHOT_PROTECTION)
  bool clear_screenshot_protection_on_page_load_ = false;
#endif

  // Holds subscriptions for TabInterface callbacks.
  std::vector<base::CallbackListSubscription> tab_subscriptions_;

  raw_ptr<tabs::TabInterface> tab_interface_;

  base::OnceClosure
      on_delay_apply_data_protection_settings_if_empty_called_for_testing_;

  mutable base::WeakPtrFactory<DataProtectionNavigationController>
      weak_ptr_factory_{this};
};

}  // namespace enterprise_data_protection

#endif  // CHROME_BROWSER_ENTERPRISE_DATA_PROTECTION_DATA_PROTECTION_NAVIGATION_CONTROLLER_H_