OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 /** @suppress {duplicate} */ | 5 /** @suppress {duplicate} */ |
6 var remoting = remoting || {}; | 6 var remoting = remoting || {}; |
7 | 7 |
8 /** | 8 /** |
9 * Type definition for the RunApplicationResponse returned by the API. | 9 * Type definition for the RunApplicationResponse returned by the API. |
10 * @typedef {{ | 10 * @typedef {{ |
(...skipping 20 matching lines...) Expand all Loading... |
31 * @implements {remoting.Activity} | 31 * @implements {remoting.Activity} |
32 */ | 32 */ |
33 remoting.AppRemotingActivity = function(appCapabilities) { | 33 remoting.AppRemotingActivity = function(appCapabilities) { |
34 /** @private {remoting.AppConnectedView} */ | 34 /** @private {remoting.AppConnectedView} */ |
35 this.connectedView_ = null; | 35 this.connectedView_ = null; |
36 | 36 |
37 /** @private */ | 37 /** @private */ |
38 this.connector_ = remoting.SessionConnector.factory.createConnector( | 38 this.connector_ = remoting.SessionConnector.factory.createConnector( |
39 document.getElementById('client-container'), appCapabilities, | 39 document.getElementById('client-container'), appCapabilities, |
40 this); | 40 this); |
| 41 |
| 42 /** @private {remoting.ClientSession} */ |
| 43 this.session_ = null; |
41 }; | 44 }; |
42 | 45 |
43 remoting.AppRemotingActivity.prototype.dispose = function() { | 46 remoting.AppRemotingActivity.prototype.dispose = function() { |
44 base.dispose(this.connectedView_); | 47 base.dispose(this.connectedView_); |
45 this.connectedView_ = null; | 48 this.connectedView_ = null; |
46 remoting.LoadingWindow.close(); | 49 remoting.LoadingWindow.close(); |
47 }; | 50 }; |
48 | 51 |
49 remoting.AppRemotingActivity.prototype.start = function() { | 52 remoting.AppRemotingActivity.prototype.start = function() { |
50 remoting.LoadingWindow.show(); | 53 remoting.LoadingWindow.show(); |
51 var that = this; | 54 var that = this; |
52 return remoting.identity.getToken().then(function(/** string */ token) { | 55 return remoting.identity.getToken().then(function(/** string */ token) { |
53 return that.getAppHostInfo_(token); | 56 return that.getAppHostInfo_(token); |
54 }).then(function(/** !remoting.Xhr.Response */ response) { | 57 }).then(function(/** !remoting.Xhr.Response */ response) { |
55 that.onAppHostResponse_(response); | 58 that.onAppHostResponse_(response); |
56 }); | 59 }); |
57 }; | 60 }; |
58 | 61 |
| 62 remoting.AppRemotingActivity.prototype.stop = function() { |
| 63 if (this.session_) { |
| 64 this.session_.disconnect(remoting.Error.none()); |
| 65 } |
| 66 }; |
| 67 |
| 68 /** @private */ |
| 69 remoting.AppRemotingActivity.prototype.cleanup_ = function() { |
| 70 base.dispose(this.connectedView_); |
| 71 this.connectedView_ = null; |
| 72 this.session_ = null; |
| 73 }; |
| 74 |
59 /** | 75 /** |
60 * @param {string} token | 76 * @param {string} token |
61 * @return {Promise<!remoting.Xhr.Response>} | 77 * @return {Promise<!remoting.Xhr.Response>} |
62 * @private | 78 * @private |
63 */ | 79 */ |
64 remoting.AppRemotingActivity.prototype.getAppHostInfo_ = function(token) { | 80 remoting.AppRemotingActivity.prototype.getAppHostInfo_ = function(token) { |
65 var url = remoting.settings.APP_REMOTING_API_BASE_URL + '/applications/' + | 81 var url = remoting.settings.APP_REMOTING_API_BASE_URL + '/applications/' + |
66 remoting.settings.getAppRemotingApplicationId() + '/run'; | 82 remoting.settings.getAppRemotingApplicationId() + '/run'; |
67 return new remoting.Xhr({ | 83 return new remoting.Xhr({ |
68 method: 'POST', | 84 method: 'POST', |
(...skipping 20 matching lines...) Expand all Loading... |
89 response.host && | 105 response.host && |
90 response.host.hostId) { | 106 response.host.hostId) { |
91 var hostJid = response.hostJid; | 107 var hostJid = response.hostJid; |
92 var host = new remoting.Host(response.host.hostId); | 108 var host = new remoting.Host(response.host.hostId); |
93 host.jabberId = hostJid; | 109 host.jabberId = hostJid; |
94 host.authorizationCode = response.authorizationCode; | 110 host.authorizationCode = response.authorizationCode; |
95 host.sharedSecret = response.sharedSecret; | 111 host.sharedSecret = response.sharedSecret; |
96 | 112 |
97 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); | 113 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); |
98 | 114 |
99 var idleDetector = new remoting.IdleDetector( | |
100 document.getElementById('idle-dialog'), | |
101 remoting.app.disconnect.bind(remoting.app)); | |
102 | |
103 /** | 115 /** |
104 * @param {string} tokenUrl Token-issue URL received from the host. | 116 * @param {string} tokenUrl Token-issue URL received from the host. |
105 * @param {string} hostPublicKey Host public key (DER and Base64 | 117 * @param {string} hostPublicKey Host public key (DER and Base64 |
106 * encoded). | 118 * encoded). |
107 * @param {string} scope OAuth scope to request the token for. | 119 * @param {string} scope OAuth scope to request the token for. |
108 * @param {function(string, string):void} onThirdPartyTokenFetched | 120 * @param {function(string, string):void} onThirdPartyTokenFetched |
109 * Callback. | 121 * Callback. |
110 */ | 122 */ |
111 var fetchThirdPartyToken = function( | 123 var fetchThirdPartyToken = function( |
112 tokenUrl, hostPublicKey, scope, onThirdPartyTokenFetched) { | 124 tokenUrl, hostPublicKey, scope, onThirdPartyTokenFetched) { |
(...skipping 17 matching lines...) Expand all Loading... |
130 } | 142 } |
131 }; | 143 }; |
132 | 144 |
133 /** | 145 /** |
134 * @param {remoting.ConnectionInfo} connectionInfo | 146 * @param {remoting.ConnectionInfo} connectionInfo |
135 */ | 147 */ |
136 remoting.AppRemotingActivity.prototype.onConnected = function(connectionInfo) { | 148 remoting.AppRemotingActivity.prototype.onConnected = function(connectionInfo) { |
137 this.connectedView_ = new remoting.AppConnectedView( | 149 this.connectedView_ = new remoting.AppConnectedView( |
138 document.getElementById('client-container'), connectionInfo); | 150 document.getElementById('client-container'), connectionInfo); |
139 | 151 |
| 152 this.session_ = connectionInfo.session(); |
| 153 var idleDetector = new remoting.IdleDetector( |
| 154 document.getElementById('idle-dialog'), this.stop.bind(this)); |
| 155 |
140 // Map Cmd to Ctrl on Mac since hosts typically use Ctrl for keyboard | 156 // Map Cmd to Ctrl on Mac since hosts typically use Ctrl for keyboard |
141 // shortcuts, but we want them to act as natively as possible. | 157 // shortcuts, but we want them to act as natively as possible. |
142 if (remoting.platformIsMac()) { | 158 if (remoting.platformIsMac()) { |
143 connectionInfo.plugin().setRemapKeys('0x0700e3>0x0700e0,0x0700e7>0x0700e4'); | 159 connectionInfo.plugin().setRemapKeys('0x0700e3>0x0700e0,0x0700e7>0x0700e4'); |
144 } | 160 } |
145 }; | 161 }; |
146 | 162 |
147 remoting.AppRemotingActivity.prototype.onDisconnected = function() { | 163 remoting.AppRemotingActivity.prototype.onDisconnected = function() { |
148 base.dispose(this.connectedView_); | 164 this.cleanup_(); |
149 this.connectedView_ = null; | |
150 chrome.app.window.current().close(); | 165 chrome.app.window.current().close(); |
151 }; | 166 }; |
152 | 167 |
153 /** | 168 /** |
154 * @param {!remoting.Error} error | 169 * @param {!remoting.Error} error |
155 */ | 170 */ |
156 remoting.AppRemotingActivity.prototype.onConnectionFailed = function(error) { | 171 remoting.AppRemotingActivity.prototype.onConnectionFailed = function(error) { |
157 this.onError(error); | 172 this.onError(error); |
158 }; | 173 }; |
159 | 174 |
160 /** | 175 /** |
161 * @param {!remoting.Error} error The error to be localized and displayed. | 176 * @param {!remoting.Error} error The error to be localized and displayed. |
162 */ | 177 */ |
163 remoting.AppRemotingActivity.prototype.onError = function(error) { | 178 remoting.AppRemotingActivity.prototype.onError = function(error) { |
164 console.error('Connection failed: ' + error.toString()); | 179 console.error('Connection failed: ' + error.toString()); |
165 remoting.LoadingWindow.close(); | 180 remoting.LoadingWindow.close(); |
166 remoting.MessageWindow.showErrorMessage( | 181 remoting.MessageWindow.showErrorMessage( |
167 chrome.i18n.getMessage(/*i18n-content*/'CONNECTION_FAILED'), | 182 chrome.i18n.getMessage(/*i18n-content*/'CONNECTION_FAILED'), |
168 chrome.i18n.getMessage(error.getTag())); | 183 chrome.i18n.getMessage(error.getTag())); |
169 base.dispose(this.connectedView_); | 184 this.cleanup_(); |
170 this.connectedView_ = null; | |
171 }; | 185 }; |
172 | 186 |
173 })(); | 187 })(); |
OLD | NEW |