Chromium Code Reviews| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 using storage_monitor::MediaStorageUtil; | 61 using storage_monitor::MediaStorageUtil; |
| 62 using storage_monitor::StorageInfo; | 62 using storage_monitor::StorageInfo; |
| 63 using web_modal::WebContentsModalDialogManager; | 63 using web_modal::WebContentsModalDialogManager; |
| 64 | 64 |
| 65 namespace extensions { | 65 namespace extensions { |
| 66 | 66 |
| 67 namespace MediaGalleries = api::media_galleries; | 67 namespace MediaGalleries = api::media_galleries; |
| 68 namespace DropPermissionForMediaFileSystem = | 68 namespace DropPermissionForMediaFileSystem = |
| 69 MediaGalleries::DropPermissionForMediaFileSystem; | 69 MediaGalleries::DropPermissionForMediaFileSystem; |
| 70 namespace GetMediaFileSystems = MediaGalleries::GetMediaFileSystems; | 70 namespace GetMediaFileSystems = MediaGalleries::GetMediaFileSystems; |
| 71 namespace AddGalleryWatch = MediaGalleries::AddGalleryWatch; | |
| 72 namespace RemoveGalleryWatch = MediaGalleries::RemoveGalleryWatch; | |
| 73 namespace GetAllGalleryWatch = MediaGalleries::GetAllGalleryWatch; | |
| 71 | 74 |
| 72 namespace { | 75 namespace { |
| 73 | 76 |
| 74 const char kDisallowedByPolicy[] = | 77 const char kDisallowedByPolicy[] = |
| 75 "Media Galleries API is disallowed by policy: "; | 78 "Media Galleries API is disallowed by policy: "; |
| 76 const char kFailedToSetGalleryPermission[] = | 79 const char kFailedToSetGalleryPermission[] = |
| 77 "Failed to set gallery permission."; | 80 "Failed to set gallery permission."; |
| 78 const char kInvalidGalleryId[] = "Invalid gallery id."; | 81 const char kInvalidGalleryId[] = "Invalid gallery id."; |
| 79 const char kMissingEventListener[] = "Missing event listener registration."; | 82 const char kMissingEventListener[] = "Missing event listener registration."; |
| 80 const char kNonExistentGalleryId[] = "Non-existent gallery id."; | 83 const char kNonExistentGalleryId[] = "Non-existent gallery id."; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 prefs::kAllowFileSelectionDialogs; | 117 prefs::kAllowFileSelectionDialogs; |
| 115 return false; | 118 return false; |
| 116 } | 119 } |
| 117 | 120 |
| 118 MediaGalleriesPreferences* preferences = | 121 MediaGalleriesPreferences* preferences = |
| 119 media_file_system_registry()->GetPreferences(profile); | 122 media_file_system_registry()->GetPreferences(profile); |
| 120 preferences->EnsureInitialized(callback); | 123 preferences->EnsureInitialized(callback); |
| 121 return true; | 124 return true; |
| 122 } | 125 } |
| 123 | 126 |
| 127 // Returns true and sets |gallery_file_path| and |gallery_pref_id| if the | |
| 128 // |gallery_id| is valid and returns false otherwise. | |
| 129 bool GetGalleryFilePathAndId(const std::string& gallery_id, | |
| 130 Profile* profile, | |
| 131 const Extension* extension, | |
| 132 base::FilePath* gallery_file_path, | |
| 133 MediaGalleryPrefId* gallery_pref_id) { | |
| 134 MediaGalleryPrefId pref_id; | |
| 135 if (!base::StringToUint64(gallery_id, &pref_id)) | |
| 136 return false; | |
| 137 MediaGalleriesPreferences* preferences = | |
| 138 g_browser_process->media_file_system_registry()->GetPreferences(profile); | |
| 139 base::FilePath file_path( | |
| 140 preferences->LookUpGalleryPathForExtension(pref_id, extension, false)); | |
| 141 if (file_path.empty()) | |
| 142 return false; | |
| 143 *gallery_pref_id = pref_id; | |
| 144 *gallery_file_path = file_path; | |
| 145 return true; | |
| 146 } | |
| 147 | |
| 124 WebContents* GetWebContents(content::RenderViewHost* rvh, | 148 WebContents* GetWebContents(content::RenderViewHost* rvh, |
| 125 Profile* profile, | 149 Profile* profile, |
| 126 const std::string& app_id) { | 150 const std::string& app_id) { |
| 127 WebContents* contents = WebContents::FromRenderViewHost(rvh); | 151 WebContents* contents = WebContents::FromRenderViewHost(rvh); |
| 128 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 152 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 129 WebContentsModalDialogManager::FromWebContents(contents); | 153 WebContentsModalDialogManager::FromWebContents(contents); |
| 130 if (!web_contents_modal_dialog_manager) { | 154 if (!web_contents_modal_dialog_manager) { |
| 131 // If there is no WebContentsModalDialogManager, then this contents is | 155 // If there is no WebContentsModalDialogManager, then this contents is |
| 132 // probably the background page for an app. Try to find a app window to | 156 // probably the background page for an app. Try to find a app window to |
| 133 // host the dialog. | 157 // host the dialog. |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 } | 442 } |
| 419 | 443 |
| 420 void MediaGalleriesEventRouter::OnListenerRemoved( | 444 void MediaGalleriesEventRouter::OnListenerRemoved( |
| 421 const EventListenerInfo& details) { | 445 const EventListenerInfo& details) { |
| 422 if (details.event_name == MediaGalleries::OnGalleryChanged::kEventName && | 446 if (details.event_name == MediaGalleries::OnGalleryChanged::kEventName && |
| 423 !ExtensionHasGalleryChangeListener(details.extension_id)) { | 447 !ExtensionHasGalleryChangeListener(details.extension_id)) { |
| 424 gallery_watch_manager()->RemoveAllWatches(profile_, details.extension_id); | 448 gallery_watch_manager()->RemoveAllWatches(profile_, details.extension_id); |
| 425 } | 449 } |
| 426 } | 450 } |
| 427 | 451 |
| 452 /////////////////////////////////////////////////////////////////////////////// | |
| 453 // MediaGalleriesGetMediaFileSystemsFunction // | |
| 454 /////////////////////////////////////////////////////////////////////////////// | |
| 428 MediaGalleriesGetMediaFileSystemsFunction:: | 455 MediaGalleriesGetMediaFileSystemsFunction:: |
| 429 ~MediaGalleriesGetMediaFileSystemsFunction() {} | 456 ~MediaGalleriesGetMediaFileSystemsFunction() {} |
| 430 | 457 |
| 431 bool MediaGalleriesGetMediaFileSystemsFunction::RunAsync() { | 458 bool MediaGalleriesGetMediaFileSystemsFunction::RunAsync() { |
| 432 media_galleries::UsageCount(media_galleries::GET_MEDIA_FILE_SYSTEMS); | 459 media_galleries::UsageCount(media_galleries::GET_MEDIA_FILE_SYSTEMS); |
| 433 scoped_ptr<GetMediaFileSystems::Params> params( | 460 scoped_ptr<GetMediaFileSystems::Params> params( |
| 434 GetMediaFileSystems::Params::Create(*args_)); | 461 GetMediaFileSystems::Params::Create(*args_)); |
| 435 EXTENSION_FUNCTION_VALIDATE(params.get()); | 462 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 436 MediaGalleries::GetMediaFileSystemsInteractivity interactive = | 463 MediaGalleries::GetMediaFileSystemsInteractivity interactive = |
| 437 MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NO; | 464 MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NO; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 525 if (!render_view_host()) { | 552 if (!render_view_host()) { |
| 526 cb.Run(std::vector<MediaFileSystemInfo>()); | 553 cb.Run(std::vector<MediaFileSystemInfo>()); |
| 527 return; | 554 return; |
| 528 } | 555 } |
| 529 MediaFileSystemRegistry* registry = media_file_system_registry(); | 556 MediaFileSystemRegistry* registry = media_file_system_registry(); |
| 530 DCHECK(registry->GetPreferences(GetProfile())->IsInitialized()); | 557 DCHECK(registry->GetPreferences(GetProfile())->IsInitialized()); |
| 531 registry->GetMediaFileSystemsForExtension( | 558 registry->GetMediaFileSystemsForExtension( |
| 532 render_view_host(), extension(), cb); | 559 render_view_host(), extension(), cb); |
| 533 } | 560 } |
| 534 | 561 |
| 562 | |
| 563 /////////////////////////////////////////////////////////////////////////////// | |
| 564 // MediaGalleriesGetAllMediaFileSystemMetadataFunction // | |
| 565 /////////////////////////////////////////////////////////////////////////////// | |
| 535 MediaGalleriesGetAllMediaFileSystemMetadataFunction:: | 566 MediaGalleriesGetAllMediaFileSystemMetadataFunction:: |
| 536 ~MediaGalleriesGetAllMediaFileSystemMetadataFunction() {} | 567 ~MediaGalleriesGetAllMediaFileSystemMetadataFunction() {} |
| 537 | 568 |
| 538 bool MediaGalleriesGetAllMediaFileSystemMetadataFunction::RunAsync() { | 569 bool MediaGalleriesGetAllMediaFileSystemMetadataFunction::RunAsync() { |
| 539 media_galleries::UsageCount( | 570 media_galleries::UsageCount( |
| 540 media_galleries::GET_ALL_MEDIA_FILE_SYSTEM_METADATA); | 571 media_galleries::GET_ALL_MEDIA_FILE_SYSTEM_METADATA); |
| 541 return Setup(GetProfile(), &error_, base::Bind( | 572 return Setup(GetProfile(), &error_, base::Bind( |
| 542 &MediaGalleriesGetAllMediaFileSystemMetadataFunction::OnPreferencesInit, | 573 &MediaGalleriesGetAllMediaFileSystemMetadataFunction::OnPreferencesInit, |
| 543 this)); | 574 this)); |
| 544 } | 575 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 587 metadata.is_removable = StorageInfo::IsRemovableDevice(gallery.device_id); | 618 metadata.is_removable = StorageInfo::IsRemovableDevice(gallery.device_id); |
| 588 metadata.is_media_device = StorageInfo::IsMediaDevice(gallery.device_id); | 619 metadata.is_media_device = StorageInfo::IsMediaDevice(gallery.device_id); |
| 589 metadata.is_available = ContainsKey(*available_devices, gallery.device_id); | 620 metadata.is_available = ContainsKey(*available_devices, gallery.device_id); |
| 590 list->Append(metadata.ToValue().release()); | 621 list->Append(metadata.ToValue().release()); |
| 591 } | 622 } |
| 592 | 623 |
| 593 SetResult(list); | 624 SetResult(list); |
| 594 SendResponse(true); | 625 SendResponse(true); |
| 595 } | 626 } |
| 596 | 627 |
| 628 /////////////////////////////////////////////////////////////////////////////// | |
| 629 // MediaGalleriesAddUserSelectedFolderFunction // | |
| 630 /////////////////////////////////////////////////////////////////////////////// | |
| 597 MediaGalleriesAddUserSelectedFolderFunction:: | 631 MediaGalleriesAddUserSelectedFolderFunction:: |
| 598 ~MediaGalleriesAddUserSelectedFolderFunction() {} | 632 ~MediaGalleriesAddUserSelectedFolderFunction() {} |
| 599 | 633 |
| 600 bool MediaGalleriesAddUserSelectedFolderFunction::RunAsync() { | 634 bool MediaGalleriesAddUserSelectedFolderFunction::RunAsync() { |
| 601 media_galleries::UsageCount(media_galleries::ADD_USER_SELECTED_FOLDER); | 635 media_galleries::UsageCount(media_galleries::ADD_USER_SELECTED_FOLDER); |
| 602 return Setup(GetProfile(), &error_, base::Bind( | 636 return Setup(GetProfile(), &error_, base::Bind( |
| 603 &MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit, this)); | 637 &MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit, this)); |
| 604 } | 638 } |
| 605 | 639 |
| 606 void MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit() { | 640 void MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit() { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 696 if (!render_view_host()) { | 730 if (!render_view_host()) { |
| 697 cb.Run(std::vector<MediaFileSystemInfo>()); | 731 cb.Run(std::vector<MediaFileSystemInfo>()); |
| 698 return; | 732 return; |
| 699 } | 733 } |
| 700 MediaFileSystemRegistry* registry = media_file_system_registry(); | 734 MediaFileSystemRegistry* registry = media_file_system_registry(); |
| 701 DCHECK(registry->GetPreferences(GetProfile())->IsInitialized()); | 735 DCHECK(registry->GetPreferences(GetProfile())->IsInitialized()); |
| 702 registry->GetMediaFileSystemsForExtension( | 736 registry->GetMediaFileSystemsForExtension( |
| 703 render_view_host(), extension(), cb); | 737 render_view_host(), extension(), cb); |
| 704 } | 738 } |
| 705 | 739 |
| 740 /////////////////////////////////////////////////////////////////////////////// | |
| 741 // MediaGalleriesDropPermissionForMediaFileSystemFunction // | |
| 742 /////////////////////////////////////////////////////////////////////////////// | |
| 706 MediaGalleriesDropPermissionForMediaFileSystemFunction:: | 743 MediaGalleriesDropPermissionForMediaFileSystemFunction:: |
| 707 ~MediaGalleriesDropPermissionForMediaFileSystemFunction() {} | 744 ~MediaGalleriesDropPermissionForMediaFileSystemFunction() {} |
| 708 | 745 |
| 709 bool MediaGalleriesDropPermissionForMediaFileSystemFunction::RunAsync() { | 746 bool MediaGalleriesDropPermissionForMediaFileSystemFunction::RunAsync() { |
| 710 media_galleries::UsageCount( | 747 media_galleries::UsageCount( |
| 711 media_galleries::DROP_PERMISSION_FOR_MEDIA_FILE_SYSTEM); | 748 media_galleries::DROP_PERMISSION_FOR_MEDIA_FILE_SYSTEM); |
| 712 | 749 |
| 713 scoped_ptr<DropPermissionForMediaFileSystem::Params> params( | 750 scoped_ptr<DropPermissionForMediaFileSystem::Params> params( |
| 714 DropPermissionForMediaFileSystem::Params::Create(*args_)); | 751 DropPermissionForMediaFileSystem::Params::Create(*args_)); |
| 715 EXTENSION_FUNCTION_VALIDATE(params.get()); | 752 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 739 | 776 |
| 740 bool dropped = preferences->SetGalleryPermissionForExtension( | 777 bool dropped = preferences->SetGalleryPermissionForExtension( |
| 741 *extension(), pref_id, false); | 778 *extension(), pref_id, false); |
| 742 if (dropped) | 779 if (dropped) |
| 743 SetResult(new base::StringValue(base::Uint64ToString(pref_id))); | 780 SetResult(new base::StringValue(base::Uint64ToString(pref_id))); |
| 744 else | 781 else |
| 745 error_ = kFailedToSetGalleryPermission; | 782 error_ = kFailedToSetGalleryPermission; |
| 746 SendResponse(dropped); | 783 SendResponse(dropped); |
| 747 } | 784 } |
| 748 | 785 |
| 786 /////////////////////////////////////////////////////////////////////////////// | |
| 787 // MediaGalleriesStartMediaScanFunction // | |
| 788 /////////////////////////////////////////////////////////////////////////////// | |
| 749 MediaGalleriesStartMediaScanFunction::~MediaGalleriesStartMediaScanFunction() {} | 789 MediaGalleriesStartMediaScanFunction::~MediaGalleriesStartMediaScanFunction() {} |
| 750 | 790 |
| 751 bool MediaGalleriesStartMediaScanFunction::RunAsync() { | 791 bool MediaGalleriesStartMediaScanFunction::RunAsync() { |
| 752 media_galleries::UsageCount(media_galleries::START_MEDIA_SCAN); | 792 media_galleries::UsageCount(media_galleries::START_MEDIA_SCAN); |
| 753 if (!CheckScanPermission(extension(), &error_)) { | 793 if (!CheckScanPermission(extension(), &error_)) { |
| 754 MediaGalleriesEventRouter::Get(GetProfile()) | 794 MediaGalleriesEventRouter::Get(GetProfile()) |
| 755 ->OnScanError(extension()->id()); | 795 ->OnScanError(extension()->id()); |
| 756 return false; | 796 return false; |
| 757 } | 797 } |
| 758 return Setup(GetProfile(), &error_, base::Bind( | 798 return Setup(GetProfile(), &error_, base::Bind( |
| 759 &MediaGalleriesStartMediaScanFunction::OnPreferencesInit, this)); | 799 &MediaGalleriesStartMediaScanFunction::OnPreferencesInit, this)); |
| 760 } | 800 } |
| 761 | 801 |
| 762 void MediaGalleriesStartMediaScanFunction::OnPreferencesInit() { | 802 void MediaGalleriesStartMediaScanFunction::OnPreferencesInit() { |
| 763 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 803 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 764 MediaGalleriesEventRouter* api = MediaGalleriesEventRouter::Get(GetProfile()); | 804 MediaGalleriesEventRouter* api = MediaGalleriesEventRouter::Get(GetProfile()); |
| 765 if (!api->ExtensionHasScanProgressListener(extension()->id())) { | 805 if (!api->ExtensionHasScanProgressListener(extension()->id())) { |
| 766 error_ = kMissingEventListener; | 806 error_ = kMissingEventListener; |
| 767 SendResponse(false); | 807 SendResponse(false); |
| 768 return; | 808 return; |
| 769 } | 809 } |
| 770 | 810 |
| 771 media_scan_manager()->StartScan(GetProfile(), extension(), user_gesture()); | 811 media_scan_manager()->StartScan(GetProfile(), extension(), user_gesture()); |
| 772 SendResponse(true); | 812 SendResponse(true); |
| 773 } | 813 } |
| 774 | 814 |
| 815 /////////////////////////////////////////////////////////////////////////////// | |
| 816 // MediaGalleriesCancelMediaScanFunction // | |
| 817 /////////////////////////////////////////////////////////////////////////////// | |
| 775 MediaGalleriesCancelMediaScanFunction:: | 818 MediaGalleriesCancelMediaScanFunction:: |
| 776 ~MediaGalleriesCancelMediaScanFunction() { | 819 ~MediaGalleriesCancelMediaScanFunction() { |
| 777 } | 820 } |
| 778 | 821 |
| 779 bool MediaGalleriesCancelMediaScanFunction::RunAsync() { | 822 bool MediaGalleriesCancelMediaScanFunction::RunAsync() { |
| 780 media_galleries::UsageCount(media_galleries::CANCEL_MEDIA_SCAN); | 823 media_galleries::UsageCount(media_galleries::CANCEL_MEDIA_SCAN); |
| 781 if (!CheckScanPermission(extension(), &error_)) { | 824 if (!CheckScanPermission(extension(), &error_)) { |
| 782 MediaGalleriesEventRouter::Get(GetProfile()) | 825 MediaGalleriesEventRouter::Get(GetProfile()) |
| 783 ->OnScanError(extension()->id()); | 826 ->OnScanError(extension()->id()); |
| 784 return false; | 827 return false; |
| 785 } | 828 } |
| 786 return Setup(GetProfile(), &error_, base::Bind( | 829 return Setup(GetProfile(), &error_, base::Bind( |
| 787 &MediaGalleriesCancelMediaScanFunction::OnPreferencesInit, this)); | 830 &MediaGalleriesCancelMediaScanFunction::OnPreferencesInit, this)); |
| 788 } | 831 } |
| 789 | 832 |
| 790 void MediaGalleriesCancelMediaScanFunction::OnPreferencesInit() { | 833 void MediaGalleriesCancelMediaScanFunction::OnPreferencesInit() { |
| 791 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 834 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 792 media_scan_manager()->CancelScan(GetProfile(), extension()); | 835 media_scan_manager()->CancelScan(GetProfile(), extension()); |
| 793 SendResponse(true); | 836 SendResponse(true); |
| 794 } | 837 } |
| 795 | 838 |
| 839 /////////////////////////////////////////////////////////////////////////////// | |
| 840 // MediaGalleriesAddScanResultsFunction // | |
| 841 /////////////////////////////////////////////////////////////////////////////// | |
| 796 MediaGalleriesAddScanResultsFunction::~MediaGalleriesAddScanResultsFunction() {} | 842 MediaGalleriesAddScanResultsFunction::~MediaGalleriesAddScanResultsFunction() {} |
| 797 | 843 |
| 798 bool MediaGalleriesAddScanResultsFunction::RunAsync() { | 844 bool MediaGalleriesAddScanResultsFunction::RunAsync() { |
| 799 media_galleries::UsageCount(media_galleries::ADD_SCAN_RESULTS); | 845 media_galleries::UsageCount(media_galleries::ADD_SCAN_RESULTS); |
| 800 if (!CheckScanPermission(extension(), &error_)) { | 846 if (!CheckScanPermission(extension(), &error_)) { |
| 801 // We don't fire a scan progress error here, as it would be unintuitive. | 847 // We don't fire a scan progress error here, as it would be unintuitive. |
| 802 return false; | 848 return false; |
| 803 } | 849 } |
| 804 if (!user_gesture()) | 850 if (!user_gesture()) |
| 805 return false; | 851 return false; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 860 if (!list.get()) { | 906 if (!list.get()) { |
| 861 SendResponse(false); | 907 SendResponse(false); |
| 862 return; | 908 return; |
| 863 } | 909 } |
| 864 | 910 |
| 865 // The custom JS binding will use this list to create DOMFileSystem objects. | 911 // The custom JS binding will use this list to create DOMFileSystem objects. |
| 866 SetResult(list.release()); | 912 SetResult(list.release()); |
| 867 SendResponse(true); | 913 SendResponse(true); |
| 868 } | 914 } |
| 869 | 915 |
| 916 /////////////////////////////////////////////////////////////////////////////// | |
| 917 // MediaGalleriesGetMetadataFunction // | |
| 918 /////////////////////////////////////////////////////////////////////////////// | |
| 870 MediaGalleriesGetMetadataFunction::~MediaGalleriesGetMetadataFunction() {} | 919 MediaGalleriesGetMetadataFunction::~MediaGalleriesGetMetadataFunction() {} |
| 871 | 920 |
| 872 bool MediaGalleriesGetMetadataFunction::RunAsync() { | 921 bool MediaGalleriesGetMetadataFunction::RunAsync() { |
| 873 std::string blob_uuid; | 922 std::string blob_uuid; |
| 874 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &blob_uuid)); | 923 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &blob_uuid)); |
| 875 | 924 |
| 876 const base::Value* options_value = NULL; | 925 const base::Value* options_value = NULL; |
| 877 if (!args_->Get(1, &options_value)) | 926 if (!args_->Get(1, &options_value)) |
| 878 return false; | 927 return false; |
| 879 scoped_ptr<MediaGalleries::MediaMetadataOptions> options = | 928 scoped_ptr<MediaGalleries::MediaMetadataOptions> options = |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1027 base::Passed(&attached_images), base::Passed(&blob_uuids))); | 1076 base::Passed(&attached_images), base::Passed(&blob_uuids))); |
| 1028 return; | 1077 return; |
| 1029 } | 1078 } |
| 1030 | 1079 |
| 1031 // All Blobs have been constructed. The renderer will take ownership. | 1080 // All Blobs have been constructed. The renderer will take ownership. |
| 1032 SetResult(result_dictionary.release()); | 1081 SetResult(result_dictionary.release()); |
| 1033 SetTransferredBlobUUIDs(*blob_uuids); | 1082 SetTransferredBlobUUIDs(*blob_uuids); |
| 1034 SendResponse(true); | 1083 SendResponse(true); |
| 1035 } | 1084 } |
| 1036 | 1085 |
| 1086 /////////////////////////////////////////////////////////////////////////////// | |
| 1087 // MediaGalleriesAddGalleryWatchFunction // | |
| 1088 /////////////////////////////////////////////////////////////////////////////// | |
| 1089 MediaGalleriesAddGalleryWatchFunction:: | |
| 1090 ~MediaGalleriesAddGalleryWatchFunction() { | |
| 1091 } | |
| 1092 | |
| 1093 bool MediaGalleriesAddGalleryWatchFunction::RunAsync() { | |
| 1094 DCHECK(GetProfile()); | |
| 1095 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 1096 if (!render_view_host() || !render_view_host()->GetProcess()) | |
| 1097 return false; | |
| 1098 | |
| 1099 scoped_ptr<AddGalleryWatch::Params> params( | |
| 1100 AddGalleryWatch::Params::Create(*args_)); | |
| 1101 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
| 1102 | |
| 1103 MediaGalleriesPreferences* preferences = | |
| 1104 g_browser_process->media_file_system_registry()->GetPreferences( | |
| 1105 GetProfile()); | |
| 1106 preferences->EnsureInitialized( | |
| 1107 base::Bind(&MediaGalleriesAddGalleryWatchFunction::OnPreferencesInit, | |
| 1108 this, | |
| 1109 params->gallery_id)); | |
| 1110 | |
| 1111 return true; | |
| 1112 } | |
| 1113 | |
| 1114 void MediaGalleriesAddGalleryWatchFunction::OnPreferencesInit( | |
| 1115 const std::string& pref_id) { | |
| 1116 base::FilePath gallery_file_path; | |
| 1117 MediaGalleryPrefId gallery_pref_id = 0; | |
| 1118 if (!GetGalleryFilePathAndId(pref_id, | |
| 1119 GetProfile(), | |
| 1120 extension(), | |
| 1121 &gallery_file_path, | |
| 1122 &gallery_pref_id)) { | |
| 1123 api::media_galleries::AddGalleryWatchResult result; | |
| 1124 error_ = kInvalidGalleryId; | |
| 1125 result.gallery_id = -1; | |
| 1126 result.success = false; | |
|
tommycli
2014/08/20 23:21:13
You don't SetResult here, so this result is never
Oren Blasberg
2014/08/21 02:45:21
As discussed in the test file, I've fixed this. Al
| |
| 1127 SendResponse(false); | |
| 1128 return; | |
| 1129 } | |
| 1130 | |
| 1131 gallery_watch_manager()->AddWatch( | |
| 1132 GetProfile(), | |
| 1133 extension(), | |
| 1134 gallery_pref_id, | |
| 1135 base::Bind(&MediaGalleriesAddGalleryWatchFunction::HandleResponse, | |
| 1136 this, | |
| 1137 gallery_pref_id)); | |
| 1138 } | |
| 1139 | |
| 1140 void MediaGalleriesAddGalleryWatchFunction::HandleResponse( | |
| 1141 MediaGalleryPrefId gallery_id, | |
| 1142 const std::string& error) { | |
| 1143 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 1144 | |
| 1145 // If an app added a file watch without any event listeners on the | |
| 1146 // onGalleryChanged event, that's an error. | |
| 1147 MediaGalleriesEventRouter* api = MediaGalleriesEventRouter::Get(GetProfile()); | |
| 1148 if (!api->ExtensionHasGalleryChangeListener(extension()->id())) { | |
| 1149 api::media_galleries::AddGalleryWatchResult result; | |
| 1150 result.gallery_id = base::Uint64ToString(gallery_id); | |
| 1151 result.success = false; | |
| 1152 SetResult(result.ToValue().release()); | |
| 1153 error_ = kMissingEventListener; | |
| 1154 SendResponse(false); | |
| 1155 return; | |
| 1156 } | |
| 1157 | |
| 1158 api::media_galleries::AddGalleryWatchResult result; | |
| 1159 result.gallery_id = base::Uint64ToString(gallery_id); | |
| 1160 result.success = error.empty(); | |
| 1161 SetResult(result.ToValue().release()); | |
| 1162 if (error.empty()) { | |
| 1163 SendResponse(true); | |
| 1164 } else { | |
| 1165 error_ = error.c_str(); | |
| 1166 SendResponse(false); | |
| 1167 } | |
| 1168 } | |
| 1169 | |
| 1170 /////////////////////////////////////////////////////////////////////////////// | |
| 1171 // MediaGalleriesRemoveGalleryWatchFunction // | |
| 1172 /////////////////////////////////////////////////////////////////////////////// | |
| 1173 | |
| 1174 MediaGalleriesRemoveGalleryWatchFunction:: | |
| 1175 ~MediaGalleriesRemoveGalleryWatchFunction() { | |
| 1176 } | |
| 1177 | |
| 1178 bool MediaGalleriesRemoveGalleryWatchFunction::RunAsync() { | |
| 1179 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 1180 if (!render_view_host() || !render_view_host()->GetProcess()) | |
| 1181 return false; | |
| 1182 | |
| 1183 scoped_ptr<RemoveGalleryWatch::Params> params( | |
| 1184 RemoveGalleryWatch::Params::Create(*args_)); | |
| 1185 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
| 1186 | |
| 1187 MediaGalleriesPreferences* preferences = | |
| 1188 g_browser_process->media_file_system_registry()->GetPreferences( | |
| 1189 GetProfile()); | |
| 1190 preferences->EnsureInitialized( | |
| 1191 base::Bind(&MediaGalleriesRemoveGalleryWatchFunction::OnPreferencesInit, | |
| 1192 this, | |
| 1193 params->gallery_id)); | |
| 1194 return true; | |
| 1195 } | |
| 1196 | |
| 1197 void MediaGalleriesRemoveGalleryWatchFunction::OnPreferencesInit( | |
| 1198 const std::string& pref_id) { | |
| 1199 base::FilePath gallery_file_path; | |
| 1200 MediaGalleryPrefId gallery_pref_id = 0; | |
| 1201 if (!GetGalleryFilePathAndId(pref_id, | |
| 1202 GetProfile(), | |
| 1203 extension(), | |
| 1204 &gallery_file_path, | |
| 1205 &gallery_pref_id)) { | |
| 1206 error_ = kInvalidGalleryId; | |
| 1207 SendResponse(false); | |
| 1208 return; | |
| 1209 } | |
| 1210 | |
| 1211 gallery_watch_manager()->RemoveWatch( | |
| 1212 GetProfile(), extension_id(), gallery_pref_id); | |
| 1213 SendResponse(true); | |
| 1214 } | |
| 1215 | |
| 1216 /////////////////////////////////////////////////////////////////////////////// | |
| 1217 // MediaGalleriesGetAllGalleryWatchFunction // | |
| 1218 /////////////////////////////////////////////////////////////////////////////// | |
| 1219 | |
| 1220 MediaGalleriesGetAllGalleryWatchFunction:: | |
| 1221 ~MediaGalleriesGetAllGalleryWatchFunction() { | |
| 1222 } | |
| 1223 | |
| 1224 bool MediaGalleriesGetAllGalleryWatchFunction::RunAsync() { | |
| 1225 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 1226 if (!render_view_host() || !render_view_host()->GetProcess()) | |
| 1227 return false; | |
| 1228 | |
| 1229 MediaGalleriesPreferences* preferences = | |
| 1230 g_browser_process->media_file_system_registry()->GetPreferences( | |
| 1231 GetProfile()); | |
| 1232 preferences->EnsureInitialized(base::Bind( | |
| 1233 &MediaGalleriesGetAllGalleryWatchFunction::OnPreferencesInit, this)); | |
| 1234 return true; | |
| 1235 } | |
| 1236 | |
| 1237 void MediaGalleriesGetAllGalleryWatchFunction::OnPreferencesInit() { | |
| 1238 std::vector<std::string> result; | |
| 1239 MediaGalleryPrefIdSet gallery_ids = | |
| 1240 gallery_watch_manager()->GetWatchSet(GetProfile(), extension_id()); | |
| 1241 for (MediaGalleryPrefIdSet::const_iterator iter = gallery_ids.begin(); | |
| 1242 iter != gallery_ids.end(); | |
| 1243 ++iter) { | |
| 1244 result.push_back(base::Uint64ToString(*iter)); | |
| 1245 } | |
| 1246 results_ = GetAllGalleryWatch::Results::Create(result); | |
| 1247 SendResponse(true); | |
| 1248 } | |
| 1249 | |
| 1250 /////////////////////////////////////////////////////////////////////////////// | |
| 1251 // MediaGalleriesRemoveAllGalleryWatchFunction // | |
| 1252 /////////////////////////////////////////////////////////////////////////////// | |
| 1253 | |
| 1254 MediaGalleriesRemoveAllGalleryWatchFunction:: | |
| 1255 ~MediaGalleriesRemoveAllGalleryWatchFunction() { | |
| 1256 } | |
| 1257 | |
| 1258 bool MediaGalleriesRemoveAllGalleryWatchFunction::RunAsync() { | |
| 1259 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 1260 if (!render_view_host() || !render_view_host()->GetProcess()) | |
| 1261 return false; | |
| 1262 | |
| 1263 MediaGalleriesPreferences* preferences = | |
| 1264 g_browser_process->media_file_system_registry()->GetPreferences( | |
| 1265 GetProfile()); | |
| 1266 preferences->EnsureInitialized(base::Bind( | |
| 1267 &MediaGalleriesRemoveAllGalleryWatchFunction::OnPreferencesInit, this)); | |
| 1268 return true; | |
| 1269 } | |
| 1270 | |
| 1271 void MediaGalleriesRemoveAllGalleryWatchFunction::OnPreferencesInit() { | |
| 1272 gallery_watch_manager()->RemoveAllWatches(GetProfile(), extension_id()); | |
| 1273 SendResponse(true); | |
| 1274 } | |
| 1275 | |
| 1037 } // namespace extensions | 1276 } // namespace extensions |
| OLD | NEW |