B2G/gecko/browser/base/content/browser-places.js
/**
   * Populate when the history menu is opened
   */
Populate when the history menu is opened
Populate when the history menu is opened
function PHM_populateUndoSubmenu() {
    var undoMenu = this._rootElt.getElementsByClassName("recentlyClosedTabsMenu")[0];
    var undoPopup = undoMenu.firstChild;
    while (undoPopup.hasChildNodes())
      undoPopup.removeChild(undoPopup.firstChild);
    if (this._ss.getClosedTabCount(window) == 0) {
      undoMenu.setAttribute("disabled", true);
      return;
    }
    undoMenu.removeAttribute("disabled");
    var undoItems = JSON.parse(this._ss.getClosedTabData(window));
    for (var i = 0; i < undoItems.length; i++) {
      var m = document.createElement("menuitem");
      m.setAttribute("label", undoItems[i].title);
      if (undoItems[i].image) {
        let iconURL = undoItems[i].image;
        if (/^https?:/.test(iconURL))
          iconURL = "moz-anno:favicon:" + iconURL;
        m.setAttribute("image", iconURL);
      }
      m.setAttribute("class", "menuitem-iconic bookmark-item menuitem-with-favicon");
      m.setAttribute("value", i);
      m.setAttribute("oncommand", "undoCloseTab(" + i + ");");
      let tabData = undoItems[i].state;
      let activeIndex = (tabData.index || tabData.entries.length) - 1;
      if (activeIndex >= 0 && tabData.entries[activeIndex])
        m.setAttribute("targetURI", tabData.entries[activeIndex].url);
      m.addEventListener("click", this._undoCloseMiddleClick, false);
      if (i == 0)
        m.setAttribute("key", "key_undoCloseTab");
      undoPopup.appendChild(m);
    }
    var strings = gNavigatorBundle;
    undoPopup.appendChild(document.createElement("menuseparator"));
    m = undoPopup.appendChild(document.createElement("menuitem"));
    m.id = "menu_restoreAllTabs";
    m.setAttribute("label", strings.getString("menuRestoreAllTabs.label"));
    m.addEventListener("command", function() {
      for (var i = 0; i < undoItems.length; i++)
        undoCloseTab();
    }, false);
  }
function PHM_populateUndoSubmenu ( ) { var undoMenu = this . _rootElt . getElementsByClassName ( "recentlyClosedTabsMenu" ) [ 0 ] ; var undoPopup = undoMenu . firstChild ; while ( undoPopup . hasChildNodes ( ) ) undoPopup . removeChild ( undoPopup . firstChild ) ; if ( this . _ss . getClosedTabCount ( window ) == 0 ) { undoMenu . setAttribute ( "disabled" , true ) ; return ; } undoMenu . removeAttribute ( "disabled" ) ; var undoItems = JSON . parse ( this . _ss . getClosedTabData ( window ) ) ; for ( var i = 0 ; i < undoItems . length ; i ++ ) { var m = document . createElement ( "menuitem" ) ; m . setAttribute ( "label" , undoItems [ i ] . title ) ; if ( undoItems [ i ] . image ) { let iconURL = undoItems [ i ] . image ; if ( / ^https?: / . test ( iconURL ) ) iconURL = "moz-anno:favicon:" + iconURL ; m . setAttribute ( "image" , iconURL ) ; } m . setAttribute ( "class" , "menuitem-iconic bookmark-item menuitem-with-favicon" ) ; m . setAttribute ( "value" , i ) ; m . setAttribute ( "oncommand" , "undoCloseTab(" + i + ");" ) ; let tabData = undoItems [ i ] . state ; let activeIndex = ( tabData . index || tabData . entries . length ) - 1 ; if ( activeIndex >= 0 && tabData . entries [ activeIndex ] ) m . setAttribute ( "targetURI" , tabData . entries [ activeIndex ] . url ) ; m . addEventListener ( "click" , this . _undoCloseMiddleClick , false ) ; if ( i == 0 ) m . setAttribute ( "key" , "key_undoCloseTab" ) ; undoPopup . appendChild ( m ) ; } var strings = gNavigatorBundle ; undoPopup . appendChild ( document . createElement ( "menuseparator" ) ) ; m = undoPopup . appendChild ( document . createElement ( "menuitem" ) ) ; m . id = "menu_restoreAllTabs" ; m . setAttribute ( "label" , strings . getString ( "menuRestoreAllTabs.label" ) ) ; m . addEventListener ( "command" , function ( ) { for ( var i = 0 ; i < undoItems . length ; i ++ ) undoCloseTab ( ) ; } , false ) ; }
Populate when the history menu is opened
Populate when the history menu is opened
// remove existing menu items // no restorable tabs, so make sure menu is disabled, and return // enable menu // populate menu // don't initiate a connection just to fetch a favicon (see bug 467828) // Set the targetURI attribute so it will be shown in tooltip and trigger // onLinkHovered. SessionStore uses one-based indexes, so we need to // normalize them. // "Restore All Tabs"