Chromium Code Reviews| Index: ui/file_manager/image_loader/request.js |
| diff --git a/ui/file_manager/image_loader/request.js b/ui/file_manager/image_loader/request.js |
| index 5e2e11162057a553087a95058448daa0c3073123..ef33101cabbb11be2158c9f0ded4227275ba9151 100644 |
| --- a/ui/file_manager/image_loader/request.js |
| +++ b/ui/file_manager/image_loader/request.js |
| @@ -228,6 +228,9 @@ Request.prototype.downloadOriginal_ = function(onSuccess, onFailure) { |
| // Fetch the image via authorized XHR and parse it. |
| var parseImage = function(contentType, blob) { |
| + if (contentType) |
| + this.contentType_ = contentType; |
| + |
| this.image_.src = URL.createObjectURL(blob); |
| }.bind(this); |
| @@ -245,6 +248,19 @@ function AuthorizedXHR() { |
| } |
| /** |
| + * A map which is used to estimate content type from extension. |
| + * @enum {string} |
| + */ |
| +AuthorizedXHR.ExtensionContentTypeMap = { |
| + gif: 'image/gif', |
| + png: 'image/png', |
| + svg: 'image/svg', |
| + bmp: 'image/bmp', |
| + jpg: 'image/jpeg', |
| + jpeg: 'image/jpeg' |
| +}; |
| + |
| +/** |
| * Aborts the current request (if running). |
| */ |
| AuthorizedXHR.prototype.abort = function() { |
| @@ -268,6 +284,12 @@ AuthorizedXHR.prototype.load = function(url, onSuccess, onFailure) { |
| // Do not call any callbacks when aborting. |
| var onMaybeSuccess = /** @type {function(string, Blob)} */ ( |
| function(contentType, response) { |
| + // When content type is not available, try to estimate it from url. |
| + if (!contentType) { |
| + contentType = AuthorizedXHR.ExtensionContentTypeMap[ |
| + this.extractExtension_(url)]; |
|
fukino
2015/02/18 10:45:22
Is reading ExtensionContentTypeMap[null] intended?
yawano
2015/02/18 11:32:50
Yes. Intention is that undefined will be set when
|
| + } |
| + |
| if (!this.aborted_) |
| onSuccess(contentType, response); |
| }.bind(this)); |
| @@ -318,6 +340,16 @@ AuthorizedXHR.prototype.load = function(url, onSuccess, onFailure) { |
| }; |
| /** |
| + * Extracts extension from url. |
| + * @param {string} url Url. |
| + * @return {?string} Extracted extensiion, e.g. png. |
| + */ |
| +AuthorizedXHR.prototype.extractExtension_ = function(url) { |
| + var result = (/\.([a-zA-Z]+)$/i).exec(url); |
| + return result ? result[1] : null; |
|
fukino
2015/02/18 10:45:22
Returning '' for missing extension looks better fo
yawano
2015/02/18 11:32:50
Done.
|
| +}; |
| + |
| +/** |
| * Fetches data using authorized XmlHttpRequest with the provided OAuth2 token. |
| * If the token is invalid, the request will fail. |
| * |