| OLD | NEW |
| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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/extensions/api/file_system/request_file_system_notifica
tion.h" |
| 71 #include "chrome/browser/ui/simple_message_box.h" | 71 #include "chrome/browser/ui/simple_message_box.h" |
| 72 #include "components/user_manager/user_manager.h" | 72 #include "components/user_manager/user_manager.h" |
| 73 #include "extensions/browser/event_router.h" | |
| 74 #include "extensions/browser/extension_registry.h" | |
| 75 #include "extensions/common/constants.h" | 73 #include "extensions/common/constants.h" |
| 76 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" | 74 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" |
| 77 #include "url/url_constants.h" | 75 #include "url/url_constants.h" |
| 78 #endif | 76 #endif |
| 79 | 77 |
| 80 using apps::SavedFileEntry; | 78 using apps::SavedFileEntry; |
| 81 using apps::SavedFilesService; | 79 using apps::SavedFilesService; |
| 82 using storage::IsolatedContext; | 80 using storage::IsolatedContext; |
| 83 | 81 |
| 84 const char kInvalidCallingPage[] = "Invalid calling page. This function can't " | 82 const char kInvalidCallingPage[] = "Invalid calling page. This function can't " |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 // with |app_id|. If not found, then returns NULL. | 240 // with |app_id|. If not found, then returns NULL. |
| 243 content::WebContents* GetWebContentsForAppId(Profile* profile, | 241 content::WebContents* GetWebContentsForAppId(Profile* profile, |
| 244 const std::string& app_id) { | 242 const std::string& app_id) { |
| 245 extensions::AppWindowRegistry* const registry = | 243 extensions::AppWindowRegistry* const registry = |
| 246 extensions::AppWindowRegistry::Get(profile); | 244 extensions::AppWindowRegistry::Get(profile); |
| 247 DCHECK(registry); | 245 DCHECK(registry); |
| 248 extensions::AppWindow* const app_window = | 246 extensions::AppWindow* const app_window = |
| 249 registry->GetCurrentAppWindowForApp(app_id); | 247 registry->GetCurrentAppWindowForApp(app_id); |
| 250 return app_window ? app_window->web_contents() : nullptr; | 248 return app_window ? app_window->web_contents() : nullptr; |
| 251 } | 249 } |
| 252 | |
| 253 // Fills a list of volumes mounted in the system. | |
| 254 void FillVolumeList( | |
| 255 Profile* profile, | |
| 256 std::vector<linked_ptr<extensions::api::file_system::Volume>>* result) { | |
| 257 using file_manager::VolumeManager; | |
| 258 VolumeManager* const volume_manager = VolumeManager::Get(profile); | |
| 259 DCHECK(volume_manager); | |
| 260 | |
| 261 using extensions::api::file_system::Volume; | |
| 262 const auto& volume_list = volume_manager->GetVolumeList(); | |
| 263 // Convert volume_list to result_volume_list. | |
| 264 for (const auto& volume : volume_list) { | |
| 265 const linked_ptr<Volume> result_volume(new Volume); | |
| 266 result_volume->volume_id = volume->volume_id(); | |
| 267 result_volume->writable = !volume->is_read_only(); | |
| 268 result->push_back(result_volume); | |
| 269 } | |
| 270 } | |
| 271 #endif | 250 #endif |
| 272 | 251 |
| 273 } // namespace | 252 } // namespace |
| 274 | 253 |
| 275 namespace extensions { | 254 namespace extensions { |
| 276 | 255 |
| 277 namespace file_system_api { | 256 namespace file_system_api { |
| 278 | 257 |
| 279 base::FilePath GetLastChooseEntryDirectory(const ExtensionPrefs* prefs, | 258 base::FilePath GetLastChooseEntryDirectory(const ExtensionPrefs* prefs, |
| 280 const std::string& extension_id) { | 259 const std::string& extension_id) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 300 std::vector<base::FilePath> graylisted_directories; | 279 std::vector<base::FilePath> graylisted_directories; |
| 301 for (size_t i = 0; i < arraysize(kGraylistedPaths); ++i) { | 280 for (size_t i = 0; i < arraysize(kGraylistedPaths); ++i) { |
| 302 base::FilePath graylisted_path; | 281 base::FilePath graylisted_path; |
| 303 if (PathService::Get(kGraylistedPaths[i], &graylisted_path)) | 282 if (PathService::Get(kGraylistedPaths[i], &graylisted_path)) |
| 304 graylisted_directories.push_back(graylisted_path); | 283 graylisted_directories.push_back(graylisted_path); |
| 305 } | 284 } |
| 306 return graylisted_directories; | 285 return graylisted_directories; |
| 307 } | 286 } |
| 308 | 287 |
| 309 #if defined(OS_CHROMEOS) | 288 #if defined(OS_CHROMEOS) |
| 310 void DispatchVolumeListChangeEvent(Profile* profile) { | |
| 311 DCHECK(profile); | |
| 312 EventRouter* const event_router = EventRouter::Get(profile); | |
| 313 if (!event_router) // Possible on shutdown. | |
| 314 return; | |
| 315 | |
| 316 extensions::ExtensionRegistry* const registry = | |
| 317 extensions::ExtensionRegistry::Get(profile); | |
| 318 if (!registry) // Possible on shutdown. | |
| 319 return; | |
| 320 | |
| 321 ConsentProvider consent_provider( | |
| 322 new ConsentProviderDelegate(profile, nullptr)); | |
| 323 extensions::api::file_system::VolumeListChangedEvent event_args; | |
| 324 FillVolumeList(profile, &event_args.volumes); | |
| 325 for (const auto& extension : registry->enabled_extensions()) { | |
| 326 if (!consent_provider.IsGrantable(*extension.get())) | |
| 327 continue; | |
| 328 event_router->DispatchEventToExtension( | |
| 329 extension->id(), | |
| 330 make_scoped_ptr(new Event( | |
| 331 extensions::api::file_system::OnVolumeListChanged::kEventName, | |
| 332 extensions::api::file_system::OnVolumeListChanged::Create( | |
| 333 event_args)))); | |
| 334 } | |
| 335 } | |
| 336 | |
| 337 ConsentProvider::ConsentProvider(DelegateInterface* delegate) | 289 ConsentProvider::ConsentProvider(DelegateInterface* delegate) |
| 338 : delegate_(delegate) { | 290 : delegate_(delegate) { |
| 339 DCHECK(delegate_); | 291 DCHECK(delegate_); |
| 340 } | 292 } |
| 341 | 293 |
| 342 ConsentProvider::~ConsentProvider() { | 294 ConsentProvider::~ConsentProvider() { |
| 343 } | 295 } |
| 344 | 296 |
| 345 void ConsentProvider::RequestConsent( | 297 void ConsentProvider::RequestConsent( |
| 346 const extensions::Extension& extension, | 298 const extensions::Extension& extension, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 case ui::DIALOG_BUTTON_CANCEL: | 354 case ui::DIALOG_BUTTON_CANCEL: |
| 403 callback.Run(CONSENT_REJECTED); | 355 callback.Run(CONSENT_REJECTED); |
| 404 break; | 356 break; |
| 405 } | 357 } |
| 406 } | 358 } |
| 407 | 359 |
| 408 ConsentProviderDelegate::ConsentProviderDelegate(Profile* profile, | 360 ConsentProviderDelegate::ConsentProviderDelegate(Profile* profile, |
| 409 content::RenderViewHost* host) | 361 content::RenderViewHost* host) |
| 410 : profile_(profile), host_(host) { | 362 : profile_(profile), host_(host) { |
| 411 DCHECK(profile_); | 363 DCHECK(profile_); |
| 364 DCHECK(host_); |
| 412 } | 365 } |
| 413 | 366 |
| 414 ConsentProviderDelegate::~ConsentProviderDelegate() { | 367 ConsentProviderDelegate::~ConsentProviderDelegate() { |
| 415 } | 368 } |
| 416 | 369 |
| 417 // static | 370 // static |
| 418 void ConsentProviderDelegate::SetAutoDialogButtonForTest( | 371 void ConsentProviderDelegate::SetAutoDialogButtonForTest( |
| 419 ui::DialogButton button) { | 372 ui::DialogButton button) { |
| 420 g_auto_dialog_button_for_test = button; | 373 g_auto_dialog_button_for_test = button; |
| 421 } | 374 } |
| 422 | 375 |
| 423 void ConsentProviderDelegate::ShowDialog( | 376 void ConsentProviderDelegate::ShowDialog( |
| 424 const extensions::Extension& extension, | 377 const extensions::Extension& extension, |
| 425 const base::WeakPtr<file_manager::Volume>& volume, | 378 const base::WeakPtr<file_manager::Volume>& volume, |
| 426 bool writable, | 379 bool writable, |
| 427 const file_system_api::ConsentProvider::ShowDialogCallback& callback) { | 380 const file_system_api::ConsentProvider::ShowDialogCallback& callback) { |
| 428 DCHECK(host_); | |
| 429 content::WebContents* const foreground_contents = | 381 content::WebContents* const foreground_contents = |
| 430 GetWebContentsForRenderViewHost(profile_, host_); | 382 GetWebContentsForRenderViewHost(profile_, host_); |
| 431 // 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 |
| 432 // 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. |
| 433 content::WebContents* const web_contents = | 385 content::WebContents* const web_contents = |
| 434 foreground_contents ? foreground_contents | 386 foreground_contents ? foreground_contents |
| 435 : GetWebContentsForAppId(profile_, extension.id()); | 387 : GetWebContentsForAppId(profile_, extension.id()); |
| 436 if (!web_contents) { | 388 if (!web_contents) { |
| 437 base::ThreadTaskRunnerHandle::Get()->PostTask( | 389 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 438 FROM_HERE, base::Bind(callback, ui::DIALOG_BUTTON_NONE)); | 390 FROM_HERE, base::Bind(callback, ui::DIALOG_BUTTON_NONE)); |
| (...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1441 | 1393 |
| 1442 ExtensionFunction::ResponseAction FileSystemGetVolumeListFunction::Run() { | 1394 ExtensionFunction::ResponseAction FileSystemGetVolumeListFunction::Run() { |
| 1443 // Only kiosk apps in kiosk sessions can use this API. | 1395 // Only kiosk apps in kiosk sessions can use this API. |
| 1444 // Additionally it is enabled for whitelisted component extensions and apps. | 1396 // Additionally it is enabled for whitelisted component extensions and apps. |
| 1445 file_system_api::ConsentProviderDelegate consent_provider_delegate( | 1397 file_system_api::ConsentProviderDelegate consent_provider_delegate( |
| 1446 chrome_details_.GetProfile(), render_view_host()); | 1398 chrome_details_.GetProfile(), render_view_host()); |
| 1447 file_system_api::ConsentProvider consent_provider(&consent_provider_delegate); | 1399 file_system_api::ConsentProvider consent_provider(&consent_provider_delegate); |
| 1448 | 1400 |
| 1449 if (!consent_provider.IsGrantable(*extension())) | 1401 if (!consent_provider.IsGrantable(*extension())) |
| 1450 return RespondNow(Error(kNotSupportedOnNonKioskSessionError)); | 1402 return RespondNow(Error(kNotSupportedOnNonKioskSessionError)); |
| 1403 |
| 1404 using file_manager::VolumeManager; |
| 1405 VolumeManager* const volume_manager = |
| 1406 VolumeManager::Get(chrome_details_.GetProfile()); |
| 1407 DCHECK(volume_manager); |
| 1408 |
| 1451 using extensions::api::file_system::Volume; | 1409 using extensions::api::file_system::Volume; |
| 1410 const auto& volume_list = volume_manager->GetVolumeList(); |
| 1452 std::vector<linked_ptr<Volume>> result_volume_list; | 1411 std::vector<linked_ptr<Volume>> result_volume_list; |
| 1453 FillVolumeList(chrome_details_.GetProfile(), &result_volume_list); | 1412 // Convert volume_list to result_volume_list. |
| 1413 for (const auto& volume : volume_list) { |
| 1414 const linked_ptr<Volume> result_volume(new Volume); |
| 1415 result_volume->volume_id = volume->volume_id(); |
| 1416 result_volume->writable = !volume->is_read_only(); |
| 1417 result_volume_list.push_back(result_volume); |
| 1418 } |
| 1454 | 1419 |
| 1455 return RespondNow( | 1420 return RespondNow( |
| 1456 ArgumentList(extensions::api::file_system::GetVolumeList::Results::Create( | 1421 ArgumentList(extensions::api::file_system::GetVolumeList::Results::Create( |
| 1457 result_volume_list).Pass())); | 1422 result_volume_list).Pass())); |
| 1458 } | 1423 } |
| 1459 #endif | 1424 #endif |
| 1460 | 1425 |
| 1461 } // namespace extensions | 1426 } // namespace extensions |
| OLD | NEW |