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 * Class to communicate with the Host components via Native Messaging. | 7 * Class to communicate with the Host components via Native Messaging. |
8 */ | 8 */ |
9 | 9 |
10 'use strict'; | 10 'use strict'; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 * Sets up connection to the Native Messaging host process and exchanges | 58 * Sets up connection to the Native Messaging host process and exchanges |
59 * 'hello' messages. If Native Messaging is not available or the host | 59 * 'hello' messages. If Native Messaging is not available or the host |
60 * process is not installed, this returns false to the callback. | 60 * process is not installed, this returns false to the callback. |
61 * | 61 * |
62 * @param {function(): void} onDone Called after successful initialization. | 62 * @param {function(): void} onDone Called after successful initialization. |
63 * @param {function(remoting.Error): void} onError Called if initialization | 63 * @param {function(remoting.Error): void} onError Called if initialization |
64 * failed. | 64 * failed. |
65 * @return {void} Nothing. | 65 * @return {void} Nothing. |
66 */ | 66 */ |
67 remoting.HostNativeMessaging.prototype.initialize = function(onDone, onError) { | 67 remoting.HostNativeMessaging.prototype.initialize = function(onDone, onError) { |
68 if (!chrome.runtime.connectNative) { | 68 console.log("NM Init"); |
weitao
2014/01/31 18:37:11
I am about to commit a CL that remove this code an
Sergey Ulanov
2014/01/31 23:34:17
Done.
|
Jamie
2014/01/31 18:39:15
Are these logs needed? If so, they should be a bit
Sergey Ulanov
2014/01/31 23:34:17
Reverted the changes in this method, but the fix i
|
69 console.log('Native Messaging API not available'); | |
70 onError(remoting.Error.UNEXPECTED); | |
71 return; | |
72 } | |
73 | |
74 // NativeMessaging API exists on Chrome 26.xxx but fails to notify | |
75 // onDisconnect in the case where the Host components are not installed. Need | |
76 // to blacklist these versions of Chrome. | |
77 var majorVersion = navigator.appVersion.match('Chrome/(\\d+)\.')[1]; | |
78 if (!majorVersion || majorVersion <= 26) { | |
79 console.log('Native Messaging not supported on this version of Chrome'); | |
80 onError(remoting.Error.UNEXPECTED); | |
81 return; | |
82 } | |
83 | |
84 try { | 69 try { |
70 console.log("NM Init2 " + this.pendingReplies_); | |
71 this.pendingReplies_ = {}; | |
85 this.port_ = chrome.runtime.connectNative( | 72 this.port_ = chrome.runtime.connectNative( |
86 'com.google.chrome.remote_desktop'); | 73 'com.google.chrome.remote_desktop'); |
87 this.port_.onMessage.addListener(this.onIncomingMessage_.bind(this)); | 74 this.port_.onMessage.addListener(this.onIncomingMessage_.bind(this)); |
88 this.port_.onDisconnect.addListener(this.onDisconnect_.bind(this)); | 75 this.port_.onDisconnect.addListener(this.onDisconnect_.bind(this)); |
89 this.postMessage_({type: 'hello'}, onDone, | 76 this.postMessage_({type: 'hello'}, onDone, |
90 onError.bind(null, remoting.Error.UNEXPECTED)); | 77 onError.bind(null, remoting.Error.UNEXPECTED)); |
78 console.log("NM Init3"); | |
91 } catch (err) { | 79 } catch (err) { |
92 console.log('Native Messaging initialization failed: ', | 80 console.log('Native Messaging initialization failed: ', |
93 /** @type {*} */ (err)); | 81 /** @type {*} */ (err)); |
94 onError(remoting.Error.UNEXPECTED); | 82 onError(remoting.Error.UNEXPECTED); |
95 return; | 83 return; |
96 } | 84 } |
97 }; | 85 }; |
98 | 86 |
99 /** | 87 /** |
100 * Verifies that |object| is of type |type|, logging an error if not. | 88 * Verifies that |object| is of type |type|, logging an error if not. |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
374 }; | 362 }; |
375 | 363 |
376 /** | 364 /** |
377 * @return {void} Nothing. | 365 * @return {void} Nothing. |
378 * @private | 366 * @private |
379 */ | 367 */ |
380 remoting.HostNativeMessaging.prototype.onDisconnect_ = function() { | 368 remoting.HostNativeMessaging.prototype.onDisconnect_ = function() { |
381 console.error('Native Message port disconnected'); | 369 console.error('Native Message port disconnected'); |
382 | 370 |
383 // Notify the error-handlers of any requests that are still outstanding. | 371 // Notify the error-handlers of any requests that are still outstanding. |
384 for (var id in this.pendingReplies_) { | 372 var pendingReplies = this.pendingReplies_; |
385 this.pendingReplies_[/** @type {number} */(id)].onError( | 373 this.pendingReplies_ = {}; |
374 | |
375 for (var id in pendingReplies) { | |
376 pendingReplies[/** @type {number} */(id)].onError( | |
386 remoting.Error.UNEXPECTED); | 377 remoting.Error.UNEXPECTED); |
387 } | 378 } |
388 this.pendingReplies_ = {}; | |
389 } | 379 } |
390 | 380 |
391 /** | 381 /** |
392 * @param {function(string):void} onDone Callback to be called with the | 382 * @param {function(string):void} onDone Callback to be called with the |
393 * local hostname. | 383 * local hostname. |
394 * @param {function(remoting.Error):void} onError The callback to be triggered | 384 * @param {function(remoting.Error):void} onError The callback to be triggered |
395 * on error. | 385 * on error. |
396 * @return {void} Nothing. | 386 * @return {void} Nothing. |
397 */ | 387 */ |
398 remoting.HostNativeMessaging.prototype.getHostName = | 388 remoting.HostNativeMessaging.prototype.getHostName = |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
605 * on error. | 595 * on error. |
606 * @return {void} Nothing. | 596 * @return {void} Nothing. |
607 */ | 597 */ |
608 remoting.HostNativeMessaging.prototype.getCredentialsFromAuthCode = | 598 remoting.HostNativeMessaging.prototype.getCredentialsFromAuthCode = |
609 function(authorizationCode, onDone, onError) { | 599 function(authorizationCode, onDone, onError) { |
610 this.postMessage_({ | 600 this.postMessage_({ |
611 type: 'getCredentialsFromAuthCode', | 601 type: 'getCredentialsFromAuthCode', |
612 authorizationCode: authorizationCode | 602 authorizationCode: authorizationCode |
613 }, onDone, onError); | 603 }, onDone, onError); |
614 }; | 604 }; |
OLD | NEW |