OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 * Type of a Files.app's instance launch. | 8 * Type of a Files.app's instance launch. |
9 * @enum {number} | 9 * @enum {number} |
10 */ | 10 */ |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 * It turns to null after initialization. | 95 * It turns to null after initialization. |
96 * | 96 * |
97 * @type {Array.<function()>} | 97 * @type {Array.<function()>} |
98 * @private | 98 * @private |
99 */ | 99 */ |
100 this.initializeCallbacks_ = []; | 100 this.initializeCallbacks_ = []; |
101 | 101 |
102 /** | 102 /** |
103 * Last time when the background page can close. | 103 * Last time when the background page can close. |
104 * | 104 * |
105 * @type {number} | 105 * @type {?number} |
106 * @private | 106 * @private |
107 */ | 107 */ |
108 this.lastTimeCanClose_ = null; | 108 this.lastTimeCanClose_ = null; |
109 | 109 |
110 // Seal self. | 110 // Seal self. |
111 Object.seal(this); | 111 Object.seal(this); |
112 | 112 |
113 // Initialize handlers. | 113 // Initialize handlers. |
114 chrome.fileBrowserHandler.onExecute.addListener(this.onExecute_.bind(this)); | 114 chrome.fileBrowserHandler.onExecute.addListener(this.onExecute_.bind(this)); |
115 chrome.app.runtime.onLaunched.addListener(this.onLaunched_.bind(this)); | 115 chrome.app.runtime.onLaunched.addListener(this.onLaunched_.bind(this)); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 setTimeout(this.tryClose.bind(this), FileBrowserBackground.CLOSE_DELAY_MS_); | 192 setTimeout(this.tryClose.bind(this), FileBrowserBackground.CLOSE_DELAY_MS_); |
193 return false; | 193 return false; |
194 } | 194 } |
195 | 195 |
196 // Otherwise we can close the background page. | 196 // Otherwise we can close the background page. |
197 return true; | 197 return true; |
198 }; | 198 }; |
199 | 199 |
200 /** | 200 /** |
201 * Opens the root directory of the volume in Files.app. | 201 * Opens the root directory of the volume in Files.app. |
202 * @param {string} volumeId ID of a volume to be opened. | 202 * @param {string} devicePath Device path to a volume to be opened. |
203 * @private | 203 * @private |
204 */ | 204 */ |
205 FileBrowserBackground.prototype.navigateToVolume = function(devicePath) { | 205 FileBrowserBackground.prototype.navigateToVolume = function(devicePath) { |
206 VolumeManager.getInstance().then(function(volumeManager) { | 206 VolumeManager.getInstance().then(function(volumeManager) { |
207 var volumeInfoList = volumeManager.volumeInfoList; | 207 var volumeInfoList = volumeManager.volumeInfoList; |
208 for (var i = 0; i < volumeInfoList.length; i++) { | 208 for (var i = 0; i < volumeInfoList.length; i++) { |
209 if (volumeInfoList.item(i).devicePath == devicePath) | 209 if (volumeInfoList.item(i).devicePath == devicePath) |
210 return volumeInfoList.item(i).resolveDisplayRoot(); | 210 return volumeInfoList.item(i).resolveDisplayRoot(); |
211 } | 211 } |
212 return Promise.reject( | 212 return Promise.reject( |
213 'Volume having the device path: ' + devicePath + ' is not found.'); | 213 'Volume having the device path: ' + devicePath + ' is not found.'); |
214 }).then(function(entry) { | 214 }).then(function(entry) { |
215 launchFileManager( | 215 launchFileManager( |
216 {currentDirectoryURL: entry.toURL()}, | 216 {currentDirectoryURL: entry.toURL()}, |
217 /* App ID */ null, | 217 /* App ID */ undefined, |
218 LaunchType.FOCUS_SAME_OR_CREATE); | 218 LaunchType.FOCUS_SAME_OR_CREATE); |
219 }).catch(function(error) { | 219 }).catch(function(error) { |
220 console.error(error.stack || error); | 220 console.error(error.stack || error); |
221 }); | 221 }); |
222 }; | 222 }; |
223 | 223 |
224 /** | 224 /** |
225 * Prefix for the file manager window ID. | 225 * Prefix for the file manager window ID. |
226 * @type {string} | 226 * @type {string} |
227 * @const | 227 * @const |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 // the selectionURL only, and the currentDirectory will be resolved | 415 // the selectionURL only, and the currentDirectory will be resolved |
416 // later. | 416 // later. |
417 selectionURL: details.entries[0].toURL() | 417 selectionURL: details.entries[0].toURL() |
418 }; | 418 }; |
419 | 419 |
420 // Every other action opens a Files app window. | 420 // Every other action opens a Files app window. |
421 // For mounted devices just focus any Files.app window. The mounted | 421 // For mounted devices just focus any Files.app window. The mounted |
422 // volume will appear on the navigation list. | 422 // volume will appear on the navigation list. |
423 launchFileManager( | 423 launchFileManager( |
424 appState, | 424 appState, |
425 /* App ID */ null, | 425 /* App ID */ undefined, |
426 LaunchType.FOCUS_SAME_OR_CREATE); | 426 LaunchType.FOCUS_SAME_OR_CREATE); |
427 }; | 427 }; |
428 | 428 |
429 /** | 429 /** |
430 * Launches the app. | 430 * Launches the app. |
431 * @private | 431 * @private |
432 */ | 432 */ |
433 FileBrowserBackground.prototype.onLaunched_ = function() { | 433 FileBrowserBackground.prototype.onLaunched_ = function() { |
434 if (nextFileManagerWindowID == 0) { | 434 if (nextFileManagerWindowID == 0) { |
435 // The app just launched. Remove window state records that are not needed | 435 // The app just launched. Remove window state records that are not needed |
436 // any more. | 436 // any more. |
437 chrome.storage.local.get(function(items) { | 437 chrome.storage.local.get(function(items) { |
438 for (var key in items) { | 438 for (var key in items) { |
439 if (items.hasOwnProperty(key)) { | 439 if (items.hasOwnProperty(key)) { |
440 if (key.match(FILES_ID_PATTERN)) | 440 if (key.match(FILES_ID_PATTERN)) |
441 chrome.storage.local.remove(key); | 441 chrome.storage.local.remove(key); |
442 } | 442 } |
443 } | 443 } |
444 }); | 444 }); |
445 } | 445 } |
446 launchFileManager(null, null, LaunchType.FOCUS_ANY_OR_CREATE); | 446 launchFileManager(null, undefined, LaunchType.FOCUS_ANY_OR_CREATE); |
447 }; | 447 }; |
448 | 448 |
449 /** | 449 /** |
450 * Restarted the app, restore windows. | 450 * Restarted the app, restore windows. |
451 * @private | 451 * @private |
452 */ | 452 */ |
453 FileBrowserBackground.prototype.onRestarted_ = function() { | 453 FileBrowserBackground.prototype.onRestarted_ = function() { |
454 // Reopen file manager windows. | 454 // Reopen file manager windows. |
455 chrome.storage.local.get(function(items) { | 455 chrome.storage.local.get(function(items) { |
456 for (var key in items) { | 456 for (var key in items) { |
457 if (items.hasOwnProperty(key)) { | 457 if (items.hasOwnProperty(key)) { |
458 var match = key.match(FILES_ID_PATTERN); | 458 var match = key.match(FILES_ID_PATTERN); |
459 if (match) { | 459 if (match) { |
460 var id = Number(match[1]); | 460 var id = Number(match[1]); |
461 try { | 461 try { |
462 var appState = JSON.parse(items[key]); | 462 var appState = /** @type {Object} */ (JSON.parse(items[key])); |
463 launchFileManager(appState, id); | 463 launchFileManager(appState, id); |
464 } catch (e) { | 464 } catch (e) { |
465 console.error('Corrupt launch data for ' + id); | 465 console.error('Corrupt launch data for ' + id); |
466 } | 466 } |
467 } | 467 } |
468 } | 468 } |
469 } | 469 } |
470 }); | 470 }); |
471 }; | 471 }; |
472 | 472 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 contexts: ['launcher'], | 521 contexts: ['launcher'], |
522 title: str('NEW_WINDOW_BUTTON_LABEL') | 522 title: str('NEW_WINDOW_BUTTON_LABEL') |
523 }); | 523 }); |
524 }; | 524 }; |
525 | 525 |
526 /** | 526 /** |
527 * Singleton instance of Background. | 527 * Singleton instance of Background. |
528 * @type {FileBrowserBackground} | 528 * @type {FileBrowserBackground} |
529 */ | 529 */ |
530 window.background = new FileBrowserBackground(); | 530 window.background = new FileBrowserBackground(); |
OLD | NEW |