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 16 matching lines...) Expand all Loading... |
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.HostNativeMessaging} @private */ | 31 /** @type {remoting.HostNativeMessaging} @private */ |
32 this.nativeMessagingHost_ = new remoting.HostNativeMessaging(); | 32 this.nativeMessagingHost_ = new remoting.HostNativeMessaging(); |
33 | 33 |
34 /** @type {remoting.HostPlugin} @private */ | 34 /** @type {remoting.HostPlugin} @private */ |
35 this.npapiHost_ = null; | 35 this.npapiHost_ = null; |
36 | 36 |
37 /** @type {remoting.HostDispatcher.State} */ | 37 /** @type {remoting.HostDispatcher.State} @private */ |
38 this.state_ = remoting.HostDispatcher.State.UNKNOWN; | 38 this.state_ = remoting.HostDispatcher.State.UNKNOWN; |
39 | 39 |
40 /** @type {Array.<function()>} */ | 40 /** @type {Array.<function()>} @private */ |
41 this.pendingRequests_ = []; | 41 this.pendingRequests_ = []; |
42 | 42 |
| 43 /** @type {function():remoting.HostPlugin} @private */ |
43 this.createPluginCallback_ = createPluginCallback; | 44 this.createPluginCallback_ = createPluginCallback; |
44 | 45 |
45 this.tryToInitialize_(); | 46 this.tryToInitialize_(); |
46 } | 47 } |
47 | 48 |
48 /** @enum {number} */ | 49 /** @enum {number} */ |
49 remoting.HostDispatcher.State = { | 50 remoting.HostDispatcher.State = { |
50 UNKNOWN: 0, | 51 UNKNOWN: 0, |
51 NATIVE_MESSAGING: 1, | 52 NATIVE_MESSAGING: 1, |
52 NPAPI: 2, | 53 NPAPI: 2, |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 onError(remoting.Error.MISSING_PLUGIN); | 320 onError(remoting.Error.MISSING_PLUGIN); |
320 } | 321 } |
321 break; | 322 break; |
322 case remoting.HostDispatcher.State.NOT_INSTALLED: | 323 case remoting.HostDispatcher.State.NOT_INSTALLED: |
323 onError(remoting.Error.MISSING_PLUGIN); | 324 onError(remoting.Error.MISSING_PLUGIN); |
324 break; | 325 break; |
325 } | 326 } |
326 }; | 327 }; |
327 | 328 |
328 /** | 329 /** |
| 330 * @param {function(remoting.HostController.AsyncResult):void} onDone |
| 331 * @param {function(remoting.Error):void} onError |
| 332 * @return {void} |
| 333 */ |
| 334 remoting.HostDispatcher.prototype.installHost = function(onDone, onError) { |
| 335 switch (this.state_) { |
| 336 case remoting.HostDispatcher.State.UNKNOWN: |
| 337 this.pendingRequests_.push( |
| 338 this.startDaemon.bind(this, config, consent, onDone, onError)); |
| 339 break; |
| 340 case remoting.HostDispatcher.State.NATIVE_MESSAGING: |
| 341 // Host already installed, no action needed. |
| 342 onDone(remoting.HostController.AsyncResult.OK); |
| 343 break; |
| 344 case remoting.HostDispatcher.State.NPAPI: |
| 345 try { |
| 346 this.npapiHost_.installHost(onDone); |
| 347 } catch (err) { |
| 348 onError(remoting.Error.MISSING_PLUGIN); |
| 349 } |
| 350 break; |
| 351 case remoting.HostDispatcher.State.NOT_INSTALLED: |
| 352 onError(remoting.Error.MISSING_PLUGIN); |
| 353 break; |
| 354 } |
| 355 }; |
| 356 |
| 357 /** |
329 * @param {Object} config | 358 * @param {Object} config |
330 * @param {boolean} consent | 359 * @param {boolean} consent |
331 * @param {function(remoting.HostController.AsyncResult):void} onDone | 360 * @param {function(remoting.HostController.AsyncResult):void} onDone |
332 * @param {function(remoting.Error):void} onError | 361 * @param {function(remoting.Error):void} onError |
333 * @return {void} | 362 * @return {void} |
334 */ | 363 */ |
335 remoting.HostDispatcher.prototype.startDaemon = | 364 remoting.HostDispatcher.prototype.startDaemon = |
336 function(config, consent, onDone, onError) { | 365 function(config, consent, onDone, onError) { |
337 switch (this.state_) { | 366 switch (this.state_) { |
338 case remoting.HostDispatcher.State.UNKNOWN: | 367 case remoting.HostDispatcher.State.UNKNOWN: |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 } | 634 } |
606 }; | 635 }; |
607 | 636 |
608 /** | 637 /** |
609 * Returns true if the NPAPI plugin is being used. | 638 * Returns true if the NPAPI plugin is being used. |
610 * @return {boolean} | 639 * @return {boolean} |
611 */ | 640 */ |
612 remoting.HostDispatcher.prototype.usingNpapiPlugin = function() { | 641 remoting.HostDispatcher.prototype.usingNpapiPlugin = function() { |
613 return this.state_ == remoting.HostDispatcher.State.NPAPI; | 642 return this.state_ == remoting.HostDispatcher.State.NPAPI; |
614 } | 643 } |
OLD | NEW |