| Index: chrome/browser/extensions/api/media_galleries/media_galleries_api.cc
|
| diff --git a/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc b/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc
|
| index 171111be5ceb700e63e902559bdf9fec49f38cab..bdab4001c4004dab02868559e0016e5c1dd97aeb 100644
|
| --- a/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc
|
| +++ b/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc
|
| @@ -84,6 +84,11 @@ const char kIsMediaDeviceKey[] = "isMediaDevice";
|
| const char kIsRemovableKey[] = "isRemovable";
|
| const char kNameKey[] = "name";
|
|
|
| +const char kMetadataKey[] = "metadata";
|
| +const char kAttachedPicturesKey[] = "attachedPictures";
|
| +const char kDataKey[] = "data";
|
| +const char kTypeKey[] = "type";
|
| +
|
| MediaFileSystemRegistry* media_file_system_registry() {
|
| return g_browser_process->media_file_system_registry();
|
| }
|
| @@ -826,28 +831,35 @@ bool MediaGalleriesGetMetadataFunction::RunImpl() {
|
| bool mime_type_only = options->metadata_type ==
|
| MediaGalleries::GET_METADATA_TYPE_MIMETYPEONLY;
|
|
|
| + // Get attached pictures by default.
|
| + bool get_attached_pictures =
|
| + options->metadata_type == MediaGalleries::GET_METADATA_TYPE_ALL ||
|
| + options->metadata_type == MediaGalleries::GET_METADATA_TYPE_NONE;
|
| +
|
| return Setup(GetProfile(), &error_, base::Bind(
|
| &MediaGalleriesGetMetadataFunction::OnPreferencesInit, this,
|
| - mime_type_only, blob_uuid));
|
| + mime_type_only, get_attached_pictures, blob_uuid));
|
| }
|
|
|
| void MediaGalleriesGetMetadataFunction::OnPreferencesInit(
|
| - bool mime_type_only, const std::string& blob_uuid) {
|
| + bool mime_type_only, bool get_attached_pictures,
|
| + const std::string& blob_uuid) {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
|
|
| // BlobReader is self-deleting.
|
| BlobReader* reader = new BlobReader(
|
| GetProfile(),
|
| blob_uuid,
|
| - base::Bind(&MediaGalleriesGetMetadataFunction::SniffMimeType, this,
|
| - mime_type_only, blob_uuid));
|
| + base::Bind(&MediaGalleriesGetMetadataFunction::GetMetadata, this,
|
| + mime_type_only, get_attached_pictures, blob_uuid));
|
| reader->SetByteRange(0, net::kMaxBytesToSniff);
|
| reader->Start();
|
| }
|
|
|
| -void MediaGalleriesGetMetadataFunction::SniffMimeType(
|
| - bool mime_type_only, const std::string& blob_uuid,
|
| - scoped_ptr<std::string> blob_header, int64 total_blob_length) {
|
| +void MediaGalleriesGetMetadataFunction::GetMetadata(
|
| + bool mime_type_only, bool get_attached_pictures,
|
| + const std::string& blob_uuid, scoped_ptr<std::string> blob_header,
|
| + int64 total_blob_length) {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
|
|
| std::string mime_type;
|
| @@ -862,26 +874,47 @@ void MediaGalleriesGetMetadataFunction::SniffMimeType(
|
| if (mime_type_only) {
|
| MediaGalleries::MediaMetadata metadata;
|
| metadata.mime_type = mime_type;
|
| - SetResult(metadata.ToValue().release());
|
| +
|
| + base::DictionaryValue* result_dictionary = new base::DictionaryValue;
|
| + result_dictionary->Set(kMetadataKey, metadata.ToValue().release());
|
| + SetResult(result_dictionary);
|
| SendResponse(true);
|
| return;
|
| }
|
|
|
| scoped_refptr<metadata::SafeMediaMetadataParser> parser(
|
| new metadata::SafeMediaMetadataParser(GetProfile(), blob_uuid,
|
| - total_blob_length, mime_type));
|
| + total_blob_length, mime_type,
|
| + get_attached_pictures));
|
| parser->Start(base::Bind(
|
| &MediaGalleriesGetMetadataFunction::OnSafeMediaMetadataParserDone, this));
|
| }
|
|
|
| void MediaGalleriesGetMetadataFunction::OnSafeMediaMetadataParserDone(
|
| - bool parse_success, base::DictionaryValue* metadata_dictionary) {
|
| + bool parse_success, base::DictionaryValue* metadata_dictionary,
|
| + const std::vector<metadata::AttachedPicture>& attached_pictures) {
|
| if (!parse_success) {
|
| SendResponse(false);
|
| return;
|
| }
|
|
|
| - SetResult(metadata_dictionary->DeepCopy());
|
| + base::DictionaryValue* result_dictionary = new base::DictionaryValue;
|
| + result_dictionary->Set(kMetadataKey, metadata_dictionary->DeepCopy());
|
| +
|
| + // The custom JS binding will use the string vectors to create Blobs.
|
| + base::ListValue* attached_pictures_list = new base::ListValue;
|
| + for (std::vector<metadata::AttachedPicture>::const_iterator it =
|
| + attached_pictures.begin();
|
| + it != attached_pictures.end(); ++it) {
|
| + base::DictionaryValue* attached_picture = new base::DictionaryValue;
|
| + attached_picture->Set(kDataKey, base::BinaryValue::CreateWithCopiedBuffer(
|
| + it->data.c_str(), it->data.length()));
|
| + attached_picture->Set(kTypeKey, new base::StringValue(it->type));
|
| + attached_pictures_list->Append(attached_picture);
|
| + }
|
| + result_dictionary->Set(kAttachedPicturesKey, attached_pictures_list);
|
| +
|
| + SetResult(result_dictionary);
|
| SendResponse(true);
|
| }
|
|
|
|
|