| 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 // Implements the Chrome Extensions Media Galleries API. | 5 // Implements the Chrome Extensions Media Galleries API. |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/api/media_galleries/media_galleries_api.h" | 7 #include "chrome/browser/extensions/api/media_galleries/media_galleries_api.h" |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 return; | 361 return; |
| 362 | 362 |
| 363 scoped_ptr<extensions::Event> event( | 363 scoped_ptr<extensions::Event> event( |
| 364 new extensions::Event(event_name, event_args.Pass())); | 364 new extensions::Event(event_name, event_args.Pass())); |
| 365 router->DispatchEventToExtension(extension_id, event.Pass()); | 365 router->DispatchEventToExtension(extension_id, event.Pass()); |
| 366 } | 366 } |
| 367 | 367 |
| 368 MediaGalleriesGetMediaFileSystemsFunction:: | 368 MediaGalleriesGetMediaFileSystemsFunction:: |
| 369 ~MediaGalleriesGetMediaFileSystemsFunction() {} | 369 ~MediaGalleriesGetMediaFileSystemsFunction() {} |
| 370 | 370 |
| 371 bool MediaGalleriesGetMediaFileSystemsFunction::RunImpl() { | 371 bool MediaGalleriesGetMediaFileSystemsFunction::RunAsync() { |
| 372 media_galleries::UsageCount(media_galleries::GET_MEDIA_FILE_SYSTEMS); | 372 media_galleries::UsageCount(media_galleries::GET_MEDIA_FILE_SYSTEMS); |
| 373 scoped_ptr<GetMediaFileSystems::Params> params( | 373 scoped_ptr<GetMediaFileSystems::Params> params( |
| 374 GetMediaFileSystems::Params::Create(*args_)); | 374 GetMediaFileSystems::Params::Create(*args_)); |
| 375 EXTENSION_FUNCTION_VALIDATE(params.get()); | 375 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 376 MediaGalleries::GetMediaFileSystemsInteractivity interactive = | 376 MediaGalleries::GetMediaFileSystemsInteractivity interactive = |
| 377 MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NO; | 377 MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NO; |
| 378 if (params->details.get() && params->details->interactive != MediaGalleries:: | 378 if (params->details.get() && params->details->interactive != MediaGalleries:: |
| 379 GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NONE) { | 379 GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NONE) { |
| 380 interactive = params->details->interactive; | 380 interactive = params->details->interactive; |
| 381 } | 381 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 } | 469 } |
| 470 MediaFileSystemRegistry* registry = media_file_system_registry(); | 470 MediaFileSystemRegistry* registry = media_file_system_registry(); |
| 471 DCHECK(registry->GetPreferences(GetProfile())->IsInitialized()); | 471 DCHECK(registry->GetPreferences(GetProfile())->IsInitialized()); |
| 472 registry->GetMediaFileSystemsForExtension( | 472 registry->GetMediaFileSystemsForExtension( |
| 473 render_view_host(), GetExtension(), cb); | 473 render_view_host(), GetExtension(), cb); |
| 474 } | 474 } |
| 475 | 475 |
| 476 MediaGalleriesGetAllMediaFileSystemMetadataFunction:: | 476 MediaGalleriesGetAllMediaFileSystemMetadataFunction:: |
| 477 ~MediaGalleriesGetAllMediaFileSystemMetadataFunction() {} | 477 ~MediaGalleriesGetAllMediaFileSystemMetadataFunction() {} |
| 478 | 478 |
| 479 bool MediaGalleriesGetAllMediaFileSystemMetadataFunction::RunImpl() { | 479 bool MediaGalleriesGetAllMediaFileSystemMetadataFunction::RunAsync() { |
| 480 media_galleries::UsageCount( | 480 media_galleries::UsageCount( |
| 481 media_galleries::GET_ALL_MEDIA_FILE_SYSTEM_METADATA); | 481 media_galleries::GET_ALL_MEDIA_FILE_SYSTEM_METADATA); |
| 482 return Setup(GetProfile(), &error_, base::Bind( | 482 return Setup(GetProfile(), &error_, base::Bind( |
| 483 &MediaGalleriesGetAllMediaFileSystemMetadataFunction::OnPreferencesInit, | 483 &MediaGalleriesGetAllMediaFileSystemMetadataFunction::OnPreferencesInit, |
| 484 this)); | 484 this)); |
| 485 } | 485 } |
| 486 | 486 |
| 487 void MediaGalleriesGetAllMediaFileSystemMetadataFunction::OnPreferencesInit() { | 487 void MediaGalleriesGetAllMediaFileSystemMetadataFunction::OnPreferencesInit() { |
| 488 MediaFileSystemRegistry* registry = media_file_system_registry(); | 488 MediaFileSystemRegistry* registry = media_file_system_registry(); |
| 489 MediaGalleriesPreferences* prefs = registry->GetPreferences(GetProfile()); | 489 MediaGalleriesPreferences* prefs = registry->GetPreferences(GetProfile()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 list->Append(metadata.ToValue().release()); | 531 list->Append(metadata.ToValue().release()); |
| 532 } | 532 } |
| 533 | 533 |
| 534 SetResult(list); | 534 SetResult(list); |
| 535 SendResponse(true); | 535 SendResponse(true); |
| 536 } | 536 } |
| 537 | 537 |
| 538 MediaGalleriesAddUserSelectedFolderFunction:: | 538 MediaGalleriesAddUserSelectedFolderFunction:: |
| 539 ~MediaGalleriesAddUserSelectedFolderFunction() {} | 539 ~MediaGalleriesAddUserSelectedFolderFunction() {} |
| 540 | 540 |
| 541 bool MediaGalleriesAddUserSelectedFolderFunction::RunImpl() { | 541 bool MediaGalleriesAddUserSelectedFolderFunction::RunAsync() { |
| 542 media_galleries::UsageCount(media_galleries::ADD_USER_SELECTED_FOLDER); | 542 media_galleries::UsageCount(media_galleries::ADD_USER_SELECTED_FOLDER); |
| 543 return Setup(GetProfile(), &error_, base::Bind( | 543 return Setup(GetProfile(), &error_, base::Bind( |
| 544 &MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit, this)); | 544 &MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit, this)); |
| 545 } | 545 } |
| 546 | 546 |
| 547 void MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit() { | 547 void MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit() { |
| 548 Profile* profile = GetProfile(); | 548 Profile* profile = GetProfile(); |
| 549 const std::string& app_id = GetExtension()->id(); | 549 const std::string& app_id = GetExtension()->id(); |
| 550 WebContents* contents = GetWebContents(render_view_host(), profile, app_id); | 550 WebContents* contents = GetWebContents(render_view_host(), profile, app_id); |
| 551 if (!contents) { | 551 if (!contents) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 } | 640 } |
| 641 MediaFileSystemRegistry* registry = media_file_system_registry(); | 641 MediaFileSystemRegistry* registry = media_file_system_registry(); |
| 642 DCHECK(registry->GetPreferences(GetProfile())->IsInitialized()); | 642 DCHECK(registry->GetPreferences(GetProfile())->IsInitialized()); |
| 643 registry->GetMediaFileSystemsForExtension( | 643 registry->GetMediaFileSystemsForExtension( |
| 644 render_view_host(), GetExtension(), cb); | 644 render_view_host(), GetExtension(), cb); |
| 645 } | 645 } |
| 646 | 646 |
| 647 MediaGalleriesDropPermissionForMediaFileSystemFunction:: | 647 MediaGalleriesDropPermissionForMediaFileSystemFunction:: |
| 648 ~MediaGalleriesDropPermissionForMediaFileSystemFunction() {} | 648 ~MediaGalleriesDropPermissionForMediaFileSystemFunction() {} |
| 649 | 649 |
| 650 bool MediaGalleriesDropPermissionForMediaFileSystemFunction::RunImpl() { | 650 bool MediaGalleriesDropPermissionForMediaFileSystemFunction::RunAsync() { |
| 651 media_galleries::UsageCount( | 651 media_galleries::UsageCount( |
| 652 media_galleries::DROP_PERMISSION_FOR_MEDIA_FILE_SYSTEM); | 652 media_galleries::DROP_PERMISSION_FOR_MEDIA_FILE_SYSTEM); |
| 653 | 653 |
| 654 scoped_ptr<DropPermissionForMediaFileSystem::Params> params( | 654 scoped_ptr<DropPermissionForMediaFileSystem::Params> params( |
| 655 DropPermissionForMediaFileSystem::Params::Create(*args_)); | 655 DropPermissionForMediaFileSystem::Params::Create(*args_)); |
| 656 EXTENSION_FUNCTION_VALIDATE(params.get()); | 656 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 657 MediaGalleryPrefId pref_id; | 657 MediaGalleryPrefId pref_id; |
| 658 if (!base::StringToUint64(params->gallery_id, &pref_id)) { | 658 if (!base::StringToUint64(params->gallery_id, &pref_id)) { |
| 659 error_ = kInvalidGalleryId; | 659 error_ = kInvalidGalleryId; |
| 660 return false; | 660 return false; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 682 *GetExtension(), pref_id, false); | 682 *GetExtension(), pref_id, false); |
| 683 if (dropped) | 683 if (dropped) |
| 684 SetResult(new base::StringValue(base::Uint64ToString(pref_id))); | 684 SetResult(new base::StringValue(base::Uint64ToString(pref_id))); |
| 685 else | 685 else |
| 686 error_ = kFailedToSetGalleryPermission; | 686 error_ = kFailedToSetGalleryPermission; |
| 687 SendResponse(dropped); | 687 SendResponse(dropped); |
| 688 } | 688 } |
| 689 | 689 |
| 690 MediaGalleriesStartMediaScanFunction::~MediaGalleriesStartMediaScanFunction() {} | 690 MediaGalleriesStartMediaScanFunction::~MediaGalleriesStartMediaScanFunction() {} |
| 691 | 691 |
| 692 bool MediaGalleriesStartMediaScanFunction::RunImpl() { | 692 bool MediaGalleriesStartMediaScanFunction::RunAsync() { |
| 693 media_galleries::UsageCount(media_galleries::START_MEDIA_SCAN); | 693 media_galleries::UsageCount(media_galleries::START_MEDIA_SCAN); |
| 694 if (!CheckScanPermission(GetExtension(), &error_)) { | 694 if (!CheckScanPermission(GetExtension(), &error_)) { |
| 695 MediaGalleriesEventRouter::Get(GetProfile())->OnScanError( | 695 MediaGalleriesEventRouter::Get(GetProfile())->OnScanError( |
| 696 GetExtension()->id()); | 696 GetExtension()->id()); |
| 697 return false; | 697 return false; |
| 698 } | 698 } |
| 699 return Setup(GetProfile(), &error_, base::Bind( | 699 return Setup(GetProfile(), &error_, base::Bind( |
| 700 &MediaGalleriesStartMediaScanFunction::OnPreferencesInit, this)); | 700 &MediaGalleriesStartMediaScanFunction::OnPreferencesInit, this)); |
| 701 } | 701 } |
| 702 | 702 |
| 703 void MediaGalleriesStartMediaScanFunction::OnPreferencesInit() { | 703 void MediaGalleriesStartMediaScanFunction::OnPreferencesInit() { |
| 704 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 704 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 705 MediaGalleriesEventRouter* api = MediaGalleriesEventRouter::Get(GetProfile()); | 705 MediaGalleriesEventRouter* api = MediaGalleriesEventRouter::Get(GetProfile()); |
| 706 if (!api->ExtensionHasScanProgressListener(GetExtension()->id())) { | 706 if (!api->ExtensionHasScanProgressListener(GetExtension()->id())) { |
| 707 error_ = kMissingEventListener; | 707 error_ = kMissingEventListener; |
| 708 SendResponse(false); | 708 SendResponse(false); |
| 709 return; | 709 return; |
| 710 } | 710 } |
| 711 | 711 |
| 712 media_scan_manager()->StartScan(GetProfile(), GetExtension(), user_gesture()); | 712 media_scan_manager()->StartScan(GetProfile(), GetExtension(), user_gesture()); |
| 713 SendResponse(true); | 713 SendResponse(true); |
| 714 } | 714 } |
| 715 | 715 |
| 716 MediaGalleriesCancelMediaScanFunction:: | 716 MediaGalleriesCancelMediaScanFunction:: |
| 717 ~MediaGalleriesCancelMediaScanFunction() { | 717 ~MediaGalleriesCancelMediaScanFunction() { |
| 718 } | 718 } |
| 719 | 719 |
| 720 bool MediaGalleriesCancelMediaScanFunction::RunImpl() { | 720 bool MediaGalleriesCancelMediaScanFunction::RunAsync() { |
| 721 media_galleries::UsageCount(media_galleries::CANCEL_MEDIA_SCAN); | 721 media_galleries::UsageCount(media_galleries::CANCEL_MEDIA_SCAN); |
| 722 if (!CheckScanPermission(GetExtension(), &error_)) { | 722 if (!CheckScanPermission(GetExtension(), &error_)) { |
| 723 MediaGalleriesEventRouter::Get(GetProfile())->OnScanError( | 723 MediaGalleriesEventRouter::Get(GetProfile())->OnScanError( |
| 724 GetExtension()->id()); | 724 GetExtension()->id()); |
| 725 return false; | 725 return false; |
| 726 } | 726 } |
| 727 return Setup(GetProfile(), &error_, base::Bind( | 727 return Setup(GetProfile(), &error_, base::Bind( |
| 728 &MediaGalleriesCancelMediaScanFunction::OnPreferencesInit, this)); | 728 &MediaGalleriesCancelMediaScanFunction::OnPreferencesInit, this)); |
| 729 } | 729 } |
| 730 | 730 |
| 731 void MediaGalleriesCancelMediaScanFunction::OnPreferencesInit() { | 731 void MediaGalleriesCancelMediaScanFunction::OnPreferencesInit() { |
| 732 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 732 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 733 media_scan_manager()->CancelScan(GetProfile(), GetExtension()); | 733 media_scan_manager()->CancelScan(GetProfile(), GetExtension()); |
| 734 SendResponse(true); | 734 SendResponse(true); |
| 735 } | 735 } |
| 736 | 736 |
| 737 MediaGalleriesAddScanResultsFunction::~MediaGalleriesAddScanResultsFunction() {} | 737 MediaGalleriesAddScanResultsFunction::~MediaGalleriesAddScanResultsFunction() {} |
| 738 | 738 |
| 739 bool MediaGalleriesAddScanResultsFunction::RunImpl() { | 739 bool MediaGalleriesAddScanResultsFunction::RunAsync() { |
| 740 media_galleries::UsageCount(media_galleries::ADD_SCAN_RESULTS); | 740 media_galleries::UsageCount(media_galleries::ADD_SCAN_RESULTS); |
| 741 if (!CheckScanPermission(GetExtension(), &error_)) { | 741 if (!CheckScanPermission(GetExtension(), &error_)) { |
| 742 // We don't fire a scan progress error here, as it would be unintuitive. | 742 // We don't fire a scan progress error here, as it would be unintuitive. |
| 743 return false; | 743 return false; |
| 744 } | 744 } |
| 745 if (!user_gesture()) | 745 if (!user_gesture()) |
| 746 return false; | 746 return false; |
| 747 | 747 |
| 748 return Setup(GetProfile(), &error_, base::Bind( | 748 return Setup(GetProfile(), &error_, base::Bind( |
| 749 &MediaGalleriesAddScanResultsFunction::OnPreferencesInit, this)); | 749 &MediaGalleriesAddScanResultsFunction::OnPreferencesInit, this)); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 return; | 804 return; |
| 805 } | 805 } |
| 806 | 806 |
| 807 // The custom JS binding will use this list to create DOMFileSystem objects. | 807 // The custom JS binding will use this list to create DOMFileSystem objects. |
| 808 SetResult(list.release()); | 808 SetResult(list.release()); |
| 809 SendResponse(true); | 809 SendResponse(true); |
| 810 } | 810 } |
| 811 | 811 |
| 812 MediaGalleriesGetMetadataFunction::~MediaGalleriesGetMetadataFunction() {} | 812 MediaGalleriesGetMetadataFunction::~MediaGalleriesGetMetadataFunction() {} |
| 813 | 813 |
| 814 bool MediaGalleriesGetMetadataFunction::RunImpl() { | 814 bool MediaGalleriesGetMetadataFunction::RunAsync() { |
| 815 std::string blob_uuid; | 815 std::string blob_uuid; |
| 816 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &blob_uuid)); | 816 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &blob_uuid)); |
| 817 | 817 |
| 818 const base::Value* options_value = NULL; | 818 const base::Value* options_value = NULL; |
| 819 if (!args_->Get(1, &options_value)) | 819 if (!args_->Get(1, &options_value)) |
| 820 return false; | 820 return false; |
| 821 scoped_ptr<MediaGalleries::MediaMetadataOptions> options = | 821 scoped_ptr<MediaGalleries::MediaMetadataOptions> options = |
| 822 MediaGalleries::MediaMetadataOptions::FromValue(*options_value); | 822 MediaGalleries::MediaMetadataOptions::FromValue(*options_value); |
| 823 if (!options) | 823 if (!options) |
| 824 return false; | 824 return false; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 if (!parse_success) { | 879 if (!parse_success) { |
| 880 SendResponse(false); | 880 SendResponse(false); |
| 881 return; | 881 return; |
| 882 } | 882 } |
| 883 | 883 |
| 884 SetResult(metadata_dictionary->DeepCopy()); | 884 SetResult(metadata_dictionary->DeepCopy()); |
| 885 SendResponse(true); | 885 SendResponse(true); |
| 886 } | 886 } |
| 887 | 887 |
| 888 } // namespace extensions | 888 } // namespace extensions |
| OLD | NEW |