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

Side by Side Diff: chrome/browser/extensions/api/file_system/file_system_api.cc

Issue 1032313002: Add a notification about auto-granted access to file systems. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed the string. Created 5 years, 9 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 (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 #include "chrome/browser/extensions/api/file_system/file_system_api.h" 5 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "apps/saved_files_service.h" 10 #include "apps/saved_files_service.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 #endif 60 #endif
61 61
62 #if defined(OS_CHROMEOS) 62 #if defined(OS_CHROMEOS)
63 #include "base/prefs/testing_pref_service.h" 63 #include "base/prefs/testing_pref_service.h"
64 #include "base/strings/string16.h" 64 #include "base/strings/string16.h"
65 #include "base/thread_task_runner_handle.h" 65 #include "base/thread_task_runner_handle.h"
66 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" 66 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
67 #include "chrome/browser/chromeos/file_manager/app_id.h" 67 #include "chrome/browser/chromeos/file_manager/app_id.h"
68 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h" 68 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h"
69 #include "chrome/browser/extensions/api/file_system/request_file_system_dialog_v iew.h" 69 #include "chrome/browser/extensions/api/file_system/request_file_system_dialog_v iew.h"
70 #include "chrome/browser/extensions/api/file_system/request_file_system_notifica tion.h"
70 #include "chrome/browser/ui/simple_message_box.h" 71 #include "chrome/browser/ui/simple_message_box.h"
71 #include "components/user_manager/user_manager.h" 72 #include "components/user_manager/user_manager.h"
72 #include "extensions/common/constants.h" 73 #include "extensions/common/constants.h"
73 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" 74 #include "extensions/common/manifest_handlers/kiosk_mode_info.h"
74 #include "url/url_constants.h" 75 #include "url/url_constants.h"
75 #endif 76 #endif
76 77
77 using apps::SavedFileEntry; 78 using apps::SavedFileEntry;
78 using apps::SavedFilesService; 79 using apps::SavedFilesService;
79 using storage::IsolatedContext; 80 using storage::IsolatedContext;
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 std::vector<base::FilePath> graylisted_directories; 274 std::vector<base::FilePath> graylisted_directories;
274 for (size_t i = 0; i < arraysize(kGraylistedPaths); ++i) { 275 for (size_t i = 0; i < arraysize(kGraylistedPaths); ++i) {
275 base::FilePath graylisted_path; 276 base::FilePath graylisted_path;
276 if (PathService::Get(kGraylistedPaths[i], &graylisted_path)) 277 if (PathService::Get(kGraylistedPaths[i], &graylisted_path))
277 graylisted_directories.push_back(graylisted_path); 278 graylisted_directories.push_back(graylisted_path);
278 } 279 }
279 return graylisted_directories; 280 return graylisted_directories;
280 } 281 }
281 282
282 #if defined(OS_CHROMEOS) 283 #if defined(OS_CHROMEOS)
283 ConsentProvider::ConsentProvider( 284 ConsentProvider::ConsentProvider(const AskUserCallback& ask_user_callback,
284 const UserConsentRequestCallback& user_consent_request_callback) 285 const NotifyUserCallback& notify_user_callback)
285 : user_consent_request_callback_(user_consent_request_callback), 286 : ask_user_callback_(ask_user_callback),
287 notify_user_callback_(notify_user_callback),
286 is_auto_launched_callback_(base::Bind(&ConsentProvider::IsAutoLaunched, 288 is_auto_launched_callback_(base::Bind(&ConsentProvider::IsAutoLaunched,
287 base::Unretained(this))) { 289 base::Unretained(this))) {
288 for (const auto& whitelisted_id : kRequestFileSystemComponentWhitelist) 290 for (const auto& whitelisted_id : kRequestFileSystemComponentWhitelist)
289 component_whitelist_.insert(whitelisted_id); 291 component_whitelist_.insert(whitelisted_id);
290 } 292 }
291 293
292 ConsentProvider::ConsentProvider() 294 ConsentProvider::ConsentProvider()
293 : is_auto_launched_callback_(base::Bind(&ConsentProvider::IsAutoLaunched, 295 : is_auto_launched_callback_(base::Bind(&ConsentProvider::IsAutoLaunched,
294 base::Unretained(this))) { 296 base::Unretained(this))) {
295 for (const auto& whitelisted_id : kRequestFileSystemComponentWhitelist) 297 for (const auto& whitelisted_id : kRequestFileSystemComponentWhitelist)
296 component_whitelist_.insert(whitelisted_id); 298 component_whitelist_.insert(whitelisted_id);
297 } 299 }
298 300
299 ConsentProvider::~ConsentProvider() { 301 ConsentProvider::~ConsentProvider() {
300 } 302 }
301 303
302 void ConsentProvider::RequestConsent( 304 void ConsentProvider::RequestConsent(
303 const extensions::Extension& extension, 305 const extensions::Extension& extension,
304 const file_manager::VolumeInfo& volume_info, 306 const file_manager::VolumeInfo& volume_info,
305 bool writable, 307 bool writable,
306 const ConsentCallback& callback) { 308 const ConsentCallback& callback) {
307 if (!IsGrantable(extension)) { 309 if (!IsGrantable(extension)) {
308 base::ThreadTaskRunnerHandle::Get()->PostTask( 310 base::ThreadTaskRunnerHandle::Get()->PostTask(
309 FROM_HERE, base::Bind(callback, CONSENT_REJECTED)); 311 FROM_HERE, base::Bind(callback, CONSENT_REJECTED));
310 return; 312 return;
311 } 313 }
312 314
313 const bool is_auto_launched = is_auto_launched_callback_.Run(extension); 315 const bool is_auto_launched = is_auto_launched_callback_.Run(extension);
314 const bool requires_consent =
315 !is_auto_launched && extension.location() != Manifest::COMPONENT;
316 316
317 if (!requires_consent) { 317 if (extension.location() == Manifest::COMPONENT) {
318 // Grant the permission without showing the dialog. 318 // Grant the permission without showing the dialog or notification.
319 base::ThreadTaskRunnerHandle::Get()->PostTask( 319 base::ThreadTaskRunnerHandle::Get()->PostTask(
320 FROM_HERE, base::Bind(callback, CONSENT_GRANTED)); 320 FROM_HERE, base::Bind(callback, CONSENT_GRANTED));
321 } else { 321 return;
322 DCHECK(!user_consent_request_callback_.is_null()); 322 } else if (is_auto_launched) {
323 // Grant the permission without showing the dialog, but with a notification.
324 DCHECK(!notify_user_callback_.is_null());
323 base::ThreadTaskRunnerHandle::Get()->PostTask( 325 base::ThreadTaskRunnerHandle::Get()->PostTask(
324 FROM_HERE, base::Bind(user_consent_request_callback_, volume_info, 326 FROM_HERE, base::Bind(notify_user_callback_, volume_info, writable));
325 writable, callback)); 327 base::ThreadTaskRunnerHandle::Get()->PostTask(
328 FROM_HERE, base::Bind(callback, CONSENT_GRANTED));
329 return;
326 } 330 }
331
332 // By default ask for user consent.
333 DCHECK(!ask_user_callback_.is_null());
334 base::ThreadTaskRunnerHandle::Get()->PostTask(
335 FROM_HERE,
336 base::Bind(ask_user_callback_, volume_info, writable, callback));
327 } 337 }
328 338
329 bool ConsentProvider::IsGrantable(const Extension& extension) { 339 bool ConsentProvider::IsGrantable(const Extension& extension) {
330 bool is_whitelisted_component = 340 bool is_whitelisted_component =
331 component_whitelist_.find(extension.id()) != component_whitelist_.end(); 341 component_whitelist_.find(extension.id()) != component_whitelist_.end();
332 342
333 const bool is_running_in_kiosk_session = 343 const bool is_running_in_kiosk_session =
334 KioskModeInfo::IsKioskOnly(&extension) && 344 KioskModeInfo::IsKioskOnly(&extension) &&
335 user_manager::UserManager::Get()->IsLoggedInAsKioskApp(); 345 user_manager::UserManager::Get()->IsLoggedInAsKioskApp();
336 346
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 1135
1126 bool FileSystemGetObservedEntriesFunction::RunSync() { 1136 bool FileSystemGetObservedEntriesFunction::RunSync() {
1127 NOTIMPLEMENTED(); 1137 NOTIMPLEMENTED();
1128 error_ = kUnknownIdError; 1138 error_ = kUnknownIdError;
1129 return false; 1139 return false;
1130 } 1140 }
1131 1141
1132 FileSystemRequestFileSystemFunction::FileSystemRequestFileSystemFunction() 1142 FileSystemRequestFileSystemFunction::FileSystemRequestFileSystemFunction()
1133 : chrome_details_(this) { 1143 : chrome_details_(this) {
1134 #if defined(OS_CHROMEOS) 1144 #if defined(OS_CHROMEOS)
1135 consent_provider_.reset(new ConsentProvider(base::Bind( 1145 consent_provider_.reset(new ConsentProvider(
1136 &FileSystemRequestFileSystemFunction::OnUserConsentRequested, this))); 1146 base::Bind(&FileSystemRequestFileSystemFunction::OnAskUser, this),
1147 base::Bind(&FileSystemRequestFileSystemFunction::OnNotifyUser, this)));
1137 #endif 1148 #endif
1138 } 1149 }
1139 1150
1140 FileSystemRequestFileSystemFunction::~FileSystemRequestFileSystemFunction() { 1151 FileSystemRequestFileSystemFunction::~FileSystemRequestFileSystemFunction() {
1141 } 1152 }
1142 1153
1143 ExtensionFunction::ResponseAction FileSystemRequestFileSystemFunction::Run() { 1154 ExtensionFunction::ResponseAction FileSystemRequestFileSystemFunction::Run() {
1144 using extensions::api::file_system::RequestFileSystem::Params; 1155 using extensions::api::file_system::RequestFileSystem::Params;
1145 const scoped_ptr<Params> params(Params::Create(*args_)); 1156 const scoped_ptr<Params> params(Params::Create(*args_));
1146 EXTENSION_FUNCTION_VALIDATE(params); 1157 EXTENSION_FUNCTION_VALIDATE(params);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 ui::DialogButton 1214 ui::DialogButton
1204 FileSystemRequestFileSystemFunction::auto_dialog_button_for_testing_ = 1215 FileSystemRequestFileSystemFunction::auto_dialog_button_for_testing_ =
1205 ui::DIALOG_BUTTON_NONE; 1216 ui::DIALOG_BUTTON_NONE;
1206 1217
1207 // static 1218 // static
1208 void FileSystemRequestFileSystemFunction::SetAutoDialogButtonForTesting( 1219 void FileSystemRequestFileSystemFunction::SetAutoDialogButtonForTesting(
1209 ui::DialogButton button) { 1220 ui::DialogButton button) {
1210 FileSystemRequestFileSystemFunction::auto_dialog_button_for_testing_ = button; 1221 FileSystemRequestFileSystemFunction::auto_dialog_button_for_testing_ = button;
1211 } 1222 }
1212 1223
1213 void FileSystemRequestFileSystemFunction::OnUserConsentRequested( 1224 void FileSystemRequestFileSystemFunction::OnAskUser(
1214 const file_manager::VolumeInfo& volume_info, 1225 const file_manager::VolumeInfo& volume_info,
1215 bool writable, 1226 bool writable,
1216 const ConsentProvider::ConsentCallback& callback) { 1227 const ConsentProvider::ConsentCallback& callback) {
1217 // The object deletes itself once the dialog is closed. 1228 // The object deletes itself once the dialog is closed.
1218 content::WebContents* const foreground_contents = 1229 content::WebContents* const foreground_contents =
1219 GetWebContentsForRenderViewHost(chrome_details_.GetProfile(), 1230 GetWebContentsForRenderViewHost(chrome_details_.GetProfile(),
1220 render_view_host()); 1231 render_view_host());
1221 // If there is no web contents handle, then the method is most probably 1232 // If there is no web contents handle, then the method is most probably
1222 // executed from a background page. Find an app window to host the dialog. 1233 // executed from a background page. Find an app window to host the dialog.
1223 content::WebContents* const web_contents = 1234 content::WebContents* const web_contents =
(...skipping 17 matching lines...) Expand all
1241 return; 1252 return;
1242 } 1253 }
1243 1254
1244 RequestFileSystemDialogView::ShowDialog( 1255 RequestFileSystemDialogView::ShowDialog(
1245 web_contents, *extension(), volume_info, writable, 1256 web_contents, *extension(), volume_info, writable,
1246 base::Bind( 1257 base::Bind(
1247 &FileSystemRequestFileSystemFunction::OnUserConsentDialogClosed, this, 1258 &FileSystemRequestFileSystemFunction::OnUserConsentDialogClosed, this,
1248 callback)); 1259 callback));
1249 } 1260 }
1250 1261
1262 void FileSystemRequestFileSystemFunction::OnNotifyUser(
1263 const file_manager::VolumeInfo& volume_info,
1264 bool writable) {
1265 RequestFileSystemNotification::ShowAutoGrantedNotification(
1266 chrome_details_.GetProfile(), *extension(), volume_info, writable);
1267 }
1268
1251 void FileSystemRequestFileSystemFunction::OnUserConsentDialogClosed( 1269 void FileSystemRequestFileSystemFunction::OnUserConsentDialogClosed(
1252 const ConsentProvider::ConsentCallback& callback, 1270 const ConsentProvider::ConsentCallback& callback,
1253 ui::DialogButton result) { 1271 ui::DialogButton result) {
1254 callback.Run(result == ui::DIALOG_BUTTON_OK 1272 callback.Run(result == ui::DIALOG_BUTTON_OK
1255 ? ConsentProvider::CONSENT_GRANTED 1273 ? ConsentProvider::CONSENT_GRANTED
1256 : ConsentProvider::CONSENT_REJECTED); 1274 : ConsentProvider::CONSENT_REJECTED);
1257 } 1275 }
1258 1276
1259 void FileSystemRequestFileSystemFunction::OnConsentReceived( 1277 void FileSystemRequestFileSystemFunction::OnConsentReceived(
1260 const std::string& volume_id, 1278 const std::string& volume_id,
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 volume_list.push_back(volume); 1424 volume_list.push_back(volume);
1407 } 1425 }
1408 1426
1409 return RespondNow( 1427 return RespondNow(
1410 ArgumentList(extensions::api::file_system::GetVolumeList::Results::Create( 1428 ArgumentList(extensions::api::file_system::GetVolumeList::Results::Create(
1411 volume_list).Pass())); 1429 volume_list).Pass()));
1412 #endif 1430 #endif
1413 } 1431 }
1414 1432
1415 } // namespace extensions 1433 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698