History cleanup, add open in tab to history.

This commit is contained in:
blakeross%telocity.com 2002-11-13 00:55:56 +00:00
Родитель 3aa03af8ad
Коммит a275b91764
5 изменённых файлов: 185 добавлений и 272 удалений

Просмотреть файл

@ -3777,17 +3777,17 @@ nsContextMenu.prototype = {
// Open linked-to URL in a new window.
openLink : function () {
// Determine linked-to URL.
openNewWindowWith(this.linkURL(), this.link);
openNewWindowWith(this.linkURL(), this.link, true);
},
// Open linked-to URL in a new tab.
openLinkInTab : function () {
// Determine linked-to URL.
openNewTabWith(this.linkURL(), this.link);
openNewTabWith(this.linkURL(), this.link, null, true);
},
// Open frame in a new tab.
openFrameInTab : function () {
// Determine linked-to URL.
openNewTabWith(this.target.ownerDocument.location.href, null);
openNewTabWith(this.target.ownerDocument.location.href, null, null, true);
},
// Reload clicked-in frame.
reloadFrame : function () {
@ -3795,7 +3795,7 @@ nsContextMenu.prototype = {
},
// Open clicked-in frame in its own window.
openFrame : function () {
openNewWindowWith(this.target.ownerDocument.location.href, null);
openNewWindowWith(this.target.ownerDocument.location.href, null, true);
},
// Open clicked-in frame in the same window
showOnlyThisFrame : function () {
@ -4253,73 +4253,18 @@ nsDefaultEngine.prototype =
return true;
}
function openNewTabWith(href, linkNode, event)
{
urlSecurityCheck(href, document);
// should we open it in a new tab?
var loadInBackground;
try {
loadInBackground = gPrefService.getBoolPref("browser.tabs.loadInBackground");
}
catch(ex) {
loadInBackground = true;
}
if (event && event.shiftKey)
loadInBackground = !loadInBackground;
var theTab = getBrowser().addTab(href, getReferrer(document));
if (!loadInBackground)
getBrowser().selectedTab = theTab;
if (linkNode)
markLinkVisited(href, linkNode);
}
function openNewWindowWith(href, linkNode)
{
urlSecurityCheck(href, document);
// if and only if the current window is a browser window and it has a document with a character
// set, then extract the current charset menu setting from the current document and use it to
// initialize the new browser window...
var charsetArg = null;
var wintype = document.firstChild.getAttribute('windowtype');
if (wintype == "navigator:browser")
charsetArg = "charset=" + window._content.document.characterSet;
var referrer = getReferrer(document);
window.openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no", href, charsetArg, referrer);
if (linkNode)
markLinkVisited(href, linkNode);
}
function markLinkVisited(href, linkNode)
{
var globalHistory = Components.classes["@mozilla.org/browser/global-history;1"]
.getService(Components.interfaces.nsIGlobalHistory);
if (!globalHistory.isVisited(href)) {
globalHistory.addPage(href);
var oldHref = linkNode.href;
linkNode.href = "";
linkNode.href = oldHref;
}
}
function handleLinkClick(event, href, linkNode)
{
switch (event.button) {
case 0:
if (event.ctrlKey) {
openNewTabWith(href, linkNode, event);
openNewTabWith(href, linkNode, event, true);
event.preventBubble();
return true;
}
// if left button clicked
if (event.shiftKey) {
openNewWindowWith(href, linkNode);
openNewWindowWith(href, linkNode, true);
event.preventBubble();
return true;
}
@ -4339,9 +4284,9 @@ function handleLinkClick(event, href, linkNode)
tab = true;
}
if (tab)
openNewTabWith(href, linkNode, event);
openNewTabWith(href, linkNode, event, true);
else
openNewWindowWith(href, linkNode);
openNewWindowWith(href, linkNode, true);
event.preventBubble();
return true;
}
@ -4359,7 +4304,7 @@ function middleMousePaste( event )
// On ctrl-middleclick, open in new tab.
if (event.ctrlKey)
openNewTabWith(url, null);
openNewTabWith(url, null, event, true);
// If ctrl wasn't down, then just load the url in the current win/tab.
loadURI(url);
@ -4377,33 +4322,6 @@ function makeURLAbsolute( base, url )
return ioService.newURI(baseURI.resolve(url), null, null).spec;
}
function isContentFrame(aFocusedWindow)
{
if (!aFocusedWindow)
return false;
var focusedTop = Components.lookupMethod(aFocusedWindow, 'top')
.call(aFocusedWindow);
return (focusedTop == window.content);
}
function urlSecurityCheck(url, doc)
{
// URL Loading Security Check
var focusedWindow = doc.commandDispatcher.focusedWindow;
var sourceURL = getContentFrameURI(focusedWindow);
const nsIScriptSecurityManager = Components.interfaces.nsIScriptSecurityManager;
var secMan = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
.getService(nsIScriptSecurityManager);
try {
secMan.checkLoadURIStr(sourceURL, url, nsIScriptSecurityManager.STANDARD);
} catch (e) {
throw "Load of " + url + " denied.";
}
}
function findParentNode(node, parentNode)
{
if (node && node.nodeType == Node.TEXT_NODE) {

Просмотреть файл

@ -40,6 +40,93 @@
* Determine whether or not a given focused DOMWindow is in the content
* area.
**/
function openNewTabWith(href, linkNode, event, securityCheck)
{
if (securityCheck)
urlSecurityCheck(href, document);
var prefSvc = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService);
prefSvc = prefSvc.getBranch(null);
// should we open it in a new tab?
var loadInBackground = true;
try {
loadInBackground = prefSvc.getBoolPref("browser.tabs.loadInBackground");
}
catch(ex) {
}
if (event && event.shiftKey)
loadInBackground = !loadInBackground;
var browser = top.document.getElementById("content");
var theTab = browser.addTab(href, getReferrer(document));
if (!loadInBackground)
browser.selectedTab = theTab;
if (linkNode)
markLinkVisited(href, linkNode);
}
function openNewWindowWith(href, linkNode, securityCheck)
{
if (securityCheck)
urlSecurityCheck(href, document);
// if and only if the current window is a browser window and it has a document with a character
// set, then extract the current charset menu setting from the current document and use it to
// initialize the new browser window...
var charsetArg = null;
var wintype = document.firstChild.getAttribute('windowtype');
if (wintype == "navigator:browser")
charsetArg = "charset=" + window._content.document.characterSet;
var referrer = getReferrer(document);
window.openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no", href, charsetArg, referrer);
if (linkNode)
markLinkVisited(href, linkNode);
}
function markLinkVisited(href, linkNode)
{
var globalHistory = Components.classes["@mozilla.org/browser/global-history;1"]
.getService(Components.interfaces.nsIGlobalHistory);
if (!globalHistory.isVisited(href)) {
globalHistory.addPage(href);
var oldHref = linkNode.href;
linkNode.href = "";
linkNode.href = oldHref;
}
}
function urlSecurityCheck(url, doc)
{
// URL Loading Security Check
var focusedWindow = doc.commandDispatcher.focusedWindow;
var sourceURL = getContentFrameURI(focusedWindow);
const nsIScriptSecurityManager = Components.interfaces.nsIScriptSecurityManager;
var secMan = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
.getService(nsIScriptSecurityManager);
try {
secMan.checkLoadURIStr(sourceURL, url, nsIScriptSecurityManager.STANDARD);
} catch (e) {
throw "Load of " + url + " denied.";
}
}
function isContentFrame(aFocusedWindow)
{
if (!aFocusedWindow)
return false;
var focusedTop = Components.lookupMethod(aFocusedWindow, 'top')
.call(aFocusedWindow);
return (focusedTop == window.content);
}
function getContentFrameURI(aFocusedWindow)
{

Просмотреть файл

@ -41,6 +41,7 @@
<script type="application/x-javascript" src="chrome://global/content/globalOverlay.js"/>
<script type="application/x-javascript" src="chrome://browser/content/history/history.js"/>
<script type="application/x-javascript" src="chrome://browser/content/bookmarks/bookmarks.js"/>
<script type="application/x-javascript" src="chrome://browser/content/contentAreaUtils.js"/>
<stringbundle id="historyBundle" src="chrome://browser/locale/history/history.properties"/>
<commandset id="selectEditMenuItems">
<command id="cmd_delete"/>
@ -57,12 +58,15 @@
<command id="cmd_copy"/>
<command id="cmd_delete"/>
<command id="cmd_selectAll"/>
<popup id="historyMenu" onpopupshowing="return updateItems();">
<menuitem id="miCollapseExpand" accesskey="&collapseExpand.accesskey;" oncommand="collapseExpand();"/>
<popup id="historyMenu" onpopupshowing="buildContextMenu();">
<menuitem id="miCollapseExpand" accesskey="&collapseExpand.accesskey;" default="true"
oncommand="collapseExpand();"/>
<menuitem id="miOpen" label="&openLinkInWindowCmd.label;" accesskey="&openLinkInWindowCmd.accesskey;" default="true"
oncommand="OpenURL(false);"/>
oncommand="OpenURL(0);"/>
<menuitem id="miOpenInNewWindow" label="&openInNewWindow.label;" accesskey="&openInNewWindow.accesskey;"
oncommand="OpenURL(true);"/>
oncommand="OpenURL(1);"/>
<menuitem id="miOpenInNewTab" label="&openInNewTab.label;" accesskey="&openInNewTab.accesskey;"
oncommand="OpenURL(2);"/>
<menuseparator id="pre-bookmarks-separator"/>
<menuitem id="miAddBookmark" label="&bookmarkLinkCmd.label;" oncommand="historyAddBookmarks();"/>
<menuitem id="miCopyLinkLocation" label="&copyLinkCmd.label;" accesskey="&copyLinkCmd.accesskey;"
@ -73,8 +77,6 @@
<menuitem id="miSelectAll" label="&selectAllCmd.label;" accesskey="&selectAllCmd.accesskey;"
command="cmd_selectAll"/>
</popup>
<data id="multipleBookmarks" label="&addToBookmarksCmd.label;" accesskey="&addToBookmarksCmd.accesskey;"/>
<data id="oneBookmark" label="&bookmarkLinkCmd.label;" accesskey="&bookmarkLinkCmd.accesskey;"/>
</popupset>
<hbox align="center">
<label value="&find.label;" accesskey="&find.accesskey;" control="search-box"/>
@ -110,7 +112,8 @@
historyOnSelect();"
hidecolumnpicker="true"
ondraggesture="if (event.originalTarget.localName == 'treechildren') nsDragAndDrop.startDrag(event, historyDNDObserver);"
ondblclick="if (validClickConditions(event)) OpenURL(event.shiftKey || event.metaKey);">
onclick="if (event.button == 1) OpenURL(2, event);"
ondblclick="if (event.button == 0) onDoubleClick(event);">
<template>
<rule>
<treechildren>

Просмотреть файл

@ -39,25 +39,23 @@
var gHistoryTree;
var gGlobalHistory;
var gHistoryBundle;
var gSearchBox;
var gHistoryGrouping = "";
function HistoryCommonInit()
{
gHistoryTree = document.getElementById("historyTree");
gHistoryBundle = document.getElementById("historyBundle");
gHistoryTree = document.getElementById("historyTree");
gSearchBox = document.getElementById("search-box");
var treeController = new nsTreeController(gHistoryTree);
var mode = document.getElementById("viewButton").getAttribute("selectedsort");
if (mode == "site")
gHistoryGrouping = document.getElementById("viewButton").getAttribute("selectedsort");
if (gHistoryGrouping == "site")
document.getElementById("bysite").setAttribute("checked", "true");
else if (mode == "visited")
else if (gHistoryGrouping == "visited")
document.getElementById("byvisited").setAttribute("checked", "true");
else if (mode == "lastvisited")
else if (gHistoryGrouping == "lastvisited")
document.getElementById("bylastvisited").setAttribute("checked", "true");
else if (mode == "dayandsite")
else if (gHistoryGrouping == "dayandsite")
document.getElementById("bydayandsite").setAttribute("checked", "true");
else
document.getElementById("byday").setAttribute("checked", "true");
@ -89,49 +87,41 @@ var historyDNDObserver = {
}
};
function validClickConditions(event)
{
var currentIndex = gHistoryTree.currentIndex;
if (currentIndex == -1) return false;
var container = isContainer(gHistoryTree, currentIndex);
return (event.button == 0 &&
event.originalTarget.localName == 'treechildren' &&
!container);
}
function collapseExpand()
{
var currentIndex = gHistoryTree.currentIndex;
gHistoryTree.treeBoxObject.view.toggleOpenState(currentIndex);
}
function OpenURL(aInNewWindow)
function onDoubleClick(event)
{
var currentIndex = gHistoryTree.currentIndex;
var builder = gHistoryTree.builder.QueryInterface(Components.interfaces.nsIXULTreeBuilder);
var url = builder.getResourceAtIndex(currentIndex).Value;
if (aInNewWindow) {
var count = gHistoryTree.treeBoxObject.view.selection.count;
if (count == 1) {
openDialog( getBrowserURL(), "_blank", "chrome,all,dialog=no", url );
}
else {
var min = new Object();
var max = new Object();
var rangeCount = gHistoryTree.treeBoxObject.view.selection.getRangeCount();
for (var i = 0; i < rangeCount; ++i) {
gHistoryTree.treeBoxObject.view.selection.getRangeAt(i, min, max);
for (var k = max.value; k >= min.value; --k) {
url = gHistoryTree.treeBoxObject.view.getCellText(k, "URL");
window.openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no", url);
}
}
}
}
else if (!isContainer(gHistoryTree, currentIndex))
openTopWin(url);
return true;
if (event.metaKey || event.shiftKey)
OpenURL(1);
else if (event.ctrlKey)
OpenURL(2, event);
else
OpenURL(0);
}
function OpenURL(aWhere, event)
{
var count = gHistoryTree.treeBoxObject.view.selection.count;
if (count != 1)
return;
var currentIndex = gHistoryTree.currentIndex;
if (isContainer(gHistoryTree, currentIndex))
return;
var builder = gHistoryTree.builder.QueryInterface(Components.interfaces.nsIXULTreeBuilder);
var url = builder.getResourceAtIndex(currentIndex).Value;
if (aWhere == 0)
openTopWin(url);
else if (aWhere == 1)
openNewWindowWith(url, null, false);
else
openNewTabWith(url, null, event, false);
}
function SortBy(sortKey)
@ -188,105 +178,66 @@ function GroupBy(groupingType)
function historyAddBookmarks()
{
var count = gHistoryTree.treeBoxObject.view.selection.count;
var url;
var title;
if (count == 1) {
var currentIndex = gHistoryTree.currentIndex;
url = gHistoryTree.treeBoxObject.view.getCellText(currentIndex, "URL");
title = gHistoryTree.treeBoxObject.view.getCellText(currentIndex, "Name");
BookmarksUtils.addBookmark(url, title, undefined, true);
}
else if (count > 1) {
var min = new Object();
var max = new Object();
var rangeCount = gHistoryTree.treeBoxObject.view.selection.getRangeCount();
for (var i = 0; i < rangeCount; ++i) {
gHistoryTree.treeBoxObject.view.selection.getRangeAt(i, min, max);
for (var k = max.value; k >= min.value; --k) {
url = gHistoryTree.treeBoxObject.view.getCellText(k, "URL");
title = gHistoryTree.treeBoxObject.view.getCellText(k, "Name");
BookmarksUtils.addBookmark(url, title, undefined, false);
}
}
}
if (count != 1)
return;
var currentIndex = gHistoryTree.currentIndex;
var url = gHistoryTree.treeBoxObject.view.getCellText(currentIndex, "URL");
var title = gHistoryTree.treeBoxObject.view.getCellText(currentIndex, "Name");
BookmarksUtils.addBookmark(url, title, undefined, true);
}
function updateItems()
function buildContextMenu()
{
var count = gHistoryTree.treeBoxObject.view.selection.count;
var openItem = document.getElementById("miOpen");
var openItemInNewWindow = document.getElementById("miOpenInNewWindow");
var openItemInNewTab = document.getElementById("miOpenInNewTab");
var bookmarkItem = document.getElementById("miAddBookmark");
var copyLocationItem = document.getElementById("miCopyLinkLocation");
var sep1 = document.getElementById("pre-bookmarks-separator");
var openItemInNewWindow = document.getElementById("miOpenInNewWindow");
var sep2 = document.getElementById("post-bookmarks-separator");
var collapseExpandItem = document.getElementById("miCollapseExpand");
if (count > 1) {
var hasContainer = false;
if (gHistoryGrouping == "day") {
var min = new Object();
var max = new Object();
var rangeCount = gHistoryTree.treeBoxObject.view.selection.getRangeCount();
for (var i = 0; i < rangeCount; ++i) {
gHistoryTree.treeBoxObject.view.selection.getRangeAt(i, min, max);
for (var k = max.value; k >= min.value; --k) {
if (isContainer(gHistoryTree, k)) {
hasContainer = true;
break;
}
}
}
}
if (hasContainer) {
bookmarkItem.setAttribute("hidden", "true");
copyLocationItem.setAttribute("hidden", "true");
sep1.setAttribute("hidden", "true");
document.getElementById("post-bookmarks-separator").setAttribute("hidden", "true");
openItem.setAttribute("hidden", "true");
openItemInNewWindow.setAttribute("hidden", "true");
collapseExpandItem.setAttribute("hidden", "true");
}
else {
bookmarkItem.removeAttribute("hidden");
copyLocationItem.removeAttribute("hidden");
sep1.removeAttribute("hidden");
bookmarkItem.setAttribute("label", document.getElementById('multipleBookmarks').getAttribute("label"));
openItem.setAttribute("hidden", "true");
openItem.removeAttribute("default");
openItemInNewWindow.setAttribute("default", "true");
}
openItem.hidden = true;
openItemInNewWindow.hidden = true;
openItemInNewTab.hidden = true;
bookmarkItem.hidden = true;
copyLocationItem.hidden = true;
sep1.hidden = true;
sep2.hidden = true;
collapseExpandItem.hidden = true;
}
else {
bookmarkItem.setAttribute("label", document.getElementById('oneBookmark').getAttribute("label"));
var currentIndex = gHistoryTree.currentIndex;
if (isContainer(gHistoryTree, currentIndex)) {
openItem.setAttribute("hidden", "true");
openItemInNewWindow.setAttribute("hidden", "true");
openItem.removeAttribute("default");
collapseExpandItem.removeAttribute("hidden");
collapseExpandItem.setAttribute("default", "true");
bookmarkItem.setAttribute("hidden", "true");
copyLocationItem.setAttribute("hidden", "true");
sep1.setAttribute("hidden", "true");
if (isContainerOpen(gHistoryTree, currentIndex))
collapseExpandItem.setAttribute("label", gHistoryBundle.getString("collapseLabel"));
else
collapseExpandItem.setAttribute("label", gHistoryBundle.getString("expandLabel"));
return true;
if ((gHistoryGrouping == "day" || gHistoryGrouping == "dayandsite")
&& isContainer(gHistoryTree, currentIndex)) {
var bundle = document.getElementById("historyBundle");
openItem.hidden = true;
openItemInNewWindow.hidden = true;
openItemInNewTab.hidden = true;
bookmarkItem.hidden = true;
copyLocationItem.hidden = true;
sep1.hidden = true;
sep2.hidden = false;
collapseExpandItem.hidden = false;
if (isContainerOpen(gHistoryTree, currentIndex))
collapseExpandItem.setAttribute("label", bundle.getString("collapseLabel"));
else
collapseExpandItem.setAttribute("label", bundle.getString("expandLabel"));
}
else {
collapseExpandItem.setAttribute("hidden", "true");
bookmarkItem.removeAttribute("hidden");
copyLocationItem.removeAttribute("hidden");
sep1.removeAttribute("hidden");
openItem.removeAttribute("hidden");
openItemInNewWindow.removeAttribute("hidden");
if (!openItem.hasAttribute("default"))
openItem.setAttribute("default", "true");
openItemInNewWindow.removeAttribute("default");
openItem.hidden = false;
openItemInNewWindow.hidden = false;
openItemInNewTab.hidden = false;
bookmarkItem.hidden = false;
copyLocationItem.hidden = false;
sep1.hidden = false;
sep2.hidden = false;
collapseExpandItem.hidden = true;
}
}
return true;
}
function searchHistory(aInput)

Просмотреть файл

@ -1,53 +1,5 @@
<!-- extracted from ./history.xul -->
<!ENTITY menuBar.tooltip "Menu Bar">
<!ENTITY fileMenu.label "File">
<!ENTITY closeCmd.label "Close">
<!ENTITY editMenu.label "Edit">
<!ENTITY undoCmd.label "Undo">
<!ENTITY redoCmd.label "Redo">
<!ENTITY cutCmd.label "Cut">
<!ENTITY copyCmd.label "Copy">
<!ENTITY pasteCmd.label "Paste">
<!ENTITY deleteCmd.label "Delete">
<!ENTITY deleteHostnameCmd.accesskey "l">
<!ENTITY deleteDomainCmd.accesskey "o">
<!ENTITY selAllCmd.label "Select All">
<!ENTITY findHisCmd.label "Search History...">
<!ENTITY findHisCmd.commandkey "f">
<!ENTITY findHisCmd.accesskey "S">
<!ENTITY groupBy.label "Group By">
<!ENTITY groupBy.accesskey "G">
<!ENTITY groupByDay.label "Day">
<!ENTITY groupByDay.accesskey "D">
<!ENTITY groupByNone.label "None">
<!ENTITY groupByNone.accesskey "N">
<!ENTITY historyWindowTitle.label "History">
<!ENTITY menuitem.view.unsorted.label "Unsorted">
<!ENTITY menuitem.view.unsorted.accesskey "u">
<!ENTITY menuitem.view.ascending.label "A > Z Sort Order">
<!ENTITY menuitem.view.ascending.accesskey "a">
<!ENTITY menuitem.view.descending.label "Z > A Sort Order">
<!ENTITY menuitem.view.descending.accesskey "z">
<!ENTITY menuitem.view.show_columns.label "Show columns">
<!ENTITY menuitem.view.show_columns.accesskey "S">
<!ENTITY find.label "Find:">
<!ENTITY find.accesskey "n">
<!ENTITY releaseCmd.label "Release Notes">
<!ENTITY tree.header.name.label "Title">
<!ENTITY tree.header.name.akey "T">
<!ENTITY tree.header.url.label "Location">
<!ENTITY tree.header.url.akey "L">
<!ENTITY tree.header.date.label "Last Visited">
<!ENTITY tree.header.date.akey "a">
<!ENTITY tree.header.firstvisitdate.label "First Visited">
<!ENTITY tree.header.firstvisitdate.akey "F">
<!ENTITY tree.header.referrer.label "Referrer">
<!ENTITY tree.header.referrer.akey "R">
<!ENTITY tree.header.hostname.label "Hostname">
<!ENTITY tree.header.hostname.akey "H">
<!ENTITY tree.header.visitcount.label "Visit Count">
<!ENTITY tree.header.visitcount.akey "V">
<!ENTITY collapseExpand.accesskey "e">
<!ENTITY byDate.label "By Date">
<!ENTITY byDate.accesskey "D">
@ -61,4 +13,6 @@
<!ENTITY byDayAndSite.label "By Date and Site">
<!ENTITY byDayAndSite.accesskey "t">
<!ENTITY openInNewWindow.label "Open in New Window">
<!ENTITY openInNewWindow.accesskey "W">
<!ENTITY openInNewWindow.accesskey "W">
<!ENTITY openInNewTab.label "Open in New Tab">
<!ENTITY openInNewTab.accesskey "T">