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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * Constructor for the Nacl bridge to the whispernet wrapper. | 8 * Constructor for the Nacl bridge to the whispernet wrapper. |
9 * @param {string} nmf The relative path to the nmf containing the location of | 9 * @param {string} nmf The relative path to the nmf containing the location of |
10 * the whispernet Nacl wrapper. | 10 * the whispernet Nacl wrapper. |
11 * @param {function()} readyCallback Callback to be called once we've loaded the | 11 * @param {function()} readyCallback Callback to be called once we've loaded the |
12 * whispernet wrapper. | 12 * whispernet wrapper. |
13 */ | 13 */ |
14 function NaclBridge(nmf, readyCallback) { | 14 function NaclBridge(nmf, readyCallback) { |
15 this.readyCallback_ = readyCallback; | 15 this.readyCallback_ = readyCallback; |
16 this.callbacks_ = []; | 16 this.callbacks_ = []; |
17 this.isEnabled_ = false; | 17 this.isEnabled_ = false; |
18 this.naclId_ = this.loadNacl_(nmf); | 18 this.naclId_ = this.loadNacl_(nmf); |
19 } | 19 } |
20 | 20 |
21 /** | 21 /** |
22 * Method to send generic byte data to the whispernet wrapper. | 22 * Method to send generic byte data to the whispernet wrapper. |
23 * @param {string} data Raw data to send to the whispernet wrapper. | 23 * @param {Object} data Raw data to send to the whispernet wrapper. |
24 */ | 24 */ |
25 NaclBridge.prototype.send = function(data) { | 25 NaclBridge.prototype.send = function(data) { |
26 if (this.isEnabled_) { | 26 if (this.isEnabled_) { |
27 this.embed_.postMessage(data); | 27 this.embed_.postMessage(data); |
28 } else { | 28 } else { |
29 console.error('Whisper Nacl Bridge not initialized!'); | 29 console.error('Whisper Nacl Bridge not initialized!'); |
30 } | 30 } |
31 }; | 31 }; |
32 | 32 |
33 /** | 33 /** |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 92 |
93 /** | 93 /** |
94 * Callback that handles Nacl errors. | 94 * Callback that handles Nacl errors. |
95 * @param {string} msg Error string. | 95 * @param {string} msg Error string. |
96 * @private | 96 * @private |
97 */ | 97 */ |
98 NaclBridge.prototype.onNaclError_ = function(msg) { | 98 NaclBridge.prototype.onNaclError_ = function(msg) { |
99 // TODO(rkc): Handle error from NaCl better. | 99 // TODO(rkc): Handle error from NaCl better. |
100 console.error('NaCl error', msg); | 100 console.error('NaCl error', msg); |
101 }; | 101 }; |
OLD | NEW |