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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 #include "ui/base/l10n/l10n_util.h" | 55 #include "ui/base/l10n/l10n_util.h" |
56 | 56 |
57 using content::WebContents; | 57 using content::WebContents; |
58 using storage_monitor::MediaStorageUtil; | 58 using storage_monitor::MediaStorageUtil; |
59 using storage_monitor::StorageInfo; | 59 using storage_monitor::StorageInfo; |
60 using web_modal::WebContentsModalDialogManager; | 60 using web_modal::WebContentsModalDialogManager; |
61 | 61 |
62 namespace extensions { | 62 namespace extensions { |
63 | 63 |
64 namespace MediaGalleries = api::media_galleries; | 64 namespace MediaGalleries = api::media_galleries; |
| 65 namespace DropPermissionForMediaFileSystem = |
| 66 MediaGalleries::DropPermissionForMediaFileSystem; |
65 namespace GetMediaFileSystems = MediaGalleries::GetMediaFileSystems; | 67 namespace GetMediaFileSystems = MediaGalleries::GetMediaFileSystems; |
66 | 68 |
67 namespace { | 69 namespace { |
68 | 70 |
69 const char kDisallowedByPolicy[] = | 71 const char kDisallowedByPolicy[] = |
70 "Media Galleries API is disallowed by policy: "; | 72 "Media Galleries API is disallowed by policy: "; |
71 const char kMissingEventListener[] = | 73 const char kMissingEventListener[] = |
72 "Missing event listener registration."; | 74 "Missing event listener registration."; |
73 const char kNoScanPermission[] = | 75 const char kNoScanPermission[] = |
74 "No permission to scan."; | 76 "No permission to scan."; |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 if (!render_view_host()) { | 638 if (!render_view_host()) { |
637 cb.Run(std::vector<MediaFileSystemInfo>()); | 639 cb.Run(std::vector<MediaFileSystemInfo>()); |
638 return; | 640 return; |
639 } | 641 } |
640 MediaFileSystemRegistry* registry = media_file_system_registry(); | 642 MediaFileSystemRegistry* registry = media_file_system_registry(); |
641 DCHECK(registry->GetPreferences(GetProfile())->IsInitialized()); | 643 DCHECK(registry->GetPreferences(GetProfile())->IsInitialized()); |
642 registry->GetMediaFileSystemsForExtension( | 644 registry->GetMediaFileSystemsForExtension( |
643 render_view_host(), GetExtension(), cb); | 645 render_view_host(), GetExtension(), cb); |
644 } | 646 } |
645 | 647 |
| 648 MediaGalleriesDropPermissionForMediaFileSystemFunction:: |
| 649 ~MediaGalleriesDropPermissionForMediaFileSystemFunction() {} |
| 650 |
| 651 bool MediaGalleriesDropPermissionForMediaFileSystemFunction::RunImpl() { |
| 652 media_galleries::UsageCount( |
| 653 media_galleries::DROP_PERMISSION_FOR_MEDIA_FILE_SYSTEM); |
| 654 |
| 655 scoped_ptr<DropPermissionForMediaFileSystem::Params> params( |
| 656 DropPermissionForMediaFileSystem::Params::Create(*args_)); |
| 657 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 658 MediaGalleryPrefId pref_id; |
| 659 if (base::StringToUint64(params->gallery_id, &pref_id)) { |
| 660 base::Closure callback = base::Bind( |
| 661 &MediaGalleriesDropPermissionForMediaFileSystemFunction:: |
| 662 OnPreferencesInit, |
| 663 this, |
| 664 pref_id); |
| 665 if (Setup(GetProfile(), &error_, callback)) |
| 666 return true; |
| 667 } |
| 668 |
| 669 scoped_ptr<base::ListValue> default_results(new base::ListValue()); |
| 670 default_results->AppendString(base::string16()); |
| 671 default_results->AppendBoolean(false); |
| 672 SetResult(default_results.release()); |
| 673 return false; |
| 674 } |
| 675 |
| 676 void MediaGalleriesDropPermissionForMediaFileSystemFunction::OnPreferencesInit( |
| 677 MediaGalleryPrefId pref_id) { |
| 678 MediaGalleriesPreferences* preferences = |
| 679 media_file_system_registry()->GetPreferences(GetProfile()); |
| 680 bool dropped = preferences->SetGalleryPermissionForExtension( |
| 681 *GetExtension(), pref_id, false); |
| 682 scoped_ptr<base::ListValue> results(new base::ListValue()); |
| 683 results->AppendString(base::Uint64ToString(pref_id)); |
| 684 results->AppendBoolean(dropped); |
| 685 SetResult(results.release()); |
| 686 SendResponse(true); |
| 687 } |
| 688 |
646 MediaGalleriesStartMediaScanFunction::~MediaGalleriesStartMediaScanFunction() {} | 689 MediaGalleriesStartMediaScanFunction::~MediaGalleriesStartMediaScanFunction() {} |
647 | 690 |
648 bool MediaGalleriesStartMediaScanFunction::RunImpl() { | 691 bool MediaGalleriesStartMediaScanFunction::RunImpl() { |
649 media_galleries::UsageCount(media_galleries::START_MEDIA_SCAN); | 692 media_galleries::UsageCount(media_galleries::START_MEDIA_SCAN); |
650 if (!CheckScanPermission(GetExtension(), &error_)) { | 693 if (!CheckScanPermission(GetExtension(), &error_)) { |
651 MediaGalleriesEventRouter::Get(GetProfile())->OnScanError( | 694 MediaGalleriesEventRouter::Get(GetProfile())->OnScanError( |
652 GetExtension()->id()); | 695 GetExtension()->id()); |
653 return false; | 696 return false; |
654 } | 697 } |
655 return Setup(GetProfile(), &error_, base::Bind( | 698 return Setup(GetProfile(), &error_, base::Bind( |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 if (!parse_success) { | 878 if (!parse_success) { |
836 SendResponse(false); | 879 SendResponse(false); |
837 return; | 880 return; |
838 } | 881 } |
839 | 882 |
840 SetResult(metadata_dictionary->DeepCopy()); | 883 SetResult(metadata_dictionary->DeepCopy()); |
841 SendResponse(true); | 884 SendResponse(true); |
842 } | 885 } |
843 | 886 |
844 } // namespace extensions | 887 } // namespace extensions |
OLD | NEW |