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 /** | 5 /** |
6 * Type of a Files.app's instance launch. | 6 * Type of a Files.app's instance launch. |
7 * @enum {number} | 7 * @enum {number} |
8 */ | 8 */ |
9 var LaunchType = { | 9 var LaunchType = { |
10 ALWAYS_CREATE: 0, | 10 ALWAYS_CREATE: 0, |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 * @param {number=} opt_id Window id. | 341 * @param {number=} opt_id Window id. |
342 * @param {LaunchType=} opt_type Launch type. Default: ALWAYS_CREATE. | 342 * @param {LaunchType=} opt_type Launch type. Default: ALWAYS_CREATE. |
343 * @param {function(string)=} opt_callback Completion callback with the App ID. | 343 * @param {function(string)=} opt_callback Completion callback with the App ID. |
344 */ | 344 */ |
345 function launchFileManager(opt_appState, opt_id, opt_type, opt_callback) { | 345 function launchFileManager(opt_appState, opt_id, opt_type, opt_callback) { |
346 var type = opt_type || LaunchType.ALWAYS_CREATE; | 346 var type = opt_type || LaunchType.ALWAYS_CREATE; |
347 opt_appState = | 347 opt_appState = |
348 /** | 348 /** |
349 * @type {(undefined| | 349 * @type {(undefined| |
350 * {currentDirectoryURL: (string|undefined), | 350 * {currentDirectoryURL: (string|undefined), |
351 * selectionURL: (string|undefined), | 351 * selectionURL: (string|undefined)})} |
352 * displayedId: (string|undefined)})} | |
353 */ | 352 */ |
354 (opt_appState); | 353 (opt_appState); |
355 | 354 |
356 // Wait until all windows are created. | 355 // Wait until all windows are created. |
357 window.background.queue.run(function(onTaskCompleted) { | 356 window.background.queue.run(function(onTaskCompleted) { |
358 // Check if there is already a window with the same URL. If so, then | 357 // Check if there is already a window with the same URL. If so, then |
359 // reuse it instead of opening a new one. | 358 // reuse it instead of opening a new one. |
360 if (type == LaunchType.FOCUS_SAME_OR_CREATE || | 359 if (type == LaunchType.FOCUS_SAME_OR_CREATE || |
361 type == LaunchType.FOCUS_ANY_OR_CREATE) { | 360 type == LaunchType.FOCUS_ANY_OR_CREATE) { |
362 if (opt_appState) { | 361 if (opt_appState) { |
(...skipping 10 matching lines...) Expand all Loading... |
373 contentWindow.appState.currentDirectoryURL) { | 372 contentWindow.appState.currentDirectoryURL) { |
374 continue; | 373 continue; |
375 } | 374 } |
376 | 375 |
377 // Selection URL specified, and it is different. | 376 // Selection URL specified, and it is different. |
378 if (opt_appState.selectionURL && | 377 if (opt_appState.selectionURL && |
379 opt_appState.selectionURL !== | 378 opt_appState.selectionURL !== |
380 contentWindow.appState.selectionURL) { | 379 contentWindow.appState.selectionURL) { |
381 continue; | 380 continue; |
382 } | 381 } |
383 | 382 window.background.appWindows[key].focus(); |
384 AppWindowWrapper.focusOnDesktop( | |
385 window.background.appWindows[key], opt_appState.displayedId); | |
386 if (opt_callback) | 383 if (opt_callback) |
387 opt_callback(key); | 384 opt_callback(key); |
388 onTaskCompleted(); | 385 onTaskCompleted(); |
389 return; | 386 return; |
390 } | 387 } |
391 } | 388 } |
392 } | 389 } |
393 | 390 |
394 // Focus any window if none is focused. Try restored first. | 391 // Focus any window if none is focused. Try restored first. |
395 if (type == LaunchType.FOCUS_ANY_OR_CREATE) { | 392 if (type == LaunchType.FOCUS_ANY_OR_CREATE) { |
(...skipping 14 matching lines...) Expand all Loading... |
410 } catch (e) { | 407 } catch (e) { |
411 console.error(e.message); | 408 console.error(e.message); |
412 } | 409 } |
413 } | 410 } |
414 // Try to focus the first non-minimized window. | 411 // Try to focus the first non-minimized window. |
415 for (var key in window.background.appWindows) { | 412 for (var key in window.background.appWindows) { |
416 if (!key.match(FILES_ID_PATTERN)) | 413 if (!key.match(FILES_ID_PATTERN)) |
417 continue; | 414 continue; |
418 | 415 |
419 if (!window.background.appWindows[key].isMinimized()) { | 416 if (!window.background.appWindows[key].isMinimized()) { |
420 AppWindowWrapper.focusOnDesktop( | 417 window.background.appWindows[key].focus(); |
421 window.background.appWindows[key], | |
422 (opt_appState || {}).displayedId); | |
423 if (opt_callback) | 418 if (opt_callback) |
424 opt_callback(key); | 419 opt_callback(key); |
425 onTaskCompleted(); | 420 onTaskCompleted(); |
426 return; | 421 return; |
427 } | 422 } |
428 } | 423 } |
429 // Restore and focus any window. | 424 // Restore and focus any window. |
430 for (var key in window.background.appWindows) { | 425 for (var key in window.background.appWindows) { |
431 if (!key.match(FILES_ID_PATTERN)) | 426 if (!key.match(FILES_ID_PATTERN)) |
432 continue; | 427 continue; |
433 | 428 |
434 AppWindowWrapper.focusOnDesktop( | 429 window.background.appWindows[key].focus(); |
435 window.background.appWindows[key], | |
436 (opt_appState || {}).displayedId); | |
437 if (opt_callback) | 430 if (opt_callback) |
438 opt_callback(key); | 431 opt_callback(key); |
439 onTaskCompleted(); | 432 onTaskCompleted(); |
440 return; | 433 return; |
441 } | 434 } |
442 } | 435 } |
443 | 436 |
444 // Create a new instance in case of ALWAYS_CREATE type, or as a fallback | 437 // Create a new instance in case of ALWAYS_CREATE type, or as a fallback |
445 // for other types. | 438 // for other types. |
446 | 439 |
447 var id = opt_id || nextFileManagerWindowID; | 440 var id = opt_id || nextFileManagerWindowID; |
448 nextFileManagerWindowID = Math.max(nextFileManagerWindowID, id + 1); | 441 nextFileManagerWindowID = Math.max(nextFileManagerWindowID, id + 1); |
449 var appId = FILES_ID_PREFIX + id; | 442 var appId = FILES_ID_PREFIX + id; |
450 | 443 |
451 var appWindow = new AppWindowWrapper( | 444 var appWindow = new AppWindowWrapper( |
452 'main.html', | 445 'main.html', |
453 appId, | 446 appId, |
454 FILE_MANAGER_WINDOW_CREATE_OPTIONS); | 447 FILE_MANAGER_WINDOW_CREATE_OPTIONS); |
455 appWindow.launch(opt_appState || {}, false, function() { | 448 appWindow.launch(opt_appState || {}, false, function() { |
456 AppWindowWrapper.focusOnDesktop( | 449 appWindow.rawAppWindow.focus(); |
457 appWindow.rawAppWindow, (opt_appState || {}).displayedId); | |
458 if (opt_callback) | 450 if (opt_callback) |
459 opt_callback(appId); | 451 opt_callback(appId); |
460 onTaskCompleted(); | 452 onTaskCompleted(); |
461 }); | 453 }); |
462 }); | 454 }); |
463 } | 455 } |
464 | 456 |
465 /** | 457 /** |
466 * Registers dialog window to the background page. | 458 * Registers dialog window to the background page. |
467 * | 459 * |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 contexts: ['launcher'], | 588 contexts: ['launcher'], |
597 title: str('NEW_WINDOW_BUTTON_LABEL') | 589 title: str('NEW_WINDOW_BUTTON_LABEL') |
598 }); | 590 }); |
599 }; | 591 }; |
600 | 592 |
601 /** | 593 /** |
602 * Singleton instance of Background. | 594 * Singleton instance of Background. |
603 * @type {FileBrowserBackground} | 595 * @type {FileBrowserBackground} |
604 */ | 596 */ |
605 window.background = new FileBrowserBackground(); | 597 window.background = new FileBrowserBackground(); |
OLD | NEW |