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 #include "chrome/browser/extensions/api/file_system/consent_provider.h" | 5 #include "chrome/browser/extensions/api/file_system/consent_provider.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
14 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" | 14 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
15 #include "chrome/browser/chromeos/file_manager/app_id.h" | 15 #include "chrome/browser/chromeos/file_manager/app_id.h" |
16 #include "chrome/browser/chromeos/file_manager/volume_manager.h" | 16 #include "chrome/browser/chromeos/file_manager/volume_manager.h" |
17 #include "chrome/browser/extensions/api/file_system/request_file_system_notifica
tion.h" | 17 #include "chrome/browser/extensions/api/file_system/request_file_system_notifica
tion.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/ui/views/extensions/request_file_system_dialog_view.h" | 19 #include "chrome/browser/ui/views/extensions/request_file_system_dialog_view.h" |
20 #include "chrome/common/extensions/api/file_system.h" | |
21 #include "components/user_manager/user_manager.h" | 20 #include "components/user_manager/user_manager.h" |
22 #include "content/public/browser/render_frame_host.h" | 21 #include "content/public/browser/render_frame_host.h" |
23 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
24 #include "extensions/browser/app_window/app_window.h" | 23 #include "extensions/browser/app_window/app_window.h" |
25 #include "extensions/browser/app_window/app_window_registry.h" | 24 #include "extensions/browser/app_window/app_window_registry.h" |
| 25 #include "extensions/common/api/file_system.h" |
26 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" | 26 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" |
27 | 27 |
28 namespace extensions { | 28 namespace extensions { |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 // List of whitelisted component apps and extensions by their ids for | 32 // List of whitelisted component apps and extensions by their ids for |
33 // chrome.fileSystem.requestFileSystem. | 33 // chrome.fileSystem.requestFileSystem. |
34 const char* const kRequestFileSystemComponentWhitelist[] = { | 34 const char* const kRequestFileSystemComponentWhitelist[] = { |
35 file_manager::kFileManagerAppId, | 35 file_manager::kFileManagerAppId, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 ConsentProvider::ConsentProvider(DelegateInterface* delegate) | 78 ConsentProvider::ConsentProvider(DelegateInterface* delegate) |
79 : delegate_(delegate) { | 79 : delegate_(delegate) { |
80 DCHECK(delegate_); | 80 DCHECK(delegate_); |
81 } | 81 } |
82 | 82 |
83 ConsentProvider::~ConsentProvider() { | 83 ConsentProvider::~ConsentProvider() { |
84 } | 84 } |
85 | 85 |
86 void ConsentProvider::RequestConsent( | 86 void ConsentProvider::RequestConsent( |
87 const Extension& extension, | 87 const Extension& extension, |
| 88 content::RenderFrameHost* host, |
88 const base::WeakPtr<file_manager::Volume>& volume, | 89 const base::WeakPtr<file_manager::Volume>& volume, |
89 bool writable, | 90 bool writable, |
90 const ConsentCallback& callback) { | 91 const ConsentCallback& callback) { |
91 DCHECK(IsGrantable(extension)); | 92 DCHECK(IsGrantable(extension)); |
92 | 93 |
93 // If a whitelisted component, then no need to ask or inform the user. | 94 // If a whitelisted component, then no need to ask or inform the user. |
94 if (extension.location() == Manifest::COMPONENT && | 95 if (extension.location() == Manifest::COMPONENT && |
95 delegate_->IsWhitelistedComponent(extension)) { | 96 delegate_->IsWhitelistedComponent(extension)) { |
96 base::ThreadTaskRunnerHandle::Get()->PostTask( | 97 base::ThreadTaskRunnerHandle::Get()->PostTask( |
97 FROM_HERE, base::Bind(callback, CONSENT_GRANTED)); | 98 FROM_HERE, base::Bind(callback, CONSENT_GRANTED)); |
98 return; | 99 return; |
99 } | 100 } |
100 | 101 |
101 // If auto-launched kiosk app, then no need to ask user either, but show the | 102 // If auto-launched kiosk app, then no need to ask user either, but show the |
102 // notification. | 103 // notification. |
103 if (delegate_->IsAutoLaunched(extension)) { | 104 if (delegate_->IsAutoLaunched(extension)) { |
104 delegate_->ShowNotification(extension, volume, writable); | 105 delegate_->ShowNotification(extension, volume, writable); |
105 base::ThreadTaskRunnerHandle::Get()->PostTask( | 106 base::ThreadTaskRunnerHandle::Get()->PostTask( |
106 FROM_HERE, base::Bind(callback, CONSENT_GRANTED)); | 107 FROM_HERE, base::Bind(callback, CONSENT_GRANTED)); |
107 return; | 108 return; |
108 } | 109 } |
109 | 110 |
110 // If it's a kiosk app running in manual-launch kiosk session, then show | 111 // If it's a kiosk app running in manual-launch kiosk session, then show |
111 // the confirmation dialog. | 112 // the confirmation dialog. |
112 if (KioskModeInfo::IsKioskOnly(&extension) && | 113 if (KioskModeInfo::IsKioskOnly(&extension) && |
113 user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) { | 114 user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) { |
114 delegate_->ShowDialog(extension, volume, writable, | 115 delegate_->ShowDialog(extension, host, volume, writable, |
115 base::Bind(&DialogResultToConsent, callback)); | 116 base::Bind(&DialogResultToConsent, callback)); |
116 return; | 117 return; |
117 } | 118 } |
118 | 119 |
119 NOTREACHED() << "Cannot request consent for non-grantable extensions."; | 120 NOTREACHED() << "Cannot request consent for non-grantable extensions."; |
120 } | 121 } |
121 | 122 |
122 bool ConsentProvider::IsGrantable(const Extension& extension) { | 123 bool ConsentProvider::IsGrantable(const Extension& extension) { |
123 const bool is_whitelisted_component = | 124 const bool is_whitelisted_component = |
124 delegate_->IsWhitelistedComponent(extension); | 125 delegate_->IsWhitelistedComponent(extension); |
125 | 126 |
126 const bool is_running_in_kiosk_session = | 127 const bool is_running_in_kiosk_session = |
127 KioskModeInfo::IsKioskOnly(&extension) && | 128 KioskModeInfo::IsKioskOnly(&extension) && |
128 user_manager::UserManager::Get()->IsLoggedInAsKioskApp(); | 129 user_manager::UserManager::Get()->IsLoggedInAsKioskApp(); |
129 | 130 |
130 return is_whitelisted_component || is_running_in_kiosk_session; | 131 return is_whitelisted_component || is_running_in_kiosk_session; |
131 } | 132 } |
132 | 133 |
133 ConsentProviderDelegate::ConsentProviderDelegate(Profile* profile, | 134 ConsentProviderDelegate::ConsentProviderDelegate(Profile* profile) |
134 content::RenderFrameHost* host) | 135 : profile_(profile) { |
135 : profile_(profile), host_(host) { | |
136 DCHECK(profile_); | 136 DCHECK(profile_); |
137 } | 137 } |
138 | 138 |
139 ConsentProviderDelegate::~ConsentProviderDelegate() { | 139 ConsentProviderDelegate::~ConsentProviderDelegate() { |
140 } | 140 } |
141 | 141 |
142 // static | 142 // static |
143 void ConsentProviderDelegate::SetAutoDialogButtonForTest( | 143 void ConsentProviderDelegate::SetAutoDialogButtonForTest( |
144 ui::DialogButton button) { | 144 ui::DialogButton button) { |
145 g_auto_dialog_button_for_test = button; | 145 g_auto_dialog_button_for_test = button; |
146 } | 146 } |
147 | 147 |
148 void ConsentProviderDelegate::ShowDialog( | 148 void ConsentProviderDelegate::ShowDialog( |
149 const Extension& extension, | 149 const Extension& extension, |
| 150 content::RenderFrameHost* host, |
150 const base::WeakPtr<file_manager::Volume>& volume, | 151 const base::WeakPtr<file_manager::Volume>& volume, |
151 bool writable, | 152 bool writable, |
152 const file_system_api::ConsentProvider::ShowDialogCallback& callback) { | 153 const file_system_api::ConsentProvider::ShowDialogCallback& callback) { |
153 DCHECK(host_); | 154 DCHECK(host); |
154 content::WebContents* web_contents = nullptr; | 155 content::WebContents* web_contents = nullptr; |
155 | 156 |
156 // Find an app window to host the dialog. | 157 // Find an app window to host the dialog. |
157 content::WebContents* const foreground_contents = | 158 content::WebContents* const foreground_contents = |
158 content::WebContents::FromRenderFrameHost(host_); | 159 content::WebContents::FromRenderFrameHost(host); |
159 if (AppWindowRegistry::Get(profile_)->GetAppWindowForWebContents( | 160 if (AppWindowRegistry::Get(profile_)->GetAppWindowForWebContents( |
160 foreground_contents)) { | 161 foreground_contents)) { |
161 web_contents = foreground_contents; | 162 web_contents = foreground_contents; |
162 } | 163 } |
163 | 164 |
164 // If there is no web contents handle, then the method is most probably | 165 // If there is no web contents handle, then the method is most probably |
165 // executed from a background page. | 166 // executed from a background page. |
166 if (!web_contents) | 167 if (!web_contents) |
167 web_contents = GetWebContentsForAppId(profile_, extension.id()); | 168 web_contents = GetWebContentsForAppId(profile_, extension.id()); |
168 | 169 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 const Extension& extension) { | 214 const Extension& extension) { |
214 for (auto* whitelisted_id : kRequestFileSystemComponentWhitelist) { | 215 for (auto* whitelisted_id : kRequestFileSystemComponentWhitelist) { |
215 if (extension.id().compare(whitelisted_id) == 0) | 216 if (extension.id().compare(whitelisted_id) == 0) |
216 return true; | 217 return true; |
217 } | 218 } |
218 return false; | 219 return false; |
219 } | 220 } |
220 | 221 |
221 } // namespace file_system_api | 222 } // namespace file_system_api |
222 } // namespace extensions | 223 } // namespace extensions |
OLD | NEW |