In NdnProtocolInfo.jsm, put all functions in the NdnProtocolInfo class instead of being global.
diff --git a/js/ndnProtocol/components/ndnProtocolService.js b/js/ndnProtocol/components/ndnProtocolService.js
index ad9bfac..a6f7f01 100644
--- a/js/ndnProtocol/components/ndnProtocolService.js
+++ b/js/ndnProtocol/components/ndnProtocolService.js
@@ -32,13 +32,13 @@
var uri = Cc["@mozilla.org/network/simple-uri;1"].createInstance(Ci.nsIURI);
// We have to trim now because nsIURI converts spaces to %20 and we can't trim in newChannel.
- var uriParts = splitUri(aSpec);
+ var uriParts = NdnProtocolInfo.splitUri(aSpec);
if (aBaseURI == null || uriParts.name.length < 1 || uriParts.name[0] == '/')
// Just reconstruct the trimmed URI.
uri.spec = "ndn:" + uriParts.name + uriParts.search + uriParts.hash;
else {
// Make a URI relative to the base name up to the file name component.
- var baseUriParts = splitUri(aBaseURI.spec);
+ var baseUriParts = NdnProtocolInfo.splitUri(aBaseURI.spec);
var baseName = new Name(baseUriParts.name);
var iFileName = baseName.indexOfFileName();
@@ -70,7 +70,7 @@
var thisNdnProtocol = this;
try {
- var uriParts = splitUri(aURI.spec);
+ var uriParts = NdnProtocolInfo.splitUri(aURI.spec);
var template = new Interest(new Name([]));
// Use the same default as NDN.expressInterest.
@@ -153,7 +153,7 @@
}
// Now that we're connected, report the host and port.
- setConnectedNdnHub(this.ndn.host, this.ndn.port);
+ NdnProtocolInfo.setConnectedNdnHub(this.ndn.host, this.ndn.port);
// If !this.uriEndsWithSegmentNumber, we use the segmentNumber to load multiple segments.
var segmentNumber = null;
diff --git a/js/ndnProtocol/content/ndnToolbar.js b/js/ndnProtocol/content/ndnToolbar.js
index 129913a..0c34fb2 100644
--- a/js/ndnProtocol/content/ndnToolbar.js
+++ b/js/ndnProtocol/content/ndnToolbar.js
@@ -8,7 +8,7 @@
}
// Parse the same as in ndnProtocolService newChannel.
- var uriParts = splitUri(window._content.document.location.href);
+ var uriParts = NdnProtocolInfo.splitUri(window._content.document.location.href);
var name = new Name(uriParts.name);
var indexOfVersion = getIndexOfVersion(name);
if (indexOfVersion < 0) {
@@ -43,4 +43,4 @@
document.getElementById("ndnHubLabel").setAttribute("value", "Hub: " + host + ":" + port);
}
-window.addEventListener("load", function() { addNdnHubChangedListener(onNdnHubChanged); }, false);
+window.addEventListener("load", function() { NdnProtocolInfo.addNdnHubChangedListener(onNdnHubChanged); }, false);
diff --git a/js/ndnProtocol/modules/NdnProtocolInfo.jsm b/js/ndnProtocol/modules/NdnProtocolInfo.jsm
index bf8bf55..3a5fc79 100644
--- a/js/ndnProtocol/modules/NdnProtocolInfo.jsm
+++ b/js/ndnProtocol/modules/NdnProtocolInfo.jsm
@@ -3,7 +3,7 @@
* See COPYING for copyright and distribution information.
*/
-var EXPORTED_SYMBOLS = ["addNdnHubChangedListener", "setConnectedNdnHub", "splitUri"];
+var EXPORTED_SYMBOLS = ["NdnProtocolInfo"];
const Cc = Components.classes;
const Ci = Components.interfaces;
@@ -11,20 +11,23 @@
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
-var ndnHubHost = null;
-var ndnHubPort = null;
-var ndnHubChangedListenerList = [];
+var NdnProtocolInfo = function NdnProtocolInfo(){
+};
+
+NdnProtocolInfo.ndnHubHost = null;
+NdnProtocolInfo.ndnHubPort = null;
+NdnProtocolInfo.ndnHubChangedListenerList = [];
/*
* When the NDN hub host or port is changed, the system calls listener(host, port).
* If the current host and port are not null, call listener with the values to initialize.
*/
-function addNdnHubChangedListener(listener) {
- ndnHubChangedListenerList.push(listener);
+NdnProtocolInfo.addNdnHubChangedListener = function(listener) {
+ NdnProtocolInfo.ndnHubChangedListenerList.push(listener);
- if (ndnHubHost != null && ndnHubPort != null) {
+ if (NdnProtocolInfo.ndnHubHost != null && NdnProtocolInfo.ndnHubPort != null) {
try {
- listener(ndnHubHost, ndnHubPort);
+ listener(NdnProtocolInfo.ndnHubHost, NdnProtocolInfo.ndnHubPort);
}
catch (ex) {
// Ignore error from the listener.
@@ -36,16 +39,16 @@
* If host and port are different than ndnHubHost or ndnHubPort, set them and call each
* listener in ndnHubChangedListenerList.
*/
-function setConnectedNdnHub(host, port) {
- if (host == ndnHubHost && port == ndnHubPort)
+NdnProtocolInfo.setConnectedNdnHub = function(host, port) {
+ if (host == NdnProtocolInfo.ndnHubHost && port == NdnProtocolInfo.ndnHubPort)
// No change.
return;
- ndnHubHost = host;
- ndnHubPort = port;
- for (var i = 0; i < ndnHubChangedListenerList.length; ++i) {
+ NdnProtocolInfo.ndnHubHost = host;
+ NdnProtocolInfo.ndnHubPort = port;
+ for (var i = 0; i < NdnProtocolInfo.ndnHubChangedListenerList.length; ++i) {
try {
- ndnHubChangedListenerList[i](host, port);
+ NdnProtocolInfo.ndnHubChangedListenerList[i](host, port);
}
catch (ex) {
// Ignore error from the listener.
@@ -59,7 +62,7 @@
* All result strings are trimmed. This does not unescape the name.
* The name may include a host and port.
*/
-function splitUri(spec) {
+NdnProtocolInfo.splitUri = function(spec) {
spec = spec.trim();
var result = {};
var preHash = spec.split('#', 1)[0];
@@ -79,4 +82,4 @@
}
return result;
-}
\ No newline at end of file
+}