File: files_policy_error_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 (106 lines) | stat: -rw-r--r-- 4,246 bytes parent folder | download | duplicates (8)
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
// 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_ERROR_DIALOG_H_
#define CHROME_BROWSER_ASH_POLICY_DLP_DIALOGS_FILES_POLICY_ERROR_DIALOG_H_

#include <map>

#include "base/memory/weak_ptr.h"
#include "chrome/browser/ash/policy/dlp/dialogs/files_policy_dialog.h"
#include "chrome/browser/chromeos/policy/dlp/dlp_confidential_file.h"
#include "chrome/browser/chromeos/policy/dlp/dlp_files_utils.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/gfx/native_widget_types.h"

namespace policy {

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

 public:
  FilesPolicyErrorDialog() = delete;
  FilesPolicyErrorDialog(const std::map<BlockReason, Info>& dialog_info_map,
                         dlp::FileAction action,
                         gfx::NativeWindow modal_parent);
  FilesPolicyErrorDialog(const FilesPolicyErrorDialog&) = delete;
  FilesPolicyErrorDialog(FilesPolicyErrorDialog&&) = delete;
  FilesPolicyErrorDialog& operator=(const FilesPolicyErrorDialog&) = delete;
  FilesPolicyErrorDialog& operator=(FilesPolicyErrorDialog&&) = delete;
  ~FilesPolicyErrorDialog() override;

 private:
  // Holds all the information of a section of the dialog.
  struct BlockedFilesSection {
    BlockedFilesSection(
        int view_id,
        const std::u16string& message,
        const std::vector<DlpConfidentialFile>& files,
        const std::vector<std::pair<GURL, std::u16string>>& learn_more_urls);
    ~BlockedFilesSection();

    BlockedFilesSection(const BlockedFilesSection& other);
    BlockedFilesSection& operator=(BlockedFilesSection&& other);

    // A unique ID attached to the view element holding `message`. This ID is
    // only set for mixed error dialogs and allows to figure out in tests
    // whether certain sections have been added to the dialog.
    int view_id;

    // The message shown to the user describing why `files` have been blocked.
    std::u16string message;

    // The blocked files.
    std::vector<DlpConfidentialFile> files;

    // Learn more URLs displayed to the user and their accessible name read out
    // by ChromeVox. A section may hold files blocked for different reasons,
    // each of which defining its own learn more URL.
    std::vector<std::pair<GURL, std::u16string>> learn_more_urls;
  };

  // PolicyDialogBase overrides:
  void MaybeAddConfidentialRows() override;
  std::u16string GetOkButton() override;
  std::u16string GetTitle() override;
  std::u16string GetMessage() override;

  // Initialize the `sections_` vector by possibly aggregating data taken from
  // the `dialog_info_map`.
  void SetupBlockedFilesSections(
      const std::map<BlockReason, Info>& dialog_info_map);

  // Appends a section to `sections_`. Details such as the displayed message and
  // list of blocked files are retrieved from `dialog_info_map`. It is no-op if
  // `reason` is not in `dialog_info_map` or there are no files blocked for the
  // given `reason`.
  void AppendBlockedFilesSection(
      BlockReason reason,
      const std::map<BlockReason, Info>& dialog_info_map);

  // Adds the given `section` to the dialog.
  // Should only be called after `SetupUpperPanel()`.
  void AddBlockedFilesSection(const BlockedFilesSection& section);

  // Called from the dialog's "OK" button.
  // Dismisses the dialog.
  void Dismiss();

  // The dialog is composed of one section in case of single error dialog or
  // more sections for mixed errors. Every section holds the information that
  // allows to populate the dialog UI such as the list of blocked files and the
  // message that should be shown to the user.
  std::vector<BlockedFilesSection> sections_;

  // Total number of blocked files for all policy reasons.
  size_t file_count_;

  base::WeakPtrFactory<FilesPolicyErrorDialog> weak_factory_{this};
};

}  // namespace policy

#endif  // CHROME_BROWSER_ASH_POLICY_DLP_DIALOGS_FILES_POLICY_ERROR_DIALOG_H_