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_populateUndoWindowSubmenu() {
    let undoMenu = this._rootElt.getElementsByClassName("recentlyClosedWindowsMenu")[0];
    let undoPopup = undoMenu.firstChild;
    let menuLabelString = gNavigatorBundle.getString("menuUndoCloseWindowLabel");
    let menuLabelStringSingleTab =
      gNavigatorBundle.getString("menuUndoCloseWindowSingleTabLabel");
    while (undoPopup.hasChildNodes())
      undoPopup.removeChild(undoPopup.firstChild);
    if (this._ss.getClosedWindowCount() == 0) {
      undoMenu.setAttribute("disabled", true);
      return;
    }
    undoMenu.removeAttribute("disabled");
    let undoItems = JSON.parse(this._ss.getClosedWindowData());
    for (let i = 0; i < undoItems.length; i++) {
      let undoItem = undoItems[i];
      let otherTabsCount = undoItem.tabs.length - 1;
      let label = (otherTabsCount == 0) ? menuLabelStringSingleTab
                                        : PluralForm.get(otherTabsCount, menuLabelString);
      let menuLabel = label.replace("#1", undoItem.title)
                           .replace("#2", otherTabsCount);
      let m = document.createElement("menuitem");
      m.setAttribute("label", menuLabel);
      let selectedTab = undoItem.tabs[undoItem.selected - 1];
      if (selectedTab.attributes.image) {
        let iconURL = selectedTab.attributes.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("oncommand", "undoCloseWindow(" + i + ");");
      let activeIndex = (selectedTab.index || selectedTab.entries.length) - 1;
      if (activeIndex >= 0 && selectedTab.entries[activeIndex])
        m.setAttribute("targetURI", selectedTab.entries[activeIndex].url);
      if (i == 0)
        m.setAttribute("key", "key_undoCloseWindow");
      undoPopup.appendChild(m);
    }
    undoPopup.appendChild(document.createElement("menuseparator"));
    let m = undoPopup.appendChild(document.createElement("menuitem"));
    m.id = "menu_restoreAllWindows";
    m.setAttribute("label", gNavigatorBundle.getString("menuRestoreAllWindows.label"));
    m.setAttribute("oncommand",
      "for (var i = 0; i < " + undoItems.length + "; i++) undoCloseWindow();");
  }
function PHM_populateUndoWindowSubmenu ( ) { let undoMenu = this . _rootElt . getElementsByClassName ( "recentlyClosedWindowsMenu" ) [ 0 ] ; let undoPopup = undoMenu . firstChild ; let menuLabelString = gNavigatorBundle . getString ( "menuUndoCloseWindowLabel" ) ; let menuLabelStringSingleTab = gNavigatorBundle . getString ( "menuUndoCloseWindowSingleTabLabel" ) ; while ( undoPopup . hasChildNodes ( ) ) undoPopup . removeChild ( undoPopup . firstChild ) ; if ( this . _ss . getClosedWindowCount ( ) == 0 ) { undoMenu . setAttribute ( "disabled" , true ) ; return ; } undoMenu . removeAttribute ( "disabled" ) ; let undoItems = JSON . parse ( this . _ss . getClosedWindowData ( ) ) ; for ( let i = 0 ; i < undoItems . length ; i ++ ) { let undoItem = undoItems [ i ] ; let otherTabsCount = undoItem . tabs . length - 1 ; let label = ( otherTabsCount == 0 ) ? menuLabelStringSingleTab : PluralForm . get ( otherTabsCount , menuLabelString ) ; let menuLabel = label . replace ( "#1" , undoItem . title ) . replace ( "#2" , otherTabsCount ) ; let m = document . createElement ( "menuitem" ) ; m . setAttribute ( "label" , menuLabel ) ; let selectedTab = undoItem . tabs [ undoItem . selected - 1 ] ; if ( selectedTab . attributes . image ) { let iconURL = selectedTab . attributes . 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 ( "oncommand" , "undoCloseWindow(" + i + ");" ) ; let activeIndex = ( selectedTab . index || selectedTab . entries . length ) - 1 ; if ( activeIndex >= 0 && selectedTab . entries [ activeIndex ] ) m . setAttribute ( "targetURI" , selectedTab . entries [ activeIndex ] . url ) ; if ( i == 0 ) m . setAttribute ( "key" , "key_undoCloseWindow" ) ; undoPopup . appendChild ( m ) ; } undoPopup . appendChild ( document . createElement ( "menuseparator" ) ) ; let m = undoPopup . appendChild ( document . createElement ( "menuitem" ) ) ; m . id = "menu_restoreAllWindows" ; m . setAttribute ( "label" , gNavigatorBundle . getString ( "menuRestoreAllWindows.label" ) ) ; m . setAttribute ( "oncommand" , "for (var i = 0; i < " + undoItems . length + "; i++) undoCloseWindow();" ) ; }
Populate when the history menu is opened
Populate when the history menu is opened
// remove existing menu items // no restorable windows, 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. // SessionStore uses one-based indexes, so we need to normalize them. // "Open All in Windows"