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

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. Created 5 years, 8 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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 287
287 #if defined(OS_CHROMEOS) 288 #if defined(OS_CHROMEOS)
288 ConsentProvider::ConsentProvider(DelegateInterface* delegate) 289 ConsentProvider::ConsentProvider(DelegateInterface* delegate)
289 : delegate_(delegate) { 290 : delegate_(delegate) {
290 DCHECK(delegate_); 291 DCHECK(delegate_);
291 } 292 }
292 293
293 ConsentProvider::~ConsentProvider() { 294 ConsentProvider::~ConsentProvider() {
294 } 295 }
295 296
296 void ConsentProvider::RequestConsent(const extensions::Extension& extension, 297 void ConsentProvider::RequestConsent(
297 base::WeakPtr<file_manager::Volume> volume, 298 const extensions::Extension& extension,
298 bool writable, 299 const base::WeakPtr<file_manager::Volume>& volume,
299 const ConsentCallback& callback) { 300 bool writable,
301 const ConsentCallback& callback) {
300 DCHECK(IsGrantable(extension)); 302 DCHECK(IsGrantable(extension));
301 303
302 // If auto-launched kiosk app, then no need to ask user. 304 // If a whitelisted component, then no need to ask or inform the user.
303 if (delegate_->IsAutoLaunched(extension)) { 305 if (extension.location() == Manifest::COMPONENT &&
306 delegate_->IsWhitelistedComponent(extension)) {
304 base::ThreadTaskRunnerHandle::Get()->PostTask( 307 base::ThreadTaskRunnerHandle::Get()->PostTask(
305 FROM_HERE, base::Bind(callback, CONSENT_GRANTED)); 308 FROM_HERE, base::Bind(callback, CONSENT_GRANTED));
306 return; 309 return;
307 } 310 }
308 311
309 // If a whitelisted component, then no need to ask user, either. 312 // If auto-launched kiosk app, then no need to ask user either, but show the
310 if (extension.location() == Manifest::COMPONENT && 313 // notification.
311 delegate_->IsWhitelistedComponent(extension)) { 314 if (delegate_->IsAutoLaunched(extension)) {
315 delegate_->ShowNotification(extension, volume, writable);
312 base::ThreadTaskRunnerHandle::Get()->PostTask( 316 base::ThreadTaskRunnerHandle::Get()->PostTask(
313 FROM_HERE, base::Bind(callback, CONSENT_GRANTED)); 317 FROM_HERE, base::Bind(callback, CONSENT_GRANTED));
314 return; 318 return;
315 } 319 }
316 320
317 // If it's a kiosk app running in manual-launch kiosk session, then show 321 // If it's a kiosk app running in manual-launch kiosk session, then show
318 // the confirmation dialog. 322 // the confirmation dialog.
319 if (KioskModeInfo::IsKioskOnly(&extension) && 323 if (KioskModeInfo::IsKioskOnly(&extension) &&
320 user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) { 324 user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) {
321 delegate_->ShowDialog(extension, volume, writable, 325 delegate_->ShowDialog(extension, volume, writable,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 } 368 }
365 369
366 // static 370 // static
367 void ConsentProviderDelegate::SetAutoDialogButtonForTest( 371 void ConsentProviderDelegate::SetAutoDialogButtonForTest(
368 ui::DialogButton button) { 372 ui::DialogButton button) {
369 g_auto_dialog_button_for_test = button; 373 g_auto_dialog_button_for_test = button;
370 } 374 }
371 375
372 void ConsentProviderDelegate::ShowDialog( 376 void ConsentProviderDelegate::ShowDialog(
373 const extensions::Extension& extension, 377 const extensions::Extension& extension,
374 base::WeakPtr<file_manager::Volume> volume, 378 const base::WeakPtr<file_manager::Volume>& volume,
375 bool writable, 379 bool writable,
376 const file_system_api::ConsentProvider::ShowDialogCallback& callback) { 380 const file_system_api::ConsentProvider::ShowDialogCallback& callback) {
377 content::WebContents* const foreground_contents = 381 content::WebContents* const foreground_contents =
378 GetWebContentsForRenderViewHost(profile_, host_); 382 GetWebContentsForRenderViewHost(profile_, host_);
379 // If there is no web contents handle, then the method is most probably 383 // If there is no web contents handle, then the method is most probably
380 // executed from a background page. Find an app window to host the dialog. 384 // executed from a background page. Find an app window to host the dialog.
381 content::WebContents* const web_contents = 385 content::WebContents* const web_contents =
382 foreground_contents ? foreground_contents 386 foreground_contents ? foreground_contents
383 : GetWebContentsForAppId(profile_, extension.id()); 387 : GetWebContentsForAppId(profile_, extension.id());
384 if (!web_contents) { 388 if (!web_contents) {
385 base::ThreadTaskRunnerHandle::Get()->PostTask( 389 base::ThreadTaskRunnerHandle::Get()->PostTask(
386 FROM_HERE, base::Bind(callback, ui::DIALOG_BUTTON_NONE)); 390 FROM_HERE, base::Bind(callback, ui::DIALOG_BUTTON_NONE));
387 return; 391 return;
388 } 392 }
389 393
390 // Short circuit the user consent dialog for tests. This is far from a pretty 394 // Short circuit the user consent dialog for tests. This is far from a pretty
391 // code design. 395 // code design.
392 if (g_auto_dialog_button_for_test != ui::DIALOG_BUTTON_NONE) { 396 if (g_auto_dialog_button_for_test != ui::DIALOG_BUTTON_NONE) {
393 base::ThreadTaskRunnerHandle::Get()->PostTask( 397 base::ThreadTaskRunnerHandle::Get()->PostTask(
394 FROM_HERE, 398 FROM_HERE,
395 base::Bind(callback, g_auto_dialog_button_for_test /* result */)); 399 base::Bind(callback, g_auto_dialog_button_for_test /* result */));
396 return; 400 return;
397 } 401 }
398 402
399 RequestFileSystemDialogView::ShowDialog(web_contents, extension, volume, 403 RequestFileSystemDialogView::ShowDialog(web_contents, extension, volume,
400 writable, base::Bind(callback)); 404 writable, base::Bind(callback));
401 } 405 }
402 406
407 void ConsentProviderDelegate::ShowNotification(
408 const extensions::Extension& extension,
409 const base::WeakPtr<file_manager::Volume>& volume,
410 bool writable) {
411 RequestFileSystemNotification::ShowAutoGrantedNotification(
412 profile_, extension, volume, writable);
413 }
414
403 bool ConsentProviderDelegate::IsAutoLaunched( 415 bool ConsentProviderDelegate::IsAutoLaunched(
404 const extensions::Extension& extension) { 416 const extensions::Extension& extension) {
405 chromeos::KioskAppManager::App app_info; 417 chromeos::KioskAppManager::App app_info;
406 return chromeos::KioskAppManager::Get()->GetApp(extension.id(), &app_info) && 418 return chromeos::KioskAppManager::Get()->GetApp(extension.id(), &app_info) &&
407 app_info.was_auto_launched_with_zero_delay; 419 app_info.was_auto_launched_with_zero_delay;
408 } 420 }
409 421
410 bool ConsentProviderDelegate::IsWhitelistedComponent( 422 bool ConsentProviderDelegate::IsWhitelistedComponent(
411 const extensions::Extension& extension) { 423 const extensions::Extension& extension) {
412 for (const auto& whitelisted_id : kRequestFileSystemComponentWhitelist) { 424 for (const auto& whitelisted_id : kRequestFileSystemComponentWhitelist) {
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 return RespondNow(Error(kSecurityError)); 1275 return RespondNow(Error(kSecurityError));
1264 1276
1265 consent_provider.RequestConsent( 1277 consent_provider.RequestConsent(
1266 *extension(), volume, writable, 1278 *extension(), volume, writable,
1267 base::Bind(&FileSystemRequestFileSystemFunction::OnConsentReceived, this, 1279 base::Bind(&FileSystemRequestFileSystemFunction::OnConsentReceived, this,
1268 volume, writable)); 1280 volume, writable));
1269 return RespondLater(); 1281 return RespondLater();
1270 } 1282 }
1271 1283
1272 void FileSystemRequestFileSystemFunction::OnConsentReceived( 1284 void FileSystemRequestFileSystemFunction::OnConsentReceived(
1273 base::WeakPtr<file_manager::Volume> volume, 1285 const base::WeakPtr<file_manager::Volume>& volume,
1274 bool writable, 1286 bool writable,
1275 ConsentProvider::Consent result) { 1287 ConsentProvider::Consent result) {
1276 using file_manager::VolumeManager; 1288 using file_manager::VolumeManager;
1277 using file_manager::Volume; 1289 using file_manager::Volume;
1278 1290
1279 switch (result) { 1291 switch (result) {
1280 case ConsentProvider::CONSENT_REJECTED: 1292 case ConsentProvider::CONSENT_REJECTED:
1281 SetError(kSecurityError); 1293 SetError(kSecurityError);
1282 SendResponse(false); 1294 SendResponse(false);
1283 return; 1295 return;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 result_volume_list.push_back(result_volume); 1417 result_volume_list.push_back(result_volume);
1406 } 1418 }
1407 1419
1408 return RespondNow( 1420 return RespondNow(
1409 ArgumentList(extensions::api::file_system::GetVolumeList::Results::Create( 1421 ArgumentList(extensions::api::file_system::GetVolumeList::Results::Create(
1410 result_volume_list).Pass())); 1422 result_volume_list).Pass()));
1411 } 1423 }
1412 #endif 1424 #endif
1413 1425
1414 } // namespace extensions 1426 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698