const Cc = Components.classes; const Ci = Components.interfaces; var service = Cc["@skrul.com/threaddemo-service;1"] .createInstance(Ci.tdIService); var asynchServiceProxy = null; function toJavaScriptConsole() { toOpenWindowByType("global:console", "chrome://global/content/console.xul"); } function toOpenWindowByType(inType, uri, features) { var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(); var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator); var topWindow = windowManagerInterface.getMostRecentWindow(inType); if (topWindow) topWindow.focus(); else if (features) window.open(uri, "_blank", features); else window.open(uri, "_blank", "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar"); } function doOnLoad() { var l = document.getElementById("ui-thread"); var thread = Cc["@mozilla.org/thread;1"] .createInstance(Ci.nsIThread).currentThread; l.value = new String(thread); } function doSimpleBackgroundThread() { service.simpleBackgroundThread(); } function doProxyCallback() { var callback = new Callback("proxy-callback-results"); service.proxyToUiThread(callback); } function doAsynchServiceStart() { var asynchServiceCallback = new Callback("asynch-service-results"); asynchServiceProxy = service.startAsynchService(asynchServiceCallback); } function doAsynchServiceStop() { if(asynchServiceProxy) { asynchServiceProxy.stop(); asynchServiceProxy = null; } } function doAsynchServiceMethodOne() { if(asynchServiceProxy) { asynchServiceProxy.methodOne(); } } function doAsynchServiceMethodTwo() { if(asynchServiceProxy) { asynchServiceProxy.methodTwo(); } } function clearListbox(listboxId) { var lb = document.getElementById(listboxId); while(lb.getRowCount() > 0) { lb.removeItemAt(0); } } // This callback is used for all UI notifications function Callback(listboxId) { this.listboxId = listboxId; } // nsISupports Callback.prototype.QueryInterface = function(aIID) { if(!aIID.equals(Ci.nsISupports) && !aIID.equals(Ci.tdICallback) && !aIID.equals(Ci.nsIClassInfo)) throw Components.results.NS_ERROR_NO_INTERFACE; return this; } // tdICallback Callback.prototype.notify = function(param) { var lb = document.getElementById(this.listboxId); var item = lb.appendItem(param); lb.ensureElementIsVisible(item); } // nsIClassInfo Callback.prototype.getInterfaces = function(count) { var ifaces = [ Ci.nsISupports, Ci.tdICallback, Ci.nsIClassInfo ]; count.value = ifaces.length; return ifaces; } Callback.prototype.getHelperForLanguage = function(language) { return null; } Callback.prototype.contractID = null; Callback.prototype.classDescription = "Callback"; Callback.prototype.classID = null; Callback.prototype.implementationLanguage = Ci.nsIProgrammingLanguage.JAVASCRIPT; Callback.prototype.flags = 0;