diff --git a/xpfe/components/history/resources/history-panel.xul b/xpfe/components/history/resources/history-panel.xul index 5dc6798b02fa..daf5f90d997c 100644 --- a/xpfe/components/history/resources/history-panel.xul +++ b/xpfe/components/history/resources/history-panel.xul @@ -30,7 +30,9 @@ + onload="HistoryCommonInit();" + onunload="HistoryPanelUnload();" + elementtofocus="historyTree"> diff --git a/xpfe/components/history/resources/history.js b/xpfe/components/history/resources/history.js index 0a061cb495f9..e7ca862007d5 100644 --- a/xpfe/components/history/resources/history.js +++ b/xpfe/components/history/resources/history.js @@ -42,6 +42,7 @@ var gLastHostname; var gLastDomain; var gGlobalHistory; var gPrefService; +var gIOService; var gDeleteByHostname; var gDeleteByDomain; var gHistoryBundle; @@ -49,12 +50,6 @@ var gHistoryStatus; var gHistoryGrouping = ""; var gWindowManager = null; -function HistoryWindowInit() -{ - HistoryCommonInit(); - gHistoryTree.focus(); -} - function HistoryCommonInit() { gHistoryTree = document.getElementById("historyTree"); @@ -113,9 +108,19 @@ function HistoryCommonInit() } SortInNewDirection(find_sort_direction(find_sort_column())); + + if (gHistoryStatus) + gHistoryTree.focus(); gHistoryTree.treeBoxObject.view.selection.select(0); } +function HistoryPanelUnload() +{ + var pb = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); + var pbi = pb.QueryInterface(Components.interfaces.nsIPrefBranchInternal); + pbi.removeObserver("browser.history.grouping", groupObserver, false); +} + function updateHistoryCommands() { goUpdateCommand("cmd_deleteByHostname"); @@ -149,27 +154,24 @@ function historyOnSelect() var match; var currentIndex = gHistoryTree.currentIndex; var rowIsContainer = gHistoryGrouping != "none" && currentIndex >= 0 && isContainer(gHistoryTree, currentIndex); - var url = rowIsContainer ? gHistoryTree.treeBoxObject.view.getCellText(currentIndex, "URL") : null; + var url = rowIsContainer ? "" : gHistoryTree.treeBoxObject.view.getCellText(currentIndex, "URL"); if (url) { - // matches scheme://(hostname)... - match = url.match(/^.*?:\/\/(?:([^\/:]*)(?::([^\/:]*))?@)?([^\/:]*)(?::([^\/:]*))?(.*)$/); + if (!gIOService) + gIOService = Components.classes['@mozilla.org/network/io-service;1'] + .getService(Components.interfaces.nsIIOService); + try { + gLastHostname = gIOService.newURI(url, null, null).host; + // matches the last foo.bar in foo.bar or baz.foo.bar + match = gLastHostname.match(/([^.]+\.[^.]+$)/); + if (match) + gLastDomain = match[1]; + } catch (e) {} + } - if (match && match.length>1) - gLastHostname = match[3]; - + if (gHistoryStatus) gHistoryStatus.label = url; - } - else { - gHistoryStatus.label = ""; - } - if (gLastHostname) { - // matches the last foo.bar in foo.bar or baz.foo.bar - match = gLastHostname.match(/([^.]+\.[^.]+$)/); - if (match) - gLastDomain = match[1]; - } document.commandDispatcher.updateCommands("select"); } diff --git a/xpfe/components/history/resources/history.xul b/xpfe/components/history/resources/history.xul index b7307d2e0281..c575a719bd79 100644 --- a/xpfe/components/history/resources/history.xul +++ b/xpfe/components/history/resources/history.xul @@ -32,7 +32,7 @@