| OLD | NEW |
| 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_CONSENT_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_CHROME_FILE_SYSTEM_DELEGATE_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_CONSENT_PROVIDER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_CHROME_FILE_SYSTEM_DELEGATE_H_ |
| 7 | 7 |
| 8 #include "base/callback_forward.h" | 8 #include "extensions/browser/api/file_system/file_system_delegate.h" |
| 9 |
| 9 #include "base/macros.h" | 10 #include "base/macros.h" |
| 10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 11 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 12 #include "ui/base/ui_base_types.h" | |
| 13 | 13 |
| 14 class Profile; | 14 #if defined(OS_CHROMEOS) |
| 15 | 15 #include "chrome/browser/extensions/api/file_system/consent_provider.h" |
| 16 namespace content { | 16 #endif |
| 17 class RenderFrameHost; | |
| 18 } // content | |
| 19 | 17 |
| 20 namespace file_manager { | 18 namespace file_manager { |
| 21 class Volume; | 19 class Volume; |
| 22 } // namespace file_manager | 20 } |
| 23 | 21 |
| 24 namespace extensions { | 22 namespace extensions { |
| 25 class Extension; | |
| 26 class ScopedSkipRequestFileSystemDialog; | |
| 27 | 23 |
| 24 #if defined(OS_CHROMEOS) |
| 28 namespace file_system_api { | 25 namespace file_system_api { |
| 29 | 26 |
| 30 // Requests consent for the chrome.fileSystem.requestFileSystem() method. | 27 // Dispatches an event about a mounted or unmounted volume in the system to |
| 31 // Interaction with UI and environmental checks (kiosk mode, whitelist) are | 28 // each extension which can request it. |
| 32 // provided by a delegate: ConsentProviderDelegate. For testing, it is | 29 void DispatchVolumeListChangeEvent(content::BrowserContext* browser_context); |
| 33 // TestingConsentProviderDelegate. | 30 |
| 34 class ConsentProvider { | 31 } // namespace file_system_api |
| 32 #endif // defined(OS_CHROMEOS) |
| 33 |
| 34 class ChromeFileSystemDelegate : public FileSystemDelegate { |
| 35 public: | 35 public: |
| 36 enum Consent { CONSENT_GRANTED, CONSENT_REJECTED, CONSENT_IMPOSSIBLE }; | 36 ChromeFileSystemDelegate(); |
| 37 typedef base::Callback<void(Consent)> ConsentCallback; | 37 ~ChromeFileSystemDelegate() override; |
| 38 typedef base::Callback<void(ui::DialogButton)> ShowDialogCallback; | |
| 39 | 38 |
| 40 // Interface for delegating user interaction for granting permissions. | 39 base::FilePath GetDefaultDirectory() override; |
| 41 class DelegateInterface { | |
| 42 public: | |
| 43 // Shows a dialog for granting permissions. | |
| 44 virtual void ShowDialog(const Extension& extension, | |
| 45 const base::WeakPtr<file_manager::Volume>& volume, | |
| 46 bool writable, | |
| 47 const ShowDialogCallback& callback) = 0; | |
| 48 | 40 |
| 49 // Shows a notification about permissions automatically granted access. | 41 std::unique_ptr<ui::SelectFilePolicy> CreateSelectFilePolicy( |
| 50 virtual void ShowNotification( | 42 content::WebContents* web_contents) override; |
| 51 const Extension& extension, | |
| 52 const base::WeakPtr<file_manager::Volume>& volume, | |
| 53 bool writable) = 0; | |
| 54 | 43 |
| 55 // Checks if the extension was launched in auto-launch kiosk mode. | 44 scoped_refptr<ui::SelectFileDialog> CreateSelectFileDialog( |
| 56 virtual bool IsAutoLaunched(const Extension& extension) = 0; | 45 ui::SelectFileDialog::Listener* listener, |
| 46 std::unique_ptr<ui::SelectFilePolicy> policy) override; |
| 57 | 47 |
| 58 // Checks if the extension is a whitelisted component extension or app. | 48 void ShowSelectFileDialogForWebContents( |
| 59 virtual bool IsWhitelistedComponent(const Extension& extension) = 0; | 49 scoped_refptr<ui::SelectFileDialog> dialog, |
| 60 }; | 50 content::WebContents* web_contents, |
| 51 ui::SelectFileDialog::Type type, |
| 52 const base::FilePath& default_path, |
| 53 const ui::SelectFileDialog::FileTypeInfo* file_types) override; |
| 61 | 54 |
| 62 explicit ConsentProvider(DelegateInterface* delegate); | 55 void ConfirmSensitiveDirectoryAccess(bool writable, |
| 63 ~ConsentProvider(); | 56 const base::string16& app_name, |
| 57 content::WebContents* web_contents, |
| 58 const base::Closure& on_accept, |
| 59 const base::Closure& on_cancel) override; |
| 64 | 60 |
| 65 // Requests consent for granting |writable| permissions to the |volume| | 61 // Finds a string describing the accept type. On success, returns true and |
| 66 // volume by the |extension|. Must be called only if the extension is | 62 // populates |description_id|. |
| 67 // grantable, which can be checked with IsGrantable(). | 63 bool GetDescriptionIdForAcceptType(const std::string& accept_type, |
| 68 void RequestConsent(const Extension& extension, | 64 int* description_id) override; |
| 69 const base::WeakPtr<file_manager::Volume>& volume, | |
| 70 bool writable, | |
| 71 const ConsentCallback& callback); | |
| 72 | 65 |
| 73 // Checks whether the |extension| can be granted access. | 66 #if defined(OS_CHROMEOS) |
| 74 bool IsGrantable(const Extension& extension); | 67 bool IsGrantable(content::BrowserContext* browser_context, |
| 68 content::RenderFrameHost* render_frame_host, |
| 69 const Extension& extension) override; |
| 70 |
| 71 // Grants or denies an extension's request for access to the named file |
| 72 // system. May prompt the user for consent. |
| 73 void RequestFileSystem(content::BrowserContext* browser_context, |
| 74 scoped_refptr<UIThreadExtensionFunction> requester, |
| 75 const Extension& extension, |
| 76 std::string volume_id, |
| 77 bool writable, |
| 78 const FileSystemCallback& success_callback, |
| 79 const ErrorCallback& error_callback) override; |
| 80 |
| 81 // Immediately calls VolumeListCallback or ErrorCallback. |
| 82 void GetVolumeList(content::BrowserContext* browser_context, |
| 83 const VolumeListCallback& success_callback, |
| 84 const ErrorCallback& error_callback) override; |
| 85 #endif // defined(OS_CHROMEOS) |
| 86 |
| 87 std::unique_ptr<file_system_api::SavedFilesServiceDelegate> |
| 88 CreateSavedFilesServiceDelegate( |
| 89 content::BrowserContext* browser_context) override; |
| 75 | 90 |
| 76 private: | 91 private: |
| 77 DelegateInterface* const delegate_; | 92 #if defined(OS_CHROMEOS) |
| 93 void OnConsentReceived(content::BrowserContext* browser_context, |
| 94 scoped_refptr<UIThreadExtensionFunction> requester, |
| 95 const FileSystemCallback& success_callback, |
| 96 const ErrorCallback& error_callback, |
| 97 const std::string& extension, |
| 98 const base::WeakPtr<file_manager::Volume>& volume, |
| 99 bool writable, |
| 100 file_system_api::ConsentProvider::Consent result); |
| 101 #endif // defined(OS_CHROMEOS) |
| 78 | 102 |
| 79 DISALLOW_COPY_AND_ASSIGN(ConsentProvider); | 103 DISALLOW_COPY_AND_ASSIGN(ChromeFileSystemDelegate); |
| 80 }; | 104 }; |
| 81 | 105 |
| 82 // Handles interaction with user as well as environment checks (whitelists, | |
| 83 // context of running extensions) for ConsentProvider. | |
| 84 class ConsentProviderDelegate : public ConsentProvider::DelegateInterface { | |
| 85 public: | |
| 86 ConsentProviderDelegate(Profile* profile, content::RenderFrameHost* host); | |
| 87 ~ConsentProviderDelegate(); | |
| 88 | |
| 89 private: | |
| 90 friend ScopedSkipRequestFileSystemDialog; | |
| 91 | |
| 92 // Sets a fake result for the user consent dialog. If ui::DIALOG_BUTTON_NONE | |
| 93 // then disabled. | |
| 94 static void SetAutoDialogButtonForTest(ui::DialogButton button); | |
| 95 | |
| 96 // ConsentProvider::DelegateInterface overrides: | |
| 97 void ShowDialog(const Extension& extension, | |
| 98 const base::WeakPtr<file_manager::Volume>& volume, | |
| 99 bool writable, | |
| 100 const file_system_api::ConsentProvider::ShowDialogCallback& | |
| 101 callback) override; | |
| 102 void ShowNotification(const Extension& extension, | |
| 103 const base::WeakPtr<file_manager::Volume>& volume, | |
| 104 bool writable) override; | |
| 105 bool IsAutoLaunched(const Extension& extension) override; | |
| 106 bool IsWhitelistedComponent(const Extension& extension) override; | |
| 107 | |
| 108 Profile* const profile_; | |
| 109 content::RenderFrameHost* const host_; | |
| 110 | |
| 111 DISALLOW_COPY_AND_ASSIGN(ConsentProviderDelegate); | |
| 112 }; | |
| 113 | |
| 114 } // namespace file_system_api | |
| 115 } // namespace extensions | 106 } // namespace extensions |
| 116 | 107 |
| 117 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_CONSENT_PROVIDER_H_ | 108 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_CHROME_FILE_SYSTEM_DELEGATE
_H_ |
| OLD | NEW |