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

Unified Diff: chrome/renderer/resources/extensions/file_system_provider_custom_bindings.js

Issue 513683002: [fsp] Add support for providing thumbnails. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use scoped_ptr for EntryMetadata. Created 6 years, 4 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/renderer/resources/extensions/file_system_provider_custom_bindings.js
diff --git a/chrome/renderer/resources/extensions/file_system_provider_custom_bindings.js b/chrome/renderer/resources/extensions/file_system_provider_custom_bindings.js
index 020c772c849df1e94f07bcba46aad5888b11fd50..bbf52b30d21c8df9c85db6ce88a6f52f8f306ae9 100644
--- a/chrome/renderer/resources/extensions/file_system_provider_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/file_system_provider_custom_bindings.js
@@ -12,6 +12,13 @@ var fileSystemNatives = requireNative('file_system_natives');
var GetDOMError = fileSystemNatives.GetDOMError;
/**
+ * Maximum size of the thumbnail in bytes.
+ * @type {number}
+ * @const
+ */
+var METADATA_THUMBNAIL_SIZE_LIMIT = 32 * 1024 * 1024;
+
+/**
* Annotates a date with its serialized value.
* @param {Date} date Input date.
* @return {Date} Date with an extra <code>value</code> attribute.
@@ -24,6 +31,24 @@ function annotateDate(date) {
}
/**
+ * Verifies if the passed image URI is valid.
+ * @param {*} uri Image URI.
+ * @return {boolean} True if valid, valse otherwise.
+ */
+function verifyImageURI(uri) {
+ // The URI is specified by a user, so the type may be incorrect.
+ if (typeof uri != 'string' && !(uri instanceof String))
+ return false;
+
+ // The URL may be very large, but we care only about the prefix.
+ var uriLowerCase = uri.substr(0, 32).toLowerCase();
hirono 2014/08/29 06:02:41 Sorry I re-thought of this. Using regexp is better
mtomasz 2014/08/29 06:17:48 Done.
+
+ return uriLowerCase.indexOf('data:image/png;') == 0 ||
+ uriLowerCase.indexOf('data:image/jpeg;') == 0 ||
+ uriLowerCase.indexOf('data:image/webp;') == 0;
+}
+
+/**
* Annotates an entry metadata by serializing its modifiedTime value.
* @param {EntryMetadata} metadata Input metadata.
* @return {EntryMetadata} metadata Annotated metadata, which can be passed
@@ -38,6 +63,8 @@ function annotateMetadata(metadata) {
};
if ('mimeType' in metadata)
result.mimeType = metadata.mimeType;
+ if ('thumbnail' in metadata)
+ result.thumbnail = metadata.thumbnail;
return result;
}
@@ -141,6 +168,25 @@ eventBindings.registerArgumentMassager(
var executionStart = Date.now();
var options = args[0];
var onSuccessCallback = function(metadata) {
+ // It is invalid to return a thumbnail when it's not requested. The
+ // restriction is added in order to avoid fetching the thumbnail while
+ // it's not needed.
+ if (!options.thumbnail && metadata.thumbnail) {
+ fileSystemProviderInternal.operationRequestedError(
+ options.fileSystemId, options.requestId, 'FAILED',
+ Date.now() - executionStart);
+ throw new Error('Thumbnail data provided, but not requested.');
+ }
+
+ // Check the format and size. Note, that in the C++ layer, there is
+ // another sanity check to avoid passing any evil URL.
+ if ('thumbnail' in metadata && !verifyImageURI(metadata.thumbnail))
+ throw new Error('Thumbnail format invalid.');
+ if ('thumbnail' in metadata &&
+ metadata.thumbnail.length > METADATA_THUMBNAIL_SIZE_LIMIT) {
+ throw new Error('Thumbnail data too large.');
+ }
+
fileSystemProviderInternal.getMetadataRequestedSuccess(
options.fileSystemId,
options.requestId,
@@ -162,6 +208,16 @@ eventBindings.registerArgumentMassager(
var options = args[0];
var onSuccessCallback = function(entries, hasNext) {
var annotatedEntries = entries.map(annotateMetadata);
+ // It is invalid to return a thumbnail when it's not requested.
+ annotatedEntries.forEach(function(metadata) {
+ if (metadata.thumbnail) {
+ fileSystemProviderInternal.operationRequestedError(
+ options.fileSystemId, options.requestId, 'FAILED',
+ Date.now() - executionStart);
+ throw new Error(
+ 'Thumbnails must not be provided when reading a directory.');
+ }
+ });
fileSystemProviderInternal.readDirectoryRequestedSuccess(
options.fileSystemId, options.requestId, annotatedEntries, hasNext,
Date.now() - executionStart);

Powered by Google App Engine
This is Rietveld 408576698