2006-09-14 05:50:57 +00:00
|
|
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2006-09-14 05:52:22 +00:00
|
|
|
* Jason Eager <jce2@po.cwru.edu>
|
|
|
|
* Blake Ross <BlakeR1234@aol.com>
|
|
|
|
* Peter Annema <disttsc@bart.nl>
|
2006-09-14 05:50:57 +00:00
|
|
|
*
|
|
|
|
*/
|
2006-09-14 05:54:53 +00:00
|
|
|
const MAX_HISTORY_MENU_ITEMS = 15;
|
2006-09-14 05:54:37 +00:00
|
|
|
const MAX_HISTORY_ITEMS = 100;
|
|
|
|
var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIRDFService);
|
|
|
|
var rdfc = Components.classes["@mozilla.org/rdf/container-utils;1"]
|
|
|
|
.getService(Components.interfaces.nsIRDFContainerUtils);
|
2006-09-14 05:51:55 +00:00
|
|
|
var localstore = rdf.GetDataSource("rdf:localstore");
|
2006-09-14 05:50:13 +00:00
|
|
|
|
2006-09-14 05:54:55 +00:00
|
|
|
function FillHistoryMenu(aParent, aMenu)
|
2006-09-14 05:50:13 +00:00
|
|
|
{
|
2006-09-14 05:54:55 +00:00
|
|
|
// Remove old entries if any
|
|
|
|
deleteHistoryItems(aParent);
|
|
|
|
|
|
|
|
var sessionHistory = getWebNavigation().sessionHistory;
|
2006-09-14 05:54:53 +00:00
|
|
|
|
2006-09-14 05:54:55 +00:00
|
|
|
var count = sessionHistory.count;
|
|
|
|
var index = sessionHistory.index;
|
|
|
|
var end;
|
|
|
|
var j;
|
|
|
|
var entry;
|
|
|
|
|
|
|
|
switch (aMenu)
|
|
|
|
{
|
|
|
|
case "back":
|
|
|
|
end = (index > MAX_HISTORY_MENU_ITEMS) ? index - MAX_HISTORY_MENU_ITEMS : 0;
|
|
|
|
for (j = index - 1; j >= end; j--)
|
|
|
|
{
|
|
|
|
entry = sessionHistory.getEntryAtIndex(j, false);
|
|
|
|
if (entry)
|
|
|
|
createMenuItem(aParent, j, entry.title);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "forward":
|
|
|
|
end = ((count-index) > MAX_HISTORY_MENU_ITEMS) ? index + MAX_HISTORY_MENU_ITEMS : count;
|
|
|
|
for (j = index + 1; j < end; j++)
|
|
|
|
{
|
|
|
|
entry = sessionHistory.getEntryAtIndex(j, false);
|
|
|
|
if (entry)
|
|
|
|
createMenuItem(aParent, j, entry.title);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "go":
|
2006-09-14 05:56:45 +00:00
|
|
|
if (count > 0) aParent.lastChild.removeAttribute( "hidden" );
|
2006-09-14 05:54:55 +00:00
|
|
|
end = count > MAX_HISTORY_MENU_ITEMS ? count - MAX_HISTORY_MENU_ITEMS : 0;
|
|
|
|
for (j = count - 1; j >= end; j--)
|
|
|
|
{
|
|
|
|
entry = sessionHistory.getEntryAtIndex(j, false);
|
|
|
|
if (entry)
|
|
|
|
createCheckboxMenuItem(aParent, j, entry.title, j==index);
|
|
|
|
}
|
|
|
|
break;
|
2006-09-14 05:50:13 +00:00
|
|
|
}
|
|
|
|
}
|
2006-09-14 05:54:53 +00:00
|
|
|
|
|
|
|
function executeUrlBarHistoryCommand( aTarget )
|
2006-09-14 05:50:13 +00:00
|
|
|
{
|
2006-09-14 05:51:50 +00:00
|
|
|
var index = aTarget.getAttribute("index");
|
2006-09-14 05:56:42 +00:00
|
|
|
var label = aTarget.getAttribute("label");
|
|
|
|
if (index != "nothing_available" && label)
|
2006-09-14 05:50:13 +00:00
|
|
|
{
|
2006-09-14 05:56:42 +00:00
|
|
|
loadURI(getShortcutOrURI(label));
|
2006-09-14 05:50:13 +00:00
|
|
|
}
|
2006-09-14 05:54:53 +00:00
|
|
|
}
|
|
|
|
|
2006-09-14 05:52:22 +00:00
|
|
|
function createUBHistoryMenu( aParent )
|
2006-09-14 05:50:13 +00:00
|
|
|
{
|
2006-09-14 05:53:38 +00:00
|
|
|
if (localstore) {
|
2006-09-14 05:54:37 +00:00
|
|
|
var entries = rdfc.MakeSeq(localstore, rdf.GetResource("nc:urlbar-history")).GetElements();
|
2006-09-14 05:53:38 +00:00
|
|
|
var i= MAX_HISTORY_MENU_ITEMS;
|
2006-09-14 05:54:53 +00:00
|
|
|
|
2006-09-14 05:53:38 +00:00
|
|
|
// Delete any old menu items only if there are legitimate
|
2006-09-14 05:54:53 +00:00
|
|
|
// urls to display, otherwise we want to display the
|
|
|
|
// '(Nothing Available)' item.
|
|
|
|
deleteHistoryItems(aParent);
|
|
|
|
if (!entries.hasMoreElements()) {
|
2006-09-14 05:57:32 +00:00
|
|
|
//Create the "Nothing Available" Menu item and disable it.
|
2006-09-14 05:55:56 +00:00
|
|
|
var na = gNavigatorBundle.getString("nothingAvailable");
|
2006-09-14 05:54:53 +00:00
|
|
|
createMenuItem(aParent, "nothing_available", na);
|
2006-09-14 05:57:32 +00:00
|
|
|
aParent.firstChild.setAttribute("disabled", "true");
|
2006-09-14 05:54:53 +00:00
|
|
|
}
|
2006-09-14 05:51:55 +00:00
|
|
|
|
2006-09-14 05:53:38 +00:00
|
|
|
while (entries.hasMoreElements() && (i-- > 0)) {
|
|
|
|
var entry = entries.getNext();
|
|
|
|
if (entry) {
|
|
|
|
entry = entry.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
|
|
|
var url = entry.Value;
|
|
|
|
createMenuItem(aParent, i, url);
|
|
|
|
}
|
2006-09-14 05:50:13 +00:00
|
|
|
}
|
2006-09-14 05:53:38 +00:00
|
|
|
}
|
2006-09-14 05:50:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function addToUrlbarHistory()
|
2006-09-14 05:54:54 +00:00
|
|
|
{
|
2006-09-14 05:56:42 +00:00
|
|
|
var urlToAdd = gURLBar.value;
|
|
|
|
if (!urlToAdd)
|
|
|
|
return;
|
|
|
|
if (localstore) {
|
2006-09-14 05:54:54 +00:00
|
|
|
var entries = rdfc.MakeSeq(localstore, rdf.GetResource("nc:urlbar-history"));
|
|
|
|
if (!entries)
|
2006-09-14 05:56:42 +00:00
|
|
|
return;
|
2006-09-14 05:54:54 +00:00
|
|
|
var elements = entries.GetElements();
|
|
|
|
if (!elements)
|
2006-09-14 05:56:42 +00:00
|
|
|
return;
|
2006-09-14 05:54:54 +00:00
|
|
|
var index = 0;
|
|
|
|
// create the nsIURI objects for comparing the 2 urls
|
2006-09-14 05:57:33 +00:00
|
|
|
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService);
|
|
|
|
|
|
|
|
try {
|
|
|
|
var unused = { };
|
2006-09-14 05:57:34 +00:00
|
|
|
var scheme = ioService.extractScheme(urlToAdd, unused, unused);
|
2006-09-14 05:57:33 +00:00
|
|
|
} catch(e) {
|
|
|
|
urlToAdd = "http://" + urlToAdd;
|
|
|
|
}
|
|
|
|
var uriToAdd = ioService.newURI(urlToAdd, null);
|
|
|
|
|
2006-09-14 05:54:54 +00:00
|
|
|
while(elements.hasMoreElements()) {
|
|
|
|
entry = elements.getNext();
|
|
|
|
if (entry) {
|
|
|
|
index ++;
|
|
|
|
entry= entry.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
2006-09-14 05:55:30 +00:00
|
|
|
var rdfValue = entry.Value;
|
2006-09-14 05:57:33 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
var unused = { };
|
2006-09-14 05:57:34 +00:00
|
|
|
var scheme = ioService.extractScheme(rdfValue, unused, unused);
|
2006-09-14 05:57:33 +00:00
|
|
|
} catch(e) {
|
|
|
|
rdfValue = "http://" + rdfValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var rdfUri = ioService.newURI(rdfValue, null);
|
|
|
|
|
2006-09-14 05:54:54 +00:00
|
|
|
if (rdfUri.equals(uriToAdd)) {
|
|
|
|
// URI already present in the database
|
|
|
|
// Remove it from its current position.
|
|
|
|
// It is inserted to the top after the while loop.
|
|
|
|
entries.RemoveElementAt(index, true);
|
2006-09-14 05:56:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // while
|
2006-09-14 05:51:55 +00:00
|
|
|
|
2006-09-14 05:54:54 +00:00
|
|
|
var entry = rdf.GetLiteral(urlToAdd);
|
|
|
|
// Otherwise, we've got a new URL in town. Add it!
|
|
|
|
// Put the value as it was typed by the user in to RDF
|
|
|
|
// Insert it to the beginning of the list.
|
|
|
|
entries.InsertElementAt(entry, 1, true);
|
2006-09-14 05:54:37 +00:00
|
|
|
|
2006-09-14 05:56:42 +00:00
|
|
|
// Remove any expired history items so that we don't let
|
2006-09-14 05:54:54 +00:00
|
|
|
// this grow without bound.
|
|
|
|
for (index = entries.GetCount(); index > MAX_HISTORY_ITEMS; --index) {
|
|
|
|
entries.RemoveElementAt(index, true);
|
|
|
|
} // for
|
|
|
|
} // localstore
|
|
|
|
}
|
2006-09-14 05:56:42 +00:00
|
|
|
|
|
|
|
function createMenuItem( aParent, aIndex, aLabel)
|
2006-09-14 05:50:13 +00:00
|
|
|
{
|
|
|
|
var menuitem = document.createElement( "menuitem" );
|
2006-09-14 05:56:42 +00:00
|
|
|
menuitem.setAttribute( "label", aLabel );
|
2006-09-14 05:50:13 +00:00
|
|
|
menuitem.setAttribute( "index", aIndex );
|
|
|
|
aParent.appendChild( menuitem );
|
|
|
|
}
|
|
|
|
|
2006-09-14 05:56:42 +00:00
|
|
|
function createCheckboxMenuItem( aParent, aIndex, aLabel, aChecked)
|
2006-09-14 05:50:13 +00:00
|
|
|
{
|
2006-09-14 05:52:22 +00:00
|
|
|
var menuitem = document.createElement( "menuitem" );
|
|
|
|
menuitem.setAttribute( "type", "checkbox" );
|
2006-09-14 05:56:42 +00:00
|
|
|
menuitem.setAttribute( "label", aLabel );
|
2006-09-14 05:52:22 +00:00
|
|
|
menuitem.setAttribute( "index", aIndex );
|
|
|
|
if (aChecked==true)
|
|
|
|
menuitem.setAttribute( "checked", "true" );
|
|
|
|
aParent.appendChild( menuitem );
|
|
|
|
}
|
|
|
|
|
2006-09-14 05:54:53 +00:00
|
|
|
function deleteHistoryItems(aParent)
|
2006-09-14 05:52:22 +00:00
|
|
|
{
|
|
|
|
var children = aParent.childNodes;
|
2006-09-14 05:50:13 +00:00
|
|
|
for (var i = 0; i < children.length; i++ )
|
|
|
|
{
|
|
|
|
var index = children[i].getAttribute( "index" );
|
2006-09-14 05:56:42 +00:00
|
|
|
if (index)
|
2006-09-14 05:52:22 +00:00
|
|
|
aParent.removeChild( children[i] );
|
2006-09-14 05:50:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateGoMenu(event)
|
|
|
|
{
|
2006-09-14 05:52:22 +00:00
|
|
|
FillHistoryMenu(event.target, "go");
|
2006-09-14 05:50:13 +00:00
|
|
|
}
|
|
|
|
|