1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/testing/mochitest/roboextender/bootstrap.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,65 @@ 1.4 + 1.5 +var Cc = Components.classes; 1.6 +var Ci = Components.interfaces; 1.7 +var Cu = Components.utils; 1.8 + 1.9 +Cu.import("resource://gre/modules/Services.jsm"); 1.10 + 1.11 +function loadIntoWindow(window) {} 1.12 +function unloadFromWindow(window) {} 1.13 + 1.14 +function _sendMessageToJava (aMsg) { 1.15 + return Services.androidBridge.handleGeckoMessage(aMsg); 1.16 +}; 1.17 + 1.18 +/* 1.19 + bootstrap.js API 1.20 +*/ 1.21 +var windowListener = { 1.22 + onOpenWindow: function(aWindow) { 1.23 + // Wait for the window to finish loading 1.24 + let domWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow); 1.25 + domWindow.addEventListener("load", function() { 1.26 + domWindow.removeEventListener("load", arguments.callee, false); 1.27 + if (domWindow) { 1.28 + domWindow.addEventListener("scroll", function(e) { 1.29 + let message = { 1.30 + type: 'robocop:scroll', 1.31 + y: XPCNativeWrapper.unwrap(e.target).documentElement.scrollTop, 1.32 + height: XPCNativeWrapper.unwrap(e.target).documentElement.scrollHeight, 1.33 + cheight: XPCNativeWrapper.unwrap(e.target).documentElement.clientHeight, 1.34 + }; 1.35 + let retVal = _sendMessageToJava(message); 1.36 + }); 1.37 + } 1.38 + }, false); 1.39 + }, 1.40 + onCloseWindow: function(aWindow) { }, 1.41 + onWindowTitleChange: function(aWindow, aTitle) { } 1.42 +}; 1.43 + 1.44 +function startup(aData, aReason) { 1.45 + let wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator); 1.46 + 1.47 + // Load into any new windows 1.48 + wm.addListener(windowListener); 1.49 + Services.obs.addObserver(function observe(aSubject, aTopic, aData) { 1.50 + dump("Robocop:Quit received -- requesting quit"); 1.51 + let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup); 1.52 + appStartup.quit(Ci.nsIAppStartup.eForceQuit); 1.53 + }, "Robocop:Quit", false); 1.54 +} 1.55 + 1.56 +function shutdown(aData, aReason) { 1.57 + // When the application is shutting down we normally don't have to clean up any UI changes 1.58 + if (aReason == APP_SHUTDOWN) return; 1.59 + 1.60 + let wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator); 1.61 + 1.62 + // Stop watching for new windows 1.63 + wm.removeListener(windowListener); 1.64 +} 1.65 + 1.66 +function install(aData, aReason) { } 1.67 +function uninstall(aData, aReason) { } 1.68 +