B2G/gecko/testing/marionette/marionette-server.js
/**
   * Receives all messages from content messageManager
   */
Receives all messages from content messageManager
Receives all messages from content messageManager
function MDA_receiveMessage(message) {
    if (this.mozBrowserClose !== null){
      let curWindow = this.getCurrentWindow();
      curWindow.removeEventListener('mozbrowserclose', this.mozBrowserClose, true);
      this.mozBrowserClose = null;
    }
    switch (message.name) {
      case "Marionette:done":
        this.sendResponse(message.json.value, message.json.command_id);
        break;
      case "Marionette:ok":
        this.sendOk(message.json.command_id);
        break;
      case "Marionette:error":
        this.sendError(message.json.message, message.json.status, message.json.stacktrace, message.json.command_id);
        break;
      case "Marionette:log":
        logger.info(message.json.message);
        break;
      case "Marionette:shareData":
        if (message.json.log) {
          this.marionetteLog.addLogs(message.json.log);
        }
        break;
      case "Marionette:runEmulatorCmd":
        this.sendToClient(message.json, -1);
        break;
      case "Marionette:switchToFrame":
        let thisWin = this.getCurrentWindow();
        let frameWindow = thisWin.QueryInterface(Ci.nsIInterfaceRequestor)
                                 .getInterface(Ci.nsIDOMWindowUtils)
                                 .getOuterWindowWithId(message.json.win);
        let thisFrame = frameWindow.document.getElementsByTagName("iframe")[message.json.frame];
        let mm = thisFrame.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader.messageManager;
        for (let i = 0; i < remoteFrames.length; i++) {
          let frame = remoteFrames[i];
          if ((frame.messageManager == mm)) {
            this.currentRemoteFrame = frame;
            this.currentRemoteFrame.command_id = message.json.command_id;
            this.messageManager = frame.messageManager;
            this.addMessageManagerListeners(this.messageManager);
            this.messageManager.sendAsyncMessage("Marionette:restart", {});
            return;
          }
        }
        this.addMessageManagerListeners(mm);
        mm.loadFrameScript(FRAME_SCRIPT, true);
        this.messageManager = mm;
        let aFrame = new MarionetteRemoteFrame(message.json.win, message.json.frame);
        aFrame.messageManager = this.messageManager;
        aFrame.command_id = message.json.command_id;
        remoteFrames.push(aFrame);
        this.currentRemoteFrame = aFrame;
        break;
      case "Marionette:switchedToFrame":
        logger.info("Switched to frame: " + JSON.stringify(message.json));
        this.currentFrameElement = message.json.frameValue;
        break;
      case "Marionette:register":
        let nullPrevious = (this.curBrowser.curFrameId == null);
        let curWin = this.getCurrentWindow();
        let listenerWindow = curWin.QueryInterface(Ci.nsIInterfaceRequestor)
                                   .getInterface(Ci.nsIDOMWindowUtils)
                                   .getOuterWindowWithId(message.json.value);
        if (!listenerWindow || (listenerWindow.location.href != message.json.href) &&
            (this.currentRemoteFrame !== null)) {
          this.currentRemoteFrame.targetFrameId = this.generateFrameId(message.json.value);
          this.sendOk(this.currentRemoteFrame.command_id);
        }
        let browserType;
        try {
          browserType = message.target.getAttribute("type");
        } catch (ex) {
        }
        let reg = {};
        if (!browserType || browserType != "content") {
          reg.id = this.curBrowser.register(this.generateFrameId(message.json.value),
                                            listenerWindow);
        }
        this.curBrowser.elementManager.seenItems[reg.id] = Cu.getWeakReference(listenerWindow);
        reg.importedScripts = this.importedScripts.path;
        if (nullPrevious && (this.curBrowser.curFrameId != null)) {
          if (!this.sendAsync("newSession",
                              { B2G: (appName == "B2G") },
                              this.newSessionCommandId)) {
            return;
          }
          if (this.curBrowser.newSession) {
            this.sendResponse(reg.id, this.newSessionCommandId);
            this.newSessionCommandId = null;
          }
        }
        return reg;
    }
  }
