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

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

Issue 2934143002: Move chrome.fileSystem implementation to //extensions (Closed)
Patch Set: devlin 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 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 13 matching lines...) Expand all
24 namespace extensions { 24 namespace extensions {
25 class Extension; 25 class Extension;
26 class ScopedSkipRequestFileSystemDialog; 26 class ScopedSkipRequestFileSystemDialog;
27 27
28 namespace file_system_api { 28 namespace file_system_api {
29 29
30 // Requests consent for the chrome.fileSystem.requestFileSystem() method. 30 // Requests consent for the chrome.fileSystem.requestFileSystem() method.
31 // Interaction with UI and environmental checks (kiosk mode, whitelist) are 31 // Interaction with UI and environmental checks (kiosk mode, whitelist) are
32 // provided by a delegate: ConsentProviderDelegate. For testing, it is 32 // provided by a delegate: ConsentProviderDelegate. For testing, it is
33 // TestingConsentProviderDelegate. 33 // TestingConsentProviderDelegate.
34 // This class may post callbacks given to it, but does not asynchronously call
35 // itself. It is generally safe to use a temporary ConsentProvider.
36 // TODO(michaelpg): Make this easier to use by replacing member functions with
37 // static methods.
34 class ConsentProvider { 38 class ConsentProvider {
35 public: 39 public:
36 enum Consent { CONSENT_GRANTED, CONSENT_REJECTED, CONSENT_IMPOSSIBLE }; 40 enum Consent { CONSENT_GRANTED, CONSENT_REJECTED, CONSENT_IMPOSSIBLE };
37 typedef base::Callback<void(Consent)> ConsentCallback; 41 typedef base::Callback<void(Consent)> ConsentCallback;
38 typedef base::Callback<void(ui::DialogButton)> ShowDialogCallback; 42 typedef base::Callback<void(ui::DialogButton)> ShowDialogCallback;
39 43
40 // Interface for delegating user interaction for granting permissions. 44 // Interface for delegating user interaction for granting permissions.
41 class DelegateInterface { 45 class DelegateInterface {
42 public: 46 public:
43 // Shows a dialog for granting permissions. 47 // Shows a dialog for granting permissions.
44 virtual void ShowDialog(const Extension& extension, 48 virtual void ShowDialog(const Extension& extension,
49 content::RenderFrameHost* host,
45 const base::WeakPtr<file_manager::Volume>& volume, 50 const base::WeakPtr<file_manager::Volume>& volume,
46 bool writable, 51 bool writable,
47 const ShowDialogCallback& callback) = 0; 52 const ShowDialogCallback& callback) = 0;
48 53
49 // Shows a notification about permissions automatically granted access. 54 // Shows a notification about permissions automatically granted access.
50 virtual void ShowNotification( 55 virtual void ShowNotification(
51 const Extension& extension, 56 const Extension& extension,
52 const base::WeakPtr<file_manager::Volume>& volume, 57 const base::WeakPtr<file_manager::Volume>& volume,
53 bool writable) = 0; 58 bool writable) = 0;
54 59
55 // Checks if the extension was launched in auto-launch kiosk mode. 60 // Checks if the extension was launched in auto-launch kiosk mode.
56 virtual bool IsAutoLaunched(const Extension& extension) = 0; 61 virtual bool IsAutoLaunched(const Extension& extension) = 0;
57 62
58 // Checks if the extension is a whitelisted component extension or app. 63 // Checks if the extension is a whitelisted component extension or app.
59 virtual bool IsWhitelistedComponent(const Extension& extension) = 0; 64 virtual bool IsWhitelistedComponent(const Extension& extension) = 0;
60 }; 65 };
61 66
62 explicit ConsentProvider(DelegateInterface* delegate); 67 explicit ConsentProvider(DelegateInterface* delegate);
63 ~ConsentProvider(); 68 ~ConsentProvider();
64 69
65 // Requests consent for granting |writable| permissions to the |volume| 70 // Requests consent for granting |writable| permissions to the |volume|
66 // volume by the |extension|. Must be called only if the extension is 71 // volume by the |extension|. Must be called only if the extension is
67 // grantable, which can be checked with IsGrantable(). 72 // grantable, which can be checked with IsGrantable().
68 void RequestConsent(const Extension& extension, 73 void RequestConsent(const Extension& extension,
74 content::RenderFrameHost* host,
69 const base::WeakPtr<file_manager::Volume>& volume, 75 const base::WeakPtr<file_manager::Volume>& volume,
70 bool writable, 76 bool writable,
71 const ConsentCallback& callback); 77 const ConsentCallback& callback);
72 78
73 // Checks whether the |extension| can be granted access. 79 // Checks whether the |extension| can be granted access.
74 bool IsGrantable(const Extension& extension); 80 bool IsGrantable(const Extension& extension);
75 81
76 private: 82 private:
77 DelegateInterface* const delegate_; 83 DelegateInterface* const delegate_;
78 84
79 DISALLOW_COPY_AND_ASSIGN(ConsentProvider); 85 DISALLOW_COPY_AND_ASSIGN(ConsentProvider);
80 }; 86 };
81 87
82 // Handles interaction with user as well as environment checks (whitelists, 88 // Handles interaction with user as well as environment checks (whitelists,
83 // context of running extensions) for ConsentProvider. 89 // context of running extensions) for ConsentProvider.
84 class ConsentProviderDelegate : public ConsentProvider::DelegateInterface { 90 class ConsentProviderDelegate : public ConsentProvider::DelegateInterface {
85 public: 91 public:
86 ConsentProviderDelegate(Profile* profile, content::RenderFrameHost* host); 92 explicit ConsentProviderDelegate(Profile* profile);
87 ~ConsentProviderDelegate(); 93 ~ConsentProviderDelegate();
88 94
89 private: 95 private:
90 friend ScopedSkipRequestFileSystemDialog; 96 friend ScopedSkipRequestFileSystemDialog;
91 97
92 // Sets a fake result for the user consent dialog. If ui::DIALOG_BUTTON_NONE 98 // Sets a fake result for the user consent dialog. If ui::DIALOG_BUTTON_NONE
93 // then disabled. 99 // then disabled.
94 static void SetAutoDialogButtonForTest(ui::DialogButton button); 100 static void SetAutoDialogButtonForTest(ui::DialogButton button);
95 101
96 // ConsentProvider::DelegateInterface overrides: 102 // ConsentProvider::DelegateInterface overrides:
97 void ShowDialog(const Extension& extension, 103 void ShowDialog(const Extension& extension,
104 content::RenderFrameHost* host,
98 const base::WeakPtr<file_manager::Volume>& volume, 105 const base::WeakPtr<file_manager::Volume>& volume,
99 bool writable, 106 bool writable,
100 const file_system_api::ConsentProvider::ShowDialogCallback& 107 const file_system_api::ConsentProvider::ShowDialogCallback&
101 callback) override; 108 callback) override;
102 void ShowNotification(const Extension& extension, 109 void ShowNotification(const Extension& extension,
103 const base::WeakPtr<file_manager::Volume>& volume, 110 const base::WeakPtr<file_manager::Volume>& volume,
104 bool writable) override; 111 bool writable) override;
105 bool IsAutoLaunched(const Extension& extension) override; 112 bool IsAutoLaunched(const Extension& extension) override;
106 bool IsWhitelistedComponent(const Extension& extension) override; 113 bool IsWhitelistedComponent(const Extension& extension) override;
107 114
108 Profile* const profile_; 115 Profile* const profile_;
109 content::RenderFrameHost* const host_;
110 116
111 DISALLOW_COPY_AND_ASSIGN(ConsentProviderDelegate); 117 DISALLOW_COPY_AND_ASSIGN(ConsentProviderDelegate);
112 }; 118 };
113 119
114 } // namespace file_system_api 120 } // namespace file_system_api
115 } // namespace extensions 121 } // namespace extensions
116 122
117 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_CONSENT_PROVIDER_H_ 123 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_CONSENT_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698