code: function mdObserver_findWindow() {
      // If a window has been opened from content, it has to be unwrapped.
      var window = domUtils.unwrapNode(mozmill.wm.getMostRecentWindow(''));
  
      // Get the WebBrowserChrome and check if it's a modal window
      var chrome = window.QueryInterface(Ci.nsIInterfaceRequestor).
                   getInterface(Ci.nsIWebNavigation).
                   QueryInterface(Ci.nsIDocShellTreeItem).
                   treeOwner.
                   QueryInterface(Ci.nsIInterfaceRequestor).
                   getInterface(Ci.nsIWebBrowserChrome);
      if (!chrome.isWindowModal()) {
        return null;
      }
  
      // Opening a modal dialog from a modal dialog would fail, if we wouldn't
      // check for the opener of the modal dialog
      var found = false;
      if (window.opener) {
        // XXX Bug 614757 - an already unwrapped node returns a wrapped node
        var opener = domUtils.unwrapNode(window.opener);
        found = (mozmill.utils.getChromeWindow(opener) == this._opener);
      }
      else {
        // Also note that it could happen that dialogs don't have an opener
        // (i.e. clear recent history). In such a case make sure that the most
        // recent window is not the passed in reference opener
        found = (window != this._opener);
      }
  
      return (found ? window : null);
    }
docs: Check if the modal dialog has been opened
  
  @returns {object} The modal dialog window found, or null.