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 * Loads and resizes an image. | 8 * Loads and resizes an image. |
9 * @constructor | 9 * @constructor |
10 */ | 10 */ |
11 function ImageLoader() { | 11 function ImageLoader() { |
12 /** | 12 /** |
13 * Persistent cache object. | 13 * Persistent cache object. |
14 * @type {Cache} | 14 * @type {Cache} |
15 * @private | 15 * @private |
16 */ | 16 */ |
17 this.cache_ = new Cache(); | 17 this.cache_ = new Cache(); |
18 | 18 |
19 /** | 19 /** |
20 * Manages pending requests and runs them in order of priorities. | 20 * Manages pending requests and runs them in order of priorities. |
21 * @type {Worker} | 21 * @type {Worker} |
22 * @private | 22 * @private |
23 */ | 23 */ |
24 this.worker_ = new Worker(); | 24 this.worker_ = new Worker(); |
25 | 25 |
26 // Grant permissions to all volumes, initialize the cache and then start the | 26 // Grant permissions to all volumes, initialize the cache and then start the |
27 // worker. | 27 // worker. |
28 chrome.fileBrowserPrivate.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.fileBrowserPrivate.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(this.cache_.initialize.bind(this.cache_))); |
38 | 38 |
39 // After all initialization promises are done, start the worker. | 39 // After all initialization promises are done, start the worker. |
40 Promise.all(initPromises).then(this.worker_.start.bind(this.worker_)); | 40 Promise.all(initPromises).then(this.worker_.start.bind(this.worker_)); |
41 | 41 |
42 // Listen for mount events, and grant permissions to volumes being mounted. | 42 // Listen for mount events, and grant permissions to volumes being mounted. |
43 chrome.fileBrowserPrivate.onMountCompleted.addListener( | 43 chrome.fileManagerPrivate.onMountCompleted.addListener( |
44 function(event) { | 44 function(event) { |
45 if (event.eventType == 'mount' && event.status == 'success') { | 45 if (event.eventType == 'mount' && event.status == 'success') { |
46 chrome.fileBrowserPrivate.requestFileSystem( | 46 chrome.fileManagerPrivate.requestFileSystem( |
47 event.volumeMetadata.volumeId, function() {}); | 47 event.volumeMetadata.volumeId, function() {}); |
48 } | 48 } |
49 }); | 49 }); |
50 }.bind(this)); | 50 }.bind(this)); |
51 | 51 |
52 // Listen for incoming requests. | 52 // Listen for incoming requests. |
53 chrome.extension.onMessageExternal.addListener(function(request, | 53 chrome.extension.onMessageExternal.addListener(function(request, |
54 sender, | 54 sender, |
55 sendResponse) { | 55 sendResponse) { |
56 if (ImageLoader.ALLOWED_CLIENTS.indexOf(sender.id) !== -1) { | 56 if (ImageLoader.ALLOWED_CLIENTS.indexOf(sender.id) !== -1) { |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 targetContext.translate(target.width / 2, target.height / 2); | 227 targetContext.translate(target.width / 2, target.height / 2); |
228 targetContext.rotate(orientation * Math.PI / 2); | 228 targetContext.rotate(orientation * Math.PI / 2); |
229 targetContext.drawImage( | 229 targetContext.drawImage( |
230 source, | 230 source, |
231 0, 0, | 231 0, 0, |
232 source.width, source.height, | 232 source.width, source.height, |
233 -drawImageWidth / 2, -drawImageHeight / 2, | 233 -drawImageWidth / 2, -drawImageHeight / 2, |
234 drawImageWidth, drawImageHeight); | 234 drawImageWidth, drawImageHeight); |
235 targetContext.restore(); | 235 targetContext.restore(); |
236 }; | 236 }; |
OLD | NEW |