OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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 EXTENSIONS_BROWSER_API_FILE_SYSTEM_FILE_SYSTEM_DELEGATE_H_ | |
6 #define EXTENSIONS_BROWSER_API_FILE_SYSTEM_FILE_SYSTEM_DELEGATE_H_ | |
7 | |
8 #include <memory> | |
9 #include <string> | |
10 #include <vector> | |
11 | |
12 #include "base/callback_forward.h" | |
13 #include "base/macros.h" | |
14 #include "base/memory/ref_counted.h" | |
15 #include "build/build_config.h" | |
16 #include "extensions/browser/api/file_system/saved_files_service_interface.h" | |
17 #include "extensions/common/api/file_system.h" | |
18 #include "ui/shell_dialogs/select_file_dialog.h" | |
19 | |
20 #if defined(OS_CHROMEOS) | |
21 class UIThreadExtensionFunction; | |
22 #endif | |
23 | |
24 namespace base { | |
25 class FilePath; | |
26 } // namespace base | |
27 | |
28 namespace content { | |
29 class BrowserContext; | |
30 class RenderFrameHost; | |
31 class WebContents; | |
32 } // namespace content | |
33 | |
34 namespace ui { | |
35 class SelectFilePolicy; | |
36 } // namespace ui | |
37 | |
38 namespace extensions { | |
39 | |
40 class Extension; | |
41 | |
42 // Delegate class for embedder-specific file system access. | |
43 class FileSystemDelegate { | |
44 public: | |
45 using ErrorCallback = base::Callback<void(const std::string&)>; | |
46 using FileSystemCallback = | |
47 base::Callback<void(const std::string& id, const std::string& path)>; | |
48 using VolumeListCallback = | |
49 base::Callback<void(const std::vector<api::file_system::Volume>&)>; | |
50 | |
51 virtual ~FileSystemDelegate() {} | |
52 | |
53 virtual base::FilePath GetDefaultDirectory() = 0; | |
54 | |
55 // Returns a new SelectFilePolicy for whether a file dialog can be shown. | |
56 virtual std::unique_ptr<ui::SelectFilePolicy> CreateSelectFilePolicy( | |
57 content::WebContents* web_contents) = 0; | |
58 | |
59 // Creates a dialog for selecting files. | |
60 virtual scoped_refptr<ui::SelectFileDialog> CreateSelectFileDialog( | |
61 ui::SelectFileDialog::Listener* listener, | |
62 std::unique_ptr<ui::SelectFilePolicy> policy) = 0; | |
63 | |
64 // Shows |dialog| to prompt the user to select files/directories. | |
65 virtual void ShowSelectFileDialogForWebContents( | |
66 scoped_refptr<ui::SelectFileDialog> dialog, | |
67 content::WebContents* web_contents, | |
68 ui::SelectFileDialog::Type type, | |
69 const base::FilePath& default_path, | |
70 const ui::SelectFileDialog::FileTypeInfo* file_types) = 0; | |
71 | |
72 // Confirms (e.g. with a dialog) whether the user wants to open the directory | |
73 // for a given app. | |
74 virtual void ConfirmSensitiveDirectoryAccess( | |
75 bool has_write_permission, | |
76 const base::string16& app_name, | |
77 content::WebContents* web_contents, | |
78 const base::Closure& on_accept, | |
79 const base::Closure& on_cancel) = 0; | |
80 | |
81 // Finds a string describing the accept type. Returns 0 if no applicable | |
82 // string ID is found. | |
83 virtual int GetDescriptionIdForAcceptType(const std::string& accept_type) = 0; | |
84 | |
85 #if defined(OS_CHROMEOS) | |
86 // Checks whether the extension can be granted access. | |
87 virtual bool IsGrantable(content::BrowserContext* browser_context, | |
88 content::RenderFrameHost* render_frame_host, | |
89 const Extension& extension) = 0; | |
90 | |
91 // Grants or denies an extension's request for access to the named file | |
92 // system. May prompt the user for consent. | |
93 virtual void RequestFileSystem( | |
94 content::BrowserContext* browser_context, | |
95 scoped_refptr<UIThreadExtensionFunction> requester, | |
96 const Extension& extension, | |
97 std::string volume_id, | |
98 bool writable, | |
99 const FileSystemCallback& success_callback, | |
100 const ErrorCallback& error_callback) = 0; | |
101 | |
102 // Immediately calls VolumeListCallback or ErrorCallback. | |
103 virtual void GetVolumeList(content::BrowserContext* browser_context, | |
104 const VolumeListCallback& success_callback, | |
105 const ErrorCallback& error_callback) = 0; | |
106 #endif | |
107 | |
108 virtual std::unique_ptr<SavedFilesServiceInterface> | |
109 CreateSavedFilesServiceInterface( | |
michaelpg
2017/06/23 21:30:53
benwells: Awkward choice between calling this "Cre
benwells
2017/06/26 02:28:15
I'd go with CreateFoo. The underlying implementati
michaelpg
2017/06/26 15:36:33
Yeah, that's better. Done.
| |
110 content::BrowserContext* browser_context) = 0; | |
111 }; | |
112 | |
113 } // namespace extensions | |
114 | |
115 #endif // EXTENSIONS_BROWSER_API_FILE_SYSTEM_FILE_SYSTEM_DELEGATE_H_ | |
OLD | NEW |