blob: 41aa8ab59e9c450aa1bd2c4e0d9725e54ef452ff [file] [log] [blame]
Jeff Thompsond51cb582013-03-17 19:00:39 -07001/*
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 Thompson02b9f4d2012-11-29 14:40:57 -08007Components.utils.import("chrome://modules/content/ndn-js.jsm");
Jeff Thompson6ad5c362012-12-27 17:57:02 -08008Components.utils.import("chrome://modules/content/NdnProtocolInfo.jsm");
Jeff Thompson02b9f4d2012-11-29 14:40:57 -08009
Jeff Thompson30779812013-02-04 23:59:45 -080010function ndnToolbarGetVersion(selector) {
Jeff Thompsond51cb582013-03-17 19:00:39 -070011 NdnProtocolInfo.getVersion(selector, window, alert);
Jeff Thompson02b9f4d2012-11-29 14:40:57 -080012}
Jeff Thompson6ad5c362012-12-27 17:57:02 -080013
14/*
15 * This is called when the connected NDN hub changes.
16 */
17function onNdnHubChanged(host, port) {
Jeff Thompsond51cb582013-03-17 19:00:39 -070018 document.getElementById("ndnHubLabel").setAttribute("value", "Hub: " + host + ":" + port);
Jeff Thompson6ad5c362012-12-27 17:57:02 -080019}
20
Jeff Thompsond51cb582013-03-17 19:00:39 -070021if (window)
22 window.addEventListener("load", function() { NdnProtocolInfo.addNdnHubChangedListener(onNdnHubChanged); },
23 false);
Jeff Thompsoneec72672013-03-10 16:45:47 -070024
25function 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}