| 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..49fdd37e0f278cb7dbc470e56de837836f207b1b 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)];
|
| + }
|
| +
|
| 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] : '';
|
| +};
|
| +
|
| +/**
|
| * Fetches data using authorized XmlHttpRequest with the provided OAuth2 token.
|
| * If the token is invalid, the request will fail.
|
| *
|
|
|