Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / file_manager / image_loader / image_loader_client.js
index 6e2ba13..fdc0d23 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-'use strict';
-
 /**
  * Client used to connect to the remote ImageLoader extension. Client class runs
  * in the extension, where the client.js is included (eg. Files.app).
@@ -17,7 +15,7 @@
 function ImageLoaderClient() {
   /**
    * Hash array with active tasks.
-   * @type {Object}
+   * @type {!Object}
    * @private
    */
   this.tasks_ = {};
@@ -45,7 +43,7 @@ ImageLoaderClient.EXTENSION_ID = 'pmfjbimdmchhbnneeidfognadeopoehp';
 
 /**
  * Returns a singleton instance.
- * @return {Client} Client instance.
+ * @return {ImageLoaderClient} Client instance.
  */
 ImageLoaderClient.getInstance = function() {
   if (!ImageLoaderClient.instance_)
@@ -87,9 +85,8 @@ ImageLoaderClient.recordPercentage = function(name, value) {
  */
 ImageLoaderClient.sendMessage_ = function(request, opt_callback) {
   opt_callback = opt_callback || function(response) {};
-  var sendMessage = chrome.runtime ? chrome.runtime.sendMessage :
-                                     chrome.extension.sendMessage;
-  sendMessage(ImageLoaderClient.EXTENSION_ID, request, opt_callback);
+  chrome.runtime.sendMessage(
+      ImageLoaderClient.EXTENSION_ID, request, opt_callback);
 };
 
 /**
@@ -120,7 +117,7 @@ ImageLoaderClient.prototype.handleMessage_ = function(message) {
  * which are not valid anymore, which will reduce cpu consumption.
  *
  * @param {string} url Url of the requested image.
- * @param {function} callback Callback used to return response.
+ * @param {function(Object)} callback Callback used to return response.
  * @param {Object=} opt_options Loader options, such as: scale, maxHeight,
  *     width, height and/or cache.
  * @param {function(): boolean=} opt_isValid Function returning false in case
@@ -129,7 +126,7 @@ ImageLoaderClient.prototype.handleMessage_ = function(message) {
  */
 ImageLoaderClient.prototype.load = function(
     url, callback, opt_options, opt_isValid) {
-  opt_options = opt_options || {};
+  opt_options = /** @type {{cache: (boolean|undefined)}} */(opt_options || {});
   opt_isValid = opt_isValid || function() { return true; };
 
   // Record cache usage.
@@ -142,7 +139,7 @@ ImageLoaderClient.prototype.load = function(
     var task = this.tasks_[taskKey];
     if (!task.isValid()) {
       // Cancel this task since it is not valid anymore.
-      this.cancel(taskKey);
+      this.cancel(parseInt(taskKey, 10));
       delete this.tasks_[taskKey];
     }
   }
@@ -158,18 +155,18 @@ ImageLoaderClient.prototype.load = function(
   var cacheKey = ImageLoaderClient.Cache.createKey(url, opt_options);
   if (opt_options.cache) {
     // Load from cache.
-    ImageLoaderClient.recordBinary('Cached', 1);
+    ImageLoaderClient.recordBinary('Cached', true);
     var cachedData = this.cache_.loadImage(cacheKey, opt_options.timestamp);
     if (cachedData) {
-      ImageLoaderClient.recordBinary('Cache.HitMiss', 1);
+      ImageLoaderClient.recordBinary('Cache.HitMiss', true);
       callback({status: 'success', data: cachedData});
       return null;
     } else {
-      ImageLoaderClient.recordBinary('Cache.HitMiss', 0);
+      ImageLoaderClient.recordBinary('Cache.HitMiss', false);
     }
   } else {
     // Remove from cache.
-    ImageLoaderClient.recordBinary('Cached', 0);
+    ImageLoaderClient.recordBinary('Cached', false);
     this.cache_.removeImage(cacheKey);
   }
 
@@ -275,10 +272,10 @@ ImageLoaderClient.Cache.prototype.saveImage = function(
     this.removeImage(key);
 
   if (ImageLoaderClient.Cache.MEMORY_LIMIT - this.size_ < data.length) {
-    ImageLoaderClient.recordBinary('Evicted', 1);
+    ImageLoaderClient.recordBinary('Evicted', true);
     this.evictCache_(data.length);
   } else {
-    ImageLoaderClient.recordBinary('Evicted', 0);
+    ImageLoaderClient.recordBinary('Evicted', false);
   }
 
   if (ImageLoaderClient.Cache.MEMORY_LIMIT - this.size_ >= data.length) {
@@ -344,12 +341,13 @@ ImageLoaderClient.Cache.prototype.removeImage = function(key) {
  * which are not valid anymore, which will reduce cpu consumption.
  *
  * @param {string} url Url of the requested image.
- * @param {Image} image Image node to load the requested picture into.
+ * @param {HTMLImageElement} image Image node to load the requested picture
+ *     into.
  * @param {Object} options Loader options, such as: orientation, scale,
  *     maxHeight, width, height and/or cache.
- * @param {function} onSuccess Callback for success.
- * @param {function} onError Callback for failure.
- * @param {function=} opt_isValid Function returning false in case
+ * @param {function()} onSuccess Callback for success.
+ * @param {function()} onError Callback for failure.
+ * @param {function(): boolean=} opt_isValid Function returning false in case
  *     a request is not valid anymore, eg. parent node has been detached.
  * @return {?number} Remote task id or null if loaded from cache.
  */