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 * @fileoverview | 6 * @fileoverview |
7 * This class implements the functionality that is specific to application | 7 * This class implements the functionality that is specific to application |
8 * remoting ("AppRemoting" or AR). | 8 * remoting ("AppRemoting" or AR). |
9 */ | 9 */ |
10 | 10 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 | 64 |
65 this.host = { | 65 this.host = { |
66 /** @type {string} */ | 66 /** @type {string} */ |
67 applicationId: '', | 67 applicationId: '', |
68 | 68 |
69 /** @type {string} */ | 69 /** @type {string} */ |
70 hostId: ''}; | 70 hostId: ''}; |
71 }; | 71 }; |
72 | 72 |
73 /** | 73 /** |
74 * Callback for when the userinfo (email and user name) is available from | 74 * Initialize the application. This is called before an OAuth token is requested |
75 * the identity API. | 75 * and should be used for tasks such as initializing the DOM, registering event |
76 * | 76 * handlers, etc. |
77 * @param {string} email The user's email address. | |
78 * @param {string} fullName The user's full name. | |
79 * @return {void} Nothing. | |
80 */ | 77 */ |
81 remoting.onUserInfoAvailable = function(email, fullName) { | 78 remoting.AppRemoting.prototype.init = function() { |
Jamie
2015/03/05 01:35:55
This was needed when fullName and email had synchr
| |
82 }; | |
83 | |
84 /** | |
85 * Initialize the application and register all event handlers. After this | |
86 * is called, the app is running and waiting for user events. | |
87 * | |
88 * @param {remoting.SessionConnector} connector | |
89 * @return {void} Nothing. | |
90 */ | |
91 remoting.AppRemoting.prototype.init = function(connector) { | |
92 remoting.initGlobalObjects(); | |
93 remoting.initIdentity(remoting.onUserInfoAvailable); | |
Jamie
2015/03/05 01:35:55
This initialization was shared between the App- an
| |
94 | |
95 // TODO(jamiewalch): Remove ClientSession's dependency on remoting.fullscreen | 79 // TODO(jamiewalch): Remove ClientSession's dependency on remoting.fullscreen |
96 // so that this is no longer required. | 80 // so that this is no longer required. |
97 remoting.fullscreen = new remoting.FullscreenAppsV2(); | 81 remoting.fullscreen = new remoting.FullscreenAppsV2(); |
98 | 82 |
99 var restoreHostWindows = function() { | 83 var restoreHostWindows = function() { |
100 if (remoting.clientSession) { | 84 if (remoting.clientSession) { |
101 remoting.clientSession.sendClientMessage('restoreAllWindows', ''); | 85 remoting.clientSession.sendClientMessage('restoreAllWindows', ''); |
102 } | 86 } |
103 }; | 87 }; |
104 chrome.app.window.current().onRestored.addListener(restoreHostWindows); | 88 chrome.app.window.current().onRestored.addListener(restoreHostWindows); |
105 | 89 |
106 remoting.windowShape.updateClientWindowShape(); | 90 remoting.windowShape.updateClientWindowShape(); |
107 | 91 |
108 // Initialize the context menus. | 92 // Initialize the context menus. |
109 if (remoting.platformIsChromeOS()) { | 93 if (remoting.platformIsChromeOS()) { |
110 var adapter = new remoting.ContextMenuChrome(); | 94 var adapter = new remoting.ContextMenuChrome(); |
111 } else { | 95 } else { |
112 var adapter = new remoting.ContextMenuDom( | 96 var adapter = new remoting.ContextMenuDom( |
113 document.getElementById('context-menu')); | 97 document.getElementById('context-menu')); |
114 } | 98 } |
115 this.contextMenu_ = new remoting.ApplicationContextMenu(adapter); | 99 this.contextMenu_ = new remoting.ApplicationContextMenu(adapter); |
116 this.keyboardLayoutsMenu_ = new remoting.KeyboardLayoutsMenu(adapter); | 100 this.keyboardLayoutsMenu_ = new remoting.KeyboardLayoutsMenu(adapter); |
117 this.windowActivationMenu_ = new remoting.WindowActivationMenu(adapter); | 101 this.windowActivationMenu_ = new remoting.WindowActivationMenu(adapter); |
118 | 102 |
103 remoting.LoadingWindow.show(); | |
104 }; | |
105 | |
106 /** | |
107 * Start the application. Once start() is called, the delegate can assume that | |
108 * the user has consented to all permissions specified in the manifest. | |
109 * | |
110 * @param {remoting.SessionConnector} connector | |
111 * @param {string} token An OAuth access token. The delegate should not cache | |
112 * this token, but can assume that it will remain valid during application | |
113 * start-up. | |
114 */ | |
115 remoting.AppRemoting.prototype.start = function(connector, token) { | |
kelvinp
2015/03/05 02:12:14
Since the delegate should not cache this token, no
kelvinp
2015/03/05 02:12:14
onAuthenticated or onInitialized would be better n
Jamie
2015/03/05 02:31:27
I want the name to reflect the fact that this is a
Jamie
2015/03/05 02:31:27
We could, but the semantics are no different from
| |
119 /** @type {remoting.AppRemoting} */ | 116 /** @type {remoting.AppRemoting} */ |
120 var that = this; | 117 var that = this; |
121 | 118 |
122 /** @param {XMLHttpRequest} xhr */ | 119 /** @param {XMLHttpRequest} xhr */ |
123 var parseAppHostResponse = function(xhr) { | 120 var parseAppHostResponse = function(xhr) { |
124 if (xhr.status == 200) { | 121 if (xhr.status == 200) { |
125 var response = /** @type {remoting.AppRemoting.AppHostResponse} */ | 122 var response = /** @type {remoting.AppRemoting.AppHostResponse} */ |
126 (base.jsonParseSafe(xhr.responseText)); | 123 (base.jsonParseSafe(xhr.responseText)); |
127 if (response && | 124 if (response && |
128 response.status && | 125 response.status && |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 } else if (xhr.status == 403) { | 174 } else if (xhr.status == 403) { |
178 that.handleError(remoting.Error.APP_NOT_AUTHORIZED); | 175 that.handleError(remoting.Error.APP_NOT_AUTHORIZED); |
179 } else if (xhr.status == 502 || xhr.status == 503) { | 176 } else if (xhr.status == 502 || xhr.status == 503) { |
180 that.handleError(remoting.Error.SERVICE_UNAVAILABLE); | 177 that.handleError(remoting.Error.SERVICE_UNAVAILABLE); |
181 } else { | 178 } else { |
182 that.handleError(remoting.Error.UNEXPECTED); | 179 that.handleError(remoting.Error.UNEXPECTED); |
183 } | 180 } |
184 } | 181 } |
185 }; | 182 }; |
186 | 183 |
187 /** @param {string} token */ | 184 remoting.xhr.start({ |
188 var getAppHost = function(token) { | 185 method: 'POST', |
189 remoting.xhr.start({ | 186 url: that.runApplicationUrl(), |
190 method: 'POST', | 187 onDone: parseAppHostResponse, |
191 url: that.runApplicationUrl(), | 188 oauthToken: token |
192 onDone: parseAppHostResponse, | 189 }); |
193 oauthToken: token | 190 }; |
194 }); | |
195 }; | |
196 | 191 |
197 /** @param {remoting.Error} error */ | 192 /** |
198 var onError = function(error) { | 193 * Report an authentication error to the user. This is called in lieu of start() |
199 that.handleError(error); | 194 * if the user cannot be authenticated or if they decline the app permissions. |
200 }; | 195 * |
201 | 196 * @param {remoting.Error} error The failure reason. |
202 remoting.LoadingWindow.show(); | 197 */ |
203 | 198 remoting.AppRemoting.prototype.signInFailed = function(error) { |
204 remoting.identity.getToken().then(getAppHost). | 199 if (error == remoting.Error.CANCELLED) { |
205 catch(remoting.Error.handler(onError)); | 200 chrome.app.window.current().close(); |
garykac
2015/03/05 02:38:25
We also call this in onDisconnected, but it also c
Jamie
2015/03/05 19:01:36
That's a good idea. I think I'll make it a follow-
garykac
2015/03/06 21:16:25
sgtm
| |
206 } | 201 remoting.LoadingWindow.close(); |
202 } else { | |
203 this.handleError(error); | |
204 } | |
205 }; | |
207 | 206 |
208 /** | 207 /** |
209 * @return {string} Application product name to be used in UI. | 208 * @return {string} Application product name to be used in UI. |
210 */ | 209 */ |
211 remoting.AppRemoting.prototype.getApplicationName = function() { | 210 remoting.AppRemoting.prototype.getApplicationName = function() { |
212 var manifest = chrome.runtime.getManifest(); | 211 var manifest = chrome.runtime.getManifest(); |
213 return manifest.name; | 212 return manifest.name; |
214 }; | 213 }; |
215 | 214 |
216 /** @return {string} */ | 215 /** @return {string} */ |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
349 * @param {remoting.Error} errorTag The error to be localized and displayed. | 348 * @param {remoting.Error} errorTag The error to be localized and displayed. |
350 * @return {void} Nothing. | 349 * @return {void} Nothing. |
351 */ | 350 */ |
352 remoting.AppRemoting.prototype.handleError = function(errorTag) { | 351 remoting.AppRemoting.prototype.handleError = function(errorTag) { |
353 console.error('Connection failed: ' + errorTag); | 352 console.error('Connection failed: ' + errorTag); |
354 remoting.LoadingWindow.close(); | 353 remoting.LoadingWindow.close(); |
355 remoting.MessageWindow.showErrorMessage( | 354 remoting.MessageWindow.showErrorMessage( |
356 chrome.i18n.getMessage(/*i18n-content*/'CONNECTION_FAILED'), | 355 chrome.i18n.getMessage(/*i18n-content*/'CONNECTION_FAILED'), |
357 chrome.i18n.getMessage(/** @type {string} */ (errorTag))); | 356 chrome.i18n.getMessage(/** @type {string} */ (errorTag))); |
358 }; | 357 }; |
OLD | NEW |