OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 that wraps low-level details of interacting with the client plugin. | 7 * Class that wraps low-level details of interacting with the client plugin. |
8 * | 8 * |
9 * This abstracts a <embed> element and controls the plugin which does | 9 * This abstracts a <embed> element and controls the plugin which does |
10 * the actual remoting work. It also handles differences between | 10 * the actual remoting work. It also handles differences between |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 var scope = /** @type {string} */ message.data['scope']; | 306 var scope = /** @type {string} */ message.data['scope']; |
307 this.fetchThirdPartyTokenHandler(tokenUrl, hostPublicKey, scope); | 307 this.fetchThirdPartyTokenHandler(tokenUrl, hostPublicKey, scope); |
308 } else if (message.method == 'pairingResponse') { | 308 } else if (message.method == 'pairingResponse') { |
309 var clientId = /** @type {string} */ message.data['clientId']; | 309 var clientId = /** @type {string} */ message.data['clientId']; |
310 var sharedSecret = /** @type {string} */ message.data['sharedSecret']; | 310 var sharedSecret = /** @type {string} */ message.data['sharedSecret']; |
311 if (typeof clientId != 'string' || typeof sharedSecret != 'string') { | 311 if (typeof clientId != 'string' || typeof sharedSecret != 'string') { |
312 console.error('Received incorrect pairingResponse message.'); | 312 console.error('Received incorrect pairingResponse message.'); |
313 return; | 313 return; |
314 } | 314 } |
315 this.onPairingComplete_(clientId, sharedSecret); | 315 this.onPairingComplete_(clientId, sharedSecret); |
| 316 } else if (message.method == 'extensionMessage') { |
| 317 // No messages currently supported. |
| 318 console.log('Unexpected message received: ' + |
| 319 message.data.type + ': ' + message.data.data); |
316 } | 320 } |
317 }; | 321 }; |
318 | 322 |
319 /** | 323 /** |
320 * Deletes the plugin. | 324 * Deletes the plugin. |
321 */ | 325 */ |
322 remoting.ClientPluginAsync.prototype.cleanup = function() { | 326 remoting.ClientPluginAsync.prototype.cleanup = function() { |
323 this.plugin.parentNode.removeChild(this.plugin); | 327 this.plugin.parentNode.removeChild(this.plugin); |
324 }; | 328 }; |
325 | 329 |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 function(clientName, onDone) { | 604 function(clientName, onDone) { |
601 if (!this.hasFeature(remoting.ClientPlugin.Feature.PINLESS_AUTH)) { | 605 if (!this.hasFeature(remoting.ClientPlugin.Feature.PINLESS_AUTH)) { |
602 return; | 606 return; |
603 } | 607 } |
604 this.onPairingComplete_ = onDone; | 608 this.onPairingComplete_ = onDone; |
605 this.plugin.postMessage(JSON.stringify( | 609 this.plugin.postMessage(JSON.stringify( |
606 { method: 'requestPairing', data: { clientName: clientName } })); | 610 { method: 'requestPairing', data: { clientName: clientName } })); |
607 }; | 611 }; |
608 | 612 |
609 /** | 613 /** |
| 614 * Send an extension message to the host. |
| 615 * |
| 616 * @param {string} type The message type. |
| 617 * @param {Object} message The message payload. |
| 618 */ |
| 619 remoting.ClientPluginAsync.prototype.sendClientMessage = |
| 620 function(type, message) { |
| 621 if (!this.hasFeature(remoting.ClientPlugin.Feature.EXTENSION_MESSAGE)) { |
| 622 return; |
| 623 } |
| 624 this.plugin.postMessage(JSON.stringify( |
| 625 { method: 'extensionMessage', |
| 626 data: { type: type, data: JSON.stringify(message) } })); |
| 627 |
| 628 }; |
| 629 |
| 630 /** |
610 * If we haven't yet received a "hello" message from the plugin, change its | 631 * If we haven't yet received a "hello" message from the plugin, change its |
611 * size so that the user can confirm it if click-to-play is enabled, or can | 632 * size so that the user can confirm it if click-to-play is enabled, or can |
612 * see the "this plugin is disabled" message if it is actually disabled. | 633 * see the "this plugin is disabled" message if it is actually disabled. |
613 * @private | 634 * @private |
614 */ | 635 */ |
615 remoting.ClientPluginAsync.prototype.showPluginForClickToPlay_ = function() { | 636 remoting.ClientPluginAsync.prototype.showPluginForClickToPlay_ = function() { |
616 if (!this.helloReceived_) { | 637 if (!this.helloReceived_) { |
617 var width = 200; | 638 var width = 200; |
618 var height = 200; | 639 var height = 200; |
619 this.plugin.width = width; | 640 this.plugin.width = width; |
620 this.plugin.height = height; | 641 this.plugin.height = height; |
621 // Center the plugin just underneath the "Connnecting..." dialog. | 642 // Center the plugin just underneath the "Connnecting..." dialog. |
622 var parentNode = this.plugin.parentNode; | 643 var parentNode = this.plugin.parentNode; |
623 var dialog = document.getElementById('client-dialog'); | 644 var dialog = document.getElementById('client-dialog'); |
624 var dialogRect = dialog.getBoundingClientRect(); | 645 var dialogRect = dialog.getBoundingClientRect(); |
625 parentNode.style.top = (dialogRect.bottom + 16) + 'px'; | 646 parentNode.style.top = (dialogRect.bottom + 16) + 'px'; |
626 parentNode.style.left = (window.innerWidth - width) / 2 + 'px'; | 647 parentNode.style.left = (window.innerWidth - width) / 2 + 'px'; |
627 } | 648 } |
628 }; | 649 }; |
OLD | NEW |