OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * Wrapper for an app window. | 6 * Wrapper for an app window. |
7 * | 7 * |
8 * Expects the following from the app scripts: | 8 * Expects the following from the app scripts: |
9 * 1. The page load handler should initialize the app using |window.appState| | 9 * 1. The page load handler should initialize the app using |window.appState| |
10 * and call |util.saveAppState|. | 10 * and call |util.saveAppState|. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 /** | 49 /** |
50 * Make a key of window geometry preferences for the given initial URL. | 50 * Make a key of window geometry preferences for the given initial URL. |
51 * @param {string} url Initialize URL that the window has. | 51 * @param {string} url Initialize URL that the window has. |
52 * @return {string} Key of window geometry preferences. | 52 * @return {string} Key of window geometry preferences. |
53 */ | 53 */ |
54 AppWindowWrapper.makeGeometryKey = function(url) { | 54 AppWindowWrapper.makeGeometryKey = function(url) { |
55 return 'windowGeometry' + ':' + url; | 55 return 'windowGeometry' + ':' + url; |
56 }; | 56 }; |
57 | 57 |
58 /** | 58 /** |
59 * Focuses the window on the specified desktop. | |
60 * @param {chrome.app.window.AppWindow} appWindow Application window. | |
61 * @param {string=} opt_profileId The profiled ID of the target window. If it is | |
62 * dropped, the window is focused on the current window. | |
63 */ | |
64 AppWindowWrapper.focusOnDesktop = function(appWindow, opt_profileId) { | |
65 new Promise(function(onFulfilled, onRejected) { | |
66 if (opt_profileId) { | |
67 onFulfilled(opt_profileId); | |
68 } else { | |
69 chrome.fileManagerPrivate.getProfiles( | |
70 function(profiles, currentId, displayedId) { | |
71 onFulfilled(currentId); | |
72 }); | |
73 } | |
74 }).then(function(profileId) { | |
75 appWindow.contentWindow.chrome.fileManagerPrivate.visitDesktop( | |
76 profileId, | |
77 function() { | |
78 appWindow.focus(); | |
79 }); | |
80 }); | |
81 }; | |
82 | |
83 /** | |
84 * Shift distance to avoid overlapping windows. | 59 * Shift distance to avoid overlapping windows. |
85 * @type {number} | 60 * @type {number} |
86 * @const | 61 * @const |
87 */ | 62 */ |
88 AppWindowWrapper.SHIFT_DISTANCE = 40; | 63 AppWindowWrapper.SHIFT_DISTANCE = 40; |
89 | 64 |
90 /** | 65 /** |
91 * Sets the icon of the window. | 66 * Sets the icon of the window. |
92 * @param {string} iconPath Path of the icon. | 67 * @param {string} iconPath Path of the icon. |
93 */ | 68 */ |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 try { | 311 try { |
337 var appState = JSON.parse(value); | 312 var appState = JSON.parse(value); |
338 } catch (e) { | 313 } catch (e) { |
339 console.error('Corrupt launch data for ' + this.id_, value); | 314 console.error('Corrupt launch data for ' + this.id_, value); |
340 opt_callback && opt_callback(); | 315 opt_callback && opt_callback(); |
341 return; | 316 return; |
342 } | 317 } |
343 this.launch(appState, true, opt_callback); | 318 this.launch(appState, true, opt_callback); |
344 }.bind(this)); | 319 }.bind(this)); |
345 }; | 320 }; |
OLD | NEW |