Jeff Thompson | d51cb58 | 2013-03-17 19:00:39 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * @author: Jeff Thompson |
| 3 | * See COPYING for copyright and distribution information. |
| 4 | * This is called from the NDN toolbar and the doorhanger popup on Firefox for Android. |
| 5 | */ |
| 6 | |
Jeff Thompson | 02b9f4d | 2012-11-29 14:40:57 -0800 | [diff] [blame] | 7 | Components.utils.import("chrome://modules/content/ndn-js.jsm"); |
Jeff Thompson | 6ad5c36 | 2012-12-27 17:57:02 -0800 | [diff] [blame] | 8 | Components.utils.import("chrome://modules/content/NdnProtocolInfo.jsm"); |
Jeff Thompson | 02b9f4d | 2012-11-29 14:40:57 -0800 | [diff] [blame] | 9 | |
Jeff Thompson | 3077981 | 2013-02-04 23:59:45 -0800 | [diff] [blame] | 10 | function ndnToolbarGetVersion(selector) { |
Jeff Thompson | d51cb58 | 2013-03-17 19:00:39 -0700 | [diff] [blame^] | 11 | NdnProtocolInfo.getVersion(selector, window, alert); |
Jeff Thompson | 02b9f4d | 2012-11-29 14:40:57 -0800 | [diff] [blame] | 12 | } |
Jeff Thompson | 6ad5c36 | 2012-12-27 17:57:02 -0800 | [diff] [blame] | 13 | |
| 14 | /* |
| 15 | * This is called when the connected NDN hub changes. |
| 16 | */ |
| 17 | function onNdnHubChanged(host, port) { |
Jeff Thompson | d51cb58 | 2013-03-17 19:00:39 -0700 | [diff] [blame^] | 18 | document.getElementById("ndnHubLabel").setAttribute("value", "Hub: " + host + ":" + port); |
Jeff Thompson | 6ad5c36 | 2012-12-27 17:57:02 -0800 | [diff] [blame] | 19 | } |
| 20 | |
Jeff Thompson | d51cb58 | 2013-03-17 19:00:39 -0700 | [diff] [blame^] | 21 | if (window) |
| 22 | window.addEventListener("load", function() { NdnProtocolInfo.addNdnHubChangedListener(onNdnHubChanged); }, |
| 23 | false); |
Jeff Thompson | eec7267 | 2013-03-10 16:45:47 -0700 | [diff] [blame] | 24 | |
| 25 | function ndnToolbarSetHub() { |
| 26 | var host = prompt("Enter hub host:", NdnProtocolInfo.ndn.host); |
| 27 | if (!host) |
| 28 | return; |
| 29 | |
| 30 | host = host.trim(); |
| 31 | if (host == "") |
| 32 | return; |
| 33 | if (host == NdnProtocolInfo.ndn.host) |
| 34 | // No change. |
| 35 | return; |
| 36 | |
| 37 | var port = 9695; |
| 38 | NdnProtocolInfo.ndn.createRoute(host, port); |
| 39 | document.getElementById("ndnHubLabel").setAttribute("value", "Hub: trying " + host + ":" + port); |
| 40 | |
| 41 | if (window._content.document.location.protocol == "ndn:") |
| 42 | // Reload with the new hub. |
| 43 | window._content.document.location = window._content.document.location.href; |
| 44 | } |