mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
Bug 87969 pasting in URL to document window should add URL to urlbar history (xpfe part), r=neil, a=asa
This commit is contained in:
parent
9208793aa8
commit
bf2e22f9b9
@ -2159,7 +2159,7 @@ function handleURLBarRevert()
|
||||
function handleURLBarCommand(aUserAction, aTriggeringEvent)
|
||||
{
|
||||
try {
|
||||
addToUrlbarHistory();
|
||||
addToUrlbarHistory(gURLBar.value);
|
||||
} catch (ex) {
|
||||
// Things may go wrong when adding url to session history,
|
||||
// but don't let that interfere with the loading of the url.
|
||||
|
@ -214,7 +214,7 @@
|
||||
|
||||
<button id="go-button" class="button-toolbar chromeclass-location"
|
||||
label="&goButton.label;" hidden="true"
|
||||
oncommand="addToUrlbarHistory(); BrowserLoadURL(event);"
|
||||
oncommand="addToUrlbarHistory(gURLBar.value); BrowserLoadURL(event);"
|
||||
ondragover="nsDragAndDrop.dragOver(event, goButtonObserver);"
|
||||
ondragdrop="nsDragAndDrop.drop(event, goButtonObserver);"
|
||||
ondragexit="nsDragAndDrop.dragExit(event, goButtonObserver);"
|
||||
|
@ -104,7 +104,7 @@ function executeUrlBarHistoryCommand( aTarget )
|
||||
{
|
||||
if (gURLBar) {
|
||||
gURLBar.value = label;
|
||||
addToUrlbarHistory();
|
||||
addToUrlbarHistory(gURLBar.value);
|
||||
BrowserLoadURL();
|
||||
} else {
|
||||
var uri = getShortcutOrURI(label);
|
||||
@ -157,89 +157,6 @@ function createUBHistoryMenu( aParent )
|
||||
}
|
||||
}
|
||||
|
||||
function addToUrlbarHistory()
|
||||
{
|
||||
var urlToAdd = gURLBar.value;
|
||||
|
||||
// Remove leading and trailing spaces first
|
||||
urlToAdd = urlToAdd.replace(/^\s+/, '').replace(/\s+$/, '');
|
||||
|
||||
if (!urlToAdd)
|
||||
return;
|
||||
if (urlToAdd.search(/[\x00-\x1F]/) != -1) // don't store bad URLs
|
||||
return;
|
||||
|
||||
if (!gRDF)
|
||||
gRDF = Components.classes["@mozilla.org/rdf/rdf-service;1"]
|
||||
.getService(Components.interfaces.nsIRDFService);
|
||||
|
||||
if (!gGlobalHistory)
|
||||
gGlobalHistory = Components.classes["@mozilla.org/browser/global-history;2"]
|
||||
.getService(Components.interfaces.nsIBrowserHistory);
|
||||
|
||||
if (!gURIFixup)
|
||||
gURIFixup = Components.classes["@mozilla.org/docshell/urifixup;1"]
|
||||
.getService(Components.interfaces.nsIURIFixup);
|
||||
if (!gLocalStore)
|
||||
gLocalStore = gRDF.GetDataSource("rdf:local-store");
|
||||
|
||||
if (!gRDFC)
|
||||
gRDFC = Components.classes["@mozilla.org/rdf/container-utils;1"]
|
||||
.getService(Components.interfaces.nsIRDFContainerUtils);
|
||||
|
||||
var entries = gRDFC.MakeSeq(gLocalStore, gRDF.GetResource("nc:urlbar-history"));
|
||||
if (!entries)
|
||||
return;
|
||||
var elements = entries.GetElements();
|
||||
if (!elements)
|
||||
return;
|
||||
var index = 0;
|
||||
|
||||
var urlToCompare = urlToAdd.toUpperCase();
|
||||
while(elements.hasMoreElements()) {
|
||||
var entry = elements.getNext();
|
||||
if (!entry) continue;
|
||||
|
||||
index ++;
|
||||
try {
|
||||
entry = entry.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
||||
} catch(ex) {
|
||||
// XXXbar not an nsIRDFLiteral for some reason. see 90337.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (urlToCompare == entry.Value.toUpperCase()) {
|
||||
// URL 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);
|
||||
break;
|
||||
}
|
||||
} // while
|
||||
|
||||
// Otherwise, we've got a new URL in town. Add it!
|
||||
|
||||
try {
|
||||
var url = getShortcutOrURI(urlToAdd);
|
||||
var fixedUpURI = gURIFixup.createFixupURI(url, 0);
|
||||
if (!fixedUpURI.schemeIs("data"))
|
||||
gGlobalHistory.markPageAsTyped(fixedUpURI);
|
||||
}
|
||||
catch(ex) {
|
||||
}
|
||||
|
||||
// Put the value as it was typed by the user in to RDF
|
||||
// Insert it to the beginning of the list.
|
||||
var entryToAdd = gRDF.GetLiteral(urlToAdd);
|
||||
entries.InsertElementAt(entryToAdd, 1, true);
|
||||
|
||||
// Remove any expired history items so that we don't let
|
||||
// this grow without bound.
|
||||
for (index = entries.GetCount(); index > MAX_URLBAR_HISTORY_ITEMS; --index) {
|
||||
entries.RemoveElementAt(index, true);
|
||||
} // for
|
||||
}
|
||||
|
||||
function createMenuItem( aParent, aIndex, aLabel)
|
||||
{
|
||||
var menuitem = document.createElement( "menuitem" );
|
||||
|
@ -258,6 +258,7 @@
|
||||
var url = readFromClipboard();
|
||||
if (!url)
|
||||
return false;
|
||||
addToUrlbarHistory(url);
|
||||
url = getShortcutOrURI(url);
|
||||
|
||||
// On ctrl-middleclick, open in new window or tab. Do not send referrer.
|
||||
@ -282,6 +283,87 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
function addToUrlbarHistory(aUrlToAdd)
|
||||
{
|
||||
// Remove leading and trailing spaces first
|
||||
aUrlToAdd = aUrlToAdd.replace(/^\s+/, '').replace(/\s+$/, '');
|
||||
|
||||
if (!aUrlToAdd)
|
||||
return;
|
||||
if (aUrlToAdd.search(/[\x00-\x1F]/) != -1) // don't store bad URLs
|
||||
return;
|
||||
|
||||
if (!gRDF)
|
||||
gRDF = Components.classes["@mozilla.org/rdf/rdf-service;1"]
|
||||
.getService(Components.interfaces.nsIRDFService);
|
||||
|
||||
if (!gGlobalHistory)
|
||||
gGlobalHistory = Components.classes["@mozilla.org/browser/global-history;2"]
|
||||
.getService(Components.interfaces.nsIBrowserHistory);
|
||||
|
||||
if (!gURIFixup)
|
||||
gURIFixup = Components.classes["@mozilla.org/docshell/urifixup;1"]
|
||||
.getService(Components.interfaces.nsIURIFixup);
|
||||
if (!gLocalStore)
|
||||
gLocalStore = gRDF.GetDataSource("rdf:local-store");
|
||||
|
||||
if (!gRDFC)
|
||||
gRDFC = Components.classes["@mozilla.org/rdf/container-utils;1"]
|
||||
.getService(Components.interfaces.nsIRDFContainerUtils);
|
||||
|
||||
var entries = gRDFC.MakeSeq(gLocalStore, gRDF.GetResource("nc:urlbar-history"));
|
||||
if (!entries)
|
||||
return;
|
||||
var elements = entries.GetElements();
|
||||
if (!elements)
|
||||
return;
|
||||
var index = 0;
|
||||
|
||||
var urlToCompare = aUrlToAdd.toUpperCase();
|
||||
while(elements.hasMoreElements()) {
|
||||
var entry = elements.getNext();
|
||||
if (!entry) continue;
|
||||
|
||||
index ++;
|
||||
try {
|
||||
entry = entry.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
||||
} catch(ex) {
|
||||
// XXXbar not an nsIRDFLiteral for some reason. see 90337.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (urlToCompare == entry.Value.toUpperCase()) {
|
||||
// URL 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);
|
||||
break;
|
||||
}
|
||||
} // while
|
||||
|
||||
// Otherwise, we've got a new URL in town. Add it!
|
||||
|
||||
try {
|
||||
var url = getShortcutOrURI(aUrlToAdd);
|
||||
var fixedUpURI = gURIFixup.createFixupURI(url, 0);
|
||||
if (!fixedUpURI.schemeIs("data"))
|
||||
gGlobalHistory.markPageAsTyped(fixedUpURI);
|
||||
}
|
||||
catch(ex) {
|
||||
}
|
||||
|
||||
// Put the value as it was typed by the user in to RDF
|
||||
// Insert it to the beginning of the list.
|
||||
var entryToAdd = gRDF.GetLiteral(aUrlToAdd);
|
||||
entries.InsertElementAt(entryToAdd, 1, true);
|
||||
|
||||
// Remove any expired history items so that we don't let
|
||||
// this grow without bound.
|
||||
for (index = entries.GetCount(); index > MAX_URLBAR_HISTORY_ITEMS; --index) {
|
||||
entries.RemoveElementAt(index, true);
|
||||
} // for
|
||||
}
|
||||
|
||||
function makeURLAbsolute( base, url )
|
||||
{
|
||||
// Construct nsIURL.
|
||||
|
Loading…
Reference in New Issue
Block a user