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

Side by Side Diff: chrome/browser/extensions/api/file_system/consent_provider.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 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_SYSTEM_API_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_CONSENT_PROVIDER_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_CONSENT_PROVIDER_H_
7 7
8 #include <memory> 8 #include "base/callback_forward.h"
9 #include <string>
10 #include <vector>
11
12 #include "base/files/file.h"
13 #include "base/files/file_path.h"
14 #include "base/macros.h" 9 #include "base/macros.h"
15 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
16 #include "base/values.h"
17 #include "build/build_config.h" 11 #include "build/build_config.h"
18 #include "chrome/browser/extensions/chrome_extension_function.h"
19 #include "chrome/browser/extensions/chrome_extension_function_details.h"
20 #include "chrome/common/extensions/api/file_system.h"
21 #include "extensions/browser/extension_function.h"
22 #include "ui/base/ui_base_types.h" 12 #include "ui/base/ui_base_types.h"
23 #include "ui/shell_dialogs/select_file_dialog.h"
24 13
25 #if defined(OS_CHROMEOS) 14 class Profile;
15
16 namespace content {
17 class RenderFrameHost;
18 } // content
19
26 namespace file_manager { 20 namespace file_manager {
27 class Volume; 21 class Volume;
28 } // namespace file_manager 22 } // namespace file_manager
29 #endif
30 23
31 namespace extensions { 24 namespace extensions {
32 class ExtensionPrefs; 25 class Extension;
33 class ScopedSkipRequestFileSystemDialog; 26 class ScopedSkipRequestFileSystemDialog;
34 27
35 namespace file_system_api { 28 namespace file_system_api {
36 29
37 // 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
39 // the given extension.
40
41 // Returns an empty path on failure.
42 base::FilePath GetLastChooseEntryDirectory(const ExtensionPrefs* prefs,
43 const std::string& extension_id);
44
45 void SetLastChooseEntryDirectory(ExtensionPrefs* prefs,
46 const std::string& extension_id,
47 const base::FilePath& path);
48
49 #if defined(OS_CHROMEOS)
50 // Dispatches an event about a mounted on unmounted volume in the system to
51 // each extension which can request it.
52 void DispatchVolumeListChangeEvent(Profile* profile);
53
54 // Requests consent for the chrome.fileSystem.requestFileSystem() method. 30 // Requests consent for the chrome.fileSystem.requestFileSystem() method.
55 // Interaction with UI and environmental checks (kiosk mode, whitelist) are 31 // Interaction with UI and environmental checks (kiosk mode, whitelist) are
56 // provided by a delegate: ConsentProviderDelegate. For testing, it is 32 // provided by a delegate: ConsentProviderDelegate. For testing, it is
57 // TestingConsentProviderDelegate. 33 // TestingConsentProviderDelegate.
58 class ConsentProvider { 34 class ConsentProvider {
59 public: 35 public:
60 enum Consent { CONSENT_GRANTED, CONSENT_REJECTED, CONSENT_IMPOSSIBLE }; 36 enum Consent { CONSENT_GRANTED, CONSENT_REJECTED, CONSENT_IMPOSSIBLE };
61 typedef base::Callback<void(Consent)> ConsentCallback; 37 typedef base::Callback<void(Consent)> ConsentCallback;
62 typedef base::Callback<void(ui::DialogButton)> ShowDialogCallback; 38 typedef base::Callback<void(ui::DialogButton)> ShowDialogCallback;
63 39
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 const base::WeakPtr<file_manager::Volume>& volume, 103 const base::WeakPtr<file_manager::Volume>& volume,
128 bool writable) override; 104 bool writable) override;
129 bool IsAutoLaunched(const Extension& extension) override; 105 bool IsAutoLaunched(const Extension& extension) override;
130 bool IsWhitelistedComponent(const Extension& extension) override; 106 bool IsWhitelistedComponent(const Extension& extension) override;
131 107
132 Profile* const profile_; 108 Profile* const profile_;
133 content::RenderFrameHost* const host_; 109 content::RenderFrameHost* const host_;
134 110
135 DISALLOW_COPY_AND_ASSIGN(ConsentProviderDelegate); 111 DISALLOW_COPY_AND_ASSIGN(ConsentProviderDelegate);
136 }; 112 };
137 #endif
138 113
139 } // namespace file_system_api 114 } // namespace file_system_api
140
141 class FileSystemGetDisplayPathFunction : public UIThreadExtensionFunction {
142 public:
143 DECLARE_EXTENSION_FUNCTION("fileSystem.getDisplayPath",
144 FILESYSTEM_GETDISPLAYPATH)
145
146 protected:
147 ~FileSystemGetDisplayPathFunction() override {}
148 ResponseAction Run() override;
149 };
150
151 class FileSystemEntryFunction : public ChromeAsyncExtensionFunction {
152 protected:
153 FileSystemEntryFunction();
154
155 ~FileSystemEntryFunction() override {}
156
157 // This is called when writable file entries are being returned. The function
158 // will ensure the files exist, creating them if necessary, and also check
159 // that none of the files are links. If it succeeds it proceeds to
160 // RegisterFileSystemsAndSendResponse, otherwise to HandleWritableFileError.
161 void PrepareFilesForWritableApp(const std::vector<base::FilePath>& path);
162
163 // This will finish the choose file process. This is either called directly
164 // from FilesSelected, or from WritableFileChecker. It is called on the UI
165 // thread.
166 void RegisterFileSystemsAndSendResponse(
167 const std::vector<base::FilePath>& path);
168
169 // Creates a result dictionary.
170 std::unique_ptr<base::DictionaryValue> CreateResult();
171
172 // Adds an entry to the result dictionary.
173 void AddEntryToResult(const base::FilePath& path,
174 const std::string& id_override,
175 base::DictionaryValue* result);
176
177 // called on the UI thread if there is a problem checking a writable file.
178 void HandleWritableFileError(const base::FilePath& error_path);
179
180 // Whether multiple entries have been requested.
181 bool multiple_;
182
183 // Whether a directory has been requested.
184 bool is_directory_;
185 };
186
187 class FileSystemGetWritableEntryFunction : public FileSystemEntryFunction {
188 public:
189 DECLARE_EXTENSION_FUNCTION("fileSystem.getWritableEntry",
190 FILESYSTEM_GETWRITABLEENTRY)
191
192 protected:
193 ~FileSystemGetWritableEntryFunction() override {}
194 bool RunAsync() override;
195
196 private:
197 void CheckPermissionAndSendResponse();
198 void SetIsDirectoryAsync();
199
200 // The path to the file for which a writable entry has been requested.
201 base::FilePath path_;
202 };
203
204 class FileSystemIsWritableEntryFunction : public UIThreadExtensionFunction {
205 public:
206 DECLARE_EXTENSION_FUNCTION("fileSystem.isWritableEntry",
207 FILESYSTEM_ISWRITABLEENTRY)
208
209 protected:
210 ~FileSystemIsWritableEntryFunction() override {}
211 ResponseAction Run() override;
212 };
213
214 class FileSystemChooseEntryFunction : public FileSystemEntryFunction {
215 public:
216 // Allow picker UI to be skipped in testing.
217 static void SkipPickerAndAlwaysSelectPathForTest(base::FilePath* path);
218 static void SkipPickerAndAlwaysSelectPathsForTest(
219 std::vector<base::FilePath>* paths);
220 static void SkipPickerAndSelectSuggestedPathForTest();
221 static void SkipPickerAndAlwaysCancelForTest();
222 static void StopSkippingPickerForTest();
223 // Allow directory access confirmation UI to be skipped in testing.
224 static void SkipDirectoryConfirmationForTest();
225 static void AutoCancelDirectoryConfirmationForTest();
226 static void StopSkippingDirectoryConfirmationForTest();
227 // Call this with the directory for test file paths. On Chrome OS, accessed
228 // path needs to be explicitly registered for smooth integration with Google
229 // Drive support.
230 static void RegisterTempExternalFileSystemForTest(const std::string& name,
231 const base::FilePath& path);
232 DECLARE_EXTENSION_FUNCTION("fileSystem.chooseEntry", FILESYSTEM_CHOOSEENTRY)
233
234 typedef std::vector<api::file_system::AcceptOption> AcceptOptions;
235
236 static void BuildFileTypeInfo(
237 ui::SelectFileDialog::FileTypeInfo* file_type_info,
238 const base::FilePath::StringType& suggested_extension,
239 const AcceptOptions* accepts,
240 const bool* acceptsAllTypes);
241 static void BuildSuggestion(const std::string* opt_name,
242 base::FilePath* suggested_name,
243 base::FilePath::StringType* suggested_extension);
244
245 protected:
246 class FilePicker;
247
248 ~FileSystemChooseEntryFunction() override {}
249 bool RunAsync() override;
250 void ShowPicker(const ui::SelectFileDialog::FileTypeInfo& file_type_info,
251 ui::SelectFileDialog::Type picker_type);
252
253 private:
254 void SetInitialPathAndShowPicker(
255 const base::FilePath& previous_path,
256 const base::FilePath& suggested_name,
257 const ui::SelectFileDialog::FileTypeInfo& file_type_info,
258 ui::SelectFileDialog::Type picker_type,
259 bool is_path_non_native_directory);
260
261 // FilesSelected and FileSelectionCanceled are called by the file picker.
262 void FilesSelected(const std::vector<base::FilePath>& path);
263 void FileSelectionCanceled();
264
265 // Check if the chosen directory is or is an ancestor of a sensitive
266 // directory. If so, show a dialog to confirm that the user wants to open the
267 // directory. Calls OnDirectoryAccessConfirmed if the directory isn't
268 // sensitive or the user chooses to open it. Otherwise, calls
269 // FileSelectionCanceled.
270 void ConfirmDirectoryAccessAsync(bool non_native_path,
271 const std::vector<base::FilePath>& paths,
272 content::WebContents* web_contents);
273 void OnDirectoryAccessConfirmed(const std::vector<base::FilePath>& paths);
274
275 base::FilePath initial_path_;
276 };
277
278 class FileSystemRetainEntryFunction : public ChromeAsyncExtensionFunction {
279 public:
280 DECLARE_EXTENSION_FUNCTION("fileSystem.retainEntry", FILESYSTEM_RETAINENTRY)
281
282 protected:
283 ~FileSystemRetainEntryFunction() override {}
284 bool RunAsync() override;
285
286 private:
287 // Retains the file entry referenced by |entry_id| in apps::SavedFilesService.
288 // |entry_id| must refer to an entry in an isolated file system. |path| is a
289 // path of the entry. |file_info| is base::File::Info of the entry if it can
290 // be obtained.
291 void RetainFileEntry(const std::string& entry_id,
292 const base::FilePath& path,
293 std::unique_ptr<base::File::Info> file_info);
294 };
295
296 class FileSystemIsRestorableFunction : public UIThreadExtensionFunction {
297 public:
298 DECLARE_EXTENSION_FUNCTION("fileSystem.isRestorable", FILESYSTEM_ISRESTORABLE)
299
300 protected:
301 ~FileSystemIsRestorableFunction() override {}
302 ResponseAction Run() override;
303 };
304
305 class FileSystemRestoreEntryFunction : public FileSystemEntryFunction {
306 public:
307 DECLARE_EXTENSION_FUNCTION("fileSystem.restoreEntry", FILESYSTEM_RESTOREENTRY)
308
309 protected:
310 ~FileSystemRestoreEntryFunction() override {}
311 bool RunAsync() override;
312 };
313
314 class FileSystemObserveDirectoryFunction : public UIThreadExtensionFunction {
315 public:
316 DECLARE_EXTENSION_FUNCTION("fileSystem.observeDirectory",
317 FILESYSTEM_OBSERVEDIRECTORY)
318
319 protected:
320 ~FileSystemObserveDirectoryFunction() override {}
321 ResponseAction Run() override;
322 };
323
324 class FileSystemUnobserveEntryFunction : public UIThreadExtensionFunction {
325 public:
326 DECLARE_EXTENSION_FUNCTION("fileSystem.unobserveEntry",
327 FILESYSTEM_UNOBSERVEENTRY)
328
329 protected:
330 ~FileSystemUnobserveEntryFunction() override {}
331 ResponseAction Run() override;
332 };
333
334 class FileSystemGetObservedEntriesFunction : public UIThreadExtensionFunction {
335 public:
336 DECLARE_EXTENSION_FUNCTION("fileSystem.getObservedEntries",
337 FILESYSTEM_GETOBSERVEDENTRIES);
338
339 protected:
340 ~FileSystemGetObservedEntriesFunction() override {}
341 ResponseAction Run() override;
342 };
343
344 #if !defined(OS_CHROMEOS)
345 // Stub for non Chrome OS operating systems.
346 class FileSystemRequestFileSystemFunction : public UIThreadExtensionFunction {
347 public:
348 DECLARE_EXTENSION_FUNCTION("fileSystem.requestFileSystem",
349 FILESYSTEM_REQUESTFILESYSTEM);
350
351 protected:
352 ~FileSystemRequestFileSystemFunction() override {}
353
354 // UIThreadExtensionFunction overrides.
355 ExtensionFunction::ResponseAction Run() override;
356 };
357
358 // Stub for non Chrome OS operating systems.
359 class FileSystemGetVolumeListFunction : public UIThreadExtensionFunction {
360 public:
361 DECLARE_EXTENSION_FUNCTION("fileSystem.getVolumeList",
362 FILESYSTEM_GETVOLUMELIST);
363
364 protected:
365 ~FileSystemGetVolumeListFunction() override {}
366
367 // UIThreadExtensionFunction overrides.
368 ExtensionFunction::ResponseAction Run() override;
369 };
370
371 #else
372 // Requests a file system for the specified volume id.
373 class FileSystemRequestFileSystemFunction : public UIThreadExtensionFunction {
374 public:
375 DECLARE_EXTENSION_FUNCTION("fileSystem.requestFileSystem",
376 FILESYSTEM_REQUESTFILESYSTEM)
377 FileSystemRequestFileSystemFunction();
378
379 protected:
380 ~FileSystemRequestFileSystemFunction() override;
381
382 // UIThreadExtensionFunction overrides.
383 ExtensionFunction::ResponseAction Run() override;
384
385 private:
386 // Called when a user grants or rejects permissions for the file system
387 // access.
388 void OnConsentReceived(const base::WeakPtr<file_manager::Volume>& volume,
389 bool writable,
390 file_system_api::ConsentProvider::Consent result);
391
392 ChromeExtensionFunctionDetails chrome_details_;
393 };
394
395 // Requests a list of available volumes.
396 class FileSystemGetVolumeListFunction : public UIThreadExtensionFunction {
397 public:
398 DECLARE_EXTENSION_FUNCTION("fileSystem.getVolumeList",
399 FILESYSTEM_GETVOLUMELIST);
400 FileSystemGetVolumeListFunction();
401
402 protected:
403 ~FileSystemGetVolumeListFunction() override;
404
405 // UIThreadExtensionFunction overrides.
406 ExtensionFunction::ResponseAction Run() override;
407
408 private:
409 ChromeExtensionFunctionDetails chrome_details_;
410 };
411 #endif
412
413 } // namespace extensions 115 } // namespace extensions
414 116
415 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ 117 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_CONSENT_PROVIDER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/BUILD.gn ('k') | chrome/browser/extensions/api/file_system/consent_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698