function MDA_receiveMessage ( message ) { if ( this . mozBrowserClose !== null ) { let curWindow = this . getCurrentWindow ( ) ; curWindow . removeEventListener ( 'mozbrowserclose' , this . mozBrowserClose , true ) ; this . mozBrowserClose = null ; } switch ( message . name ) { case "Marionette:done" : this . sendResponse ( message . json . value , message . json . command_id ) ; break ; case "Marionette:ok" : this . sendOk ( message . json . command_id ) ; break ; case "Marionette:error" : this . sendError ( message . json . message , message . json . status , message . json . stacktrace , message . json . command_id ) ; break ; case "Marionette:log" : logger . info ( message . json . message ) ; break ; case "Marionette:shareData" : if ( message . json . log ) { this . marionetteLog . addLogs ( message . json . log ) ; } break ; case "Marionette:runEmulatorCmd" : this . sendToClient ( message . json , - 1 ) ; break ; case "Marionette:switchToFrame" : let thisWin = this . getCurrentWindow ( ) ; let frameWindow = thisWin . QueryInterface ( Ci . nsIInterfaceRequestor ) . getInterface ( Ci . nsIDOMWindowUtils ) . getOuterWindowWithId ( message . json . win ) ; let thisFrame = frameWindow . document . getElementsByTagName ( "iframe" ) [ message . json . frame ] ; let mm = thisFrame . QueryInterface ( Ci . nsIFrameLoaderOwner ) . frameLoader . messageManager ; for ( let i = 0 ; i < remoteFrames . length ; i ++ ) { let frame = remoteFrames [ i ] ; if ( ( frame . messageManager == mm ) ) { this . currentRemoteFrame = frame ; this . currentRemoteFrame . command_id = message . json . command_id ; this . messageManager = frame . messageManager ; this . addMessageManagerListeners ( this . messageManager ) ; this . messageManager . sendAsyncMessage ( "Marionette:restart" , { } ) ; return ; } } this . addMessageManagerListeners ( mm ) ; mm . loadFrameScript ( FRAME_SCRIPT , true ) ; this . messageManager = mm ; let aFrame = new MarionetteRemoteFrame ( message . json . win , message . json . frame ) ; aFrame . messageManager = this . messageManager ; aFrame . command_id = message . json . command_id ; remoteFrames . push ( aFrame ) ; this . currentRemoteFrame = aFrame ; break ; case "Marionette:switchedToFrame" : logger . info ( "Switched to frame: " + JSON . stringify ( message . json ) ) ; this . currentFrameElement = message . json . frameValue ; break ; case "Marionette:register" : let nullPrevious = ( this . curBrowser . curFrameId == null ) ; let curWin = this . getCurrentWindow ( ) ; let listenerWindow = curWin . QueryInterface ( Ci . nsIInterfaceRequestor ) . getInterface ( Ci . nsIDOMWindowUtils ) . getOuterWindowWithId ( message . json . value ) ; if ( ! listenerWindow || ( listenerWindow . location . href != message . json . href ) && ( this . currentRemoteFrame !== null ) ) { this . currentRemoteFrame . targetFrameId = this . generateFrameId ( message . json . value ) ; this . sendOk ( this . currentRemoteFrame . command_id ) ; } let browserType ; try { browserType = message . target . getAttribute ( "type" ) ; } catch ( ex ) { } let reg = { } ; if ( ! browserType || browserType != "content" ) { reg . id = this . curBrowser . register ( this . generateFrameId ( message . json . value ) , listenerWindow ) ; } this . curBrowser . elementManager . seenItems [ reg . id ] = Cu . getWeakReference ( listenerWindow ) ; reg . importedScripts = this . importedScripts . path ; if ( nullPrevious && ( this . curBrowser . curFrameId != null ) ) { if ( ! this . sendAsync ( "newSession" , { B2G : ( appName == "B2G" ) } , this . newSessionCommandId ) ) { return ; } if ( this . curBrowser . newSession ) { this . sendResponse ( reg . id , this . newSessionCommandId ) ; this . newSessionCommandId = null ; } } return reg ; } }
Receives all messages from content messageManager
Receives all messages from content messageManager
// We need to just check if we need to remove the mozbrowserclose listener //log server-side messages //log messages from tests // Switch to a remote frame. // See if this frame already has our frame script loaded in it; if so, // just wake it up. // Load the frame script in this frame, and set the frame's ChromeMessageSender // as the active message manager. // This code processes the content listener's registration information // and either accepts the listener, or ignores it // The outerWindowID from an OOP frame will not be meaningful to // the parent process here, since each process maintains its own // independent window list.  So, it will either be null (!listenerWindow) // or it will point to some random window, which will hopefully  // cause an href mistmach.  Currently this only happens // in B2G for OOP frames registered in Marionette:switchToFrame, so // we'll acknowledge the switchToFrame message here. // XXX: Should have a better way of determining that this message // is from a remote frame. // browserType remains undefined.