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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** @suppress {duplicate} */ | 7 /** @suppress {duplicate} */ |
8 var remoting = remoting || {}; | 8 var remoting = remoting || {}; |
9 | 9 |
10 /** @constructor */ | 10 /** @constructor */ |
(...skipping 14 matching lines...) Expand all Loading... |
25 this.onResult = function() {}; | 25 this.onResult = function() {}; |
26 | 26 |
27 /** @type {number} */ | 27 /** @type {number} */ |
28 this.duration = 0; | 28 this.duration = 0; |
29 | 29 |
30 /** @type {string} */ | 30 /** @type {string} */ |
31 this.infobox = ''; | 31 this.infobox = ''; |
32 | 32 |
33 /** @type {?function():void} */ | 33 /** @type {?function():void} */ |
34 this.onTimeout = function() {}; | 34 this.onTimeout = function() {}; |
| 35 |
| 36 /** @type {string} */ |
| 37 this.htmlFile = ''; |
| 38 |
| 39 /** @type {string} */ |
| 40 this.frame = ''; |
35 }; | 41 }; |
36 | 42 |
37 /** | 43 /** |
38 * Create a new message window. | 44 * Create a new message window. |
39 * | 45 * |
40 * @param {remoting.MessageWindowOptions} options Message window create options | 46 * @param {remoting.MessageWindowOptions} options Message window create options |
41 * @constructor | 47 * @constructor |
42 */ | 48 */ |
43 remoting.MessageWindow = function(options) { | 49 remoting.MessageWindow = function(options) { |
44 var title = options.title; | 50 var title = options.title; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 buttonLabel: okButtonLabel, | 92 buttonLabel: okButtonLabel, |
87 cancelButtonLabel: cancelButtonLabel, | 93 cancelButtonLabel: cancelButtonLabel, |
88 showSpinner: (duration != 0) | 94 showSpinner: (duration != 0) |
89 }; | 95 }; |
90 | 96 |
91 var windowAttributes = { | 97 var windowAttributes = { |
92 bounds: { | 98 bounds: { |
93 width: 400, | 99 width: 400, |
94 height: 100 | 100 height: 100 |
95 }, | 101 }, |
96 resizable: false | 102 resizable: false, |
| 103 frame: options.frame || 'chrome' |
97 }; | 104 }; |
98 | 105 |
99 /** @type {remoting.MessageWindow} */ | 106 /** @type {remoting.MessageWindow} */ |
100 var that = this; | 107 var that = this; |
101 | 108 |
102 /** @param {AppWindow} appWindow */ | 109 /** @param {AppWindow} appWindow */ |
103 var onCreate = function(appWindow) { | 110 var onCreate = function(appWindow) { |
104 that.setWindow_(/** @type {Window} */(appWindow.contentWindow)); | 111 that.setWindow_(/** @type {Window} */(appWindow.contentWindow)); |
105 var onLoad = function() { | 112 var onLoad = function() { |
106 appWindow.contentWindow.postMessage(message_struct, '*'); | 113 appWindow.contentWindow.postMessage(message_struct, '*'); |
107 }; | 114 }; |
108 appWindow.contentWindow.addEventListener('load', onLoad, false); | 115 appWindow.contentWindow.addEventListener('load', onLoad, false); |
109 }; | 116 }; |
110 | 117 |
111 chrome.app.window.create('message_window.html', windowAttributes, onCreate); | 118 var htmlFile = options.htmlFile || 'message_window.html'; |
| 119 chrome.app.window.create(htmlFile, windowAttributes, onCreate); |
112 | 120 |
113 if (duration != 0) { | 121 if (duration != 0) { |
114 this.timer_ = window.setTimeout(this.onTimeoutHandler_.bind(this), | 122 this.timer_ = window.setTimeout(this.onTimeoutHandler_.bind(this), |
115 duration); | 123 duration); |
116 } | 124 } |
117 }; | 125 }; |
118 | 126 |
119 /** | 127 /** |
120 * Called when the timer runs out. This in turn calls the window's | 128 * Called when the timer runs out. This in turn calls the window's |
121 * timeout handler (if any). | 129 * timeout handler (if any). |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 var options = /** @type {remoting.MessageWindowOptions} */ ({ | 259 var options = /** @type {remoting.MessageWindowOptions} */ ({ |
252 title: title, | 260 title: title, |
253 message: message, | 261 message: message, |
254 buttonLabel: chrome.i18n.getMessage(/*i18n-content*/'OK'), | 262 buttonLabel: chrome.i18n.getMessage(/*i18n-content*/'OK'), |
255 onResult: remoting.MessageWindow.quitApp | 263 onResult: remoting.MessageWindow.quitApp |
256 }); | 264 }); |
257 return new remoting.MessageWindow(options); | 265 return new remoting.MessageWindow(options); |
258 }; | 266 }; |
259 | 267 |
260 /** | 268 /** |
261 * Static method to create and show a timed message box. | |
262 * | |
263 * @param {string} title The title of the message box. | |
264 * @param {string} message The message. | |
265 * @param {string} infobox Additional information to be displayed in an infobox, | |
266 * or the empty string if there is no additional information. | |
267 * @param {string} buttonLabel The text for the primary button. | |
268 * @param {function(number):void} onResult The callback to invoke when the | |
269 * user closes the message window. | |
270 * @param {number} duration Time for wait before calling onTime | |
271 * @param {?function():void} onTimeout Callback function. | |
272 * @return {remoting.MessageWindow} | |
273 */ | |
274 remoting.MessageWindow.showTimedMessageWindow = function( | |
275 title, message, infobox, buttonLabel, onResult, duration, onTimeout) { | |
276 var options = /** @type {remoting.MessageWindowOptions} */ ({ | |
277 title: title, | |
278 message: message, | |
279 infobox: infobox, | |
280 buttonLabel: buttonLabel, | |
281 onResult: onResult, | |
282 duration: duration, | |
283 onTimeout: onTimeout | |
284 }); | |
285 return new remoting.MessageWindow(options); | |
286 }; | |
287 | |
288 /** | |
289 * Cancel the current connection and close all app windows. | 269 * Cancel the current connection and close all app windows. |
290 * | 270 * |
291 * @param {number} result The dialog result. | 271 * @param {number} result The dialog result. |
292 */ | 272 */ |
293 remoting.MessageWindow.quitApp = function(result) { | 273 remoting.MessageWindow.quitApp = function(result) { |
294 remoting.MessageWindowManager.closeAllMessageWindows(); | 274 remoting.MessageWindowManager.closeAllMessageWindows(); |
295 window.close(); | 275 window.close(); |
296 }; | 276 }; |
OLD | NEW |