Chromium Code Reviews| 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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 var id = opt_id || nextFileManagerWindowID; | 372 var id = opt_id || nextFileManagerWindowID; |
| 373 nextFileManagerWindowID = Math.max(nextFileManagerWindowID, id + 1); | 373 nextFileManagerWindowID = Math.max(nextFileManagerWindowID, id + 1); |
| 374 var appId = FILES_ID_PREFIX + id; | 374 var appId = FILES_ID_PREFIX + id; |
| 375 | 375 |
| 376 var appWindow = new AppWindowWrapper( | 376 var appWindow = new AppWindowWrapper( |
| 377 'main.html', | 377 'main.html', |
| 378 appId, | 378 appId, |
| 379 FILE_MANAGER_WINDOW_CREATE_OPTIONS); | 379 FILE_MANAGER_WINDOW_CREATE_OPTIONS); |
| 380 appWindow.launch(opt_appState || {}, false, function() { | 380 appWindow.launch(opt_appState || {}, false, function() { |
| 381 AppWindowWrapper.focusOnDesktop( | 381 AppWindowWrapper.focusOnDesktop( |
| 382 appWindow.window_, (opt_appState || {}).displayedId); | 382 appWindow.rawAppWindow, (opt_appState || {}).displayedId); |
| 383 if (opt_callback) | 383 if (opt_callback) |
| 384 opt_callback(appId); | 384 opt_callback(appId); |
| 385 onTaskCompleted(); | 385 onTaskCompleted(); |
| 386 }); | 386 }); |
| 387 }); | 387 }); |
| 388 } | 388 } |
| 389 | 389 |
| 390 /** | 390 /** |
| 391 * Registers dialog window to the background page. | 391 * Registers dialog window to the background page. |
| 392 * | 392 * |
| 393 * @param {Window} dialogWindow Window of the dialog. | 393 * @param {Window} dialogWindow Window of the dialog. |
| 394 */ | 394 */ |
| 395 function registerDialog(dialogWindow) { | 395 function registerDialog(dialogWindow) { |
| 396 var id = DIALOG_ID_PREFIX + (nextFileManagerDialogID++); | 396 var id = DIALOG_ID_PREFIX + (nextFileManagerDialogID++); |
| 397 background.dialogs[id] = dialogWindow; | 397 background.dialogs[id] = dialogWindow; |
| 398 dialogWindow.addEventListener('pagehide', function() { | 398 dialogWindow.addEventListener('pagehide', function() { |
| 399 delete background.dialogs[id]; | 399 delete background.dialogs[id]; |
| 400 }); | 400 }); |
| 401 } | 401 } |
| 402 | 402 |
| 403 /** | 403 /** |
| 404 * Executes a file browser task. | 404 * Executes a file browser task. |
| 405 * | 405 * |
| 406 * @param {string} action Task id. | 406 * @param {string} action Task id. |
| 407 * @param {Object} details Details object. | 407 * @param {Object} details Details object. |
| 408 * @private | 408 * @private |
| 409 */ | 409 */ |
| 410 FileBrowserBackground.prototype.onExecute_ = function(action, details) { | 410 FileBrowserBackground.prototype.onExecute_ = function(action, details) { |
| 411 switch (action) { | 411 var appState = { |
| 412 case 'play': | 412 params: {action: action}, |
| 413 var urls = util.entriesToURLs(details.entries); | 413 // It is not allowed to call getParent() here, since there may be |
| 414 launchAudioPlayer({items: urls, position: 0}); | 414 // no permissions to access it at this stage. Therefore we are passing |
| 415 break; | 415 // the selectionURL only, and the currentDirectory will be resolved |
| 416 // later. | |
| 417 selectionURL: details.entries[0].toURL() | |
| 418 }; | |
| 416 | 419 |
| 417 default: | 420 // Every other action opens a Files app window. |
| 418 var appState = { | 421 // For mounted devices just focus any Files.app window. The mounted |
| 419 params: {action: action}, | 422 // volume will appear on the navigation list. |
| 420 // It is not allowed to call getParent() here, since there may be | 423 launchFileManager( |
| 421 // no permissions to access it at this stage. Therefore we are passing | 424 appState, |
|
hirono
2014/10/10 07:56:14
nit: 4 spaces indent
| |
| 422 // the selectionURL only, and the currentDirectory will be resolved | 425 /* App ID */ null, |
| 423 // later. | 426 LaunchType.FOCUS_SAME_OR_CREATE); |
| 424 selectionURL: details.entries[0].toURL() | |
| 425 }; | |
| 426 | |
| 427 // Every other action opens a Files app window. | |
| 428 // For mounted devices just focus any Files.app window. The mounted | |
| 429 // volume will appear on the navigation list. | |
| 430 launchFileManager( | |
| 431 appState, | |
| 432 /* App ID */ null, | |
| 433 LaunchType.FOCUS_SAME_OR_CREATE); | |
| 434 break; | |
| 435 } | |
| 436 }; | 427 }; |
| 437 | 428 |
| 438 /** | 429 /** |
| 439 * Icon of the audio player. | |
| 440 * TODO(yoshiki): Consider providing an exact size icon, instead of relying | |
| 441 * on downsampling by ash. | |
| 442 * | |
| 443 * @type {string} | |
| 444 * @const | |
| 445 */ | |
| 446 var AUDIO_PLAYER_ICON = 'audio_player/icons/audio-player-64.png'; | |
| 447 | |
| 448 // The instance of audio player. Until it's ready, this is null. | |
| 449 var audioPlayer = null; | |
| 450 | |
| 451 // Queue to serializes the initialization, launching and reloading of the audio | |
| 452 // player, so races won't happen. | |
| 453 var audioPlayerInitializationQueue = new AsyncUtil.Queue(); | |
| 454 | |
| 455 audioPlayerInitializationQueue.run(function(callback) { | |
| 456 /** | |
| 457 * Audio player window create options. | |
| 458 * @type {Object} | |
| 459 */ | |
| 460 var audioPlayerCreateOptions = Object.freeze({ | |
| 461 type: 'panel', | |
| 462 hidden: true, | |
| 463 minHeight: 44 + 73, // 44px: track, 73px: controller | |
| 464 minWidth: 292, | |
| 465 height: 44 + 73, // collapsed | |
| 466 width: 292 | |
| 467 }); | |
| 468 | |
| 469 audioPlayer = new SingletonAppWindowWrapper('audio_player.html', | |
| 470 audioPlayerCreateOptions); | |
| 471 callback(); | |
| 472 }); | |
| 473 | |
| 474 /** | |
| 475 * Launches the audio player. | |
| 476 * @param {Object} playlist Playlist. | |
| 477 * @param {string=} opt_displayedId ProfileID of the desktop where the audio | |
| 478 * player should show. | |
| 479 */ | |
| 480 function launchAudioPlayer(playlist, opt_displayedId) { | |
| 481 audioPlayerInitializationQueue.run(function(callback) { | |
| 482 audioPlayer.launch(playlist, false, function(appWindow) { | |
| 483 audioPlayer.setIcon(AUDIO_PLAYER_ICON); | |
| 484 AppWindowWrapper.focusOnDesktop(audioPlayer.rawAppWindow, | |
| 485 opt_displayedId); | |
| 486 }); | |
| 487 callback(); | |
| 488 }); | |
| 489 } | |
| 490 | |
| 491 /** | |
| 492 * Launches the app. | 430 * Launches the app. |
| 493 * @private | 431 * @private |
| 494 */ | 432 */ |
| 495 FileBrowserBackground.prototype.onLaunched_ = function() { | 433 FileBrowserBackground.prototype.onLaunched_ = function() { |
| 496 if (nextFileManagerWindowID == 0) { | 434 if (nextFileManagerWindowID == 0) { |
| 497 // 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 |
| 498 // any more. | 436 // any more. |
| 499 chrome.storage.local.get(function(items) { | 437 chrome.storage.local.get(function(items) { |
| 500 for (var key in items) { | 438 for (var key in items) { |
| 501 if (items.hasOwnProperty(key)) { | 439 if (items.hasOwnProperty(key)) { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 523 try { | 461 try { |
| 524 var appState = JSON.parse(items[key]); | 462 var appState = JSON.parse(items[key]); |
| 525 launchFileManager(appState, id); | 463 launchFileManager(appState, id); |
| 526 } catch (e) { | 464 } catch (e) { |
| 527 console.error('Corrupt launch data for ' + id); | 465 console.error('Corrupt launch data for ' + id); |
| 528 } | 466 } |
| 529 } | 467 } |
| 530 } | 468 } |
| 531 } | 469 } |
| 532 }); | 470 }); |
| 533 | |
| 534 // Reopen audio player. | |
| 535 audioPlayerInitializationQueue.run(function(callback) { | |
| 536 audioPlayer.reopen(function() { | |
| 537 // If the audioPlayer is reopened, change its window's icon. Otherwise | |
| 538 // there is no reopened window so just skip the call of setIcon. | |
| 539 if (audioPlayer.rawAppWindow) | |
| 540 audioPlayer.setIcon(AUDIO_PLAYER_ICON); | |
| 541 }); | |
| 542 callback(); | |
| 543 }); | |
| 544 }; | 471 }; |
| 545 | 472 |
| 546 /** | 473 /** |
| 547 * Handles clicks on a custom item on the launcher context menu. | 474 * Handles clicks on a custom item on the launcher context menu. |
| 548 * @param {OnClickData} info Event details. | 475 * @param {OnClickData} info Event details. |
| 549 * @private | 476 * @private |
| 550 */ | 477 */ |
| 551 FileBrowserBackground.prototype.onContextMenuClicked_ = function(info) { | 478 FileBrowserBackground.prototype.onContextMenuClicked_ = function(info) { |
| 552 if (info.menuItemId == 'new-window') { | 479 if (info.menuItemId == 'new-window') { |
| 553 // Find the focused window (if any) and use it's current url for the | 480 // Find the focused window (if any) and use it's current url for the |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 594 contexts: ['launcher'], | 521 contexts: ['launcher'], |
| 595 title: str('NEW_WINDOW_BUTTON_LABEL') | 522 title: str('NEW_WINDOW_BUTTON_LABEL') |
| 596 }); | 523 }); |
| 597 }; | 524 }; |
| 598 | 525 |
| 599 /** | 526 /** |
| 600 * Singleton instance of Background. | 527 * Singleton instance of Background. |
| 601 * @type {FileBrowserBackground} | 528 * @type {FileBrowserBackground} |
| 602 */ | 529 */ |
| 603 window.background = new FileBrowserBackground(); | 530 window.background = new FileBrowserBackground(); |
| OLD | NEW |