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 25 matching lines...) Expand all Loading... |
36 | 36 |
37 /** @type {remoting.HostPlugin} @private */ | 37 /** @type {remoting.HostPlugin} @private */ |
38 this.npapiHost_ = null; | 38 this.npapiHost_ = null; |
39 | 39 |
40 /** @type {remoting.HostDispatcher.State} */ | 40 /** @type {remoting.HostDispatcher.State} */ |
41 this.state_ = remoting.HostDispatcher.State.UNKNOWN; | 41 this.state_ = remoting.HostDispatcher.State.UNKNOWN; |
42 | 42 |
43 /** @type {Array.<function()>} */ | 43 /** @type {Array.<function()>} */ |
44 this.pendingRequests_ = []; | 44 this.pendingRequests_ = []; |
45 | 45 |
46 /** @param {boolean} success */ | 46 function sendPendingRequests() { |
47 var onNativeMessagingInit = function(success) { | |
48 if (success) { | |
49 console.log('Native Messaging supported.'); | |
50 that.state_ = remoting.HostDispatcher.State.NATIVE_MESSAGING; | |
51 } else { | |
52 console.log('Native Messaging unsupported, falling back to NPAPI.'); | |
53 that.npapiHost_ = createPluginCallback(); | |
54 that.state_ = remoting.HostDispatcher.State.NPAPI; | |
55 } | |
56 // Send pending requests. | |
57 for (var i = 0; i < that.pendingRequests_.length; i++) { | 47 for (var i = 0; i < that.pendingRequests_.length; i++) { |
58 that.pendingRequests_[i](); | 48 that.pendingRequests_[i](); |
59 } | 49 } |
60 that.pendingRequests_ = null; | 50 that.pendingRequests_ = null; |
61 }; | 51 } |
62 | 52 |
63 this.nativeMessagingHost_.initialize(onNativeMessagingInit); | 53 function onNativeMessagingInit() { |
| 54 console.log('Native Messaging supported.'); |
| 55 that.state_ = remoting.HostDispatcher.State.NATIVE_MESSAGING; |
| 56 sendPendingRequests(); |
| 57 } |
| 58 |
| 59 function onNativeMessagingFailed(error) { |
| 60 console.log('Native Messaging unsupported, falling back to NPAPI.'); |
| 61 that.npapiHost_ = createPluginCallback(); |
| 62 that.state_ = remoting.HostDispatcher.State.NPAPI; |
| 63 sendPendingRequests(); |
| 64 } |
| 65 |
| 66 this.nativeMessagingHost_.initialize(onNativeMessagingInit, |
| 67 onNativeMessagingFailed); |
64 }; | 68 }; |
65 | 69 |
66 /** @enum {number} */ | 70 /** @enum {number} */ |
67 remoting.HostDispatcher.State = { | 71 remoting.HostDispatcher.State = { |
68 UNKNOWN: 0, | 72 UNKNOWN: 0, |
69 NATIVE_MESSAGING: 1, | 73 NATIVE_MESSAGING: 1, |
70 NPAPI: 2 | 74 NPAPI: 2 |
71 }; | 75 }; |
72 | 76 |
73 /** | 77 /** |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 break; | 428 break; |
425 case remoting.HostDispatcher.State.NPAPI: | 429 case remoting.HostDispatcher.State.NPAPI: |
426 try { | 430 try { |
427 this.npapiHost_.deletePairedClient(client, onDone); | 431 this.npapiHost_.deletePairedClient(client, onDone); |
428 } catch (err) { | 432 } catch (err) { |
429 onError(remoting.Error.MISSING_PLUGIN); | 433 onError(remoting.Error.MISSING_PLUGIN); |
430 } | 434 } |
431 break; | 435 break; |
432 } | 436 } |
433 }; | 437 }; |
OLD | NEW |