1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CONTENT_PUBLIC_BROWSER_NATIVE_FILE_SYSTEM_WRITE_ITEM_H_
6 #define CONTENT_PUBLIC_BROWSER_NATIVE_FILE_SYSTEM_WRITE_ITEM_H_
7 
8 #include <cstdint>
9 #include <string>
10 
11 #include "base/files/file_path.h"
12 #include "content/common/content_export.h"
13 #include "url/gurl.h"
14 #include "url/origin.h"
15 
16 namespace content {
17 class BrowserContext;
18 class WebContents;
19 
20 // Represents the state of a NativeFileSystemFileWriter when it is closed,
21 // containing all the data necessary to do a safe browsing download protection
22 // check on the data written to disk.
23 struct CONTENT_EXPORT NativeFileSystemWriteItem {
24   NativeFileSystemWriteItem();
25   ~NativeFileSystemWriteItem();
26   NativeFileSystemWriteItem(const NativeFileSystemWriteItem&) = delete;
27   NativeFileSystemWriteItem& operator=(const NativeFileSystemWriteItem&) =
28       delete;
29 
30   // The path on disk where the data will eventually end up.
31   base::FilePath target_file_path;
32   // The path on disk where the data was written to. If the safe browsing check
33   // completes the file at |full_path| will be moved to |target_file_path|.
34   base::FilePath full_path;
35   // SHA256 hash of the file contents.
36   std::string sha256_hash;
37   // Size of the file in bytes.
38   int64_t size = 0;
39 
40   // URL of the frame in which the write operation took place.
41   GURL frame_url;
42   // True iff the frame had a transient user activation when the writer was
43   // created.
44   bool has_user_gesture = false;
45 
46   // BrowserContext and WebContents the writer is associated with. These fields
47   // can be nullptr when calling
48   // NativeFileSystemPermissionContext::PerformSafeBrowsingChecks(), in which
49   // case they will be filled by that method.
50   WebContents* web_contents = nullptr;
51   BrowserContext* browser_context = nullptr;
52 };
53 
54 }  // namespace content
55 
56 #endif  // CONTENT_PUBLIC_BROWSER_NATIVE_FILE_SYSTEM_WRITE_ITEM_H_
57