File: dlp_content_restriction_set.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 (117 lines) | stat: -rw-r--r-- 4,333 bytes parent folder | download | duplicates (5)
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
// Copyright 2020 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_CHROMEOS_POLICY_DLP_DLP_CONTENT_RESTRICTION_SET_H_
#define CHROME_BROWSER_CHROMEOS_POLICY_DLP_DLP_CONTENT_RESTRICTION_SET_H_

#include "chrome/browser/chromeos/policy/dlp/dlp_rules_manager.h"

#include <array>

#include "url/gurl.h"

namespace policy {

// Enum representing the possible restrictions applied to on-screen content.
// These values are used in bitmask in DlpContentRestrictionSet and should
// correspond to the type in which the mask is stored.
enum class DlpContentRestriction : int {
  // Do not allow any screenshots or video capture of the corresponding content.
  kScreenshot = 0,
  // Enforce ePrivacy screen when content is visible.
  kPrivacyScreen = 1,
  // Do not allow printing.
  kPrint = 2,
  // Do not allow screen share.
  kScreenShare = 3,
  // Should be equal to the last restriction.
  kMaxValue = kScreenShare,
};

// Represents result of evaluating restriction - both the level at which it
// should be enforced and the url that caused it.
struct RestrictionLevelAndUrl {
  RestrictionLevelAndUrl() = default;
  RestrictionLevelAndUrl(DlpRulesManager::Level level, GURL url)
      : level(level), url(url) {}
  RestrictionLevelAndUrl(const RestrictionLevelAndUrl&) = default;
  RestrictionLevelAndUrl& operator=(const RestrictionLevelAndUrl&) = default;
  ~RestrictionLevelAndUrl() = default;

  // Restrictions with the same level, but different URLs are considered the
  // same as they don't affect the current restriction enforcement.
  bool operator==(const RestrictionLevelAndUrl& other) const {
    return level == other.level;
  }

  DlpRulesManager::Level level = DlpRulesManager::Level::kNotSet;
  GURL url;
};

// Represents set of levels of all restrictions applied to on-screen content.
// Allowed to be copied and assigned.
class DlpContentRestrictionSet {
 public:
  DlpContentRestrictionSet();
  // TODO(b/324549895): Remove this constructor. Content restrictions shouldn't
  // be set without a url since it's used for reporting.
  DlpContentRestrictionSet(DlpContentRestriction restriction,
                           DlpRulesManager::Level level);

  DlpContentRestrictionSet(const DlpContentRestrictionSet& restriction_set);
  DlpContentRestrictionSet& operator=(const DlpContentRestrictionSet&);

  ~DlpContentRestrictionSet();

  friend bool operator==(const DlpContentRestrictionSet&,
                         const DlpContentRestrictionSet&) = default;

  // Sets the |restriction| to the |level| if not set to a higher one yet and
  // remembers the |url| in this case.
  void SetRestriction(DlpContentRestriction restriction,
                      DlpRulesManager::Level level,
                      const GURL& gurl);

  // Returns the level for the |restriction|.
  DlpRulesManager::Level GetRestrictionLevel(
      DlpContentRestriction restriction) const;

  // Returns the url for most restrictive level for the |restriction|.
  const GURL& GetRestrictionUrl(DlpContentRestriction restriction) const;

  // Returns the level and url for the |restriction|.
  RestrictionLevelAndUrl GetRestrictionLevelAndUrl(
      DlpContentRestriction restriction) const;

  // Returns whether no restrictions should be applied.
  bool IsEmpty() const;

  // Sets all the restrictions to the highest level from |other| and this.
  void UnionWith(const DlpContentRestrictionSet& other);

  // Returns a new set that contains restrictions that exist in this, but not in
  // |other|.
  DlpContentRestrictionSet DifferenceWith(
      const DlpContentRestrictionSet& other) const;

  // Returns which content restrictions are being applied to the |url| according
  // to the policies.
  static DlpContentRestrictionSet GetForURL(const GURL& url);

  static void SetRestrictionsForURLForTesting(
      const GURL& url,
      const DlpContentRestrictionSet& restrictions);

 private:
  friend class DlpContentManagerTestHelper;

  // The current level and url of each of the restrictions.
  std::array<RestrictionLevelAndUrl,
             static_cast<int>(DlpContentRestriction::kMaxValue) + 1>
      restrictions_;
};

}  // namespace policy

#endif  // CHROME_BROWSER_CHROMEOS_POLICY_DLP_DLP_CONTENT_RESTRICTION_SET_H_