Bug 1364911 - Wait for the history subview to be populated before opening it. r=Gijs

MozReview-Commit-ID: 7F1zPhYjVnL

--HG--
extra : rebase_source : fb175b80ec45dc2a1f901403bd8aa5cc2b4ffd69
extra : source : 9c81323fba749d1a209c1e5ee34b5705ec2418cc
This commit is contained in:
Paolo Amadini 2017-05-15 15:03:48 +01:00
parent 1f7b56a7b8
commit 132e133c40

View File

@ -176,102 +176,106 @@ const CustomizableWidgets = [
tooltiptext: "history-panelmenu.tooltiptext2",
defaultArea: CustomizableUI.AREA_PANEL,
onViewShowing(aEvent) {
// Populate our list of history
const kMaxResults = 15;
let doc = aEvent.target.ownerDocument;
let win = doc.defaultView;
aEvent.detail.addBlocker(new Promise((resolve, reject) => {
// Populate our list of history
const kMaxResults = 15;
let doc = aEvent.target.ownerDocument;
let win = doc.defaultView;
let options = PlacesUtils.history.getNewQueryOptions();
options.excludeQueries = true;
options.queryType = options.QUERY_TYPE_HISTORY;
options.sortingMode = options.SORT_BY_DATE_DESCENDING;
options.maxResults = kMaxResults;
let query = PlacesUtils.history.getNewQuery();
let options = PlacesUtils.history.getNewQueryOptions();
options.excludeQueries = true;
options.queryType = options.QUERY_TYPE_HISTORY;
options.sortingMode = options.SORT_BY_DATE_DESCENDING;
options.maxResults = kMaxResults;
let query = PlacesUtils.history.getNewQuery();
let items = doc.getElementById("PanelUI-historyItems");
// Clear previous history items.
while (items.firstChild) {
items.firstChild.remove();
}
let items = doc.getElementById("PanelUI-historyItems");
// Clear previous history items.
while (items.firstChild) {
items.firstChild.remove();
}
// Get all statically placed buttons to supply them with keyboard shortcuts.
let staticButtons = items.parentNode.getElementsByTagNameNS(kNSXUL, "toolbarbutton");
for (let i = 0, l = staticButtons.length; i < l; ++i)
CustomizableUI.addShortcut(staticButtons[i]);
// Get all statically placed buttons to supply them with keyboard shortcuts.
let staticButtons = items.parentNode.getElementsByTagNameNS(kNSXUL, "toolbarbutton");
for (let i = 0, l = staticButtons.length; i < l; ++i)
CustomizableUI.addShortcut(staticButtons[i]);
PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase)
.asyncExecuteLegacyQueries([query], 1, options, {
handleResult(aResultSet) {
let onItemCommand = function(aItemCommandEvent) {
// Only handle the click event for middle clicks, we're using the command
// event otherwise.
if (aItemCommandEvent.type == "click" &&
aItemCommandEvent.button != 1) {
return;
PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase)
.asyncExecuteLegacyQueries([query], 1, options, {
handleResult(aResultSet) {
let onItemCommand = function(aItemCommandEvent) {
// Only handle the click event for middle clicks, we're using the command
// event otherwise.
if (aItemCommandEvent.type == "click" &&
aItemCommandEvent.button != 1) {
return;
}
let item = aItemCommandEvent.target;
win.openUILink(item.getAttribute("targetURI"), aItemCommandEvent);
CustomizableUI.hidePanelForNode(item);
};
let fragment = doc.createDocumentFragment();
let row;
while ((row = aResultSet.getNextRow())) {
let uri = row.getResultByIndex(1);
let title = row.getResultByIndex(2);
let item = doc.createElementNS(kNSXUL, "toolbarbutton");
item.setAttribute("label", title || uri);
item.setAttribute("targetURI", uri);
item.setAttribute("class", "subviewbutton");
item.addEventListener("command", onItemCommand);
item.addEventListener("click", onItemCommand);
item.setAttribute("image", "page-icon:" + uri);
fragment.appendChild(item);
}
let item = aItemCommandEvent.target;
win.openUILink(item.getAttribute("targetURI"), aItemCommandEvent);
CustomizableUI.hidePanelForNode(item);
};
let fragment = doc.createDocumentFragment();
let row;
while ((row = aResultSet.getNextRow())) {
let uri = row.getResultByIndex(1);
let title = row.getResultByIndex(2);
items.appendChild(fragment);
},
handleError(aError) {
log.debug("History view tried to show but had an error: " + aError);
reject();
},
handleCompletion(aReason) {
log.debug("History view is being shown!");
resolve();
},
});
let item = doc.createElementNS(kNSXUL, "toolbarbutton");
item.setAttribute("label", title || uri);
item.setAttribute("targetURI", uri);
item.setAttribute("class", "subviewbutton");
item.addEventListener("command", onItemCommand);
item.addEventListener("click", onItemCommand);
item.setAttribute("image", "page-icon:" + uri);
fragment.appendChild(item);
}
items.appendChild(fragment);
},
handleError(aError) {
log.debug("History view tried to show but had an error: " + aError);
},
handleCompletion(aReason) {
log.debug("History view is being shown!");
},
});
let recentlyClosedTabs = doc.getElementById("PanelUI-recentlyClosedTabs");
while (recentlyClosedTabs.firstChild) {
recentlyClosedTabs.firstChild.remove();
}
let recentlyClosedTabs = doc.getElementById("PanelUI-recentlyClosedTabs");
while (recentlyClosedTabs.firstChild) {
recentlyClosedTabs.firstChild.remove();
}
let recentlyClosedWindows = doc.getElementById("PanelUI-recentlyClosedWindows");
while (recentlyClosedWindows.firstChild) {
recentlyClosedWindows.firstChild.remove();
}
let recentlyClosedWindows = doc.getElementById("PanelUI-recentlyClosedWindows");
while (recentlyClosedWindows.firstChild) {
recentlyClosedWindows.firstChild.remove();
}
let utils = RecentlyClosedTabsAndWindowsMenuUtils;
let tabsFragment = utils.getTabsFragment(doc.defaultView, "toolbarbutton", true,
"menuRestoreAllTabsSubview.label");
let separator = doc.getElementById("PanelUI-recentlyClosedTabs-separator");
let elementCount = tabsFragment.childElementCount;
separator.hidden = !elementCount;
while (--elementCount >= 0) {
let element = tabsFragment.children[elementCount];
CustomizableUI.addShortcut(element);
element.classList.add("subviewbutton", "cui-withicon");
}
recentlyClosedTabs.appendChild(tabsFragment);
let utils = RecentlyClosedTabsAndWindowsMenuUtils;
let tabsFragment = utils.getTabsFragment(doc.defaultView, "toolbarbutton", true,
"menuRestoreAllTabsSubview.label");
let separator = doc.getElementById("PanelUI-recentlyClosedTabs-separator");
let elementCount = tabsFragment.childElementCount;
separator.hidden = !elementCount;
while (--elementCount >= 0) {
let element = tabsFragment.children[elementCount];
CustomizableUI.addShortcut(element);
element.classList.add("subviewbutton", "cui-withicon");
}
recentlyClosedTabs.appendChild(tabsFragment);
let windowsFragment = utils.getWindowsFragment(doc.defaultView, "toolbarbutton", true,
"menuRestoreAllWindowsSubview.label");
separator = doc.getElementById("PanelUI-recentlyClosedWindows-separator");
elementCount = windowsFragment.childElementCount;
separator.hidden = !elementCount;
while (--elementCount >= 0) {
let element = windowsFragment.children[elementCount];
CustomizableUI.addShortcut(element);
element.classList.add("subviewbutton", "cui-withicon");
}
recentlyClosedWindows.appendChild(windowsFragment);
let windowsFragment = utils.getWindowsFragment(doc.defaultView, "toolbarbutton", true,
"menuRestoreAllWindowsSubview.label");
separator = doc.getElementById("PanelUI-recentlyClosedWindows-separator");
elementCount = windowsFragment.childElementCount;
separator.hidden = !elementCount;
while (--elementCount >= 0) {
let element = windowsFragment.children[elementCount];
CustomizableUI.addShortcut(element);
element.classList.add("subviewbutton", "cui-withicon");
}
recentlyClosedWindows.appendChild(windowsFragment);
}));
},
onCreated(aNode) {
// Middle clicking recently closed items won't close the panel - cope: