File: files_policy_dialog.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; 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,806; 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 (229 lines) | stat: -rw-r--r-- 8,583 bytes parent folder | download | duplicates (2)
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
// Copyright 2023 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_ASH_POLICY_DLP_DIALOGS_FILES_POLICY_DIALOG_H_
#define CHROME_BROWSER_ASH_POLICY_DLP_DIALOGS_FILES_POLICY_DIALOG_H_

#include <optional>
#include <string>
#include <utility>

#include "base/files/file_path.h"
#include "chrome/browser/chromeos/policy/dlp/dialogs/policy_dialog_base.h"
#include "chrome/browser/chromeos/policy/dlp/dlp_confidential_file.h"
#include "chrome/browser/chromeos/policy/dlp/dlp_file_destination.h"
#include "chrome/browser/chromeos/policy/dlp/dlp_files_utils.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/views/widget/widget.h"

namespace policy {

class FilesPolicyDialogFactory;

// Dialog type (warning or error).
enum class FilesDialogType {
  kUnknown,  // Not a valid type - no dialog will be created.
  kWarning,  // Warning dialog - user can select to proceed or not.
  kError,    // Error dialog - overview of blocked files.
};

// Type of policy.
enum class Policy {
  kDlp,                   // Data Leak Prevention policy.
  kEnterpriseConnectors,  // Enterprise Connectors policy.
};

// FilesPolicyDialog is a window modal dialog used to show detailed overview of
// warnings and files blocked by data protection policies.
class FilesPolicyDialog : public PolicyDialogBase {
  METADATA_HEADER(FilesPolicyDialog, PolicyDialogBase)

 public:
  // Reasons for which a file can be blocked either because of an Enterprise
  // Connectors or DLP policy.
  // Please keep in sync with the `available_reasons` array below!
  // TODO(b/302653030): consider whether unifying BlockReason and Policy.
  enum class BlockReason {
    // File was blocked because of Data Leak Prevention policies.
    kDlp,
    // File was blocked because added to an Enterprise Connectors scanned
    // directory after the scan begun, and thus the file was not scanned.
    kEnterpriseConnectorsUnknownScanResult,
    // File was blocked because the scan failed.
    kEnterpriseConnectorsScanFailed,
    // File was blocked because it contains sensitive data (e.g., SSNs).
    kEnterpriseConnectorsSensitiveData,
    // File was blocked because it's a malware.
    kEnterpriseConnectorsMalware,
    // File was blocked because it could not be scanned due to encryption.
    kEnterpriseConnectorsEncryptedFile,
    // File was blocked because it could not be uploaded due to its size.
    kEnterpriseConnectorsLargeFile,
    // File was blocked because of Enterprise Connectors policies. This can be
    // used to mark files that do not require a more specific description of the
    // reason for which they were blocked.
    kEnterpriseConnectors,
  };

  // All the available reasons.
  // Please keep the array in sync with the `BlockReason` enum above!
  static constexpr std::array<BlockReason, 8> available_reasons{
      BlockReason::kDlp,
      BlockReason::kEnterpriseConnectorsUnknownScanResult,
      BlockReason::kEnterpriseConnectorsScanFailed,
      BlockReason::kEnterpriseConnectorsSensitiveData,
      BlockReason::kEnterpriseConnectorsMalware,
      BlockReason::kEnterpriseConnectorsEncryptedFile,
      BlockReason::kEnterpriseConnectorsLargeFile,
      BlockReason::kEnterpriseConnectors};

  // Returns the ID of the view that contains all details related to the given
  // `reason` in a mixed error dialog.
  static PolicyDialogBase::ViewIds MapBlockReasonToViewID(BlockReason reason);

  // Class holding information to build a dialog such as a message to the user,
  // a list of files involved, an optional learn more link, and for warning
  // scenarios whether the user is required to provide a justification to bypass
  // the warning. These info map to a section in the dialog.
  class Info {
   public:
    // Creates default dialog settings for warning scenarios.
    static Info Warn(BlockReason reason,
                     const std::vector<base::FilePath>& paths);

    // Creates default dialog settings for error scenarios.
    static Info Error(BlockReason reason,
                      const std::vector<base::FilePath>& paths);

    ~Info();
    Info(const Info& other);
    Info& operator=(Info&& other);

