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 | 8 * NativeMessaging Host or the Host NPAPI plugin, depending on whether |
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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 case remoting.HostDispatcher.State.NATIVE_MESSAGING: | 121 case remoting.HostDispatcher.State.NATIVE_MESSAGING: |
122 this.nativeMessagingHost_.generateKeyPair(callback); | 122 this.nativeMessagingHost_.generateKeyPair(callback); |
123 break; | 123 break; |
124 case remoting.HostDispatcher.State.NPAPI: | 124 case remoting.HostDispatcher.State.NPAPI: |
125 this.npapiHost_.generateKeyPair(callback); | 125 this.npapiHost_.generateKeyPair(callback); |
126 break; | 126 break; |
127 } | 127 } |
128 }; | 128 }; |
129 | 129 |
130 /** | 130 /** |
131 * @param {string} config | 131 * @param {Object} config |
132 * @param {function(remoting.HostController.AsyncResult):void} callback | 132 * @param {function(remoting.HostController.AsyncResult):void} callback |
133 * @return {void} | 133 * @return {void} |
134 */ | 134 */ |
135 remoting.HostDispatcher.prototype.updateDaemonConfig = function(config, | 135 remoting.HostDispatcher.prototype.updateDaemonConfig = function(config, |
136 callback) { | 136 callback) { |
137 switch (this.state_) { | 137 switch (this.state_) { |
138 case remoting.HostDispatcher.State.UNKNOWN: | 138 case remoting.HostDispatcher.State.UNKNOWN: |
139 this.pendingRequests_.push(this.updateDaemonConfig.bind(this, callback)); | 139 this.pendingRequests_.push(this.updateDaemonConfig.bind(this, callback)); |
140 break; | 140 break; |
141 case remoting.HostDispatcher.State.NATIVE_MESSAGING: | 141 case remoting.HostDispatcher.State.NATIVE_MESSAGING: |
142 this.nativeMessagingHost_.updateDaemonConfig(config, callback); | 142 this.nativeMessagingHost_.updateDaemonConfig(config, callback); |
143 break; | 143 break; |
144 case remoting.HostDispatcher.State.NPAPI: | 144 case remoting.HostDispatcher.State.NPAPI: |
145 this.npapiHost_.updateDaemonConfig(config, callback); | 145 this.npapiHost_.updateDaemonConfig(JSON.stringify(config), callback); |
146 break; | 146 break; |
147 } | 147 } |
148 | |
149 }; | 148 }; |
150 | 149 |
151 /** | 150 /** |
152 * @param {function(string):void} callback | 151 * @param {function(Object):void} callback |
153 * @return {void} | 152 * @return {void} |
154 */ | 153 */ |
155 remoting.HostDispatcher.prototype.getDaemonConfig = function(callback) { | 154 remoting.HostDispatcher.prototype.getDaemonConfig = function(callback) { |
155 /** | |
156 * Converts the config string from the NPAPI plugin to an Object, to pass to | |
157 * |callback|. | |
158 * @param {string} configStr | |
159 * @return {void} | |
160 */ | |
161 function callbackForNpapi(configStr) { | |
162 var config = null; | |
163 try { | |
164 config = JSON.parse(configStr); | |
165 } catch (err) { | |
166 // TODO(lambroslambrou): Call error handler here when that's implemented. | |
167 } | |
168 if (typeof(config) != 'object') { | |
169 config = null; | |
Jamie
2013/05/22 00:54:21
Would this also be an error? If so, please move th
Lambros
2013/05/23 00:22:48
Done.
| |
170 } | |
171 callback(/** @type {Object} */ (config)); | |
172 } | |
173 | |
156 switch (this.state_) { | 174 switch (this.state_) { |
157 case remoting.HostDispatcher.State.UNKNOWN: | 175 case remoting.HostDispatcher.State.UNKNOWN: |
158 this.pendingRequests_.push(this.getDaemonConfig.bind(this, callback)); | 176 this.pendingRequests_.push(this.getDaemonConfig.bind(this, callback)); |
159 break; | 177 break; |
160 case remoting.HostDispatcher.State.NATIVE_MESSAGING: | 178 case remoting.HostDispatcher.State.NATIVE_MESSAGING: |
161 this.nativeMessagingHost_.getDaemonConfig(callback); | 179 this.nativeMessagingHost_.getDaemonConfig(callback); |
162 break; | 180 break; |
163 case remoting.HostDispatcher.State.NPAPI: | 181 case remoting.HostDispatcher.State.NPAPI: |
164 this.npapiHost_.getDaemonConfig(callback); | 182 this.npapiHost_.getDaemonConfig(callbackForNpapi); |
165 break; | 183 break; |
166 } | 184 } |
167 }; | 185 }; |
168 | 186 |
169 /** | 187 /** |
170 * @param {function(string):void} callback | 188 * @param {function(string):void} callback |
171 * @return {void} | 189 * @return {void} |
172 */ | 190 */ |
173 remoting.HostDispatcher.prototype.getDaemonVersion = function(callback) { | 191 remoting.HostDispatcher.prototype.getDaemonVersion = function(callback) { |
174 switch (this.state_) { | 192 switch (this.state_) { |
(...skipping 22 matching lines...) Expand all Loading... | |
197 case remoting.HostDispatcher.State.NATIVE_MESSAGING: | 215 case remoting.HostDispatcher.State.NATIVE_MESSAGING: |
198 this.nativeMessagingHost_.getUsageStatsConsent(callback); | 216 this.nativeMessagingHost_.getUsageStatsConsent(callback); |
199 break; | 217 break; |
200 case remoting.HostDispatcher.State.NPAPI: | 218 case remoting.HostDispatcher.State.NPAPI: |
201 this.npapiHost_.getUsageStatsConsent(callback); | 219 this.npapiHost_.getUsageStatsConsent(callback); |
202 break; | 220 break; |
203 } | 221 } |
204 }; | 222 }; |
205 | 223 |
206 /** | 224 /** |
207 * @param {string} config | 225 * @param {Object} config |
208 * @param {boolean} consent | 226 * @param {boolean} consent |
209 * @param {function(remoting.HostController.AsyncResult):void} callback | 227 * @param {function(remoting.HostController.AsyncResult):void} callback |
210 * @return {void} | 228 * @return {void} |
211 */ | 229 */ |
212 remoting.HostDispatcher.prototype.startDaemon = function(config, consent, | 230 remoting.HostDispatcher.prototype.startDaemon = function(config, consent, |
213 callback) { | 231 callback) { |
214 switch (this.state_) { | 232 switch (this.state_) { |
215 case remoting.HostDispatcher.State.UNKNOWN: | 233 case remoting.HostDispatcher.State.UNKNOWN: |
216 this.pendingRequests_.push(this.startDaemon.bind(this, config, consent, | 234 this.pendingRequests_.push(this.startDaemon.bind(this, config, consent, |
217 callback)); | 235 callback)); |
218 break; | 236 break; |
219 case remoting.HostDispatcher.State.NATIVE_MESSAGING: | 237 case remoting.HostDispatcher.State.NATIVE_MESSAGING: |
220 this.nativeMessagingHost_.startDaemon(config, consent, callback); | 238 this.nativeMessagingHost_.startDaemon(config, consent, callback); |
221 break; | 239 break; |
222 case remoting.HostDispatcher.State.NPAPI: | 240 case remoting.HostDispatcher.State.NPAPI: |
223 this.npapiHost_.startDaemon(config, consent, callback); | 241 this.npapiHost_.startDaemon(JSON.stringify(config), consent, callback); |
224 break; | 242 break; |
225 } | 243 } |
226 }; | 244 }; |
227 | 245 |
228 /** | 246 /** |
229 * @param {function(remoting.HostController.AsyncResult):void} callback | 247 * @param {function(remoting.HostController.AsyncResult):void} callback |
230 * @return {void} | 248 * @return {void} |
231 */ | 249 */ |
232 remoting.HostDispatcher.prototype.stopDaemon = function(callback) { | 250 remoting.HostDispatcher.prototype.stopDaemon = function(callback) { |
233 switch (this.state_) { | 251 switch (this.state_) { |
(...skipping 27 matching lines...) Expand all Loading... | |
261 var state = this.npapiHost_.daemonState; | 279 var state = this.npapiHost_.daemonState; |
262 if (state === undefined) { | 280 if (state === undefined) { |
263 // If the plug-in can't be instantiated, for example on ChromeOS, then | 281 // If the plug-in can't be instantiated, for example on ChromeOS, then |
264 // return something sensible. | 282 // return something sensible. |
265 state = remoting.HostController.State.NOT_IMPLEMENTED; | 283 state = remoting.HostController.State.NOT_IMPLEMENTED; |
266 } | 284 } |
267 callback(state); | 285 callback(state); |
268 break; | 286 break; |
269 } | 287 } |
270 } | 288 } |
OLD | NEW |