File: download_protection_delegate.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 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 (120 lines) | stat: -rw-r--r-- 4,885 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
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
// Copyright 2025 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_SAFE_BROWSING_DOWNLOAD_PROTECTION_DOWNLOAD_PROTECTION_DELEGATE_H_
#define CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_DOWNLOAD_PROTECTION_DELEGATE_H_

#include <memory>
#include <vector>

#include "chrome/browser/safe_browsing/download_protection/download_protection_util.h"
#include "net/traffic_annotation/network_traffic_annotation.h"

class GURL;
class Profile;

namespace base {
class FilePath;
}

namespace content {
struct FileSystemAccessWriteItem;
}

namespace download {
class DownloadItem;
}

namespace network {
struct ResourceRequest;
}

namespace safe_browsing {

class ClientDownloadRequest;

// Interface providing platform-specific logic for Download Protection, used
// with DownloadProtectionService, CheckClientDownloadRequest, and
// DownloadRequestMaker.
class DownloadProtectionDelegate {
 public:
  // Creates the appropriate implementation instance.
  static std::unique_ptr<DownloadProtectionDelegate> CreateForPlatform();

  virtual ~DownloadProtectionDelegate() = default;

  // Returns whether the download URL should be checked based on user
  // preferences.
  virtual bool ShouldCheckDownloadUrl(download::DownloadItem* item) const = 0;

  // Returns whether the download item may be checked by CheckClientDownload().
  // This is based on user preferences, properties of the file, and potentially
  // random sampling.
  // A return value of false indicates that the delegate does not permit the
  // download to be checked.
  // A return value of true indicates that checking the download is permitted,
  // but caller may apply further logic to determine whether a check occurs.
  // TODO(chlily): Implementations of this method currently rely on the checks
  // in IsSupportedDownload. This is redundant. Refactor this logic to eliminate
  // IsSupportedDownload().
  virtual bool MayCheckClientDownload(download::DownloadItem* item) const = 0;

  // Returns whether the File System Access write may be checked by
  // CheckFileSystemAccessWrite().
  virtual bool MayCheckFileSystemAccessWrite(
      content::FileSystemAccessWriteItem* item) const = 0;

  // Returns enum value indicating whether the download item may be checked by
  // CheckClientDownload() based on whether the file supports the check.
  // TODO(chlily): Remove this method. The only place where it is called seems
  // to be vestigial, and does not affect whether CheckClientDownload ultimately
  // happens.
  virtual MayCheckDownloadResult IsSupportedDownload(
      download::DownloadItem& item,
      const base::FilePath& target_path) const = 0;

  // Called after the ClientDownloadRequest has been constructed, prior to
  // serializing the ClientDownloadRequest into a string to send in the POST
  // request body of the network request. Allows the delegate to request final
  // modifications to apply to the request, in the form of a vector of callbacks
  // to invoke, each of which will yield a modification to be made to
  // ClientDownloadRequest.
  //
  // `item` is the download this pertains to, which may be null, e.g. if this
  // request is not for a download. `profile` is the Profile associated with the
  // underlying item being checked (a DownloadItem or
  // FileSystemAccessWriteItem).
  virtual std::vector<PendingClientDownloadRequestModification>
  ProduceClientDownloadRequestModifications(const download::DownloadItem* item,
                                            Profile* profile);

  // Called immediately prior to consuming the ResourceRequest used to send out
  // a download ping. Allows the delegate to make final modifications to the
  // ResourceRequest. The delegate must add the appropriate Content-Type HTTP
  // header in this method.
  virtual void FinalizeResourceRequest(
      network::ResourceRequest& resource_request) = 0;

  // Returns the URL that will be contacted for download protection requests.
  virtual const GURL& GetDownloadRequestUrl() const = 0;

  // Sampling rate for when an allowlisted download may generate a sampled ping,
  // if other requirements are met.
  virtual float GetAllowlistedDownloadSampleRate() const = 0;

  // Sampling rate for when an unsupported download may generate a sampled ping,
  // if other requirements are met.
  virtual float GetUnsupportedFileSampleRate(
      const base::FilePath& filename) const = 0;

  // Completes the network traffic annotation for CheckClientDownloadRequest.
  virtual net::NetworkTrafficAnnotationTag
  CompleteClientDownloadRequestTrafficAnnotation(
      const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation)
      const = 0;
};

}  // namespace safe_browsing

#endif  // CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_DOWNLOAD_PROTECTION_DELEGATE_H_