| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Client used to connect to the remote ImageLoader extension. Client class runs | 8 * Client used to connect to the remote ImageLoader extension. Client class runs |
| 9 * in the extension, where the client.js is included (eg. Files.app). | 9 * in the extension, where the client.js is included (eg. Files.app). |
| 10 * It sends remote requests using IPC to the ImageLoader class and forwards | 10 * It sends remote requests using IPC to the ImageLoader class and forwards |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 // Record cache usage. | 134 // Record cache usage. |
| 135 ImageLoaderClient.recordPercentage('Cache.Usage', this.cache_.getUsage()); | 135 ImageLoaderClient.recordPercentage('Cache.Usage', this.cache_.getUsage()); |
| 136 | 136 |
| 137 // Cancel old, invalid tasks. | 137 // Cancel old, invalid tasks. |
| 138 var taskKeys = Object.keys(this.tasks_); | 138 var taskKeys = Object.keys(this.tasks_); |
| 139 for (var index = 0; index < taskKeys.length; index++) { | 139 for (var index = 0; index < taskKeys.length; index++) { |
| 140 var taskKey = taskKeys[index]; | 140 var taskKey = taskKeys[index]; |
| 141 var task = this.tasks_[taskKey]; | 141 var task = this.tasks_[taskKey]; |
| 142 if (!task.isValid()) { | 142 if (!task.isValid()) { |
| 143 // Cancel this task since it is not valid anymore. | 143 // Cancel this task since it is not valid anymore. |
| 144 this.cancel(taskKey); | 144 this.cancel(parseInt(taskKey, 10)); |
| 145 delete this.tasks_[taskKey]; | 145 delete this.tasks_[taskKey]; |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 // Replace the extension id. | 149 // Replace the extension id. |
| 150 var sourceId = chrome.i18n.getMessage('@@extension_id'); | 150 var sourceId = chrome.i18n.getMessage('@@extension_id'); |
| 151 var targetId = ImageLoaderClient.EXTENSION_ID; | 151 var targetId = ImageLoaderClient.EXTENSION_ID; |
| 152 | 152 |
| 153 url = url.replace('filesystem:chrome-extension://' + sourceId, | 153 url = url.replace('filesystem:chrome-extension://' + sourceId, |
| 154 'filesystem:chrome-extension://' + targetId); | 154 'filesystem:chrome-extension://' + targetId); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 delete this.images_[key]; | 336 delete this.images_[key]; |
| 337 }; | 337 }; |
| 338 | 338 |
| 339 // Helper functions. | 339 // Helper functions. |
| 340 | 340 |
| 341 /** | 341 /** |
| 342 * Loads and resizes and image. Use opt_isValid to easily cancel requests | 342 * Loads and resizes and image. Use opt_isValid to easily cancel requests |
| 343 * which are not valid anymore, which will reduce cpu consumption. | 343 * which are not valid anymore, which will reduce cpu consumption. |
| 344 * | 344 * |
| 345 * @param {string} url Url of the requested image. | 345 * @param {string} url Url of the requested image. |
| 346 * @param {Image} image Image node to load the requested picture into. | 346 * @param {HTMLImageElement} image Image node to load the requested picture |
| 347 * into. |
| 347 * @param {Object} options Loader options, such as: orientation, scale, | 348 * @param {Object} options Loader options, such as: orientation, scale, |
| 348 * maxHeight, width, height and/or cache. | 349 * maxHeight, width, height and/or cache. |
| 349 * @param {function()} onSuccess Callback for success. | 350 * @param {function()} onSuccess Callback for success. |
| 350 * @param {function()} onError Callback for failure. | 351 * @param {function()} onError Callback for failure. |
| 351 * @param {function(): boolean=} opt_isValid Function returning false in case | 352 * @param {function(): boolean=} opt_isValid Function returning false in case |
| 352 * a request is not valid anymore, eg. parent node has been detached. | 353 * a request is not valid anymore, eg. parent node has been detached. |
| 353 * @return {?number} Remote task id or null if loaded from cache. | 354 * @return {?number} Remote task id or null if loaded from cache. |
| 354 */ | 355 */ |
| 355 ImageLoaderClient.loadToImage = function( | 356 ImageLoaderClient.loadToImage = function( |
| 356 url, image, options, onSuccess, onError, opt_isValid) { | 357 url, image, options, onSuccess, onError, opt_isValid) { |
| 357 var callback = function(result) { | 358 var callback = function(result) { |
| 358 if (result.status == 'error') { | 359 if (result.status == 'error') { |
| 359 onError(); | 360 onError(); |
| 360 return; | 361 return; |
| 361 } | 362 } |
| 362 image.src = result.data; | 363 image.src = result.data; |
| 363 onSuccess(); | 364 onSuccess(); |
| 364 }; | 365 }; |
| 365 | 366 |
| 366 return ImageLoaderClient.getInstance().load( | 367 return ImageLoaderClient.getInstance().load( |
| 367 url, callback, options, opt_isValid); | 368 url, callback, options, opt_isValid); |
| 368 }; | 369 }; |
| OLD | NEW |