third_party/js/mozmill/shared-modules/utils.js
function handleWindow(type, text, callback, dontClose) {
  // Set the window opener function to use depending on the type
  var func_ptr = null;
  switch (type) {
    case "type":
      func_ptr = mozmill.utils.getWindowByType;
      break;
    case "title":
      func_ptr = mozmill.utils.getWindowByTitle;
      break;
    default:
      throw new Error(arguments.callee.name + ": Unknown opener type - " + type);
  }

  var window = null;
  var controller = null;

  try {
    // Wait until the window has been opened
    mozmill.utils.waitFor(function () {
      window = func_ptr(text);
      return window != null;
    }, "Window has been found.");

    // XXX: We still have to find a reliable way to wait until the new window
    // content has been finished loading. Let's wait for now.
    controller = new mozmill.controller.MozMillController(window);
    controller.sleep(200);

    if (callback) {
      callback(controller);
    }

    // Check if we have to close the window
    dontClose = dontClose || false;
    if (dontClose == false & window != null) {
      controller.window.close();
      mozmill.utils.waitFor(function () {
        return func_ptr(text) != window;
      }, "Window has been closed.");

      window = null;
      controller = null;
    }

    return controller;
  } catch (ex) {
    if (window)
      window.close();

    throw ex;
  }
}
function handleWindow(type, text, callback, dontClose) {
  // Set the window opener function to use depending on the type
  var func_ptr = null;
  switch (type) {
    case "type":
      func_ptr = mozmill.utils.getWindowByType;
      break;
    case "title":
      func_ptr = mozmill.utils.getWindowByTitle;
      break;
    default:
      throw new Error(arguments.callee.name + ": Unknown opener type - " + type);
  }

  var window = null;
  var controller = null;

  try {
    // Wait until the window has been opened
    mozmill.utils.waitFor(function () {
      window = func_ptr(text);
      return window != null;
    }, "Window has been found.");

    // XXX: We still have to find a reliable way to wait until the new window
    // content has been finished loading. Let's wait for now.
    controller = new mozmill.controller.MozMillController(window);
    controller.sleep(200);

    if (callback) {
      callback(controller);
    }

    // Check if we have to close the window
    dontClose = dontClose || false;
    if (dontClose == false & window != null) {
      controller.window.close();
      mozmill.utils.waitFor(function () {
        return func_ptr(text) != window;
      }, "Window has been closed.");

      window = null;
      controller = null;
    }

    return controller;
  } catch (ex) {
    if (window)
      window.close();

    throw ex;
  }
}
function handleWindow ( type , text , callback , dontClose ) { // Set the window opener function to use depending on the type var func_ptr = null ; switch ( type ) { case "type" : func_ptr = mozmill . utils . getWindowByType ; break ; case "title" : func_ptr = mozmill . utils . getWindowByTitle ; break ; default : throw new Error ( arguments . callee . name + ": Unknown opener type - " + type ) ; } var window = null ; var controller = null ; try { // Wait until the window has been opened mozmill . utils . waitFor ( function ( ) { window = func_ptr ( text ) ; return window != null ; } , "Window has been found." ) ; // XXX: We still have to find a reliable way to wait until the new window // content has been finished loading. Let's wait for now. controller = new mozmill . controller . MozMillController ( window ) ; controller . sleep ( 200 ) ; if ( callback ) { callback ( controller ) ; } // Check if we have to close the window dontClose = dontClose || false ; if ( dontClose == false & window != null ) { controller . window . close ( ) ; mozmill . utils . waitFor ( function ( ) { return func_ptr ( text ) != window ; } , "Window has been closed." ) ; window = null ; controller = null ; } return controller ; } catch ( ex ) { if ( window ) window . close ( ) ; throw ex ; } }
Function to handle non-modal windows

@param {string} type
Specifies how to check for the new window (possible values: type or title)
@param {string} text
The window type of title string to search for
@param {function} callback (optional)
Callback function to call for window specific tests
@param {boolean} dontClose (optional)
Doens't close the window after the return from the callback handler
@returns The MozMillController of the window (if the window hasn't been closed)
Function to handle non - modal windows