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/common/api/file_system.h" |
| 17 #include "ui/shell_dialogs/select_file_dialog.h" |
| 18 |
| 19 #if defined(OS_CHROMEOS) |
| 20 class UIThreadExtensionFunction; |
| 21 #endif |
| 22 |
| 23 namespace base { |
| 24 class FilePath; |
| 25 } // namespace base |
| 26 |
| 27 namespace content { |
| 28 class BrowserContext; |
| 29 class RenderFrameHost; |
| 30 class WebContents; |
| 31 } // namespace content |
| 32 |
| 33 namespace ui { |
| 34 class SelectFilePolicy; |
| 35 } // namespace ui |
| 36 |
| 37 namespace extensions { |
| 38 |
| 39 class Extension; |
| 40 class SavedFilesServiceInterface; |
| 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 SavedFilesServiceInterface* GetSavedFilesService( |
| 109 content::BrowserContext* browser_context) = 0; |
| 110 }; |
| 111 |
| 112 } // namespace extensions |
| 113 |
| 114 #endif // EXTENSIONS_BROWSER_API_FILE_SYSTEM_FILE_SYSTEM_DELEGATE_H_ |
OLD | NEW |