Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: extensions/browser/api/file_system/file_system_delegate.h

Issue 2934143002: Move chrome.fileSystem implementation to //extensions (Closed)
Patch Set: rebase Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_ENTRY_PICKER_H_ 5 #ifndef EXTENSIONS_BROWSER_API_FILE_SYSTEM_FILE_SYSTEM_DELEGATE_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_ENTRY_PICKER_H_ 6 #define EXTENSIONS_BROWSER_API_FILE_SYSTEM_FILE_SYSTEM_DELEGATE_H_
7 7
8 #include <memory>
9 #include <string>
8 #include <vector> 10 #include <vector>
9 11
10 #include "base/callback.h" 12 #include "base/callback_forward.h"
13 #include "base/macros.h"
11 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "build/build_config.h"
16 #include "extensions/common/api/file_system.h"
12 #include "ui/shell_dialogs/select_file_dialog.h" 17 #include "ui/shell_dialogs/select_file_dialog.h"
13 18
19 class UIThreadExtensionFunction;
20
14 namespace base { 21 namespace base {
15 class FilePath; 22 class FilePath;
16 } // namespace base 23 } // namespace base
17 24
18 namespace content { 25 namespace content {
26 class BrowserContext;
27 class RenderFrameHost;
19 class WebContents; 28 class WebContents;
20 } // namespace content 29 } // namespace content
21 30
22 namespace extensions { 31 namespace extensions {
23 32
24 // Shows a dialog to the user to ask for the filename for a file to save or 33 class Extension;
25 // open. Deletes itself once the dialog is closed. 34 class SavedFilesServiceInterface;
26 class FileEntryPicker : public ui::SelectFileDialog::Listener { 35
36 // Delegate class for embedder-specific file system access.
37 class FileSystemDelegate {
27 public: 38 public:
39 using ErrorCallback = base::Callback<void(const std::string&)>;
40 using FileSystemCallback =
41 base::Callback<void(const std::string& id, const std::string& path)>;
28 using FilesSelectedCallback = 42 using FilesSelectedCallback =
29 base::OnceCallback<void(const std::vector<base::FilePath>& paths)>; 43 base::OnceCallback<void(const std::vector<base::FilePath>& paths)>;
44 using VolumeListCallback =
45 base::Callback<void(const std::vector<api::file_system::Volume>&)>;
30 46
31 // Creates a file picker. After the user picks file(s) or cancels, the 47 virtual ~FileSystemDelegate() {}
32 // relevant callback is called and this object deletes itself.
33 // The dialog is modal to the |web_contents|'s window.
34 // See SelectFileDialog::SelectFile for the other parameters.
35 FileEntryPicker(content::WebContents* web_contents,
36 const base::FilePath& suggested_name,
37 const ui::SelectFileDialog::FileTypeInfo& file_type_info,
38 ui::SelectFileDialog::Type picker_type,
39 FilesSelectedCallback files_selected_callback,
40 base::OnceClosure file_selection_canceled_callback);
41 48
42 private: 49 virtual base::FilePath GetDefaultDirectory() = 0;
43 ~FileEntryPicker() override; // FileEntryPicker deletes itself.
44 50
45 // ui::SelectFileDialog::Listener implementation. 51 // Shows a dialog to prompt the user to select files/directories. Returns
46 void FileSelected(const base::FilePath& path, 52 // false if the dialog cannot be shown, i.e. there is no valid WebContents.
47 int index, 53 virtual bool ShowSelectFileDialog(
48 void* params) override; 54 scoped_refptr<UIThreadExtensionFunction> extension_function,
49 void FileSelectedWithExtraInfo(const ui::SelectedFileInfo& file, 55 ui::SelectFileDialog::Type type,
50 int index, 56 const base::FilePath& default_path,
51 void* params) override; 57 const ui::SelectFileDialog::FileTypeInfo* file_types,
52 void MultiFilesSelected(const std::vector<base::FilePath>& files, 58 FileSystemDelegate::FilesSelectedCallback files_selected_callback,
53 void* params) override; 59 base::OnceClosure file_selection_canceled_callback) = 0;
54 void MultiFilesSelectedWithExtraInfo(
55 const std::vector<ui::SelectedFileInfo>& files,
56 void* params) override;
57 void FileSelectionCanceled(void* params) override;
58 60
59 FilesSelectedCallback files_selected_callback_; 61 // Confirms (e.g. with a dialog) whether the user wants to open the directory
60 base::OnceClosure file_selection_canceled_callback_; 62 // for a given app.
61 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; 63 virtual void ConfirmSensitiveDirectoryAccess(
64 bool has_write_permission,
65 const base::string16& app_name,
66 content::WebContents* web_contents,
67 const base::Closure& on_accept,
68 const base::Closure& on_cancel) = 0;
62 69
63 DISALLOW_COPY_AND_ASSIGN(FileEntryPicker); 70 // Finds a string describing the accept type. Returns 0 if no applicable
71 // string ID is found.
72 virtual int GetDescriptionIdForAcceptType(const std::string& accept_type) = 0;
73
74 #if defined(OS_CHROMEOS)
75 // Checks whether the extension can be granted access.
76 virtual bool IsGrantable(content::BrowserContext* browser_context,
77 content::RenderFrameHost* render_frame_host,
78 const Extension& extension) = 0;
79
80 // Grants or denies an extension's request for access to the named file
81 // system. May prompt the user for consent.
82 virtual void RequestFileSystem(
83 content::BrowserContext* browser_context,
84 scoped_refptr<UIThreadExtensionFunction> requester,
85 const Extension& extension,
86 std::string volume_id,
87 bool writable,
88 const FileSystemCallback& success_callback,
89 const ErrorCallback& error_callback) = 0;
90
91 // Immediately calls VolumeListCallback or ErrorCallback.
92 virtual void GetVolumeList(content::BrowserContext* browser_context,
93 const VolumeListCallback& success_callback,
94 const ErrorCallback& error_callback) = 0;
95 #endif
96
97 virtual SavedFilesServiceInterface* GetSavedFilesService(
98 content::BrowserContext* browser_context) = 0;
64 }; 99 };
65 100
66 } // namespace extensions 101 } // namespace extensions
67 102
68 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_ENTRY_PICKER_H_ 103 #endif // EXTENSIONS_BROWSER_API_FILE_SYSTEM_FILE_SYSTEM_DELEGATE_H_
OLDNEW
« no previous file with comments | « extensions/browser/api/file_system/file_system_api.cc ('k') | extensions/common/api/file_system.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698