michael@0: michael@0: var Cc = Components.classes; michael@0: var Ci = Components.interfaces; michael@0: var Cu = Components.utils; michael@0: michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: function loadIntoWindow(window) {} michael@0: function unloadFromWindow(window) {} michael@0: michael@0: function _sendMessageToJava (aMsg) { michael@0: return Services.androidBridge.handleGeckoMessage(aMsg); michael@0: }; michael@0: michael@0: /* michael@0: bootstrap.js API michael@0: */ michael@0: var windowListener = { michael@0: onOpenWindow: function(aWindow) { michael@0: // Wait for the window to finish loading michael@0: let domWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow); michael@0: domWindow.addEventListener("load", function() { michael@0: domWindow.removeEventListener("load", arguments.callee, false); michael@0: if (domWindow) { michael@0: domWindow.addEventListener("scroll", function(e) { michael@0: let message = { michael@0: type: 'robocop:scroll', michael@0: y: XPCNativeWrapper.unwrap(e.target).documentElement.scrollTop, michael@0: height: XPCNativeWrapper.unwrap(e.target).documentElement.scrollHeight, michael@0: cheight: XPCNativeWrapper.unwrap(e.target).documentElement.clientHeight, michael@0: }; michael@0: let retVal = _sendMessageToJava(message); michael@0: }); michael@0: } michael@0: }, false); michael@0: }, michael@0: onCloseWindow: function(aWindow) { }, michael@0: onWindowTitleChange: function(aWindow, aTitle) { } michael@0: }; michael@0: michael@0: function startup(aData, aReason) { michael@0: let wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator); michael@0: michael@0: // Load into any new windows michael@0: wm.addListener(windowListener); michael@0: Services.obs.addObserver(function observe(aSubject, aTopic, aData) { michael@0: dump("Robocop:Quit received -- requesting quit"); michael@0: let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup); michael@0: appStartup.quit(Ci.nsIAppStartup.eForceQuit); michael@0: }, "Robocop:Quit", false); michael@0: } michael@0: michael@0: function shutdown(aData, aReason) { michael@0: // When the application is shutting down we normally don't have to clean up any UI changes michael@0: if (aReason == APP_SHUTDOWN) return; michael@0: michael@0: let wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator); michael@0: michael@0: // Stop watching for new windows michael@0: wm.removeListener(windowListener); michael@0: } michael@0: michael@0: function install(aData, aReason) { } michael@0: function uninstall(aData, aReason) { } michael@0: