Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: ui/file_manager/image_loader/image_loader.js

Issue 631143002: Fix all type errors in image_loader. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 * Loads and resizes an image. 8 * Loads and resizes an image.
9 * @constructor 9 * @constructor
10 */ 10 */
(...skipping 16 matching lines...) Expand all
27 // scheduler. 27 // scheduler.
28 chrome.fileManagerPrivate.getVolumeMetadataList(function(volumeMetadataList) { 28 chrome.fileManagerPrivate.getVolumeMetadataList(function(volumeMetadataList) {
29 var initPromises = volumeMetadataList.map(function(volumeMetadata) { 29 var initPromises = volumeMetadataList.map(function(volumeMetadata) {
30 var requestPromise = new Promise(function(callback) { 30 var requestPromise = new Promise(function(callback) {
31 chrome.fileManagerPrivate.requestFileSystem( 31 chrome.fileManagerPrivate.requestFileSystem(
32 volumeMetadata.volumeId, 32 volumeMetadata.volumeId,
33 callback); 33 callback);
34 }); 34 });
35 return requestPromise; 35 return requestPromise;
36 }); 36 });
37 initPromises.push(new Promise(this.cache_.initialize.bind(this.cache_))); 37 initPromises.push(new Promise(function(resolve, reject) {
fukino 2014/10/07 09:52:44 The executor function which is given to Promise co
38 this.cache_.initialize(resolve);
39 }.bind(this)));
38 40
39 // After all initialization promises are done, start the scheduler. 41 // After all initialization promises are done, start the scheduler.
40 Promise.all(initPromises).then(this.scheduler_.start.bind(this.scheduler_)); 42 Promise.all(initPromises).then(this.scheduler_.start.bind(this.scheduler_));
41 43
42 // Listen for mount events, and grant permissions to volumes being mounted. 44 // Listen for mount events, and grant permissions to volumes being mounted.
43 chrome.fileManagerPrivate.onMountCompleted.addListener( 45 chrome.fileManagerPrivate.onMountCompleted.addListener(
44 function(event) { 46 function(event) {
45 if (event.eventType == 'mount' && event.status == 'success') { 47 if (event.eventType == 'mount' && event.status == 'success') {
46 chrome.fileManagerPrivate.requestFileSystem( 48 chrome.fileManagerPrivate.requestFileSystem(
47 event.volumeMetadata.volumeId, function() {}); 49 event.volumeMetadata.volumeId, function() {});
48 } 50 }
49 }); 51 });
50 }.bind(this)); 52 }.bind(this));
51 53
52 // Listen for incoming requests. 54 // Listen for incoming requests.
53 chrome.extension.onMessageExternal.addListener( 55 chrome.runtime.onMessageExternal.addListener(
54 function(request, sender, sendResponse) { 56 function(request, sender, sendResponse) {
55 if (ImageLoader.ALLOWED_CLIENTS.indexOf(sender.id) !== -1) { 57 if (ImageLoader.ALLOWED_CLIENTS.indexOf(sender.id) !== -1) {
56 // Sending a response may fail if the receiver already went offline. 58 // Sending a response may fail if the receiver already went offline.
57 // This is not an error, but a normal and quite common situation. 59 // This is not an error, but a normal and quite common situation.
58 var failSafeSendResponse = function(response) { 60 var failSafeSendResponse = function(response) {
59 try { 61 try {
60 sendResponse(response); 62 sendResponse(response);
61 } 63 }
62 catch (e) { 64 catch (e) {
63 // Ignore the error. 65 // Ignore the error.
64 } 66 }
65 }; 67 };
66 return this.onMessage_(sender.id, request, failSafeSendResponse); 68 return this.onMessage_(sender.id,
69 /** @type {LoadImageRequest} */ (request),
70 failSafeSendResponse);
67 } 71 }
68 }.bind(this)); 72 }.bind(this));
69 } 73 }
70 74
71 /** 75 /**
72 * List of extensions allowed to perform image requests. 76 * List of extensions allowed to perform image requests.
73 * 77 *
74 * @const 78 * @const
75 * @type {Array.<string>} 79 * @type {Array.<string>}
76 */ 80 */
77 ImageLoader.ALLOWED_CLIENTS = [ 81 ImageLoader.ALLOWED_CLIENTS = [
78 'hhaomjibdihmijegdhdafkllkbggdgoj', // File Manager's extension id. 82 'hhaomjibdihmijegdhdafkllkbggdgoj', // File Manager's extension id.
79 'nlkncpkkdoccmpiclbokaimcnedabhhm' // Gallery extension id. 83 'nlkncpkkdoccmpiclbokaimcnedabhhm' // Gallery extension id.
80 ]; 84 ];
81 85
82 /** 86 /**
83 * Handles a request. Depending on type of the request, starts or stops 87 * Handles a request. Depending on type of the request, starts or stops
84 * an image task. 88 * an image task.
85 * 89 *
86 * @param {string} senderId Sender's extension id. 90 * @param {string} senderId Sender's extension id.
87 * @param {Object} request Request message as a hash array. 91 * @param {LoadImageRequest} request Request message as a hash array.
88 * @param {function(Object)} callback Callback to be called to return response. 92 * @param {function(Object)} callback Callback to be called to return response.
89 * @return {boolean} True if the message channel should stay alive until the 93 * @return {boolean} True if the message channel should stay alive until the
90 * callback is called. 94 * callback is called.
91 * @private 95 * @private
92 */ 96 */
93 ImageLoader.prototype.onMessage_ = function(senderId, request, callback) { 97 ImageLoader.prototype.onMessage_ = function(senderId, request, callback) {
94 var requestId = senderId + ':' + request.taskId; 98 var requestId = senderId + ':' + request.taskId;
95 if (request.cancel) { 99 if (request.cancel) {
96 // Cancel a task. 100 // Cancel a task.
97 this.scheduler_.remove(requestId); 101 this.scheduler_.remove(requestId);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 targetContext.translate(target.width / 2, target.height / 2); 228 targetContext.translate(target.width / 2, target.height / 2);
225 targetContext.rotate(orientation * Math.PI / 2); 229 targetContext.rotate(orientation * Math.PI / 2);
226 targetContext.drawImage( 230 targetContext.drawImage(
227 source, 231 source,
228 0, 0, 232 0, 0,
229 source.width, source.height, 233 source.width, source.height,
230 -drawImageWidth / 2, -drawImageHeight / 2, 234 -drawImageWidth / 2, -drawImageHeight / 2,
231 drawImageWidth, drawImageHeight); 235 drawImageWidth, drawImageHeight);
232 targetContext.restore(); 236 targetContext.restore();
233 }; 237 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698