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 * Number of runtime errors catched in the background page. | 8 * Number of runtime errors catched in the background page. |
9 * @type {number} | 9 * @type {number} |
10 */ | 10 */ |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 * @param {string} iconPath Path of the icon. | 287 * @param {string} iconPath Path of the icon. |
288 */ | 288 */ |
289 AppWindowWrapper.prototype.setIcon = function(iconPath) { | 289 AppWindowWrapper.prototype.setIcon = function(iconPath) { |
290 this.window_.setIcon(iconPath); | 290 this.window_.setIcon(iconPath); |
291 }; | 291 }; |
292 | 292 |
293 /** | 293 /** |
294 * Opens the window. | 294 * Opens the window. |
295 * | 295 * |
296 * @param {Object} appState App state. | 296 * @param {Object} appState App state. |
| 297 * @param {boolean} reopen True if the launching is triggered automatically. |
| 298 * False otherwize. |
297 * @param {function()=} opt_callback Completion callback. | 299 * @param {function()=} opt_callback Completion callback. |
298 */ | 300 */ |
299 AppWindowWrapper.prototype.launch = function(appState, opt_callback) { | 301 AppWindowWrapper.prototype.launch = function(appState, reopen, opt_callback) { |
300 // Check if the window is opened or not. | 302 // Check if the window is opened or not. |
301 if (this.openingOrOpened_) { | 303 if (this.openingOrOpened_) { |
302 console.error('The window is already opened.'); | 304 console.error('The window is already opened.'); |
303 if (opt_callback) | 305 if (opt_callback) |
304 opt_callback(); | 306 opt_callback(); |
305 return; | 307 return; |
306 } | 308 } |
307 this.openingOrOpened_ = true; | 309 this.openingOrOpened_ = true; |
308 | 310 |
309 // Save application state. | 311 // Save application state. |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 nextBottom % screen.availHeight : nextTop; | 387 nextBottom % screen.availHeight : nextTop; |
386 } | 388 } |
387 this.window_.moveTo(candidateBounds.left, candidateBounds.top); | 389 this.window_.moveTo(candidateBounds.left, candidateBounds.top); |
388 | 390 |
389 // Save the properties. | 391 // Save the properties. |
390 var appWindow = this.window_; | 392 var appWindow = this.window_; |
391 background.appWindows[this.id_] = appWindow; | 393 background.appWindows[this.id_] = appWindow; |
392 var contentWindow = appWindow.contentWindow; | 394 var contentWindow = appWindow.contentWindow; |
393 contentWindow.appID = this.id_; | 395 contentWindow.appID = this.id_; |
394 contentWindow.appState = this.appState_; | 396 contentWindow.appState = this.appState_; |
| 397 contentWindow.appReopen = reopen; |
395 contentWindow.appInitialURL = this.url_; | 398 contentWindow.appInitialURL = this.url_; |
396 if (window.IN_TEST) | 399 if (window.IN_TEST) |
397 contentWindow.IN_TEST = true; | 400 contentWindow.IN_TEST = true; |
398 | 401 |
399 // Register event listners. | 402 // Register event listners. |
400 appWindow.onBoundsChanged.addListener(this.onBoundsChanged_.bind(this)); | 403 appWindow.onBoundsChanged.addListener(this.onBoundsChanged_.bind(this)); |
401 appWindow.onClosed.addListener(this.onClosed_.bind(this)); | 404 appWindow.onClosed.addListener(this.onClosed_.bind(this)); |
402 | 405 |
403 // Callback. | 406 // Callback. |
404 if (opt_callback) | 407 if (opt_callback) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 * Inherits from AppWindowWrapper. | 470 * Inherits from AppWindowWrapper. |
468 */ | 471 */ |
469 SingletonAppWindowWrapper.prototype = {__proto__: AppWindowWrapper.prototype}; | 472 SingletonAppWindowWrapper.prototype = {__proto__: AppWindowWrapper.prototype}; |
470 | 473 |
471 /** | 474 /** |
472 * Open the window. | 475 * Open the window. |
473 * | 476 * |
474 * Activates an existing window or creates a new one. | 477 * Activates an existing window or creates a new one. |
475 * | 478 * |
476 * @param {Object} appState App state. | 479 * @param {Object} appState App state. |
| 480 * @param {boolean} reopen True if the launching is triggered automatically. |
| 481 * False otherwize. |
477 * @param {function()=} opt_callback Completion callback. | 482 * @param {function()=} opt_callback Completion callback. |
478 */ | 483 */ |
479 SingletonAppWindowWrapper.prototype.launch = function(appState, opt_callback) { | 484 SingletonAppWindowWrapper.prototype.launch = |
| 485 function(appState, reopen, opt_callback) { |
480 // If the window is not opened yet, just call the parent method. | 486 // If the window is not opened yet, just call the parent method. |
481 if (!this.openingOrOpened_) { | 487 if (!this.openingOrOpened_) { |
482 AppWindowWrapper.prototype.launch.call(this, appState, opt_callback); | 488 AppWindowWrapper.prototype.launch.call( |
| 489 this, appState, reopen, opt_callback); |
483 return; | 490 return; |
484 } | 491 } |
485 | 492 |
486 // If the window is already opened, reload the window. | 493 // If the window is already opened, reload the window. |
487 // The queue is used to wait until the window is opened. | 494 // The queue is used to wait until the window is opened. |
488 this.queue.run(function(nextStep) { | 495 this.queue.run(function(nextStep) { |
489 this.window_.contentWindow.appState = appState; | 496 this.window_.contentWindow.appState = appState; |
| 497 this.window_.contentWindow.appReopen = reopen; |
490 this.window_.contentWindow.reload(); | 498 this.window_.contentWindow.reload(); |
491 if (opt_callback) | 499 if (opt_callback) |
492 opt_callback(); | 500 opt_callback(); |
493 nextStep(); | 501 nextStep(); |
494 }.bind(this)); | 502 }.bind(this)); |
495 }; | 503 }; |
496 | 504 |
497 /** | 505 /** |
498 * Reopen a window if its state is saved in the local storage. | 506 * Reopen a window if its state is saved in the local storage. |
499 * @param {function()=} opt_callback Completion callback. | 507 * @param {function()=} opt_callback Completion callback. |
500 */ | 508 */ |
501 SingletonAppWindowWrapper.prototype.reopen = function(opt_callback) { | 509 SingletonAppWindowWrapper.prototype.reopen = function(opt_callback) { |
502 chrome.storage.local.get(this.id_, function(items) { | 510 chrome.storage.local.get(this.id_, function(items) { |
503 var value = items[this.id_]; | 511 var value = items[this.id_]; |
504 if (!value) { | 512 if (!value) { |
505 opt_callback && opt_callback(); | 513 opt_callback && opt_callback(); |
506 return; // No app state persisted. | 514 return; // No app state persisted. |
507 } | 515 } |
508 | 516 |
509 try { | 517 try { |
510 var appState = JSON.parse(value); | 518 var appState = JSON.parse(value); |
511 } catch (e) { | 519 } catch (e) { |
512 console.error('Corrupt launch data for ' + this.id_, value); | 520 console.error('Corrupt launch data for ' + this.id_, value); |
513 opt_callback && opt_callback(); | 521 opt_callback && opt_callback(); |
514 return; | 522 return; |
515 } | 523 } |
516 this.launch(appState, opt_callback); | 524 this.launch(appState, true, opt_callback); |
517 }.bind(this)); | 525 }.bind(this)); |
518 }; | 526 }; |
519 | 527 |
520 /** | 528 /** |
521 * Prefix for the file manager window ID. | 529 * Prefix for the file manager window ID. |
522 */ | 530 */ |
523 var FILES_ID_PREFIX = 'files#'; | 531 var FILES_ID_PREFIX = 'files#'; |
524 | 532 |
525 /** | 533 /** |
526 * Regexp matching a file manager window ID. | 534 * Regexp matching a file manager window ID. |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 // for other types. | 658 // for other types. |
651 | 659 |
652 var id = opt_id || nextFileManagerWindowID; | 660 var id = opt_id || nextFileManagerWindowID; |
653 nextFileManagerWindowID = Math.max(nextFileManagerWindowID, id + 1); | 661 nextFileManagerWindowID = Math.max(nextFileManagerWindowID, id + 1); |
654 var appId = FILES_ID_PREFIX + id; | 662 var appId = FILES_ID_PREFIX + id; |
655 | 663 |
656 var appWindow = new AppWindowWrapper( | 664 var appWindow = new AppWindowWrapper( |
657 'main.html', | 665 'main.html', |
658 appId, | 666 appId, |
659 FILE_MANAGER_WINDOW_CREATE_OPTIONS); | 667 FILE_MANAGER_WINDOW_CREATE_OPTIONS); |
660 appWindow.launch(opt_appState || {}, function() { | 668 appWindow.launch(opt_appState || {}, false, function() { |
661 AppWindowWrapper.focusOnDesktop( | 669 AppWindowWrapper.focusOnDesktop( |
662 appWindow.window_, (opt_appState || {}).displayedId); | 670 appWindow.window_, (opt_appState || {}).displayedId); |
663 if (opt_callback) | 671 if (opt_callback) |
664 opt_callback(appId); | 672 opt_callback(appId); |
665 onTaskCompleted(); | 673 onTaskCompleted(); |
666 }); | 674 }); |
667 }); | 675 }); |
668 } | 676 } |
669 | 677 |
670 /** | 678 /** |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 }); | 784 }); |
777 | 785 |
778 /** | 786 /** |
779 * Launches the audio player. | 787 * Launches the audio player. |
780 * @param {Object} playlist Playlist. | 788 * @param {Object} playlist Playlist. |
781 * @param {string=} opt_displayedId ProfileID of the desktop where the audio | 789 * @param {string=} opt_displayedId ProfileID of the desktop where the audio |
782 * player should show. | 790 * player should show. |
783 */ | 791 */ |
784 function launchAudioPlayer(playlist, opt_displayedId) { | 792 function launchAudioPlayer(playlist, opt_displayedId) { |
785 audioPlayerInitializationQueue.run(function(callback) { | 793 audioPlayerInitializationQueue.run(function(callback) { |
786 audioPlayer.launch(playlist, function(appWindow) { | 794 audioPlayer.launch(playlist, false, function(appWindow) { |
787 audioPlayer.setIcon(AUDIO_PLAYER_ICON); | 795 audioPlayer.setIcon(AUDIO_PLAYER_ICON); |
788 AppWindowWrapper.focusOnDesktop(audioPlayer.rawAppWindow, | 796 AppWindowWrapper.focusOnDesktop(audioPlayer.rawAppWindow, |
789 opt_displayedId); | 797 opt_displayedId); |
790 }); | 798 }); |
791 callback(); | 799 callback(); |
792 }); | 800 }); |
793 } | 801 } |
794 | 802 |
795 var videoPlayer = new SingletonAppWindowWrapper('video_player.html', | 803 var videoPlayer = new SingletonAppWindowWrapper('video_player.html', |
796 {hidden: true}); | 804 {hidden: true}); |
797 | 805 |
798 /** | 806 /** |
799 * Launches the video player. | 807 * Launches the video player. |
800 * @param {string} url Video url. | 808 * @param {string} url Video url. |
801 * @param {string=} opt_displayedId ProfileID of the desktop where the video | 809 * @param {string=} opt_displayedId ProfileID of the desktop where the video |
802 * player should show. | 810 * player should show. |
803 */ | 811 */ |
804 function launchVideoPlayer(url, opt_displayedId) { | 812 function launchVideoPlayer(url, opt_displayedId) { |
805 videoPlayer.launch({url: url}, function(appWindow) { | 813 videoPlayer.launch({url: url}, false, function(appWindow) { |
806 AppWindowWrapper.focusOnDesktop(videoPlayer.rawAppWindow, opt_displayedId); | 814 AppWindowWrapper.focusOnDesktop(videoPlayer.rawAppWindow, opt_displayedId); |
807 }); | 815 }); |
808 } | 816 } |
809 | 817 |
810 /** | 818 /** |
811 * Launches the app. | 819 * Launches the app. |
812 * @private | 820 * @private |
813 */ | 821 */ |
814 Background.prototype.onLaunched_ = function() { | 822 Background.prototype.onLaunched_ = function() { |
815 if (nextFileManagerWindowID == 0) { | 823 if (nextFileManagerWindowID == 0) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 contexts: ['launcher'], | 920 contexts: ['launcher'], |
913 title: str('NEW_WINDOW_BUTTON_LABEL') | 921 title: str('NEW_WINDOW_BUTTON_LABEL') |
914 }); | 922 }); |
915 }; | 923 }; |
916 | 924 |
917 /** | 925 /** |
918 * Singleton instance of Background. | 926 * Singleton instance of Background. |
919 * @type {Background} | 927 * @type {Background} |
920 */ | 928 */ |
921 window.background = new Background(); | 929 window.background = new Background(); |
OLD | NEW |