OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 provides an interface between the HostController and either the | 7 * This class provides an interface between the HostController and either the |
8 * NativeMessaging Host or the Host NPAPI plugin, depending on whether or not | 8 * NativeMessaging Host or the Host NPAPI plugin, depending on whether or not |
9 * NativeMessaging is supported. Since the test for NativeMessaging support is | 9 * NativeMessaging is supported. Since the test for NativeMessaging support is |
10 * asynchronous, this class stores any requests on a queue, pending the result | 10 * asynchronous, this class stores any requests on a queue, pending the result |
(...skipping 10 matching lines...) Expand all Loading... | |
21 /** @suppress {duplicate} */ | 21 /** @suppress {duplicate} */ |
22 var remoting = remoting || {}; | 22 var remoting = remoting || {}; |
23 | 23 |
24 /** | 24 /** |
25 * @constructor | 25 * @constructor |
26 * @param {function():remoting.HostPlugin} createPluginCallback Callback to | 26 * @param {function():remoting.HostPlugin} createPluginCallback Callback to |
27 * instantiate the NPAPI plugin when NativeMessaging is determined to be | 27 * instantiate the NPAPI plugin when NativeMessaging is determined to be |
28 * unsupported. | 28 * unsupported. |
29 */ | 29 */ |
30 remoting.HostDispatcher = function(createPluginCallback) { | 30 remoting.HostDispatcher = function(createPluginCallback) { |
31 /** @type {remoting.HostDispatcher} */ | |
32 var that = this; | |
33 | |
34 /** @type {remoting.HostNativeMessaging} @private */ | 31 /** @type {remoting.HostNativeMessaging} @private */ |
35 this.nativeMessagingHost_ = new remoting.HostNativeMessaging(); | 32 this.nativeMessagingHost_ = new remoting.HostNativeMessaging(); |
36 | 33 |
37 /** @type {remoting.HostPlugin} @private */ | 34 /** @type {remoting.HostPlugin} @private */ |
38 this.npapiHost_ = null; | 35 this.npapiHost_ = null; |
39 | 36 |
40 /** @type {remoting.HostDispatcher.State} */ | 37 /** @type {remoting.HostDispatcher.State} */ |
41 this.state_ = remoting.HostDispatcher.State.UNKNOWN; | 38 this.state_ = remoting.HostDispatcher.State.UNKNOWN; |
42 | 39 |
43 /** @type {Array.<function()>} */ | 40 /** @type {Array.<function()>} */ |
44 this.pendingRequests_ = []; | 41 this.pendingRequests_ = []; |
45 | 42 |
43 this.createPluginCallback_ = createPluginCallback; | |
44 | |
45 this.tryToInitialize_(); | |
46 } | |
47 | |
48 /** @enum {number} */ | |
49 remoting.HostDispatcher.State = { | |
50 UNKNOWN: 0, | |
51 NATIVE_MESSAGING: 1, | |
52 NPAPI: 2, | |
53 NOT_INSTALLED: 3 | |
54 }; | |
55 | |
56 remoting.HostDispatcher.prototype.tryToInitialize_ = function() { | |
57 /** @type {remoting.HostDispatcher} */ | |
58 var that = this; | |
59 | |
60 if (this.state_ != remoting.HostDispatcher.State.UNKNOWN) | |
61 return; | |
62 | |
46 function sendPendingRequests() { | 63 function sendPendingRequests() { |
47 for (var i = 0; i < that.pendingRequests_.length; i++) { | 64 var pendingRequests = that.pendingRequests_; |
48 that.pendingRequests_[i](); | 65 that.pendingRequests_ = []; |
66 for (var i = 0; i < pendingRequests.length; i++) { | |
67 pendingRequests[i](); | |
49 } | 68 } |
50 that.pendingRequests_ = null; | |
51 } | 69 } |
52 | 70 |
53 function onNativeMessagingInit() { | 71 function onNativeMessagingInit() { |
54 console.log('Native Messaging supported.'); | |
55 that.state_ = remoting.HostDispatcher.State.NATIVE_MESSAGING; | 72 that.state_ = remoting.HostDispatcher.State.NATIVE_MESSAGING; |
56 sendPendingRequests(); | 73 sendPendingRequests(); |
57 } | 74 } |
58 | 75 |
59 function onNativeMessagingFailed(error) { | 76 function onNativeMessagingFailed(error) { |
60 console.log('Native Messaging unsupported, falling back to NPAPI.'); | 77 that.npapiHost_ = that.createPluginCallback_(); |
61 that.npapiHost_ = createPluginCallback(); | 78 |
62 that.state_ = remoting.HostDispatcher.State.NPAPI; | 79 that.state_ = that.npapiHost_ ? remoting.HostDispatcher.State.NPAPI |
80 : remoting.HostDispatcher.State.NOT_INSTALLED; | |
63 sendPendingRequests(); | 81 sendPendingRequests(); |
64 } | 82 } |
65 | 83 |
66 this.nativeMessagingHost_.initialize(onNativeMessagingInit, | 84 this.nativeMessagingHost_.initialize(onNativeMessagingInit, |
67 onNativeMessagingFailed); | 85 onNativeMessagingFailed); |
68 }; | 86 }; |
69 | 87 |
70 /** @enum {number} */ | |
71 remoting.HostDispatcher.State = { | |
72 UNKNOWN: 0, | |
73 NATIVE_MESSAGING: 1, | |
74 NPAPI: 2 | |
75 }; | |
76 | |
77 /** | 88 /** |
78 * @param {remoting.HostController.Feature} feature The feature to test for. | 89 * @param {remoting.HostController.Feature} feature The feature to test for. |
79 * @param {function(boolean):void} onDone | 90 * @param {function(boolean):void} onDone |
80 * @return {void} | 91 * @return {void} |
81 */ | 92 */ |
82 remoting.HostDispatcher.prototype.hasFeature = function( | 93 remoting.HostDispatcher.prototype.hasFeature = function( |
83 feature, onDone) { | 94 feature, onDone) { |
84 switch (this.state_) { | 95 switch (this.state_) { |
85 case remoting.HostDispatcher.State.UNKNOWN: | 96 case remoting.HostDispatcher.State.UNKNOWN: |
86 this.pendingRequests_.push( | 97 this.pendingRequests_.push( |
87 this.hasFeature.bind(this, feature, onDone)); | 98 this.hasFeature.bind(this, feature, onDone)); |
88 break; | 99 break; |
89 case remoting.HostDispatcher.State.NATIVE_MESSAGING: | 100 case remoting.HostDispatcher.State.NATIVE_MESSAGING: |
90 onDone(this.nativeMessagingHost_.hasFeature(feature)); | 101 onDone(this.nativeMessagingHost_.hasFeature(feature)); |
91 break; | 102 break; |
92 case remoting.HostDispatcher.State.NPAPI: | 103 case remoting.HostDispatcher.State.NPAPI: |
93 // If this is an old NPAPI plugin that doesn't list supportedFeatures, | 104 // If this is an old NPAPI plugin that doesn't list supportedFeatures, |
94 // assume it is an old plugin that doesn't support any new feature. | 105 // assume it is an old plugin that doesn't support any new feature. |
95 var supportedFeatures = []; | 106 var supportedFeatures = []; |
96 if (typeof(this.npapiHost_.supportedFeatures) == 'string') { | 107 if (typeof(this.npapiHost_.supportedFeatures) == 'string') { |
97 supportedFeatures = this.npapiHost_.supportedFeatures.split(' '); | 108 supportedFeatures = this.npapiHost_.supportedFeatures.split(' '); |
98 } | 109 } |
99 onDone(supportedFeatures.indexOf(feature) >= 0); | 110 onDone(supportedFeatures.indexOf(feature) >= 0); |
100 break; | 111 break; |
112 case remoting.HostDispatcher.State.NOT_INSTALLED: | |
113 onDone(false); | |
114 break; | |
101 } | 115 } |
102 }; | 116 }; |
103 | 117 |
104 /** | 118 /** |
105 * @param {function(string):void} onDone | 119 * @param {function(string):void} onDone |
106 * @param {function(remoting.Error):void} onError | 120 * @param {function(remoting.Error):void} onError |
107 * @return {void} | 121 * @return {void} |
108 */ | 122 */ |
109 remoting.HostDispatcher.prototype.getHostName = function(onDone, onError) { | 123 remoting.HostDispatcher.prototype.getHostName = function(onDone, onError) { |
110 switch (this.state_) { | 124 switch (this.state_) { |
111 case remoting.HostDispatcher.State.UNKNOWN: | 125 case remoting.HostDispatcher.State.UNKNOWN: |
112 this.pendingRequests_.push( | 126 this.pendingRequests_.push( |
113 this.getHostName.bind(this, onDone, onError)); | 127 this.getHostName.bind(this, onDone, onError)); |
114 break; | 128 break; |
115 case remoting.HostDispatcher.State.NATIVE_MESSAGING: | 129 case remoting.HostDispatcher.State.NATIVE_MESSAGING: |
116 this.nativeMessagingHost_.getHostName(onDone, onError); | 130 this.nativeMessagingHost_.getHostName(onDone, onError); |
117 break; | 131 break; |
118 case remoting.HostDispatcher.State.NPAPI: | 132 case remoting.HostDispatcher.State.NPAPI: |
119 try { | 133 try { |
120 this.npapiHost_.getHostName(onDone); | 134 this.npapiHost_.getHostName(onDone); |
121 } catch (err) { | 135 } catch (err) { |
122 onError(remoting.Error.MISSING_PLUGIN); | 136 onError(remoting.Error.MISSING_PLUGIN); |
123 } | 137 } |
124 break; | 138 break; |
139 case remoting.HostDispatcher.State.NOT_INSTALLED: | |
140 onError(remoting.Error.MISSING_PLUGIN); | |
141 break; | |
125 } | 142 } |
126 }; | 143 }; |
127 | 144 |
128 /** | 145 /** |
129 * @param {string} hostId | 146 * @param {string} hostId |
130 * @param {string} pin | 147 * @param {string} pin |
131 * @param {function(string):void} onDone | 148 * @param {function(string):void} onDone |
132 * @param {function(remoting.Error):void} onError | 149 * @param {function(remoting.Error):void} onError |
133 * @return {void} | 150 * @return {void} |
134 */ | 151 */ |
135 remoting.HostDispatcher.prototype.getPinHash = | 152 remoting.HostDispatcher.prototype.getPinHash = |
136 function(hostId, pin, onDone, onError) { | 153 function(hostId, pin, onDone, onError) { |
137 switch (this.state_) { | 154 switch (this.state_) { |
138 case remoting.HostDispatcher.State.UNKNOWN: | 155 case remoting.HostDispatcher.State.UNKNOWN: |
139 this.pendingRequests_.push( | 156 this.pendingRequests_.push( |
140 this.getPinHash.bind(this, hostId, pin, onDone, onError)); | 157 this.getPinHash.bind(this, hostId, pin, onDone, onError)); |
141 break; | 158 break; |
142 case remoting.HostDispatcher.State.NATIVE_MESSAGING: | 159 case remoting.HostDispatcher.State.NATIVE_MESSAGING: |
143 this.nativeMessagingHost_.getPinHash(hostId, pin, onDone, onError); | 160 this.nativeMessagingHost_.getPinHash(hostId, pin, onDone, onError); |
144 break; | 161 break; |
145 case remoting.HostDispatcher.State.NPAPI: | 162 case remoting.HostDispatcher.State.NPAPI: |
146 try { | 163 try { |
147 this.npapiHost_.getPinHash(hostId, pin, onDone); | 164 this.npapiHost_.getPinHash(hostId, pin, onDone); |
148 } catch (err) { | 165 } catch (err) { |
149 onError(remoting.Error.MISSING_PLUGIN); | 166 onError(remoting.Error.MISSING_PLUGIN); |
150 } | 167 } |
151 break; | 168 break; |
169 case remoting.HostDispatcher.State.NOT_INSTALLED: | |
170 onError(remoting.Error.MISSING_PLUGIN); | |
171 break; | |
152 } | 172 } |
153 }; | 173 }; |
154 | 174 |
155 /** | 175 /** |
156 * @param {function(string, string):void} onDone | 176 * @param {function(string, string):void} onDone |
157 * @param {function(remoting.Error):void} onError | 177 * @param {function(remoting.Error):void} onError |
158 * @return {void} | 178 * @return {void} |
159 */ | 179 */ |
160 remoting.HostDispatcher.prototype.generateKeyPair = function(onDone, onError) { | 180 remoting.HostDispatcher.prototype.generateKeyPair = function(onDone, onError) { |
161 switch (this.state_) { | 181 switch (this.state_) { |
162 case remoting.HostDispatcher.State.UNKNOWN: | 182 case remoting.HostDispatcher.State.UNKNOWN: |
163 this.pendingRequests_.push( | 183 this.pendingRequests_.push( |
164 this.generateKeyPair.bind(this, onDone, onError)); | 184 this.generateKeyPair.bind(this, onDone, onError)); |
165 break; | 185 break; |
166 case remoting.HostDispatcher.State.NATIVE_MESSAGING: | 186 case remoting.HostDispatcher.State.NATIVE_MESSAGING: |
167 this.nativeMessagingHost_.generateKeyPair(onDone, onError); | 187 this.nativeMessagingHost_.generateKeyPair(onDone, onError); |
168 break; | 188 break; |
169 case remoting.HostDispatcher.State.NPAPI: | 189 case remoting.HostDispatcher.State.NPAPI: |
170 try { | 190 try { |
171 this.npapiHost_.generateKeyPair(onDone); | 191 this.npapiHost_.generateKeyPair(onDone); |
172 } catch (err) { | 192 } catch (err) { |
173 onError(remoting.Error.MISSING_PLUGIN); | 193 onError(remoting.Error.MISSING_PLUGIN); |
174 } | 194 } |
175 break; | 195 break; |
196 case remoting.HostDispatcher.State.NOT_INSTALLED: | |
197 onError(remoting.Error.MISSING_PLUGIN); | |
198 break; | |
176 } | 199 } |
177 }; | 200 }; |
178 | 201 |
179 /** | 202 /** |
180 * @param {Object} config | 203 * @param {Object} config |
181 * @param {function(remoting.HostController.AsyncResult):void} onDone | 204 * @param {function(remoting.HostController.AsyncResult):void} onDone |
182 * @param {function(remoting.Error):void} onError | 205 * @param {function(remoting.Error):void} onError |
183 * @return {void} | 206 * @return {void} |
184 */ | 207 */ |
185 remoting.HostDispatcher.prototype.updateDaemonConfig = | 208 remoting.HostDispatcher.prototype.updateDaemonConfig = |
186 function(config, onDone, onError) { | 209 function(config, onDone, onError) { |
187 switch (this.state_) { | 210 switch (this.state_) { |
188 case remoting.HostDispatcher.State.UNKNOWN: | 211 case remoting.HostDispatcher.State.UNKNOWN: |
189 this.pendingRequests_.push( | 212 this.pendingRequests_.push( |
190 this.updateDaemonConfig.bind(this, config, onDone, onError)); | 213 this.updateDaemonConfig.bind(this, config, onDone, onError)); |
191 break; | 214 break; |
192 case remoting.HostDispatcher.State.NATIVE_MESSAGING: | 215 case remoting.HostDispatcher.State.NATIVE_MESSAGING: |
193 this.nativeMessagingHost_.updateDaemonConfig(config, onDone, onError); | 216 this.nativeMessagingHost_.updateDaemonConfig(config, onDone, onError); |
194 break; | 217 break; |
195 case remoting.HostDispatcher.State.NPAPI: | 218 case remoting.HostDispatcher.State.NPAPI: |
196 try { | 219 try { |
197 this.npapiHost_.updateDaemonConfig(JSON.stringify(config), onDone); | 220 this.npapiHost_.updateDaemonConfig(JSON.stringify(config), onDone); |
198 } catch (err) { | 221 } catch (err) { |
199 onError(remoting.Error.MISSING_PLUGIN); | 222 onError(remoting.Error.MISSING_PLUGIN); |
200 } | 223 } |
201 break; | 224 break; |
225 case remoting.HostDispatcher.State.NOT_INSTALLED: | |
226 onError(remoting.Error.MISSING_PLUGIN); | |
227 break; | |
202 } | 228 } |
203 }; | 229 }; |
204 | 230 |
205 /** | 231 /** |
206 * @param {function(Object):void} onDone | 232 * @param {function(Object):void} onDone |
207 * @param {function(remoting.Error):void} onError | 233 * @param {function(remoting.Error):void} onError |
208 * @return {void} | 234 * @return {void} |
209 */ | 235 */ |
210 remoting.HostDispatcher.prototype.getDaemonConfig = function(onDone, onError) { | 236 remoting.HostDispatcher.prototype.getDaemonConfig = function(onDone, onError) { |
211 /** | 237 /** |
(...skipping 19 matching lines...) Expand all Loading... | |
231 case remoting.HostDispatcher.State.NATIVE_MESSAGING: | 257 case remoting.HostDispatcher.State.NATIVE_MESSAGING: |
232 this.nativeMessagingHost_.getDaemonConfig(onDone, onError); | 258 this.nativeMessagingHost_.getDaemonConfig(onDone, onError); |
233 break; | 259 break; |
234 case remoting.HostDispatcher.State.NPAPI: | 260 case remoting.HostDispatcher.State.NPAPI: |
235 try { | 261 try { |
236 this.npapiHost_.getDaemonConfig(callbackForNpapi); | 262 this.npapiHost_.getDaemonConfig(callbackForNpapi); |
237 } catch (err) { | 263 } catch (err) { |
238 onError(remoting.Error.MISSING_PLUGIN); | 264 onError(remoting.Error.MISSING_PLUGIN); |
239 } | 265 } |
240 break; | 266 break; |
267 case remoting.HostDispatcher.State.NOT_INSTALLED: | |
268 onDone({}); | |
Jamie
2014/01/31 18:39:15
Why is this not onError like the other cases? Mayb
Sergey Ulanov
2014/01/31 23:34:17
For most other things we can'd do anything without
| |
269 break; | |
241 } | 270 } |
242 }; | 271 }; |
243 | 272 |
244 /** | 273 /** |
245 * @param {function(string):void} onDone | 274 * @param {function(string):void} onDone |
246 * @param {function(remoting.Error):void} onError | 275 * @param {function(remoting.Error):void} onError |
247 * @return {void} | 276 * @return {void} |
248 */ | 277 */ |
249 remoting.HostDispatcher.prototype.getDaemonVersion = function(onDone, onError) { | 278 remoting.HostDispatcher.prototype.getDaemonVersion = function(onDone, onError) { |
250 switch (this.state_) { | 279 switch (this.state_) { |
251 case remoting.HostDispatcher.State.UNKNOWN: | 280 case remoting.HostDispatcher.State.UNKNOWN: |
252 this.pendingRequests_.push( | 281 this.pendingRequests_.push( |
253 this.getDaemonVersion.bind(this, onDone, onError)); | 282 this.getDaemonVersion.bind(this, onDone, onError)); |
254 break; | 283 break; |
255 case remoting.HostDispatcher.State.NATIVE_MESSAGING: | 284 case remoting.HostDispatcher.State.NATIVE_MESSAGING: |
256 onDone(this.nativeMessagingHost_.getDaemonVersion()); | 285 onDone(this.nativeMessagingHost_.getDaemonVersion()); |
257 break; | 286 break; |
258 case remoting.HostDispatcher.State.NPAPI: | 287 case remoting.HostDispatcher.State.NPAPI: |
259 try { | 288 try { |
260 this.npapiHost_.getDaemonVersion(onDone); | 289 this.npapiHost_.getDaemonVersion(onDone); |
261 } catch (err) { | 290 } catch (err) { |
262 onError(remoting.Error.MISSING_PLUGIN); | 291 onError(remoting.Error.MISSING_PLUGIN); |
263 } | 292 } |
264 break; | 293 break; |
294 case remoting.HostDispatcher.State.NOT_INSTALLED: | |
295 onError(remoting.Error.MISSING_PLUGIN); | |
296 break; | |
265 } | 297 } |
266 }; | 298 }; |
267 | 299 |
268 /** | 300 /** |
269 * @param {function(boolean, boolean, boolean):void} onDone | 301 * @param {function(boolean, boolean, boolean):void} onDone |
270 * @param {function(remoting.Error):void} onError | 302 * @param {function(remoting.Error):void} onError |
271 * @return {void} | 303 * @return {void} |
272 */ | 304 */ |
273 remoting.HostDispatcher.prototype.getUsageStatsConsent = | 305 remoting.HostDispatcher.prototype.getUsageStatsConsent = |
274 function(onDone, onError) { | 306 function(onDone, onError) { |
275 switch (this.state_) { | 307 switch (this.state_) { |
276 case remoting.HostDispatcher.State.UNKNOWN: | 308 case remoting.HostDispatcher.State.UNKNOWN: |
277 this.pendingRequests_.push( | 309 this.pendingRequests_.push( |
278 this.getUsageStatsConsent.bind(this, onDone, onError)); | 310 this.getUsageStatsConsent.bind(this, onDone, onError)); |
279 break; | 311 break; |
280 case remoting.HostDispatcher.State.NATIVE_MESSAGING: | 312 case remoting.HostDispatcher.State.NATIVE_MESSAGING: |
281 this.nativeMessagingHost_.getUsageStatsConsent(onDone, onError); | 313 this.nativeMessagingHost_.getUsageStatsConsent(onDone, onError); |
282 break; | 314 break; |
283 case remoting.HostDispatcher.State.NPAPI: | 315 case remoting.HostDispatcher.State.NPAPI: |
284 try { | 316 try { |
285 this.npapiHost_.getUsageStatsConsent(onDone); | 317 this.npapiHost_.getUsageStatsConsent(onDone); |
286 } catch (err) { | 318 } catch (err) { |
287 onError(remoting.Error.MISSING_PLUGIN); | 319 onError(remoting.Error.MISSING_PLUGIN); |
288 } | 320 } |
289 break; | 321 break; |
322 case remoting.HostDispatcher.State.NOT_INSTALLED: | |
323 onError(remoting.Error.MISSING_PLUGIN); | |
324 break; | |
290 } | 325 } |
291 }; | 326 }; |
292 | 327 |
293 /** | 328 /** |
294 * @param {Object} config | 329 * @param {Object} config |
295 * @param {boolean} consent | 330 * @param {boolean} consent |
296 * @param {function(remoting.HostController.AsyncResult):void} onDone | 331 * @param {function(remoting.HostController.AsyncResult):void} onDone |
297 * @param {function(remoting.Error):void} onError | 332 * @param {function(remoting.Error):void} onError |
298 * @return {void} | 333 * @return {void} |
299 */ | 334 */ |
300 remoting.HostDispatcher.prototype.startDaemon = | 335 remoting.HostDispatcher.prototype.startDaemon = |
301 function(config, consent, onDone, onError) { | 336 function(config, consent, onDone, onError) { |
302 switch (this.state_) { | 337 switch (this.state_) { |
303 case remoting.HostDispatcher.State.UNKNOWN: | 338 case remoting.HostDispatcher.State.UNKNOWN: |
304 this.pendingRequests_.push( | 339 this.pendingRequests_.push( |
305 this.startDaemon.bind(this, config, consent, onDone, onError)); | 340 this.startDaemon.bind(this, config, consent, onDone, onError)); |
306 break; | 341 break; |
307 case remoting.HostDispatcher.State.NATIVE_MESSAGING: | 342 case remoting.HostDispatcher.State.NATIVE_MESSAGING: |
308 this.nativeMessagingHost_.startDaemon(config, consent, onDone, onError); | 343 this.nativeMessagingHost_.startDaemon(config, consent, onDone, onError); |
309 break; | 344 break; |
310 case remoting.HostDispatcher.State.NPAPI: | 345 case remoting.HostDispatcher.State.NPAPI: |
311 try { | 346 try { |
312 this.npapiHost_.startDaemon(JSON.stringify(config), consent, onDone); | 347 this.npapiHost_.startDaemon(JSON.stringify(config), consent, onDone); |
313 } catch (err) { | 348 } catch (err) { |
314 onError(remoting.Error.MISSING_PLUGIN); | 349 onError(remoting.Error.MISSING_PLUGIN); |
315 } | 350 } |
316 break; | 351 break; |
352 case remoting.HostDispatcher.State.NOT_INSTALLED: | |
353 onError(remoting.Error.MISSING_PLUGIN); | |
354 break; | |
317 } | 355 } |
318 }; | 356 }; |
319 | 357 |
320 /** | 358 /** |
321 * @param {function(remoting.HostController.AsyncResult):void} onDone | 359 * @param {function(remoting.HostController.AsyncResult):void} onDone |
322 * @param {function(remoting.Error):void} onError | 360 * @param {function(remoting.Error):void} onError |
323 * @return {void} | 361 * @return {void} |
324 */ | 362 */ |
325 remoting.HostDispatcher.prototype.stopDaemon = function(onDone, onError) { | 363 remoting.HostDispatcher.prototype.stopDaemon = function(onDone, onError) { |
326 switch (this.state_) { | 364 switch (this.state_) { |
327 case remoting.HostDispatcher.State.UNKNOWN: | 365 case remoting.HostDispatcher.State.UNKNOWN: |
328 this.pendingRequests_.push(this.stopDaemon.bind(this, onDone, onError)); | 366 this.pendingRequests_.push(this.stopDaemon.bind(this, onDone, onError)); |
329 break; | 367 break; |
330 case remoting.HostDispatcher.State.NATIVE_MESSAGING: | 368 case remoting.HostDispatcher.State.NATIVE_MESSAGING: |
331 this.nativeMessagingHost_.stopDaemon(onDone, onError); | 369 this.nativeMessagingHost_.stopDaemon(onDone, onError); |
332 break; | 370 break; |
333 case remoting.HostDispatcher.State.NPAPI: | 371 case remoting.HostDispatcher.State.NPAPI: |
334 try { | 372 try { |
335 this.npapiHost_.stopDaemon(onDone); | 373 this.npapiHost_.stopDaemon(onDone); |
336 } catch (err) { | 374 } catch (err) { |
337 onError(remoting.Error.MISSING_PLUGIN); | 375 onError(remoting.Error.MISSING_PLUGIN); |
338 } | 376 } |
339 break; | 377 break; |
378 case remoting.HostDispatcher.State.NOT_INSTALLED: | |
379 onError(remoting.Error.MISSING_PLUGIN); | |
380 break; | |
340 } | 381 } |
341 }; | 382 }; |
342 | 383 |
343 /** | 384 /** |
344 * @param {function(remoting.HostController.State):void} onDone | 385 * @param {function(remoting.HostController.State):void} onDone |
345 * @param {function(remoting.Error):void} onError | 386 * @param {function(remoting.Error):void} onError |
346 * @return {void} | 387 * @return {void} |
347 */ | 388 */ |
348 remoting.HostDispatcher.prototype.getDaemonState = function(onDone, onError) { | 389 remoting.HostDispatcher.prototype.getDaemonState = function(onDone, onError) { |
390 // If the host was in not-initialized state try initializing it again in case | |
391 // it was installed. | |
392 if (this.state_ == remoting.HostDispatcher.State.NOT_INSTALLED) { | |
393 this.state_ = remoting.HostDispatcher.State.UNKNOWN; | |
394 this.tryToInitialize_(); | |
395 } | |
396 | |
397 this.getDaemonStateInternal_(onDone, onError); | |
398 } | |
399 | |
400 /** | |
401 * @param {function(remoting.HostController.State):void} onDone | |
402 * @param {function(remoting.Error):void} onError | |
403 * @return {void} | |
404 */ | |
405 remoting.HostDispatcher.prototype.getDaemonStateInternal_ = | |
406 function(onDone, onError) { | |
349 switch (this.state_) { | 407 switch (this.state_) { |
350 case remoting.HostDispatcher.State.UNKNOWN: | 408 case remoting.HostDispatcher.State.UNKNOWN: |
351 this.pendingRequests_.push( | 409 this.pendingRequests_.push( |
352 this.getDaemonState.bind(this, onDone, onError)); | 410 this.getDaemonStateInternal_.bind(this, onDone, onError)); |
353 break; | 411 break; |
354 case remoting.HostDispatcher.State.NATIVE_MESSAGING: | 412 case remoting.HostDispatcher.State.NATIVE_MESSAGING: |
355 this.nativeMessagingHost_.getDaemonState(onDone, onError); | 413 this.nativeMessagingHost_.getDaemonState(onDone, onError); |
356 break; | 414 break; |
357 case remoting.HostDispatcher.State.NPAPI: | 415 case remoting.HostDispatcher.State.NPAPI: |
358 // Call the callback directly, since NPAPI exposes the state directly as | 416 // Call the callback directly, since NPAPI exposes the state directly as |
359 // a field member, rather than an asynchronous method. | 417 // a field member, rather than an asynchronous method. |
360 var state = this.npapiHost_.daemonState; | 418 var state = this.npapiHost_.daemonState; |
361 if (state === undefined) { | 419 if (state === undefined) { |
362 onError(remoting.Error.MISSING_PLUGIN); | 420 onError(remoting.Error.MISSING_PLUGIN); |
363 } else { | 421 } else { |
364 onDone(state); | 422 onDone(state); |
365 } | 423 } |
366 break; | 424 break; |
425 case remoting.HostDispatcher.State.NOT_INSTALLED: | |
426 onDone(remoting.HostController.State.NOT_INSTALLED); | |
427 break; | |
367 } | 428 } |
368 }; | 429 }; |
369 | 430 |
370 /** | 431 /** |
371 * @param {function(Array.<remoting.PairedClient>):void} onDone | 432 * @param {function(Array.<remoting.PairedClient>):void} onDone |
372 * @param {function(remoting.Error):void} onError | 433 * @param {function(remoting.Error):void} onError |
373 * @return {void} | 434 * @return {void} |
374 */ | 435 */ |
375 remoting.HostDispatcher.prototype.getPairedClients = function(onDone, onError) { | 436 remoting.HostDispatcher.prototype.getPairedClients = function(onDone, onError) { |
376 /** | 437 /** |
(...skipping 20 matching lines...) Expand all Loading... | |
397 case remoting.HostDispatcher.State.NATIVE_MESSAGING: | 458 case remoting.HostDispatcher.State.NATIVE_MESSAGING: |
398 this.nativeMessagingHost_.getPairedClients(onDone, onError); | 459 this.nativeMessagingHost_.getPairedClients(onDone, onError); |
399 break; | 460 break; |
400 case remoting.HostDispatcher.State.NPAPI: | 461 case remoting.HostDispatcher.State.NPAPI: |
401 try { | 462 try { |
402 this.npapiHost_.getPairedClients(callbackForNpapi); | 463 this.npapiHost_.getPairedClients(callbackForNpapi); |
403 } catch (err) { | 464 } catch (err) { |
404 onError(remoting.Error.MISSING_PLUGIN); | 465 onError(remoting.Error.MISSING_PLUGIN); |
405 } | 466 } |
406 break; | 467 break; |
468 case remoting.HostDispatcher.State.NOT_INSTALLED: | |
469 onDone(remoting.HostController.State.NOT_INSTALLED); | |
Jamie
2014/01/31 18:39:15
This is the wrong type for onDone. I think you mea
Sergey Ulanov
2014/01/31 23:34:17
Done
| |
470 break; | |
407 } | 471 } |
408 }; | 472 }; |
409 | 473 |
410 /** | 474 /** |
411 * The pairing API returns a boolean to indicate success or failure, but | 475 * The pairing API returns a boolean to indicate success or failure, but |
412 * the JS API is defined in terms of onDone and onError callbacks. This | 476 * the JS API is defined in terms of onDone and onError callbacks. This |
413 * function converts one to the other. | 477 * function converts one to the other. |
414 * | 478 * |
415 * @param {function():void} onDone Success callback. | 479 * @param {function():void} onDone Success callback. |
416 * @param {function(remoting.Error):void} onError Error callback. | 480 * @param {function(remoting.Error):void} onError Error callback. |
(...skipping 25 matching lines...) Expand all Loading... | |
442 case remoting.HostDispatcher.State.NATIVE_MESSAGING: | 506 case remoting.HostDispatcher.State.NATIVE_MESSAGING: |
443 this.nativeMessagingHost_.clearPairedClients(callback, onError); | 507 this.nativeMessagingHost_.clearPairedClients(callback, onError); |
444 break; | 508 break; |
445 case remoting.HostDispatcher.State.NPAPI: | 509 case remoting.HostDispatcher.State.NPAPI: |
446 try { | 510 try { |
447 this.npapiHost_.clearPairedClients(callback); | 511 this.npapiHost_.clearPairedClients(callback); |
448 } catch (err) { | 512 } catch (err) { |
449 onError(remoting.Error.MISSING_PLUGIN); | 513 onError(remoting.Error.MISSING_PLUGIN); |
450 } | 514 } |
451 break; | 515 break; |
516 case remoting.HostDispatcher.State.NOT_INSTALLED: | |
517 onDone(remoting.HostController.State.NOT_INSTALLED); | |
Jamie
2014/01/31 18:39:15
onDone take no parameters; perhaps you need to cal
Sergey Ulanov
2014/01/31 23:34:17
Yes.
| |
518 break; | |
452 } | 519 } |
453 }; | 520 }; |
454 | 521 |
455 /** | 522 /** |
456 * @param {string} client | 523 * @param {string} client |
457 * @param {function():void} onDone | 524 * @param {function():void} onDone |
458 * @param {function(remoting.Error):void} onError | 525 * @param {function(remoting.Error):void} onError |
459 * @return {void} | 526 * @return {void} |
460 */ | 527 */ |
461 remoting.HostDispatcher.prototype.deletePairedClient = | 528 remoting.HostDispatcher.prototype.deletePairedClient = |
462 function(client, onDone, onError) { | 529 function(client, onDone, onError) { |
463 var callback = | 530 var callback = |
464 remoting.HostDispatcher.runCallback_.bind(null, onDone, onError); | 531 remoting.HostDispatcher.runCallback_.bind(null, onDone, onError); |
465 switch (this.state_) { | 532 switch (this.state_) { |
466 case remoting.HostDispatcher.State.UNKNOWN: | 533 case remoting.HostDispatcher.State.UNKNOWN: |
467 this.pendingRequests_.push( | 534 this.pendingRequests_.push( |
468 this.deletePairedClient.bind(this, client, onDone, onError)); | 535 this.deletePairedClient.bind(this, client, onDone, onError)); |
469 break; | 536 break; |
470 case remoting.HostDispatcher.State.NATIVE_MESSAGING: | 537 case remoting.HostDispatcher.State.NATIVE_MESSAGING: |
471 this.nativeMessagingHost_.deletePairedClient(client, callback, onError); | 538 this.nativeMessagingHost_.deletePairedClient(client, callback, onError); |
472 break; | 539 break; |
473 case remoting.HostDispatcher.State.NPAPI: | 540 case remoting.HostDispatcher.State.NPAPI: |
474 try { | 541 try { |
475 this.npapiHost_.deletePairedClient(client, callback); | 542 this.npapiHost_.deletePairedClient(client, callback); |
476 } catch (err) { | 543 } catch (err) { |
477 onError(remoting.Error.MISSING_PLUGIN); | 544 onError(remoting.Error.MISSING_PLUGIN); |
478 } | 545 } |
479 break; | 546 break; |
547 case remoting.HostDispatcher.State.NOT_INSTALLED: | |
548 onDone(remoting.HostController.State.NOT_INSTALLED); | |
Jamie
2014/01/31 18:39:15
onError?
Sergey Ulanov
2014/01/31 23:34:17
Done.
| |
549 break; | |
480 } | 550 } |
481 }; | 551 }; |
482 | 552 |
483 /** | 553 /** |
484 * @param {function(string):void} onDone | 554 * @param {function(string):void} onDone |
485 * @param {function(remoting.Error):void} onError | 555 * @param {function(remoting.Error):void} onError |
486 * @return {void} | 556 * @return {void} |
487 */ | 557 */ |
488 remoting.HostDispatcher.prototype.getHostClientId = | 558 remoting.HostDispatcher.prototype.getHostClientId = |
489 function(onDone, onError) { | 559 function(onDone, onError) { |
490 switch (this.state_) { | 560 switch (this.state_) { |
491 case remoting.HostDispatcher.State.UNKNOWN: | 561 case remoting.HostDispatcher.State.UNKNOWN: |
492 this.pendingRequests_.push( | 562 this.pendingRequests_.push( |
493 this.getHostClientId.bind(this, onDone, onError)); | 563 this.getHostClientId.bind(this, onDone, onError)); |
494 break; | 564 break; |
495 case remoting.HostDispatcher.State.NATIVE_MESSAGING: | 565 case remoting.HostDispatcher.State.NATIVE_MESSAGING: |
496 this.nativeMessagingHost_.getHostClientId(onDone, onError); | 566 this.nativeMessagingHost_.getHostClientId(onDone, onError); |
497 break; | 567 break; |
498 case remoting.HostDispatcher.State.NPAPI: | 568 case remoting.HostDispatcher.State.NPAPI: |
499 // The NPAPI plugin is packaged with the webapp, not the host, so it | 569 // The NPAPI plugin is packaged with the webapp, not the host, so it |
500 // doesn't have access to the API keys baked into the installed host. | 570 // doesn't have access to the API keys baked into the installed host. |
501 onError(remoting.Error.UNEXPECTED); | 571 onError(remoting.Error.UNEXPECTED); |
502 break; | 572 break; |
573 case remoting.HostDispatcher.State.NOT_INSTALLED: | |
574 onDone(remoting.HostController.State.NOT_INSTALLED); | |
Jamie
2014/01/31 18:39:15
onError?
Sergey Ulanov
2014/01/31 23:34:17
Done.
| |
575 break; | |
503 } | 576 } |
504 }; | 577 }; |
505 | 578 |
506 /** | 579 /** |
507 * @param {string} authorizationCode | 580 * @param {string} authorizationCode |
508 * @param {function(string, string):void} onDone | 581 * @param {function(string, string):void} onDone |
509 * @param {function(remoting.Error):void} onError | 582 * @param {function(remoting.Error):void} onError |
510 * @return {void} | 583 * @return {void} |
511 */ | 584 */ |
512 remoting.HostDispatcher.prototype.getCredentialsFromAuthCode = | 585 remoting.HostDispatcher.prototype.getCredentialsFromAuthCode = |
513 function(authorizationCode, onDone, onError) { | 586 function(authorizationCode, onDone, onError) { |
514 switch (this.state_) { | 587 switch (this.state_) { |
515 case remoting.HostDispatcher.State.UNKNOWN: | 588 case remoting.HostDispatcher.State.UNKNOWN: |
516 this.pendingRequests_.push( | 589 this.pendingRequests_.push( |
517 this.getCredentialsFromAuthCode.bind( | 590 this.getCredentialsFromAuthCode.bind( |
518 this, authorizationCode, onDone, onError)); | 591 this, authorizationCode, onDone, onError)); |
519 break; | 592 break; |
520 case remoting.HostDispatcher.State.NATIVE_MESSAGING: | 593 case remoting.HostDispatcher.State.NATIVE_MESSAGING: |
521 this.nativeMessagingHost_.getCredentialsFromAuthCode( | 594 this.nativeMessagingHost_.getCredentialsFromAuthCode( |
522 authorizationCode, onDone, onError); | 595 authorizationCode, onDone, onError); |
523 break; | 596 break; |
524 case remoting.HostDispatcher.State.NPAPI: | 597 case remoting.HostDispatcher.State.NPAPI: |
525 // The NPAPI plugin is packaged with the webapp, not the host, so it | 598 // The NPAPI plugin is packaged with the webapp, not the host, so it |
526 // doesn't have access to the API keys baked into the installed host. | 599 // doesn't have access to the API keys baked into the installed host. |
527 onError(remoting.Error.UNEXPECTED); | 600 onError(remoting.Error.UNEXPECTED); |
528 break; | 601 break; |
602 case remoting.HostDispatcher.State.NOT_INSTALLED: | |
603 onDone(remoting.HostController.State.NOT_INSTALLED); | |
Jamie
2014/01/31 18:39:15
onError?
Sergey Ulanov
2014/01/31 23:34:17
Done.
| |
604 break; | |
529 } | 605 } |
530 }; | 606 }; |
OLD | NEW |