Chromium Code Reviews| Index: chrome/browser/extensions/api/file_system/chrome_file_system_delegate.h |
| diff --git a/chrome/browser/extensions/api/file_system/consent_provider.h b/chrome/browser/extensions/api/file_system/chrome_file_system_delegate.h |
| similarity index 10% |
| copy from chrome/browser/extensions/api/file_system/consent_provider.h |
| copy to chrome/browser/extensions/api/file_system/chrome_file_system_delegate.h |
| index 3a517b6f68d8296547812c32ab50f57d2c7d023f..97ef32790fae278302391895ab454dc11d5005ed 100644 |
| --- a/chrome/browser/extensions/api/file_system/consent_provider.h |
| +++ b/chrome/browser/extensions/api/file_system/chrome_file_system_delegate.h |
| @@ -2,116 +2,107 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#ifndef CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_CONSENT_PROVIDER_H_ |
| -#define CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_CONSENT_PROVIDER_H_ |
| +#ifndef CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_CHROME_FILE_SYSTEM_DELEGATE_H_ |
| +#define CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_CHROME_FILE_SYSTEM_DELEGATE_H_ |
| + |
| +#include "extensions/browser/api/file_system/file_system_delegate.h" |
| -#include "base/callback_forward.h" |
| #include "base/macros.h" |
| #include "base/memory/weak_ptr.h" |
| #include "build/build_config.h" |
| -#include "ui/base/ui_base_types.h" |
| - |
| -class Profile; |
| -namespace content { |
| -class RenderFrameHost; |
| -} // content |
| +#if defined(OS_CHROMEOS) |
| +#include "chrome/browser/extensions/api/file_system/consent_provider.h" |
| +#endif |
| namespace file_manager { |
| class Volume; |
| -} // namespace file_manager |
| +} |
| namespace extensions { |
| -class Extension; |
| -class ScopedSkipRequestFileSystemDialog; |
| +#if defined(OS_CHROMEOS) |
| namespace file_system_api { |
| -// Requests consent for the chrome.fileSystem.requestFileSystem() method. |
| -// Interaction with UI and environmental checks (kiosk mode, whitelist) are |
| -// provided by a delegate: ConsentProviderDelegate. For testing, it is |
| -// TestingConsentProviderDelegate. |
| -class ConsentProvider { |
| - public: |
| - enum Consent { CONSENT_GRANTED, CONSENT_REJECTED, CONSENT_IMPOSSIBLE }; |
| - typedef base::Callback<void(Consent)> ConsentCallback; |
| - typedef base::Callback<void(ui::DialogButton)> ShowDialogCallback; |
| - |
| - // Interface for delegating user interaction for granting permissions. |
| - class DelegateInterface { |
| - public: |
| - // Shows a dialog for granting permissions. |
| - virtual void ShowDialog(const Extension& extension, |
| - const base::WeakPtr<file_manager::Volume>& volume, |
| - bool writable, |
| - const ShowDialogCallback& callback) = 0; |
| - |
| - // Shows a notification about permissions automatically granted access. |
| - virtual void ShowNotification( |
| - const Extension& extension, |
| - const base::WeakPtr<file_manager::Volume>& volume, |
| - bool writable) = 0; |
| - |
| - // Checks if the extension was launched in auto-launch kiosk mode. |
| - virtual bool IsAutoLaunched(const Extension& extension) = 0; |
| - |
| - // Checks if the extension is a whitelisted component extension or app. |
| - virtual bool IsWhitelistedComponent(const Extension& extension) = 0; |
| - }; |
| - |
| - explicit ConsentProvider(DelegateInterface* delegate); |
| - ~ConsentProvider(); |
| - |
| - // Requests consent for granting |writable| permissions to the |volume| |
| - // volume by the |extension|. Must be called only if the extension is |
| - // grantable, which can be checked with IsGrantable(). |
| - void RequestConsent(const Extension& extension, |
| - const base::WeakPtr<file_manager::Volume>& volume, |
| - bool writable, |
| - const ConsentCallback& callback); |
| - |
| - // Checks whether the |extension| can be granted access. |
| - bool IsGrantable(const Extension& extension); |
| - |
| - private: |
| - DelegateInterface* const delegate_; |
| +// Dispatches an event about a mounted or unmounted volume in the system to |
| +// each extension which can request it. |
| +void DispatchVolumeListChangeEvent(content::BrowserContext* browser_context); |
| - DISALLOW_COPY_AND_ASSIGN(ConsentProvider); |
| -}; |
| +} // namespace file_system_api |
| +#endif // defined(OS_CHROMEOS) |
| -// Handles interaction with user as well as environment checks (whitelists, |
| -// context of running extensions) for ConsentProvider. |
| -class ConsentProviderDelegate : public ConsentProvider::DelegateInterface { |
| +class ChromeFileSystemDelegate : public FileSystemDelegate { |
| public: |
| - ConsentProviderDelegate(Profile* profile, content::RenderFrameHost* host); |
| - ~ConsentProviderDelegate(); |
| + ChromeFileSystemDelegate(); |
| + ~ChromeFileSystemDelegate() override; |
| + |
|
Devlin
2017/06/14 14:53:22
// FileSystemDelegate:
michaelpg
2017/06/21 00:40:07
Done.
|
| + base::FilePath GetDefaultDirectory() override; |
| + |
| + std::unique_ptr<ui::SelectFilePolicy> CreateSelectFilePolicy( |
| + content::WebContents* web_contents) override; |
| + |
| + scoped_refptr<ui::SelectFileDialog> CreateSelectFileDialog( |
| + ui::SelectFileDialog::Listener* listener, |
| + std::unique_ptr<ui::SelectFilePolicy> policy) override; |
| + |
| + void ShowSelectFileDialogForWebContents( |
| + scoped_refptr<ui::SelectFileDialog> dialog, |
| + content::WebContents* web_contents, |
| + ui::SelectFileDialog::Type type, |
| + const base::FilePath& default_path, |
| + const ui::SelectFileDialog::FileTypeInfo* file_types) override; |
| + |
| + void ConfirmSensitiveDirectoryAccess(bool writable, |
| + const base::string16& app_name, |
| + content::WebContents* web_contents, |
| + const base::Closure& on_accept, |
| + const base::Closure& on_cancel) override; |
| + |
| + // Finds a string describing the accept type. On success, returns true and |
| + // populates |description_id|. |
| + bool GetDescriptionIdForAcceptType(const std::string& accept_type, |
| + int* description_id) override; |
| + |
| +#if defined(OS_CHROMEOS) |
| + bool IsGrantable(content::BrowserContext* browser_context, |
| + content::RenderFrameHost* render_frame_host, |
| + const Extension& extension) override; |
| + |
| + // Grants or denies an extension's request for access to the named file |
| + // system. May prompt the user for consent. |
|
Devlin
2017/06/14 14:53:22
Shouldn't need comments for overridden methods.
michaelpg
2017/06/21 00:40:07
Done.
|
| + void RequestFileSystem(content::BrowserContext* browser_context, |
| + scoped_refptr<UIThreadExtensionFunction> requester, |
| + const Extension& extension, |
| + std::string volume_id, |
| + bool writable, |
| + const FileSystemCallback& success_callback, |
| + const ErrorCallback& error_callback) override; |
| + |
| + // Immediately calls VolumeListCallback or ErrorCallback. |
| + void GetVolumeList(content::BrowserContext* browser_context, |
| + const VolumeListCallback& success_callback, |
| + const ErrorCallback& error_callback) override; |
| +#endif // defined(OS_CHROMEOS) |
| + |
| + std::unique_ptr<file_system_api::SavedFilesServiceDelegate> |
| + CreateSavedFilesServiceDelegate( |
| + content::BrowserContext* browser_context) override; |
| private: |
| - friend ScopedSkipRequestFileSystemDialog; |
| - |
| - // Sets a fake result for the user consent dialog. If ui::DIALOG_BUTTON_NONE |
| - // then disabled. |
| - static void SetAutoDialogButtonForTest(ui::DialogButton button); |
| - |
| - // ConsentProvider::DelegateInterface overrides: |
| - void ShowDialog(const Extension& extension, |
| - const base::WeakPtr<file_manager::Volume>& volume, |
| - bool writable, |
| - const file_system_api::ConsentProvider::ShowDialogCallback& |
| - callback) override; |
| - void ShowNotification(const Extension& extension, |
| - const base::WeakPtr<file_manager::Volume>& volume, |
| - bool writable) override; |
| - bool IsAutoLaunched(const Extension& extension) override; |
| - bool IsWhitelistedComponent(const Extension& extension) override; |
| - |
| - Profile* const profile_; |
| - content::RenderFrameHost* const host_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(ConsentProviderDelegate); |
| +#if defined(OS_CHROMEOS) |
| + void OnConsentReceived(content::BrowserContext* browser_context, |
| + scoped_refptr<UIThreadExtensionFunction> requester, |
| + const FileSystemCallback& success_callback, |
| + const ErrorCallback& error_callback, |
| + const std::string& extension, |
| + const base::WeakPtr<file_manager::Volume>& volume, |
| + bool writable, |
| + file_system_api::ConsentProvider::Consent result); |
| +#endif // defined(OS_CHROMEOS) |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ChromeFileSystemDelegate); |
| }; |
| -} // namespace file_system_api |
| } // namespace extensions |
| -#endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_CONSENT_PROVIDER_H_ |
| +#endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_CHROME_FILE_SYSTEM_DELEGATE_H_ |