function initClientMessageHandler(worker, workerWindow) {
  function _messageHandler(event) {
    // We will ignore all messages destined for otherType.
    let data = event.data;
    let portid = data.portId;
    let port;
    if (!data.portFromType || data.portFromType === "client") {
      // this is a message posted by ourself so ignore it.
      return;
    }
    switch (data.portTopic) {
      // No "port-create" here - client ports are created explicitly.

      case "port-close":
        // the worker side of the port was closed, so close this side too.
        port = worker.ports[portid];
        if (!port) {
          // port already closed (which will happen when we call port.close()
          // below - the worker side will send us this message but we've
          // already closed it.)
          return;
        }
        delete worker.ports[portid];
        port.close();
        break;

      case "port-message":
        // the client posted a message to this worker port.
        port = worker.ports[portid];
        if (!port) {
          return;
        }
        port._onmessage(data.data);
        break;

      default:
        break;
    }
  }
  // this can probably go once debugged and working correctly!
  function messageHandler(event) {
    try {
      _messageHandler(event);
    } catch (ex) {
      Cu.reportError("FrameWorker: Error handling client port control message: " + ex + "\n" + ex.stack);
    }
  }
  workerWindow.addEventListener('message', messageHandler);
}
// And this is the message listener for the *client* (ie, chrome) side of the world.
And this is the message listener for the *client*  side of the world.
And this is the message listener for the * client * side of the world .
function initClientMessageHandler(worker, workerWindow) {
  function _messageHandler(event) {
    let data = event.data;
    let portid = data.portId;
    let port;
    if (!data.portFromType || data.portFromType === "client") {
      return;
    }
    switch (data.portTopic) {
      case "port-close":
        port = worker.ports[portid];
        if (!port) {
          return;
        }
        delete worker.ports[portid];
        port.close();
        break;
      case "port-message":
        port = worker.ports[portid];
        if (!port) {
          return;
        }
        port._onmessage(data.data);
        break;
      default:
        break;
    }
  }
  function messageHandler(event) {
    try {
      _messageHandler(event);
    } catch (ex) {
      Cu.reportError("FrameWorker: Error handling client port control message: " + ex + "\n" + ex.stack);
    }
  }
  workerWindow.addEventListener('message', messageHandler);
}
function initClientMessageHandler ( worker , workerWindow ) { function _messageHandler ( event ) { let data = event . data ; let portid = data . portId ; let port ; if ( ! data . portFromType || data . portFromType === "client" ) { return ; } switch ( data . portTopic ) { case "port-close" : port = worker . ports [ portid ] ; if ( ! port ) { return ; } delete worker . ports [ portid ] ; port . close ( ) ; break ; case "port-message" : port = worker . ports [ portid ] ; if ( ! port ) { return ; } port . _onmessage ( data . data ) ; break ; default : break ; } } function messageHandler ( event ) { try { _messageHandler ( event ) ; } catch ( ex ) { Cu . reportError ( "FrameWorker: Error handling client port control message: " + ex + "\n" + ex . stack ) ; } } workerWindow . addEventListener ( 'message' , messageHandler ) ; }
And this is the message listener for the *client* (ie, chrome) side of the world.
And this is the message listener for the * client * ( ie chrome ) side of the world .
// We will ignore all messages destined for otherType. // this is a message posted by ourself so ignore it. // No "port-create" here - client ports are created explicitly. // the worker side of the port was closed, so close this side too. // port already closed (which will happen when we call port.close() // below - the worker side will send us this message but we've // already closed it.) // the client posted a message to this worker port. // this can probably go once debugged and working correctly!