File: download_commands.h

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; 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 (89 lines) | stat: -rw-r--r-- 3,645 bytes parent folder | download | duplicates (4)
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
// Copyright 2015 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_DOWNLOAD_DOWNLOAD_COMMANDS_H_
#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_COMMANDS_H_

#include "base/gtest_prod_util.h"
#include "base/memory/weak_ptr.h"
#include "base/task/sequenced_task_runner.h"
#include "build/build_config.h"
#include "url/gurl.h"

#if !BUILDFLAG(IS_ANDROID)
class Browser;
#endif

class DownloadUIModel;

class DownloadCommands {
 public:
  // These values are persisted to logs. Entries should not be renumbered and
  // numeric values should never be reused.
  enum Command {
    SHOW_IN_FOLDER = 0,  // Open a folder view window with the item selected.
    OPEN_WHEN_COMPLETE = 1,       // Open the download when it's finished.
    ALWAYS_OPEN_TYPE = 2,         // Default this file extension to always open.
    PLATFORM_OPEN = 3,            // Open using platform handler.
    CANCEL = 4,                   // Cancel the download.
    PAUSE = 5,                    // Pause a download.
    RESUME = 6,                   // Resume a download.
    DISCARD = 7,                  // Discard the malicious download.
    KEEP = 8,                     // Keep the malicious download.
    LEARN_MORE_SCANNING = 9,      // Show info about download scanning.
    LEARN_MORE_INTERRUPTED = 10,  // Show info about interrupted downloads.
    LEARN_MORE_INSECURE_DOWNLOAD = 11,  // Show info about insecure downloads.
    LEARN_MORE_DOWNLOAD_BLOCKED = 12,   // Show info about blocked downloads.
    OPEN_SAFE_BROWSING_SETTING = 13,    // Open settings page for Safe Browsing.
    COPY_TO_CLIPBOARD = 14,             // Copy the contents to the clipboard.
    DEEP_SCAN = 15,             // Send file to Safe Browsing for deep scanning.
    BYPASS_DEEP_SCANNING = 16,  // Bypass the prompt to deep scan.
    REVIEW = 17,                // Show enterprise download review dialog.
    RETRY = 18,                 // Retry the download.
    CANCEL_DEEP_SCAN = 19,  // Cancel deep scan and return to scanning prompt.
    BYPASS_DEEP_SCANNING_AND_OPEN = 20,  // Bypass the prompt to deep scan and
                                         // open the file.
    OPEN_WITH_MEDIA_APP = 21,  // Open file using the ChromeOS media app.
    EDIT_WITH_MEDIA_APP = 22,  // Open file using the ChromeOS media app with
                               // an editing hint.

    kMaxValue = EDIT_WITH_MEDIA_APP,  // Keep last.
  };

  // |model| must outlive DownloadCommands.
  // TODO(shaktisahu): Investigate if model lifetime is shorter than |this|.
  explicit DownloadCommands(base::WeakPtr<DownloadUIModel> model);

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

  virtual ~DownloadCommands();

  bool IsCommandEnabled(Command command) const;
  bool IsCommandChecked(Command command) const;
  bool IsCommandVisible(Command command) const;
  void ExecuteCommand(Command command);

#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || \
    BUILDFLAG(IS_MAC)
  bool IsDownloadPdf() const;
  bool CanOpenPdfInSystemViewer() const;
  Browser* GetBrowser() const;
#endif

  GURL GetLearnMoreURLForInterruptedDownload() const;
  void CopyFileAsImageToClipboard();
  bool CanBeCopiedToClipboard() const;

 private:
  FRIEND_TEST_ALL_PREFIXES(
      DownloadCommandsTest,
      GetLearnMoreURLForInterruptedDownload_ContainsContext);

  base::WeakPtr<DownloadUIModel> model_;

  scoped_refptr<base::SequencedTaskRunner> task_runner_;
};

#endif  // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_COMMANDS_H_