    bool operator==(const Info& other) const;

    const std::vector<DlpConfidentialFile>& GetFiles() const;

    // For warning scenarios only, returns whether bypassing the warning
    // requires a user justification.
    bool DoesBypassRequireJustification() const;

    // Sets whether bypassing a warning requires a user justification.
    void SetBypassRequiresJustification(bool value);

    // Returns the message that should be shown in the dialog.
    std::u16string GetMessage() const;

    // Overrides the default message.
    void SetMessage(const std::optional<std::u16string>& message);

    // Returns whether a custom message was set.
    bool HasCustomMessage() const;

    // Returns the learn more URL that should be shown in the dialog, if any.
    std::optional<GURL> GetLearnMoreURL() const;

    // Overrides the default learn more URL.
    void SetLearnMoreURL(const std::optional<GURL>& url);

    // Returns an accessible learn more link name, if available. An empty string
    // otherwise.
    std::u16string GetAccessibleLearnMoreLinkName() const;

    // Returns whether at least one of the default values (e.g., message, learn
    // more URL, etc...) has been overridden with a custom value.
    bool HasCustomDetails() const;

   private:
    Info();

    // The files that should be displayed.
    std::vector<DlpConfidentialFile> files_;

    // Whether the user is required to write a justification to bypass the
    // warning. This is only relevant for warning scenarios.
    bool bypass_requires_justification_ = false;

    // Default or admin defined message.
    std::u16string message_;

    // Whether `message_` is a custom message.
    bool is_custom_message_ = false;

    // Whether `learn_more_url_` is a custom url.
    bool is_custom_learn_more_url_ = false;

    // Learn more link name providing more info for users using a ChromeVox
    // reader.
    std::u16string accessible_learn_more_link_name_;

    // Default, admin defined learn more URL, or none of them.
    std::optional<GURL> learn_more_url_;
  };

  FilesPolicyDialog() = delete;
  FilesPolicyDialog(size_t file_count,
                    dlp::FileAction action,
                    gfx::NativeWindow modal_parent);
  FilesPolicyDialog(const FilesPolicyDialog& other) = delete;
  FilesPolicyDialog& operator=(const FilesPolicyDialog& other) = delete;
  ~FilesPolicyDialog() override;

  // Creates and shows an instance of FilesPolicyWarnDialog. Returns owning
  // Widget.
  static views::Widget* CreateWarnDialog(
      WarningWithJustificationCallback callback,
      dlp::FileAction action,
      gfx::NativeWindow modal_parent,
      Info dialog_info,
      std::optional<DlpFileDestination> destination = std::nullopt);

  // Creates and shows an instance of FilesPolicyErrorDialog. Returns owning
  // Widget.
  static views::Widget* CreateErrorDialog(
      const std::map<BlockReason, Info>& dialog_info_map,
      dlp::FileAction action,
      gfx::NativeWindow modal_parent);

  static void SetFactory(FilesPolicyDialogFactory* factory);

 protected:
  // PolicyDialogBase overrides:
  void SetupScrollView() override;
  void AddConfidentialRow(const gfx::ImageSkia& icon,
                          const std::u16string& title) override;

  dlp::FileAction action_;
  // Number of files listed in the dialog.
  size_t file_count_;

 private:
  // PolicyDialogBase overrides:
  views::Label* AddTitle(const std::u16string& title) override;
  views::Label* AddMessage(const std::u16string& message) override;
};

// Interface for creating warn and error FilesPolicyDialogs.
// Used in tests.
class FilesPolicyDialogFactory {
 public:
  virtual ~FilesPolicyDialogFactory() = default;

  virtual views::Widget* CreateWarnDialog(
      WarningWithJustificationCallback callback,
      dlp::FileAction action,
      gfx::NativeWindow modal_parent,
      std::optional<DlpFileDestination> destination,
      FilesPolicyDialog::Info settings) = 0;

  virtual views::Widget* CreateErrorDialog(
      const std::map<FilesPolicyDialog::BlockReason, FilesPolicyDialog::Info>&
          dialog_info_map,
      dlp::FileAction action,
      gfx::NativeWindow modal_parent) = 0;
};

}  // namespace policy

#endif  // CHROME_BROWSER_ASH_POLICY_DLP_DIALOGS_FILES_POLICY_DIALOG_H_