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

Side by Side Diff: chrome/browser/extensions/api/media_galleries/media_galleries_api.cc

Issue 250143002: Media Galleries API: Audio/Video attached pictures support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: transition to AttachedPicture struct and eliminate a copy Created 6 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 | Annotate | Revision Log
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 // 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 const char kNonExistentGalleryId[] = "Non-existent gallery id."; 77 const char kNonExistentGalleryId[] = "Non-existent gallery id.";
78 const char kNoScanPermission[] = "No permission to scan."; 78 const char kNoScanPermission[] = "No permission to scan.";
79 79
80 const char kDeviceIdKey[] = "deviceId"; 80 const char kDeviceIdKey[] = "deviceId";
81 const char kGalleryIdKey[] = "galleryId"; 81 const char kGalleryIdKey[] = "galleryId";
82 const char kIsAvailableKey[] = "isAvailable"; 82 const char kIsAvailableKey[] = "isAvailable";
83 const char kIsMediaDeviceKey[] = "isMediaDevice"; 83 const char kIsMediaDeviceKey[] = "isMediaDevice";
84 const char kIsRemovableKey[] = "isRemovable"; 84 const char kIsRemovableKey[] = "isRemovable";
85 const char kNameKey[] = "name"; 85 const char kNameKey[] = "name";
86 86
87 const char kMetadataKey[] = "metadata";
88 const char kAttachedPicturesKey[] = "attachedPictures";
89 const char kDataKey[] = "data";
90 const char kTypeKey[] = "type";
91
87 MediaFileSystemRegistry* media_file_system_registry() { 92 MediaFileSystemRegistry* media_file_system_registry() {
88 return g_browser_process->media_file_system_registry(); 93 return g_browser_process->media_file_system_registry();
89 } 94 }
90 95
91 MediaScanManager* media_scan_manager() { 96 MediaScanManager* media_scan_manager() {
92 return media_file_system_registry()->media_scan_manager(); 97 return media_file_system_registry()->media_scan_manager();
93 } 98 }
94 99
95 // Checks whether the MediaGalleries API is currently accessible (it may be 100 // Checks whether the MediaGalleries API is currently accessible (it may be
96 // disallowed even if an extension has the requisite permission). Then 101 // disallowed even if an extension has the requisite permission). Then
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 if (!args_->Get(1, &options_value)) 824 if (!args_->Get(1, &options_value))
820 return false; 825 return false;
821 scoped_ptr<MediaGalleries::MediaMetadataOptions> options = 826 scoped_ptr<MediaGalleries::MediaMetadataOptions> options =
822 MediaGalleries::MediaMetadataOptions::FromValue(*options_value); 827 MediaGalleries::MediaMetadataOptions::FromValue(*options_value);
823 if (!options) 828 if (!options)
824 return false; 829 return false;
825 830
826 bool mime_type_only = options->metadata_type == 831 bool mime_type_only = options->metadata_type ==
827 MediaGalleries::GET_METADATA_TYPE_MIMETYPEONLY; 832 MediaGalleries::GET_METADATA_TYPE_MIMETYPEONLY;
828 833
834 // Get attached pictures by default.
835 bool get_attached_pictures =
836 options->metadata_type == MediaGalleries::GET_METADATA_TYPE_ALL ||
837 options->metadata_type == MediaGalleries::GET_METADATA_TYPE_NONE;
838
829 return Setup(GetProfile(), &error_, base::Bind( 839 return Setup(GetProfile(), &error_, base::Bind(
830 &MediaGalleriesGetMetadataFunction::OnPreferencesInit, this, 840 &MediaGalleriesGetMetadataFunction::OnPreferencesInit, this,
831 mime_type_only, blob_uuid)); 841 mime_type_only, get_attached_pictures, blob_uuid));
832 } 842 }
833 843
834 void MediaGalleriesGetMetadataFunction::OnPreferencesInit( 844 void MediaGalleriesGetMetadataFunction::OnPreferencesInit(
835 bool mime_type_only, const std::string& blob_uuid) { 845 bool mime_type_only, bool get_attached_pictures,
846 const std::string& blob_uuid) {
836 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 847 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
837 848
838 // BlobReader is self-deleting. 849 // BlobReader is self-deleting.
839 BlobReader* reader = new BlobReader( 850 BlobReader* reader = new BlobReader(
840 GetProfile(), 851 GetProfile(),
841 blob_uuid, 852 blob_uuid,
842 base::Bind(&MediaGalleriesGetMetadataFunction::SniffMimeType, this, 853 base::Bind(&MediaGalleriesGetMetadataFunction::GetMetadata, this,
843 mime_type_only, blob_uuid)); 854 mime_type_only, get_attached_pictures, blob_uuid));
844 reader->SetByteRange(0, net::kMaxBytesToSniff); 855 reader->SetByteRange(0, net::kMaxBytesToSniff);
845 reader->Start(); 856 reader->Start();
846 } 857 }
847 858
848 void MediaGalleriesGetMetadataFunction::SniffMimeType( 859 void MediaGalleriesGetMetadataFunction::GetMetadata(
849 bool mime_type_only, const std::string& blob_uuid, 860 bool mime_type_only, bool get_attached_pictures,
850 scoped_ptr<std::string> blob_header, int64 total_blob_length) { 861 const std::string& blob_uuid, scoped_ptr<std::string> blob_header,
862 int64 total_blob_length) {
851 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 863 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
852 864
853 std::string mime_type; 865 std::string mime_type;
854 bool mime_type_sniffed = net::SniffMimeTypeFromLocalData( 866 bool mime_type_sniffed = net::SniffMimeTypeFromLocalData(
855 blob_header->c_str(), blob_header->size(), &mime_type); 867 blob_header->c_str(), blob_header->size(), &mime_type);
856 868
857 if (!mime_type_sniffed) { 869 if (!mime_type_sniffed) {
858 SendResponse(false); 870 SendResponse(false);
859 return; 871 return;
860 } 872 }
861 873
862 if (mime_type_only) { 874 if (mime_type_only) {
863 MediaGalleries::MediaMetadata metadata; 875 MediaGalleries::MediaMetadata metadata;
864 metadata.mime_type = mime_type; 876 metadata.mime_type = mime_type;
865 SetResult(metadata.ToValue().release()); 877
878 base::DictionaryValue* result_dictionary = new base::DictionaryValue;
879 result_dictionary->Set(kMetadataKey, metadata.ToValue().release());
880 SetResult(result_dictionary);
866 SendResponse(true); 881 SendResponse(true);
867 return; 882 return;
868 } 883 }
869 884
870 scoped_refptr<metadata::SafeMediaMetadataParser> parser( 885 scoped_refptr<metadata::SafeMediaMetadataParser> parser(
871 new metadata::SafeMediaMetadataParser(GetProfile(), blob_uuid, 886 new metadata::SafeMediaMetadataParser(GetProfile(), blob_uuid,
872 total_blob_length, mime_type)); 887 total_blob_length, mime_type,
888 get_attached_pictures));
873 parser->Start(base::Bind( 889 parser->Start(base::Bind(
874 &MediaGalleriesGetMetadataFunction::OnSafeMediaMetadataParserDone, this)); 890 &MediaGalleriesGetMetadataFunction::OnSafeMediaMetadataParserDone, this));
875 } 891 }
876 892
877 void MediaGalleriesGetMetadataFunction::OnSafeMediaMetadataParserDone( 893 void MediaGalleriesGetMetadataFunction::OnSafeMediaMetadataParserDone(
878 bool parse_success, base::DictionaryValue* metadata_dictionary) { 894 bool parse_success, base::DictionaryValue* metadata_dictionary,
895 const std::vector<metadata::AttachedPicture>& attached_pictures) {
879 if (!parse_success) { 896 if (!parse_success) {
880 SendResponse(false); 897 SendResponse(false);
881 return; 898 return;
882 } 899 }
883 900
884 SetResult(metadata_dictionary->DeepCopy()); 901 base::DictionaryValue* result_dictionary = new base::DictionaryValue;
902 result_dictionary->Set(kMetadataKey, metadata_dictionary->DeepCopy());
903
904 // The custom JS binding will use the string vectors to create Blobs.
905 base::ListValue* attached_pictures_list = new base::ListValue;
906 for (std::vector<metadata::AttachedPicture>::const_iterator it =
907 attached_pictures.begin();
908 it != attached_pictures.end(); ++it) {
909 base::DictionaryValue* attached_picture = new base::DictionaryValue;
910 attached_picture->Set(kDataKey, base::BinaryValue::CreateWithCopiedBuffer(
911 it->data.c_str(), it->data.length()));
912 attached_picture->Set(kTypeKey, new base::StringValue(it->type));
913 attached_pictures_list->Append(attached_picture);
914 }
915 result_dictionary->Set(kAttachedPicturesKey, attached_pictures_list);
916
917 SetResult(result_dictionary);
885 SendResponse(true); 918 SendResponse(true);
886 } 919 }
887 920
888 } // namespace extensions 921 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698