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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 var type = opt_type || LaunchType.ALWAYS_CREATE; | 367 var type = opt_type || LaunchType.ALWAYS_CREATE; |
368 | 368 |
369 // Wait until all windows are created. | 369 // Wait until all windows are created. |
370 background.queue.run(function(onTaskCompleted) { | 370 background.queue.run(function(onTaskCompleted) { |
371 // Check if there is already a window with the same path. If so, then | 371 // Check if there is already a window with the same path. If so, then |
372 // reuse it instead of opening a new one. | 372 // reuse it instead of opening a new one. |
373 if (type == LaunchType.FOCUS_SAME_OR_CREATE || | 373 if (type == LaunchType.FOCUS_SAME_OR_CREATE || |
374 type == LaunchType.FOCUS_ANY_OR_CREATE) { | 374 type == LaunchType.FOCUS_ANY_OR_CREATE) { |
375 if (opt_appState && opt_appState.defaultPath) { | 375 if (opt_appState && opt_appState.defaultPath) { |
376 for (var key in background.appWindows) { | 376 for (var key in background.appWindows) { |
| 377 if (!key.match(FILES_ID_PATTERN)) |
| 378 continue; |
| 379 |
377 var contentWindow = background.appWindows[key].contentWindow; | 380 var contentWindow = background.appWindows[key].contentWindow; |
378 if (contentWindow.appState && | 381 if (contentWindow.appState && |
379 opt_appState.defaultPath == contentWindow.appState.defaultPath) { | 382 opt_appState.defaultPath == contentWindow.appState.defaultPath) { |
380 background.appWindows[key].focus(); | 383 background.appWindows[key].focus(); |
381 if (opt_callback) | 384 if (opt_callback) |
382 opt_callback(key); | 385 opt_callback(key); |
383 onTaskCompleted(); | 386 onTaskCompleted(); |
384 return; | 387 return; |
385 } | 388 } |
386 } | 389 } |
387 } | 390 } |
388 } | 391 } |
389 | 392 |
390 // Focus any window if none is focused. Try restored first. | 393 // Focus any window if none is focused. Try restored first. |
391 if (type == LaunchType.FOCUS_ANY_OR_CREATE) { | 394 if (type == LaunchType.FOCUS_ANY_OR_CREATE) { |
392 // If there is already a focused window, then finish. | 395 // If there is already a focused window, then finish. |
393 for (var key in background.appWindows) { | 396 for (var key in background.appWindows) { |
| 397 if (!key.match(FILES_ID_PATTERN)) |
| 398 continue; |
| 399 |
394 // The isFocused() method should always be available, but in case | 400 // The isFocused() method should always be available, but in case |
395 // Files.app's failed on some error, wrap it with try catch. | 401 // Files.app's failed on some error, wrap it with try catch. |
396 try { | 402 try { |
397 if (background.appWindows[key].contentWindow.isFocused()) { | 403 if (background.appWindows[key].contentWindow.isFocused()) { |
398 if (opt_callback) | 404 if (opt_callback) |
399 opt_callback(key); | 405 opt_callback(key); |
400 onTaskCompleted(); | 406 onTaskCompleted(); |
401 return; | 407 return; |
402 } | 408 } |
403 } catch (e) { | 409 } catch (e) { |
404 console.error(e.message); | 410 console.error(e.message); |
405 } | 411 } |
406 } | 412 } |
407 // Try to focus the first non-minimized window. | 413 // Try to focus the first non-minimized window. |
408 for (var key in background.appWindows) { | 414 for (var key in background.appWindows) { |
| 415 if (!key.match(FILES_ID_PATTERN)) |
| 416 continue; |
| 417 |
409 if (!background.appWindows[key].isMinimized()) { | 418 if (!background.appWindows[key].isMinimized()) { |
410 background.appWindows[key].focus(); | 419 background.appWindows[key].focus(); |
411 if (opt_callback) | 420 if (opt_callback) |
412 opt_callback(key); | 421 opt_callback(key); |
413 onTaskCompleted(); | 422 onTaskCompleted(); |
414 return; | 423 return; |
415 } | 424 } |
416 } | 425 } |
417 // Restore and focus any window. | 426 // Restore and focus any window. |
418 for (var key in background.appWindows) { | 427 for (var key in background.appWindows) { |
| 428 if (!key.match(FILES_ID_PATTERN)) |
| 429 continue; |
| 430 |
419 background.appWindows[key].focus(); | 431 background.appWindows[key].focus(); |
420 if (opt_callback) | 432 if (opt_callback) |
421 opt_callback(key); | 433 opt_callback(key); |
422 onTaskCompleted(); | 434 onTaskCompleted(); |
423 return; | 435 return; |
424 } | 436 } |
425 } | 437 } |
426 | 438 |
427 // Create a new instance in case of ALWAYS_CREATE type, or as a fallback | 439 // Create a new instance in case of ALWAYS_CREATE type, or as a fallback |
428 // for other types. | 440 // for other types. |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 contexts: ['launcher'], | 665 contexts: ['launcher'], |
654 title: str('NEW_WINDOW_BUTTON_LABEL') | 666 title: str('NEW_WINDOW_BUTTON_LABEL') |
655 }); | 667 }); |
656 }; | 668 }; |
657 | 669 |
658 /** | 670 /** |
659 * Singleton instance of Background. | 671 * Singleton instance of Background. |
660 * @type {Background} | 672 * @type {Background} |
661 */ | 673 */ |
662 window.background = new Background(); | 674 window.background = new Background(); |
OLD | NEW |