| 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_CONSENT_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_CONSENT_PROVIDER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_CONSENT_PROVIDER_H_ |
| 7 | 7 |
| 8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 public: | 35 public: |
| 36 enum Consent { CONSENT_GRANTED, CONSENT_REJECTED, CONSENT_IMPOSSIBLE }; | 36 enum Consent { CONSENT_GRANTED, CONSENT_REJECTED, CONSENT_IMPOSSIBLE }; |
| 37 typedef base::Callback<void(Consent)> ConsentCallback; | 37 typedef base::Callback<void(Consent)> ConsentCallback; |
| 38 typedef base::Callback<void(ui::DialogButton)> ShowDialogCallback; | 38 typedef base::Callback<void(ui::DialogButton)> ShowDialogCallback; |
| 39 | 39 |
| 40 // Interface for delegating user interaction for granting permissions. | 40 // Interface for delegating user interaction for granting permissions. |
| 41 class DelegateInterface { | 41 class DelegateInterface { |
| 42 public: | 42 public: |
| 43 // Shows a dialog for granting permissions. | 43 // Shows a dialog for granting permissions. |
| 44 virtual void ShowDialog(const Extension& extension, | 44 virtual void ShowDialog(const Extension& extension, |
| 45 content::RenderFrameHost* host, |
| 45 const base::WeakPtr<file_manager::Volume>& volume, | 46 const base::WeakPtr<file_manager::Volume>& volume, |
| 46 bool writable, | 47 bool writable, |
| 47 const ShowDialogCallback& callback) = 0; | 48 const ShowDialogCallback& callback) = 0; |
| 48 | 49 |
| 49 // Shows a notification about permissions automatically granted access. | 50 // Shows a notification about permissions automatically granted access. |
| 50 virtual void ShowNotification( | 51 virtual void ShowNotification( |
| 51 const Extension& extension, | 52 const Extension& extension, |
| 52 const base::WeakPtr<file_manager::Volume>& volume, | 53 const base::WeakPtr<file_manager::Volume>& volume, |
| 53 bool writable) = 0; | 54 bool writable) = 0; |
| 54 | 55 |
| 55 // Checks if the extension was launched in auto-launch kiosk mode. | 56 // Checks if the extension was launched in auto-launch kiosk mode. |
| 56 virtual bool IsAutoLaunched(const Extension& extension) = 0; | 57 virtual bool IsAutoLaunched(const Extension& extension) = 0; |
| 57 | 58 |
| 58 // Checks if the extension is a whitelisted component extension or app. | 59 // Checks if the extension is a whitelisted component extension or app. |
| 59 virtual bool IsWhitelistedComponent(const Extension& extension) = 0; | 60 virtual bool IsWhitelistedComponent(const Extension& extension) = 0; |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 explicit ConsentProvider(DelegateInterface* delegate); | 63 explicit ConsentProvider(DelegateInterface* delegate); |
| 63 ~ConsentProvider(); | 64 ~ConsentProvider(); |
| 64 | 65 |
| 65 // Requests consent for granting |writable| permissions to the |volume| | 66 // Requests consent for granting |writable| permissions to the |volume| |
| 66 // volume by the |extension|. Must be called only if the extension is | 67 // volume by the |extension|. Must be called only if the extension is |
| 67 // grantable, which can be checked with IsGrantable(). | 68 // grantable, which can be checked with IsGrantable(). |
| 68 void RequestConsent(const Extension& extension, | 69 void RequestConsent(const Extension& extension, |
| 70 content::RenderFrameHost* host, |
| 69 const base::WeakPtr<file_manager::Volume>& volume, | 71 const base::WeakPtr<file_manager::Volume>& volume, |
| 70 bool writable, | 72 bool writable, |
| 71 const ConsentCallback& callback); | 73 const ConsentCallback& callback); |
| 72 | 74 |
| 73 // Checks whether the |extension| can be granted access. | 75 // Checks whether the |extension| can be granted access. |
| 74 bool IsGrantable(const Extension& extension); | 76 bool IsGrantable(const Extension& extension); |
| 75 | 77 |
| 76 private: | 78 private: |
| 77 DelegateInterface* const delegate_; | 79 DelegateInterface* const delegate_; |
| 78 | 80 |
| 79 DISALLOW_COPY_AND_ASSIGN(ConsentProvider); | 81 DISALLOW_COPY_AND_ASSIGN(ConsentProvider); |
| 80 }; | 82 }; |
| 81 | 83 |
| 82 // Handles interaction with user as well as environment checks (whitelists, | 84 // Handles interaction with user as well as environment checks (whitelists, |
| 83 // context of running extensions) for ConsentProvider. | 85 // context of running extensions) for ConsentProvider. |
| 84 class ConsentProviderDelegate : public ConsentProvider::DelegateInterface { | 86 class ConsentProviderDelegate : public ConsentProvider::DelegateInterface { |
| 85 public: | 87 public: |
| 86 ConsentProviderDelegate(Profile* profile, content::RenderFrameHost* host); | 88 explicit ConsentProviderDelegate(Profile* profile); |
| 87 ~ConsentProviderDelegate(); | 89 ~ConsentProviderDelegate(); |
| 88 | 90 |
| 89 private: | 91 private: |
| 90 friend ScopedSkipRequestFileSystemDialog; | 92 friend ScopedSkipRequestFileSystemDialog; |
| 91 | 93 |
| 92 // Sets a fake result for the user consent dialog. If ui::DIALOG_BUTTON_NONE | 94 // Sets a fake result for the user consent dialog. If ui::DIALOG_BUTTON_NONE |
| 93 // then disabled. | 95 // then disabled. |
| 94 static void SetAutoDialogButtonForTest(ui::DialogButton button); | 96 static void SetAutoDialogButtonForTest(ui::DialogButton button); |
| 95 | 97 |
| 96 // ConsentProvider::DelegateInterface overrides: | 98 // ConsentProvider::DelegateInterface overrides: |
| 97 void ShowDialog(const Extension& extension, | 99 void ShowDialog(const Extension& extension, |
| 100 content::RenderFrameHost* host, |
| 98 const base::WeakPtr<file_manager::Volume>& volume, | 101 const base::WeakPtr<file_manager::Volume>& volume, |
| 99 bool writable, | 102 bool writable, |
| 100 const file_system_api::ConsentProvider::ShowDialogCallback& | 103 const file_system_api::ConsentProvider::ShowDialogCallback& |
| 101 callback) override; | 104 callback) override; |
| 102 void ShowNotification(const Extension& extension, | 105 void ShowNotification(const Extension& extension, |
| 103 const base::WeakPtr<file_manager::Volume>& volume, | 106 const base::WeakPtr<file_manager::Volume>& volume, |
| 104 bool writable) override; | 107 bool writable) override; |
| 105 bool IsAutoLaunched(const Extension& extension) override; | 108 bool IsAutoLaunched(const Extension& extension) override; |
| 106 bool IsWhitelistedComponent(const Extension& extension) override; | 109 bool IsWhitelistedComponent(const Extension& extension) override; |
| 107 | 110 |
| 108 Profile* const profile_; | 111 Profile* const profile_; |
| 109 content::RenderFrameHost* const host_; | |
| 110 | 112 |
| 111 DISALLOW_COPY_AND_ASSIGN(ConsentProviderDelegate); | 113 DISALLOW_COPY_AND_ASSIGN(ConsentProviderDelegate); |
| 112 }; | 114 }; |
| 113 | 115 |
| 114 } // namespace file_system_api | 116 } // namespace file_system_api |
| 115 } // namespace extensions | 117 } // namespace extensions |
| 116 | 118 |
| 117 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_CONSENT_PROVIDER_H_ | 119 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_CONSENT_PROVIDER_H_ |
| OLD | NEW |