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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
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..6c3c56b46ea0a63558a8ae9a66a89599daa3d9e4 100644
--- a/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc
+++ b/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc
@@ -826,13 +826,19 @@ 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.
@@ -840,14 +846,15 @@ void MediaGalleriesGetMetadataFunction::OnPreferencesInit(
GetProfile(),
blob_uuid,
base::Bind(&MediaGalleriesGetMetadataFunction::SniffMimeType, this,
- mime_type_only, blob_uuid));
+ 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) {
+ 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 +869,53 @@ void MediaGalleriesGetMetadataFunction::SniffMimeType(
if (mime_type_only) {
MediaGalleries::MediaMetadata metadata;
metadata.mime_type = mime_type;
- SetResult(metadata.ToValue().release());
+
+ // 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.
+ base::ListValue* result_list = new base::ListValue();
+ result_list->Append(metadata.ToValue().release());
+ result_list->Append(new base::ListValue());
+ result_list->Append(new base::ListValue());
+
+ SetResult(result_list);
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<std::string>& attached_pictures_bytes,
+ const std::vector<std::string>& attached_pictures_types) {
if (!parse_success) {
SendResponse(false);
return;
}
- SetResult(metadata_dictionary->DeepCopy());
+ base::ListValue* result_list = new base::ListValue();
+ result_list->Append(metadata_dictionary->DeepCopy());
+
+ // 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.
+ base::ListValue* attached_images_bytes_list = new base::ListValue();
+ for (std::vector<std::string>::const_iterator it =
+ attached_pictures_bytes.begin();
+ it != attached_pictures_bytes.end(); ++it) {
+ attached_images_bytes_list->Append(
+ base::BinaryValue::CreateWithCopiedBuffer(it->c_str(), it->length()));
+ }
+ result_list->Append(attached_images_bytes_list);
+
+ base::ListValue* attached_images_types_list = new base::ListValue();
+ attached_images_types_list->AppendStrings(attached_pictures_types);
+ result_list->Append(attached_images_types_list);
+
+ SetResult(result_list);
SendResponse(true);
}

Powered by Google App Engine
This is Rietveld 408576698