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 // FileSystemDelegate: |
41 class DelegateInterface { | 40 base::FilePath GetDefaultDirectory() override; |
42 public: | 41 std::unique_ptr<ui::SelectFilePolicy> CreateSelectFilePolicy( |
43 // Shows a dialog for granting permissions. | 42 content::WebContents* web_contents) override; |
44 virtual void ShowDialog(const Extension& extension, | 43 scoped_refptr<ui::SelectFileDialog> CreateSelectFileDialog( |
45 const base::WeakPtr<file_manager::Volume>& volume, | 44 ui::SelectFileDialog::Listener* listener, |
46 bool writable, | 45 std::unique_ptr<ui::SelectFilePolicy> policy) override; |
47 const ShowDialogCallback& callback) = 0; | 46 void ShowSelectFileDialogForWebContents( |
48 | 47 scoped_refptr<ui::SelectFileDialog> dialog, |
49 // Shows a notification about permissions automatically granted access. | 48 content::WebContents* web_contents, |
50 virtual void ShowNotification( | 49 ui::SelectFileDialog::Type type, |
51 const Extension& extension, | 50 const base::FilePath& default_path, |
52 const base::WeakPtr<file_manager::Volume>& volume, | 51 const ui::SelectFileDialog::FileTypeInfo* file_types) override; |
53 bool writable) = 0; | 52 void ConfirmSensitiveDirectoryAccess(bool has_write_permission, |
54 | 53 const base::string16& app_name, |
55 // Checks if the extension was launched in auto-launch kiosk mode. | 54 content::WebContents* web_contents, |
56 virtual bool IsAutoLaunched(const Extension& extension) = 0; | 55 const base::Closure& on_accept, |
57 | 56 const base::Closure& on_cancel) override; |
58 // Checks if the extension is a whitelisted component extension or app. | 57 bool GetDescriptionIdForAcceptType(const std::string& accept_type, |
59 virtual bool IsWhitelistedComponent(const Extension& extension) = 0; | 58 int* description_id) override; |
60 }; | 59 #if defined(OS_CHROMEOS) |
61 | 60 bool IsGrantable(content::BrowserContext* browser_context, |
62 explicit ConsentProvider(DelegateInterface* delegate); | 61 content::RenderFrameHost* render_frame_host, |
63 ~ConsentProvider(); | 62 const Extension& extension) override; |
64 | 63 void RequestFileSystem(content::BrowserContext* browser_context, |
65 // Requests consent for granting |writable| permissions to the |volume| | 64 scoped_refptr<UIThreadExtensionFunction> requester, |
66 // volume by the |extension|. Must be called only if the extension is | 65 const Extension& extension, |
67 // grantable, which can be checked with IsGrantable(). | 66 std::string volume_id, |
68 void RequestConsent(const Extension& extension, | 67 bool writable, |
69 const base::WeakPtr<file_manager::Volume>& volume, | 68 const FileSystemCallback& success_callback, |
70 bool writable, | 69 const ErrorCallback& error_callback) override; |
71 const ConsentCallback& callback); | 70 void GetVolumeList(content::BrowserContext* browser_context, |
72 | 71 const VolumeListCallback& success_callback, |
73 // Checks whether the |extension| can be granted access. | 72 const ErrorCallback& error_callback) override; |
74 bool IsGrantable(const Extension& extension); | 73 #endif // defined(OS_CHROMEOS) |
| 74 std::unique_ptr<file_system_api::SavedFilesServiceDelegate> |
| 75 CreateSavedFilesServiceDelegate( |
| 76 content::BrowserContext* browser_context) override; |
75 | 77 |
76 private: | 78 private: |
77 DelegateInterface* const delegate_; | 79 #if defined(OS_CHROMEOS) |
| 80 void OnConsentReceived(content::BrowserContext* browser_context, |
| 81 scoped_refptr<UIThreadExtensionFunction> requester, |
| 82 const FileSystemCallback& success_callback, |
| 83 const ErrorCallback& error_callback, |
| 84 const std::string& extension, |
| 85 const base::WeakPtr<file_manager::Volume>& volume, |
| 86 bool writable, |
| 87 file_system_api::ConsentProvider::Consent result); |
| 88 #endif // defined(OS_CHROMEOS) |
78 | 89 |
79 DISALLOW_COPY_AND_ASSIGN(ConsentProvider); | 90 DISALLOW_COPY_AND_ASSIGN(ChromeFileSystemDelegate); |
80 }; | 91 }; |
81 | 92 |
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 | 93 } // namespace extensions |
116 | 94 |
117 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_CONSENT_PROVIDER_H_ | 95 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_CHROME_FILE_SYSTEM_DELEGATE
_H_ |
OLD | NEW |