Commit 5e19ebf3 authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

[quickview] Show RAW image EXIF metadata in <files-metadata-box>

Update the metadata sub-system to extract RAW image file ifd via Image
Loader. Add metadata/BUILD.gn dependency on Image Loader.

Change metadata box controller to request ifd for RAW images, and show
the result in the <files-metadata-box>. Change ‘openQuickViewImageRaw’
test to verify that RAW image metadata is shown in the metadata box.

Test: browser_tests —gtest_filter=“QuickView*openQuickViewImageRaw”
Bug: 965370
Change-Id: Ie70aba24904e392724c3ce6b1183f1b24b207b06
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1697701
Commit-Queue: Noel Gordon <noel@chromium.org>
Reviewed-by: default avatarAlex Danilo <adanilo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676324}
parent d4ae68ef
...@@ -51,6 +51,7 @@ js_library("content_metadata_provider") { ...@@ -51,6 +51,7 @@ js_library("content_metadata_provider") {
":metadata_provider", ":metadata_provider",
"../../../common/js:file_type", "../../../common/js:file_type",
"../../../common/js:util", "../../../common/js:util",
"../../js:thumbnail_loader",
] ]
} }
......
...@@ -84,21 +84,18 @@ class ContentMetadataProvider extends MetadataProvider { ...@@ -84,21 +84,18 @@ class ContentMetadataProvider extends MetadataProvider {
* @private * @private
*/ */
getImpl_(entry, names, callback) { getImpl_(entry, names, callback) {
// Directories do not have a thumbnail.
if (entry.isDirectory) { if (entry.isDirectory) {
setTimeout( const error = this.createError_(entry.toURL(), 'get', 'no thumbnail');
callback.bind( setTimeout(callback.bind(null, error), 0);
null,
this.createError_(
entry.toURL(), 'get',
'we don\'t generate thumbnails for directory')),
0);
return; return;
} }
// TODO(ryoh): mediaGalleries API does not handle
// image metadata correctly. const type = FileType.getType(entry);
// TODO(ryoh): mediaGalleries API does not handle image metadata correctly.
// We parse it in our pure js parser. // We parse it in our pure js parser.
// chrome/browser/media_galleries/fileapi/supported_image_type_validator.cc // chrome/browser/media_galleries/fileapi/supported_image_type_validator.cc
const type = FileType.getType(entry);
if (type && type.type === 'image') { if (type && type.type === 'image') {
const url = entry.toURL(); const url = entry.toURL();
if (this.callbacks_[url]) { if (this.callbacks_[url]) {
...@@ -109,6 +106,55 @@ class ContentMetadataProvider extends MetadataProvider { ...@@ -109,6 +106,55 @@ class ContentMetadataProvider extends MetadataProvider {
} }
return; return;
} }
if (type && type.type === 'raw' && names.includes('ifd')) {
names.splice(names.indexOf('ifd'), 1); // Remove ifd from names.
/**
* Creates an ifdError metadata item: when reading the fileEntry failed
* or extracting its ifd data failed.
* @param {!Entry} fileEntry
* @param {string} error
*/
function createIfdError(fileEntry, error) {
const url = fileEntry.toURL();
const step = 'read file entry';
const item = new MetadataItem();
item.ifdError = new ContentMetadataProvider.Error(url, step, error);
return item;
}
new Promise((resolve, reject) => {
entry.file(
file => {
const request = LoadImageRequest.createForUrl(entry.toURL());
request.maxWidth = ThumbnailLoader.THUMBNAIL_MAX_WIDTH;
request.maxHeight = ThumbnailLoader.THUMBNAIL_MAX_HEIGHT;
request.timestamp = file.lastModified;
request.cache = true;
request.priority = 0;
ImageLoaderClient.getInstance().load(request, resolve);
},
error => {
callback(createIfdError(entry, error.toString()));
});
}).then(result => {
if (result.status === LoadImageResponseStatus.SUCCESS) {
const item = new MetadataItem();
if (result.ifd) {
item.ifd = /** @type {!Object} */ (JSON.parse(result.ifd));
}
callback(item);
} else {
callback(createIfdError(entry, 'raw file has no ifd data'));
}
});
if (!names.length) {
return;
}
}
this.getFromMediaGalleries_(entry, names).then(callback); this.getFromMediaGalleries_(entry, names).then(callback);
} }
......
...@@ -209,6 +209,16 @@ MetadataBoxController.prototype.onGeneralMetadataLoaded_ = function( ...@@ -209,6 +209,16 @@ MetadataBoxController.prototype.onGeneralMetadataLoaded_ = function(
this.metadataBox_.metadataRendered('meta'); this.metadataBox_.metadataRendered('meta');
}); });
} }
} else if (type === 'raw') {
const data = ['ifd'];
this.metadataModel_.get([entry], data).then(items => {
const raw = items[0].ifd ? items[0].ifd : {};
this.metadataBox_.type = items[0].ifd ? 'image' : '';
this.metadataBox_.ifd = items[0].ifd ? {raw} : null;
this.metadataBox_.imageWidth = raw.width || 0;
this.metadataBox_.imageHeight = raw.height || 0;
this.metadataBox_.metadataRendered('meta');
});
} }
}; };
......
...@@ -855,9 +855,13 @@ ...@@ -855,9 +855,13 @@
const mimeType = await getQuickViewMetadataBoxField(appId, 'Type'); const mimeType = await getQuickViewMetadataBoxField(appId, 'Type');
chrome.test.assertEq('image/x-olympus-orf', mimeType); chrome.test.assertEq('image/x-olympus-orf', mimeType);
// Check: the image EXIF metadata should be displayed. // Check: the RAW image EXIF metadata should be displayed.
// TODO(crbug.com/965370) Make the metadata controller extract and display const size = await getQuickViewMetadataBoxField(appId, 'Dimensions');
// the RAW image EXIF metadata in the metadata box. chrome.test.assertEq('4608 x 3456', size);
const model = await getQuickViewMetadataBoxField(appId, 'Device model');
chrome.test.assertEq(model, 'E-M1');
const film = await getQuickViewMetadataBoxField(appId, 'Device settings');
chrome.test.assertEq('f/8 0.002 12mm ISO200', film);
}; };
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment