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

Side by Side Diff: chrome/browser/extensions/api/file_system/file_system_api.h

Issue 2924943003: Break ConsentProvider classes into own file (Closed)
Patch Set: rebase Created 3 years, 6 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_SYSTEM_API_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/files/file.h" 12 #include "base/files/file.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "chrome/browser/extensions/chrome_extension_function.h" 18 #include "chrome/browser/extensions/chrome_extension_function.h"
19 #include "chrome/browser/extensions/chrome_extension_function_details.h" 19 #include "chrome/browser/extensions/chrome_extension_function_details.h"
20 #include "chrome/common/extensions/api/file_system.h" 20 #include "chrome/common/extensions/api/file_system.h"
21 #include "extensions/browser/extension_function.h" 21 #include "extensions/browser/extension_function.h"
22 #include "ui/base/ui_base_types.h"
23 #include "ui/shell_dialogs/select_file_dialog.h" 22 #include "ui/shell_dialogs/select_file_dialog.h"
24 23
25 #if defined(OS_CHROMEOS) 24 #if defined(OS_CHROMEOS)
26 namespace file_manager { 25 #include "chrome/browser/extensions/api/file_system/consent_provider.h"
27 class Volume;
28 } // namespace file_manager
29 #endif 26 #endif
30 27
31 namespace extensions { 28 namespace extensions {
32 class ExtensionPrefs; 29 class ExtensionPrefs;
33 class ScopedSkipRequestFileSystemDialog;
34 30
35 namespace file_system_api { 31 namespace file_system_api {
36 32
37 // Methods to get and set the path of the directory containing the last file 33 // Methods to get and set the path of the directory containing the last file
38 // chosen by the user in response to a chrome.fileSystem.chooseEntry() call for 34 // chosen by the user in response to a chrome.fileSystem.chooseEntry() call for
39 // the given extension. 35 // the given extension.
40 36
41 // Returns an empty path on failure. 37 // Returns an empty path on failure.
42 base::FilePath GetLastChooseEntryDirectory(const ExtensionPrefs* prefs, 38 base::FilePath GetLastChooseEntryDirectory(const ExtensionPrefs* prefs,
43 const std::string& extension_id); 39 const std::string& extension_id);
44 40
45 void SetLastChooseEntryDirectory(ExtensionPrefs* prefs, 41 void SetLastChooseEntryDirectory(ExtensionPrefs* prefs,
46 const std::string& extension_id, 42 const std::string& extension_id,
47 const base::FilePath& path); 43 const base::FilePath& path);
48 44
49 #if defined(OS_CHROMEOS) 45 #if defined(OS_CHROMEOS)
50 // Dispatches an event about a mounted on unmounted volume in the system to 46 // Dispatches an event about a mounted on unmounted volume in the system to
51 // each extension which can request it. 47 // each extension which can request it.
52 void DispatchVolumeListChangeEvent(Profile* profile); 48 void DispatchVolumeListChangeEvent(Profile* profile);
53
54 // Requests consent for the chrome.fileSystem.requestFileSystem() method.
55 // Interaction with UI and environmental checks (kiosk mode, whitelist) are
56 // provided by a delegate: ConsentProviderDelegate. For testing, it is
57 // TestingConsentProviderDelegate.
58 class ConsentProvider {
59 public:
60 enum Consent { CONSENT_GRANTED, CONSENT_REJECTED, CONSENT_IMPOSSIBLE };
61 typedef base::Callback<void(Consent)> ConsentCallback;
62 typedef base::Callback<void(ui::DialogButton)> ShowDialogCallback;
63
64 // Interface for delegating user interaction for granting permissions.
65 class DelegateInterface {
66 public:
67 // Shows a dialog for granting permissions.
68 virtual void ShowDialog(const Extension& extension,
69 const base::WeakPtr<file_manager::Volume>& volume,
70 bool writable,
71 const ShowDialogCallback& callback) = 0;
72
73 // Shows a notification about permissions automatically granted access.
74 virtual void ShowNotification(
75 const Extension& extension,
76 const base::WeakPtr<file_manager::Volume>& volume,
77 bool writable) = 0;
78
79 // Checks if the extension was launched in auto-launch kiosk mode.
80 virtual bool IsAutoLaunched(const Extension& extension) = 0;
81
82 // Checks if the extension is a whitelisted component extension or app.
83 virtual bool IsWhitelistedComponent(const Extension& extension) = 0;
84 };
85
86 explicit ConsentProvider(DelegateInterface* delegate);
87 ~ConsentProvider();
88
89 // Requests consent for granting |writable| permissions to the |volume|
90 // volume by the |extension|. Must be called only if the extension is
91 // grantable, which can be checked with IsGrantable().
92 void RequestConsent(const Extension& extension,
93 const base::WeakPtr<file_manager::Volume>& volume,
94 bool writable,
95 const ConsentCallback& callback);
96
97 // Checks whether the |extension| can be granted access.
98 bool IsGrantable(const Extension& extension);
99
100 private:
101 DelegateInterface* const delegate_;
102
103 DISALLOW_COPY_AND_ASSIGN(ConsentProvider);
104 };
105
106 // Handles interaction with user as well as environment checks (whitelists,
107 // context of running extensions) for ConsentProvider.
108 class ConsentProviderDelegate : public ConsentProvider::DelegateInterface {
109 public:
110 ConsentProviderDelegate(Profile* profile, content::RenderFrameHost* host);
111 ~ConsentProviderDelegate();
112
113 private:
114 friend ScopedSkipRequestFileSystemDialog;
115
116 // Sets a fake result for the user consent dialog. If ui::DIALOG_BUTTON_NONE
117 // then disabled.
118 static void SetAutoDialogButtonForTest(ui::DialogButton button);
119
120 // ConsentProvider::DelegateInterface overrides:
121 void ShowDialog(const Extension& extension,
122 const base::WeakPtr<file_manager::Volume>& volume,
123 bool writable,
124 const file_system_api::ConsentProvider::ShowDialogCallback&
125 callback) override;
126 void ShowNotification(const Extension& extension,
127 const base::WeakPtr<file_manager::Volume>& volume,
128 bool writable) override;
129 bool IsAutoLaunched(const Extension& extension) override;
130 bool IsWhitelistedComponent(const Extension& extension) override;
131
132 Profile* const profile_;
133 content::RenderFrameHost* const host_;
134
135 DISALLOW_COPY_AND_ASSIGN(ConsentProviderDelegate);
136 };
137 #endif 49 #endif
138 50
139 } // namespace file_system_api 51 } // namespace file_system_api
140 52
141 class FileSystemGetDisplayPathFunction : public UIThreadExtensionFunction { 53 class FileSystemGetDisplayPathFunction : public UIThreadExtensionFunction {
142 public: 54 public:
143 DECLARE_EXTENSION_FUNCTION("fileSystem.getDisplayPath", 55 DECLARE_EXTENSION_FUNCTION("fileSystem.getDisplayPath",
144 FILESYSTEM_GETDISPLAYPATH) 56 FILESYSTEM_GETDISPLAYPATH)
145 57
146 protected: 58 protected:
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 ExtensionFunction::ResponseAction Run() override; 318 ExtensionFunction::ResponseAction Run() override;
407 319
408 private: 320 private:
409 ChromeExtensionFunctionDetails chrome_details_; 321 ChromeExtensionFunctionDetails chrome_details_;
410 }; 322 };
411 #endif 323 #endif
412 324
413 } // namespace extensions 325 } // namespace extensions
414 326
415 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ 327 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698