diff --git a/mozmill/extension/resource/modules/inspection.js b/mozmill/extension/resource/modules/inspection.js index 2283baf2..c79e5fa3 100644 --- a/mozmill/extension/resource/modules/inspection.js +++ b/mozmill/extension/resource/modules/inspection.js @@ -39,6 +39,7 @@ var EXPORTED_SYMBOLS = ["inspectElement"] var elementslib = {}; Components.utils.import('resource://mozmill/modules/elementslib.js', elementslib); var mozmill = {}; Components.utils.import('resource://mozmill/modules/mozmill.js', mozmill); +var utils = {}; Components.utils.import('resource://mozmill/modules/utils.js', utils); var arrays = {}; Components.utils.import('resource://mozmill/stdlib/arrays.js', arrays); var dom = {}; Components.utils.import('resource://mozmill/stdlib/dom.js', dom); @@ -145,6 +146,10 @@ var getDocument = function (elem) { return elem; } +var getTopWindow = function(doc) { + return utils.getChromeWindow(doc.defaultView); +} + var attributeToIgnore = ['focus', 'focused', 'selected', 'select', 'flex', // General Omissions 'linkedpanel', 'last-tab', 'afterselected', // From Tabs UI, thanks Farhad 'style', // Gets set dynamically all the time, also effected by dx display code @@ -262,57 +267,45 @@ var copyToClipboard = function(str){ gClipboardHelper.copyString(str); } -var getControllerAndDocument = function (_document, windowtype) { - if (windowtype == null || windowtype == 'navigator:browser') { - var c = mozmill.getBrowserController(); - if (c.tabs.activeTab == _document) { - return {'controllerString':'mozmill.getBrowserController()', - 'documentString' :'controller.tabs.activeTab',} - } - } - var controllerString = null; - var documentString = null; - var w = null; - - if (windowtype == null || windowtype == '') { - var windowtype = wm.getMostRecentWindow('').document.documentElement.getAttribute('windowtype'); - } - +var getControllerAndDocument = function (_document, _window) { + var windowtype = _window.document.documentElement.getAttribute('windowtype'); + var controllerString, documentString; + // TODO replace with object based cases - if (windowtype == 'navigator:browser') { - var w = wm.getMostRecentWindow('navigator:browser'); - controllerString = 'mozmill.getBrowserController()' - } else if (windowtype == 'Browser:Preferences') { - var w = wm.getMostRecentWindow('Browser:Preferences'); - controllerString = 'mozmill.getPreferencesController()' - } else if (windowtype == 'Extension:Manager') { - var w = wm.getMostRecentWindow('Extension:Manager'); - controllerString = 'mozmill.getAddonsController()' - } - - if (!w) { - if (windowtype == null) { - var windowtype = ''; - } - w = wm.getMostRecentWindow(windowtype); - controllerString = 'new mozmill.controller.MozMillController(mozmill.utils.getWindowByTitle("'+w.document.title+'"))'; + switch(windowtype) { + case 'navigator:browser': + controllerString = 'mozmill.getBrowserController()'; + var activeTab = mozmill.getBrowserController().tabs.activeTab; + break; + case 'Browser:Preferences': + controllerString = 'mozmill.getPreferencesController()'; + break; + case 'Extension:Manager': + controllerString = 'mozmill.getAddonsController()'; + break; + default: + if(windowtype) + controllerString = 'new mozmill.controller.MozMillController(mozmill.utils.getWindowByType("' + windowtype + '"))'; + else if(_window.document.title) + controllerString = 'new mozmill.controller.MozMillController(mozmill.utils.getWindowByTitle("'+_window.document.title+'"))'; + else + controllerString = 'Cannot find window'; + break; } - - if(windowtype == 'navigator:browser' && c.tabs.activeTab == _document.defaultView.top.document) { + + if(activeTab == _document) { + documentString = 'controller.tabs.activeTab'; + } else if(activeTab == _document.defaultView.top.document) { // if this document is from an iframe in the active tab - var stub = getDocumentStub(_document, c.tabs.activeTab.defaultView); - var windowString = 'controller.tabs.activeTab.defaultView'; - } - else { - var stub = getDocumentStub(_document, w); - var windowString = 'controller.window'; + var stub = getDocumentStub(_document, activeTab.defaultView); + documentString = 'controller.tabs.activeTab.defaultView' + stub; + } else { + var stub = getDocumentStub(_document, _window); + if(stub) + documentString = 'controller.window' + stub; + else + documentString = 'Cannot find document'; } - if(stub) - documentString = windowString + stub; - else if (controllerString == 'mozmill.getBrowserController()') - documentString = 'controller.tabs.activeTab'; - else - documentString = 'Cannot find document'; return {'controllerString':controllerString, 'documentString':documentString} } @@ -351,7 +344,8 @@ var inspectElement = function(e){ } var windowtype = _document.documentElement.getAttribute('windowtype'); - r = getControllerAndDocument(_document, windowtype); + var _window = getTopWindow(_document); + r = getControllerAndDocument(_document, _window); // displayText = "Controller: " + r.controllerString + '\n\n'; if ( isNotAnonymous(target) ) { diff --git a/mozmill/extension/resource/modules/utils.js b/mozmill/extension/resource/modules/utils.js index ba2b8ce9..894a86d4 100644 --- a/mozmill/extension/resource/modules/utils.js +++ b/mozmill/extension/resource/modules/utils.js @@ -39,7 +39,7 @@ var EXPORTED_SYMBOLS = ["openFile", "saveFile", "saveAsFile", "genBoiler", "getFile", "Copy", "getChromeWindow", "getWindows", "runEditor", - "runFile", "getWindowByTitle", "tempfile", + "runFile", "getWindowByTitle", "getWindowByType", "tempfile", "getMethodInWindows", "getPreference", "setPreference"]; var hwindow = Components.classes["@mozilla.org/appshell/appShellService;1"] @@ -104,6 +104,12 @@ function getWindowByTitle(title) { } } +function getWindowByType(type) { + var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] + .getService(Components.interfaces.nsIWindowMediator); + return wm.getMostRecentWindow(type); +} + function tempfile(appention) { if (appention == undefined) { var appention = "mozmill.utils.tempfile" @@ -440,4 +446,4 @@ function setPreference(aName, aValue) { // //mozmill.jsTest.sendJSReport(method, result, null, jsSuiteSummary); // // Fire the polling loop back up // //mozmill.MozMillController.continueLoop(); - // }; \ No newline at end of file + // };