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 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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; |
| 825 | 825 |
| 826 bool mime_type_only = options->metadata_type == | 826 bool mime_type_only = options->metadata_type == |
| 827 MediaGalleries::GET_METADATA_TYPE_MIMETYPEONLY; | 827 MediaGalleries::GET_METADATA_TYPE_MIMETYPEONLY; |
| 828 | 828 |
| 829 // Get attached pictures by default. | |
| 830 bool get_attached_pictures = | |
| 831 options->metadata_type == MediaGalleries::GET_METADATA_TYPE_ALL || | |
| 832 options->metadata_type == MediaGalleries::GET_METADATA_TYPE_NONE; | |
| 833 | |
| 829 return Setup(GetProfile(), &error_, base::Bind( | 834 return Setup(GetProfile(), &error_, base::Bind( |
| 830 &MediaGalleriesGetMetadataFunction::OnPreferencesInit, this, | 835 &MediaGalleriesGetMetadataFunction::OnPreferencesInit, this, |
| 831 mime_type_only, blob_uuid)); | 836 mime_type_only, get_attached_pictures, blob_uuid)); |
| 832 } | 837 } |
| 833 | 838 |
| 834 void MediaGalleriesGetMetadataFunction::OnPreferencesInit( | 839 void MediaGalleriesGetMetadataFunction::OnPreferencesInit( |
| 835 bool mime_type_only, const std::string& blob_uuid) { | 840 bool mime_type_only, bool get_attached_pictures, |
| 841 const std::string& blob_uuid) { | |
| 836 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 842 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 837 | 843 |
| 838 // BlobReader is self-deleting. | 844 // BlobReader is self-deleting. |
| 839 BlobReader* reader = new BlobReader( | 845 BlobReader* reader = new BlobReader( |
| 840 GetProfile(), | 846 GetProfile(), |
| 841 blob_uuid, | 847 blob_uuid, |
| 842 base::Bind(&MediaGalleriesGetMetadataFunction::SniffMimeType, this, | 848 base::Bind(&MediaGalleriesGetMetadataFunction::SniffMimeType, this, |
| 843 mime_type_only, blob_uuid)); | 849 mime_type_only, get_attached_pictures, blob_uuid)); |
| 844 reader->SetByteRange(0, net::kMaxBytesToSniff); | 850 reader->SetByteRange(0, net::kMaxBytesToSniff); |
| 845 reader->Start(); | 851 reader->Start(); |
| 846 } | 852 } |
| 847 | 853 |
| 848 void MediaGalleriesGetMetadataFunction::SniffMimeType( | 854 void MediaGalleriesGetMetadataFunction::SniffMimeType( |
| 849 bool mime_type_only, const std::string& blob_uuid, | 855 bool mime_type_only, bool get_attached_pictures, |
| 850 scoped_ptr<std::string> blob_header, int64 total_blob_length) { | 856 const std::string& blob_uuid, scoped_ptr<std::string> blob_header, |
| 857 int64 total_blob_length) { | |
| 851 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 858 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 852 | 859 |
| 853 std::string mime_type; | 860 std::string mime_type; |
| 854 bool mime_type_sniffed = net::SniffMimeTypeFromLocalData( | 861 bool mime_type_sniffed = net::SniffMimeTypeFromLocalData( |
| 855 blob_header->c_str(), blob_header->size(), &mime_type); | 862 blob_header->c_str(), blob_header->size(), &mime_type); |
| 856 | 863 |
| 857 if (!mime_type_sniffed) { | 864 if (!mime_type_sniffed) { |
| 858 SendResponse(false); | 865 SendResponse(false); |
| 859 return; | 866 return; |
| 860 } | 867 } |
| 861 | 868 |
| 862 if (mime_type_only) { | 869 if (mime_type_only) { |
| 863 MediaGalleries::MediaMetadata metadata; | 870 MediaGalleries::MediaMetadata metadata; |
| 864 metadata.mime_type = mime_type; | 871 metadata.mime_type = mime_type; |
| 865 SetResult(metadata.ToValue().release()); | 872 |
| 873 // The custom JS binding needs the extra empty list parameters. | |
|
vandebo (ex-Chrome)
2014/04/23 23:22:45
Instead of using a list, use a dictionary.
tommycli
2014/04/29 00:15:51
Done.
| |
| 874 base::ListValue* result_list = new base::ListValue(); | |
| 875 result_list->Append(metadata.ToValue().release()); | |
| 876 result_list->Append(new base::ListValue()); | |
| 877 result_list->Append(new base::ListValue()); | |
| 878 | |
| 879 SetResult(result_list); | |
| 866 SendResponse(true); | 880 SendResponse(true); |
| 867 return; | 881 return; |
| 868 } | 882 } |
| 869 | 883 |
| 870 scoped_refptr<metadata::SafeMediaMetadataParser> parser( | 884 scoped_refptr<metadata::SafeMediaMetadataParser> parser( |
| 871 new metadata::SafeMediaMetadataParser(GetProfile(), blob_uuid, | 885 new metadata::SafeMediaMetadataParser(GetProfile(), blob_uuid, |
| 872 total_blob_length, mime_type)); | 886 total_blob_length, mime_type, |
| 887 get_attached_pictures)); | |
| 873 parser->Start(base::Bind( | 888 parser->Start(base::Bind( |
| 874 &MediaGalleriesGetMetadataFunction::OnSafeMediaMetadataParserDone, this)); | 889 &MediaGalleriesGetMetadataFunction::OnSafeMediaMetadataParserDone, this)); |
| 875 } | 890 } |
| 876 | 891 |
| 877 void MediaGalleriesGetMetadataFunction::OnSafeMediaMetadataParserDone( | 892 void MediaGalleriesGetMetadataFunction::OnSafeMediaMetadataParserDone( |
| 878 bool parse_success, base::DictionaryValue* metadata_dictionary) { | 893 bool parse_success, base::DictionaryValue* metadata_dictionary, |
| 894 const std::vector<std::string>& attached_pictures_bytes, | |
| 895 const std::vector<std::string>& attached_pictures_types) { | |
| 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::ListValue* result_list = new base::ListValue(); |
| 902 result_list->Append(metadata_dictionary->DeepCopy()); | |
| 903 | |
| 904 // The custom JS binding will use the string vectors to create Blobs. | |
|
vandebo (ex-Chrome)
2014/04/23 23:22:45
Can't we create the blob backing store on the brow
tommycli
2014/05/07 21:39:04
Done.
| |
| 905 base::ListValue* attached_images_bytes_list = new base::ListValue(); | |
| 906 for (std::vector<std::string>::const_iterator it = | |
| 907 attached_pictures_bytes.begin(); | |
| 908 it != attached_pictures_bytes.end(); ++it) { | |
| 909 attached_images_bytes_list->Append( | |
| 910 base::BinaryValue::CreateWithCopiedBuffer(it->c_str(), it->length())); | |
| 911 } | |
| 912 result_list->Append(attached_images_bytes_list); | |
| 913 | |
| 914 base::ListValue* attached_images_types_list = new base::ListValue(); | |
| 915 attached_images_types_list->AppendStrings(attached_pictures_types); | |
| 916 result_list->Append(attached_images_types_list); | |
| 917 | |
| 918 SetResult(result_list); | |
| 885 SendResponse(true); | 919 SendResponse(true); |
| 886 } | 920 } |
| 887 | 921 |
| 888 } // namespace extensions | 922 } // namespace extensions |
| OLD | NEW |