OLD | NEW |
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 <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 void SetLastChooseEntryDirectory(ExtensionPrefs* prefs, | 42 void SetLastChooseEntryDirectory(ExtensionPrefs* prefs, |
43 const std::string& extension_id, | 43 const std::string& extension_id, |
44 const base::FilePath& path); | 44 const base::FilePath& path); |
45 | 45 |
46 std::vector<base::FilePath> GetGrayListedDirectories(); | 46 std::vector<base::FilePath> GetGrayListedDirectories(); |
47 | 47 |
48 #if defined(OS_CHROMEOS) | 48 #if defined(OS_CHROMEOS) |
49 // Requests consent for the chrome.fileSystem.requestFileSystem() method. | 49 // Requests consent for the chrome.fileSystem.requestFileSystem() method. |
50 // Interaction with UI and environmental checks (kiosk mode, whitelist) are | 50 // Interaction with UI and environmental checks (kiosk mode, whitelist) are |
51 // provided by a delegate: FileSystemRequestFileSystemFunction. For testing, | 51 // provided by a delegate: ConsentProviderDelegate. For testing, it is |
52 // it is TestingConsentProviderDelegate. | 52 // TestingConsentProviderDelegate. |
53 class ConsentProvider { | 53 class ConsentProvider { |
54 public: | 54 public: |
55 enum Consent { CONSENT_GRANTED, CONSENT_REJECTED, CONSENT_IMPOSSIBLE }; | 55 enum Consent { CONSENT_GRANTED, CONSENT_REJECTED, CONSENT_IMPOSSIBLE }; |
56 typedef base::Callback<void(Consent)> ConsentCallback; | 56 typedef base::Callback<void(Consent)> ConsentCallback; |
57 typedef base::Callback<void(ui::DialogButton)> ShowDialogCallback; | 57 typedef base::Callback<void(ui::DialogButton)> ShowDialogCallback; |
58 | 58 |
59 // Interface for delegating user interaction for granting permissions. | 59 // Interface for delegating user interaction for granting permissions. |
60 class DelegateInterface { | 60 class DelegateInterface { |
61 public: | 61 public: |
62 // Shows a dialog for granting permissions. | 62 // Shows a dialog for granting permissions. |
(...skipping 27 matching lines...) Expand all Loading... |
90 private: | 90 private: |
91 DelegateInterface* const delegate_; | 91 DelegateInterface* const delegate_; |
92 | 92 |
93 // Converts the clicked button to a consent result and passes it via the | 93 // Converts the clicked button to a consent result and passes it via the |
94 // |callback|. | 94 // |callback|. |
95 void DialogResultToConsent(const ConsentCallback& callback, | 95 void DialogResultToConsent(const ConsentCallback& callback, |
96 ui::DialogButton button); | 96 ui::DialogButton button); |
97 | 97 |
98 DISALLOW_COPY_AND_ASSIGN(ConsentProvider); | 98 DISALLOW_COPY_AND_ASSIGN(ConsentProvider); |
99 }; | 99 }; |
| 100 |
| 101 // Handles interaction with user as well as environment checks (whitelists, |
| 102 // context of running extensions) for ConsentProvider. |
| 103 class ConsentProviderDelegate : public ConsentProvider::DelegateInterface { |
| 104 public: |
| 105 ConsentProviderDelegate(Profile* profile, content::RenderViewHost* host); |
| 106 ~ConsentProviderDelegate(); |
| 107 |
| 108 private: |
| 109 friend ScopedSkipRequestFileSystemDialog; |
| 110 |
| 111 // Sets a fake result for the user consent dialog. If ui::DIALOG_BUTTON_NONE |
| 112 // then disabled. |
| 113 static void SetAutoDialogButtonForTest(ui::DialogButton button); |
| 114 |
| 115 // ConsentProvider::DelegateInterface overrides: |
| 116 void ShowDialog(const extensions::Extension& extension, |
| 117 base::WeakPtr<file_manager::Volume> volume, |
| 118 bool writable, |
| 119 const file_system_api::ConsentProvider::ShowDialogCallback& |
| 120 callback) override; |
| 121 bool IsAutoLaunched(const extensions::Extension& extension) override; |
| 122 bool IsWhitelistedComponent(const extensions::Extension& extension) override; |
| 123 |
| 124 Profile* const profile_; |
| 125 content::RenderViewHost* const host_; |
| 126 |
| 127 DISALLOW_COPY_AND_ASSIGN(ConsentProviderDelegate); |
| 128 }; |
100 #endif | 129 #endif |
101 | 130 |
102 } // namespace file_system_api | 131 } // namespace file_system_api |
103 | 132 |
104 class FileSystemGetDisplayPathFunction : public ChromeSyncExtensionFunction { | 133 class FileSystemGetDisplayPathFunction : public ChromeSyncExtensionFunction { |
105 public: | 134 public: |
106 DECLARE_EXTENSION_FUNCTION("fileSystem.getDisplayPath", | 135 DECLARE_EXTENSION_FUNCTION("fileSystem.getDisplayPath", |
107 FILESYSTEM_GETDISPLAYPATH) | 136 FILESYSTEM_GETDISPLAYPATH) |
108 | 137 |
109 protected: | 138 protected: |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 #if !defined(OS_CHROMEOS) | 337 #if !defined(OS_CHROMEOS) |
309 // Stub for non Chrome OS operating systems. | 338 // Stub for non Chrome OS operating systems. |
310 class FileSystemRequestFileSystemFunction : public UIThreadExtensionFunction { | 339 class FileSystemRequestFileSystemFunction : public UIThreadExtensionFunction { |
311 public: | 340 public: |
312 DECLARE_EXTENSION_FUNCTION("fileSystem.requestFileSystem", | 341 DECLARE_EXTENSION_FUNCTION("fileSystem.requestFileSystem", |
313 FILESYSTEM_REQUESTFILESYSTEM); | 342 FILESYSTEM_REQUESTFILESYSTEM); |
314 | 343 |
315 protected: | 344 protected: |
316 ~FileSystemRequestFileSystemFunction() override {} | 345 ~FileSystemRequestFileSystemFunction() override {} |
317 | 346 |
318 // AsyncExtensionFunction overrides. | 347 // UIThreadExtensionFunction overrides. |
| 348 ExtensionFunction::ResponseAction Run() override; |
| 349 }; |
| 350 |
| 351 // Stub for non Chrome OS operating systems. |
| 352 class FileSystemGetVolumeListFunction : public UIThreadExtensionFunction { |
| 353 public: |
| 354 DECLARE_EXTENSION_FUNCTION("fileSystem.getVolumeList", |
| 355 FILESYSTEM_GETVOLUMELIST); |
| 356 |
| 357 protected: |
| 358 ~FileSystemGetVolumeListFunction() override {} |
| 359 |
| 360 // UIThreadExtensionFunction overrides. |
319 ExtensionFunction::ResponseAction Run() override; | 361 ExtensionFunction::ResponseAction Run() override; |
320 }; | 362 }; |
321 | 363 |
322 #else | 364 #else |
323 // Requests a file system for the specified volume id. | 365 // Requests a file system for the specified volume id. |
324 class FileSystemRequestFileSystemFunction | 366 class FileSystemRequestFileSystemFunction : public UIThreadExtensionFunction { |
325 : public UIThreadExtensionFunction, | |
326 public file_system_api::ConsentProvider::DelegateInterface { | |
327 public: | 367 public: |
328 DECLARE_EXTENSION_FUNCTION("fileSystem.requestFileSystem", | 368 DECLARE_EXTENSION_FUNCTION("fileSystem.requestFileSystem", |
329 FILESYSTEM_REQUESTFILESYSTEM) | 369 FILESYSTEM_REQUESTFILESYSTEM) |
330 FileSystemRequestFileSystemFunction(); | 370 FileSystemRequestFileSystemFunction(); |
331 | 371 |
332 protected: | 372 protected: |
333 ~FileSystemRequestFileSystemFunction() override; | 373 ~FileSystemRequestFileSystemFunction() override; |
334 | 374 |
335 // AsyncExtensionFunction overrides. | 375 // UIThreadExtensionFunction overrides. |
336 ExtensionFunction::ResponseAction Run() override; | 376 ExtensionFunction::ResponseAction Run() override; |
337 | 377 |
338 private: | 378 private: |
339 friend ScopedSkipRequestFileSystemDialog; | |
340 | |
341 // Sets a fake result for the user consent dialog. If ui::DIALOG_BUTTON_NONE | |
342 // then disabled. | |
343 static void SetAutoDialogButtonForTest(ui::DialogButton button); | |
344 | |
345 // ConsentProvider::DelegateInterface overrides: | |
346 void ShowDialog(const extensions::Extension& extension, | |
347 base::WeakPtr<file_manager::Volume> volume, | |
348 bool writable, | |
349 const file_system_api::ConsentProvider::ShowDialogCallback& | |
350 callback) override; | |
351 bool IsAutoLaunched(const extensions::Extension& extension) override; | |
352 bool IsWhitelistedComponent(const extensions::Extension& extension) override; | |
353 | |
354 // Called when a user grants or rejects permissions for the file system | 379 // Called when a user grants or rejects permissions for the file system |
355 // access. | 380 // access. |
356 void OnConsentReceived(base::WeakPtr<file_manager::Volume> volume, | 381 void OnConsentReceived(base::WeakPtr<file_manager::Volume> volume, |
357 bool writable, | 382 bool writable, |
358 file_system_api::ConsentProvider::Consent result); | 383 file_system_api::ConsentProvider::Consent result); |
359 | 384 |
360 ChromeExtensionFunctionDetails chrome_details_; | 385 ChromeExtensionFunctionDetails chrome_details_; |
| 386 file_system_api::ConsentProviderDelegate consent_provider_delegate_; |
| 387 file_system_api::ConsentProvider consent_provider_; |
| 388 }; |
| 389 |
| 390 // Requests a list of available volumes. |
| 391 class FileSystemGetVolumeListFunction : public UIThreadExtensionFunction { |
| 392 public: |
| 393 DECLARE_EXTENSION_FUNCTION("fileSystem.getVolumeList", |
| 394 FILESYSTEM_GETVOLUMELIST); |
| 395 FileSystemGetVolumeListFunction(); |
| 396 |
| 397 protected: |
| 398 ~FileSystemGetVolumeListFunction() override; |
| 399 |
| 400 // UIThreadExtensionFunction overrides. |
| 401 ExtensionFunction::ResponseAction Run() override; |
| 402 |
| 403 private: |
| 404 ChromeExtensionFunctionDetails chrome_details_; |
| 405 file_system_api::ConsentProviderDelegate consent_provider_delegate_; |
361 file_system_api::ConsentProvider consent_provider_; | 406 file_system_api::ConsentProvider consent_provider_; |
362 }; | 407 }; |
363 #endif | 408 #endif |
364 | 409 |
365 } // namespace extensions | 410 } // namespace extensions |
366 | 411 |
367 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ | 412 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ |
OLD | NEW |