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 provides an interface between the HostSession and either the | 7 * This class provides an interface between the HostSession 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, the connection is attemped on either the the NativeMessaging | 10 * asynchronous, the connection is attemped on either the the NativeMessaging |
(...skipping 20 matching lines...) Expand all Loading... |
31 * @param {function():remoting.HostPlugin} createPluginCallback Callback to | 31 * @param {function():remoting.HostPlugin} createPluginCallback Callback to |
32 * instantiate the NPAPI plugin when NativeMessaging is determined to be | 32 * instantiate the NPAPI plugin when NativeMessaging is determined to be |
33 * unsupported. | 33 * unsupported. |
34 * @param {string} email The user's email address. | 34 * @param {string} email The user's email address. |
35 * @param {string} authServiceWithToken Concatenation of the auth service | 35 * @param {string} authServiceWithToken Concatenation of the auth service |
36 * (e.g. oauth2) and the access token. | 36 * (e.g. oauth2) and the access token. |
37 * @param {function(remoting.HostSession.State):void} onStateChanged Callback to | 37 * @param {function(remoting.HostSession.State):void} onStateChanged Callback to |
38 * invoke when the host state changes. | 38 * invoke when the host state changes. |
39 * @param {function(boolean):void} onNatPolicyChanged Callback to invoke when | 39 * @param {function(boolean):void} onNatPolicyChanged Callback to invoke when |
40 * the nat traversal policy changes. | 40 * the nat traversal policy changes. |
| 41 * @param {function(string):void} logDebugInfo Callback allowing the plugin |
| 42 * to log messages to the debug log. |
41 * @param {string} xmppServerAddress XMPP server host name (or IP address) and | 43 * @param {string} xmppServerAddress XMPP server host name (or IP address) and |
42 * port. | 44 * port. |
43 * @param {boolean} xmppServerUseTls Whether to use TLS on connections to the | 45 * @param {boolean} xmppServerUseTls Whether to use TLS on connections to the |
44 * XMPP server | 46 * XMPP server |
45 * @param {string} directoryBotJid XMPP JID for the remoting directory server | 47 * @param {string} directoryBotJid XMPP JID for the remoting directory server |
46 * bot. | 48 * bot. |
47 * @param {function():void} onError Callback to invoke if neither the native | 49 * @param {function():void} onError Callback to invoke if neither the native |
48 * messaging host nor the npapi plugin works. | 50 * messaging host nor the npapi plugin works. |
49 */ | 51 */ |
50 remoting.HostIt2MeDispatcher.prototype.initAndConnect = | 52 remoting.HostIt2MeDispatcher.prototype.initAndConnect = |
51 function(createPluginCallback, email, authServiceWithToken, onStateChanged, | 53 function(createPluginCallback, email, authServiceWithToken, onStateChanged, |
52 onNatPolicyChanged, xmppServerAddress, xmppServerUseTls, | 54 onNatPolicyChanged, logDebugInfo, xmppServerAddress, |
53 directoryBotJid, onError) { | 55 xmppServerUseTls, directoryBotJid, onError) { |
| 56 /** @type {remoting.HostIt2MeDispatcher} */ |
54 var that = this; | 57 var that = this; |
| 58 |
55 function onNativeMessagingStarted() { | 59 function onNativeMessagingStarted() { |
56 console.log('Native Messaging supported.'); | 60 console.log('Native Messaging supported.'); |
57 that.nativeMessagingHost_.connect( | 61 that.nativeMessagingHost_.connect( |
58 email, authServiceWithToken, onStateChanged, onNatPolicyChanged, | 62 email, authServiceWithToken, onStateChanged, onNatPolicyChanged, |
59 xmppServerAddress, xmppServerUseTls, directoryBotJid); | 63 xmppServerAddress, xmppServerUseTls, directoryBotJid); |
60 } | 64 } |
61 | 65 |
62 function onNativeMessagingFailed() { | 66 function onNativeMessagingFailed() { |
63 console.log('Native Messaging unsupported, falling back to NPAPI.'); | 67 console.log('Native Messaging unsupported, falling back to NPAPI.'); |
64 that.npapiHost_ = createPluginCallback(); | 68 that.npapiHost_ = createPluginCallback(); |
65 // TODO(weitaosu): is there a better way to check whether NPAPI plugin is | 69 // TODO(weitaosu): is there a better way to check whether NPAPI plugin is |
66 // supported? | 70 // supported? |
67 if (that.npapiHost_.hasOwnProperty('REQUESTED_ACCESS_CODE')) { | 71 if (that.npapiHost_.hasOwnProperty('REQUESTED_ACCESS_CODE')) { |
68 that.npapiHost_.xmppServerAddress = xmppServerAddress; | 72 that.npapiHost_.xmppServerAddress = xmppServerAddress; |
69 that.npapiHost_.xmppServerUseTls = xmppServerUseTls; | 73 that.npapiHost_.xmppServerUseTls = xmppServerUseTls; |
70 that.npapiHost_.directoryBotJid = directoryBotJid; | 74 that.npapiHost_.directoryBotJid = directoryBotJid; |
71 that.npapiHost_.onStateChanged = onStateChanged; | 75 that.npapiHost_.onStateChanged = onStateChanged; |
72 that.npapiHost_.onNatTraversalPolicyChanged = onNatTraversalPolicyChanged; | 76 that.npapiHost_.onNatTraversalPolicyChanged = onNatPolicyChanged; |
73 that.npapiHost_.logDebugInfo = logDebugInfo; | 77 that.npapiHost_.logDebugInfo = logDebugInfo; |
74 that.npapiHost_.localize(chrome.i18n.getMessage); | 78 that.npapiHost_.localize(chrome.i18n.getMessage); |
75 that.npapiHost_.connect(email, authServiceWithToken); | 79 that.npapiHost_.connect(email, authServiceWithToken); |
76 } else { | 80 } else { |
77 onError(); | 81 onError(); |
78 } | 82 } |
79 } | 83 } |
80 | 84 |
81 this.nativeMessagingHost_.initialize( | 85 this.nativeMessagingHost_.initialize( |
82 onNativeMessagingStarted, onNativeMessagingFailed, onError); | 86 onNativeMessagingStarted, onNativeMessagingFailed, onError); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 }; | 131 }; |
128 | 132 |
129 /** | 133 /** |
130 * @return {void} | 134 * @return {void} |
131 */ | 135 */ |
132 remoting.HostIt2MeDispatcher.prototype.cleanup = function() { | 136 remoting.HostIt2MeDispatcher.prototype.cleanup = function() { |
133 if (this.npapiHost_) { | 137 if (this.npapiHost_) { |
134 this.npapiHost_.parentNode.removeChild(this.npapiHost_); | 138 this.npapiHost_.parentNode.removeChild(this.npapiHost_); |
135 } | 139 } |
136 }; | 140 }; |
OLD | NEW |