| Index: ui/file_manager/image_loader/image_loader_util.js
|
| diff --git a/ui/file_manager/image_loader/image_loader.js b/ui/file_manager/image_loader/image_loader_util.js
|
| similarity index 56%
|
| copy from ui/file_manager/image_loader/image_loader.js
|
| copy to ui/file_manager/image_loader/image_loader_util.js
|
| index 491d614dfd80ebe785bba7e4f7383956b841747f..e9d9c4b8137eaf7303f7baee0713f46bb8d73faf 100644
|
| --- a/ui/file_manager/image_loader/image_loader.js
|
| +++ b/ui/file_manager/image_loader/image_loader_util.js
|
| @@ -1,133 +1,8 @@
|
| -// Copyright 2013 The Chromium Authors. All rights reserved.
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -/**
|
| - * Loads and resizes an image.
|
| - * @constructor
|
| - */
|
| -function ImageLoader() {
|
| - /**
|
| - * Persistent cache object.
|
| - * @type {ImageCache}
|
| - * @private
|
| - */
|
| - this.cache_ = new ImageCache();
|
| -
|
| - /**
|
| - * Manages pending requests and runs them in order of priorities.
|
| - * @type {Scheduler}
|
| - * @private
|
| - */
|
| - this.scheduler_ = new Scheduler();
|
| -
|
| - /**
|
| - * Piex loader for RAW images.
|
| - * @private {!PiexLoader}
|
| - */
|
| - this.piexLoader_ = new PiexLoader();
|
| -
|
| - // Grant permissions to all volumes, initialize the cache and then start the
|
| - // scheduler.
|
| - chrome.fileManagerPrivate.getVolumeMetadataList(function(volumeMetadataList) {
|
| - // Listen for mount events, and grant permissions to volumes being mounted.
|
| - chrome.fileManagerPrivate.onMountCompleted.addListener(
|
| - function(event) {
|
| - if (event.eventType === 'mount' && event.status === 'success') {
|
| - chrome.fileSystem.requestFileSystem(
|
| - {volumeId: event.volumeMetadata.volumeId}, function() {});
|
| - }
|
| - });
|
| - var initPromises = volumeMetadataList.map(function(volumeMetadata) {
|
| - var requestPromise = new Promise(function(callback) {
|
| - chrome.fileSystem.requestFileSystem(
|
| - {volumeId: volumeMetadata.volumeId},
|
| - /** @type {function(FileSystem=)} */(callback));
|
| - });
|
| - return requestPromise;
|
| - });
|
| - initPromises.push(new Promise(function(resolve, reject) {
|
| - this.cache_.initialize(resolve);
|
| - }.bind(this)));
|
| -
|
| - // After all initialization promises are done, start the scheduler.
|
| - Promise.all(initPromises).then(this.scheduler_.start.bind(this.scheduler_));
|
| - }.bind(this));
|
| -
|
| - // Listen for incoming requests.
|
| - chrome.runtime.onMessageExternal.addListener(
|
| - function(request, sender, sendResponse) {
|
| - if (ImageLoader.ALLOWED_CLIENTS.indexOf(sender.id) !== -1) {
|
| - // Sending a response may fail if the receiver already went offline.
|
| - // This is not an error, but a normal and quite common situation.
|
| - var failSafeSendResponse = function(response) {
|
| - try {
|
| - sendResponse(response);
|
| - }
|
| - catch (e) {
|
| - // Ignore the error.
|
| - }
|
| - };
|
| - if (typeof request.orientation === 'number') {
|
| - request.orientation =
|
| - ImageOrientation.fromDriveOrientation(request.orientation);
|
| - } else {
|
| - request.orientation = new ImageOrientation(1, 0, 0, 1);
|
| - }
|
| - return this.onMessage_(sender.id,
|
| - /** @type {LoadImageRequest} */ (request),
|
| - failSafeSendResponse);
|
| - }
|
| - }.bind(this));
|
| -}
|
| -
|
| -/**
|
| - * List of extensions allowed to perform image requests.
|
| - *
|
| - * @const
|
| - * @type {Array<string>}
|
| - */
|
| -ImageLoader.ALLOWED_CLIENTS = [
|
| - 'hhaomjibdihmijegdhdafkllkbggdgoj', // File Manager's extension id.
|
| - 'nlkncpkkdoccmpiclbokaimcnedabhhm', // Gallery's extension id.
|
| - 'jcgeabjmjgoblfofpppfkcoakmfobdko', // Video Player's extension id.
|
| -];
|
| -
|
| -/**
|
| - * Handles a request. Depending on type of the request, starts or stops
|
| - * an image task.
|
| - *
|
| - * @param {string} senderId Sender's extension id.
|
| - * @param {!LoadImageRequest} request Request message as a hash array.
|
| - * @param {function(Object)} callback Callback to be called to return response.
|
| - * @return {boolean} True if the message channel should stay alive until the
|
| - * callback is called.
|
| - * @private
|
| - */
|
| -ImageLoader.prototype.onMessage_ = function(senderId, request, callback) {
|
| - var requestId = senderId + ':' + request.taskId;
|
| - if (request.cancel) {
|
| - // Cancel a task.
|
| - this.scheduler_.remove(requestId);
|
| - return false; // No callback calls.
|
| - } else {
|
| - // Create a request task and add it to the scheduler (queue).
|
| - var requestTask = new ImageRequest(
|
| - requestId, this.cache_, this.piexLoader_, request, callback);
|
| - this.scheduler_.add(requestTask);
|
| - return true; // Request will call the callback.
|
| - }
|
| -};
|
| -
|
| -/**
|
| - * Returns the singleton instance.
|
| - * @return {ImageLoader} ImageLoader object.
|
| - */
|
| -ImageLoader.getInstance = function() {
|
| - if (!ImageLoader.instance_)
|
| - ImageLoader.instance_ = new ImageLoader();
|
| - return ImageLoader.instance_;
|
| -};
|
| +var ImageLoaderUtil = {};
|
|
|
| /**
|
| * Checks if the options contain any image processing.
|
| @@ -137,8 +12,9 @@ ImageLoader.getInstance = function() {
|
| * @param {Object} options Resizing options as a hash array.
|
| * @return {boolean} True if yes, false if not.
|
| */
|
| -ImageLoader.shouldProcess = function(width, height, options) {
|
| - var targetDimensions = ImageLoader.resizeDimensions(width, height, options);
|
| +ImageLoaderUtil.shouldProcess = function(width, height, options) {
|
| + var targetDimensions = ImageLoaderUtil.resizeDimensions(
|
| + width, height, options);
|
|
|
| // Dimensions has to be adjusted.
|
| if (targetDimensions.width != width || targetDimensions.height != height)
|
| @@ -168,7 +44,7 @@ ImageLoader.shouldProcess = function(width, height, options) {
|
| * @param {Object} options Resizing options as a hash array.
|
| * @return {Object} Dimensions, eg. {width: 100, height: 50}.
|
| */
|
| -ImageLoader.resizeDimensions = function(width, height, options) {
|
| +ImageLoaderUtil.resizeDimensions = function(width, height, options) {
|
| var scale = options.scale || 1;
|
| var targetDimensions = options.orientation.getSizeAfterCancelling(
|
| width * scale, height * scale);
|
| @@ -206,9 +82,10 @@ ImageLoader.resizeDimensions = function(width, height, options) {
|
| * @param {HTMLCanvasElement} target Target canvas.
|
| * @param {Object} options Resizing options as a hash array.
|
| */
|
| -ImageLoader.resizeAndCrop = function(source, target, options) {
|
| +ImageLoaderUtil.resizeAndCrop = function(source, target, options) {
|
| // Calculates copy parameters.
|
| - var copyParameters = ImageLoader.calculateCopyParameters(source, options);
|
| + var copyParameters = ImageLoaderUtil.calculateCopyParameters(
|
| + source, options);
|
| target.width = copyParameters.canvas.width;
|
| target.height = copyParameters.canvas.height;
|
|
|
| @@ -238,16 +115,16 @@ ImageLoader.resizeAndCrop = function(source, target, options) {
|
| * canvas: {width:number, height:number}
|
| * }}
|
| */
|
| -ImageLoader.CopyParameters;
|
| +ImageLoaderUtil.CopyParameters;
|
|
|
| /**
|
| * Calculates copy parameters.
|
| *
|
| * @param {HTMLCanvasElement|Image} source Source image or canvas.
|
| * @param {Object} options Resizing options as a hash array.
|
| - * @return {!ImageLoader.CopyParameters} Calculated copy parameters.
|
| + * @return {!ImageLoaderUtil.CopyParameters} Calculated copy parameters.
|
| */
|
| -ImageLoader.calculateCopyParameters = function(source, options) {
|
| +ImageLoaderUtil.calculateCopyParameters = function(source, options) {
|
| if (options.crop) {
|
| // When an image is cropped, target should be a fixed size square.
|
| assert(options.width);
|
| @@ -279,7 +156,7 @@ ImageLoader.calculateCopyParameters = function(source, options) {
|
| }
|
|
|
| // Target dimension is calculated in the rotated(transformed) coordinate.
|
| - var targetCanvasDimensions = ImageLoader.resizeDimensions(
|
| + var targetCanvasDimensions = ImageLoaderUtil.resizeDimensions(
|
| source.width, source.height, options);
|
|
|
| var targetDimensions = options.orientation.getSizeAfterCancelling(
|
| @@ -309,7 +186,7 @@ ImageLoader.calculateCopyParameters = function(source, options) {
|
| * Matrix converts AdobeRGB color space into sRGB color space.
|
| * @const {!Array<number>}
|
| */
|
| -ImageLoader.MATRIX_FROM_ADOBE_TO_STANDARD = [
|
| +ImageLoaderUtil.MATRIX_FROM_ADOBE_TO_STANDARD = [
|
| 1.39836, -0.39836, 0.00000,
|
| 0.00000, 1.00000, 0.00000,
|
| 0.00000, -0.04293, 1.04293
|
| @@ -320,11 +197,11 @@ ImageLoader.MATRIX_FROM_ADOBE_TO_STANDARD = [
|
| * @param {HTMLCanvasElement} target Target canvas.
|
| * @param {ColorSpace} colorSpace Current color space.
|
| */
|
| -ImageLoader.convertColorSpace = function(target, colorSpace) {
|
| +ImageLoaderUtil.convertColorSpace = function(target, colorSpace) {
|
| if (colorSpace === ColorSpace.SRGB)
|
| return;
|
| if (colorSpace === ColorSpace.ADOBE_RGB) {
|
| - var matrix = ImageLoader.MATRIX_FROM_ADOBE_TO_STANDARD;
|
| + var matrix = ImageLoaderUtil.MATRIX_FROM_ADOBE_TO_STANDARD;
|
| var context = target.getContext('2d');
|
| var imageData = context.getImageData(0, 0, target.width, target.height);
|
| var data = imageData.data;
|
| @@ -356,4 +233,4 @@ ImageLoader.convertColorSpace = function(target, colorSpace) {
|
| }
|
| context.putImageData(imageData, 0, 0);
|
| }
|
| -};
|
| +};
|
|
|