From ad2f3218b98987d41bd8b2d55e3ca7e35fcc01a1 Mon Sep 17 00:00:00 2001 From: "sspitzer%mozilla.org" Date: Wed, 27 Dec 2006 21:51:06 +0000 Subject: [PATCH] fix for regression bug #364018 cannot drag and drop url from location bar or webpage to bookmark toolbar. r=mano git-svn-id: svn://10.0.0.236/trunk@217483 18797224-902f-48f8-a5cc-f745e15eee43 --- .../components/bookmarks/content/bookmarks.js | 61 +++++++++++-------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/mozilla/browser/components/bookmarks/content/bookmarks.js b/mozilla/browser/components/bookmarks/content/bookmarks.js index 01861ec5dd3..fc2c7d5dc1f 100644 --- a/mozilla/browser/components/bookmarks/content/bookmarks.js +++ b/mozilla/browser/components/bookmarks/content/bookmarks.js @@ -1897,18 +1897,44 @@ var BookmarksUtils = { return selection; }, + getTitleForURLFromHistory: function(aURL, aDefaultName) + { +#ifndef MOZ_PLACES + // look up in the history ds to retrieve the name + var rSource = RDF.GetResource(aURL); + var HISTDS = RDF.GetDataSource("rdf:history"); + var nameArc = RDF.GetResource(gNC_NS+"Name"); + var rName = HISTDS.GetTarget(rSource, nameArc, true); + return (rName ? rName.QueryInterface(kRDFLITIID).Value : aDefaultName); +#else + var histsvc = + Components.classes["@mozilla.org/browser/nav-history-service;1"] + .getService(Components.interfaces.nsINavHistoryService); + + // query for the URL + var options = histsvc.getNewQueryOptions(); + options.resultType = options.RESULTS_AS_URI; + var query = histsvc.getNewQuery(); + query.uri = IOSVC.newURI(aURL, null, null); + var result = histsvc.executeQuery(query, options); + var root = result.root; + root.containerOpen = true; + var cc = root.childCount; + for (var i=0; i < cc; ++i) { + var node = root.getChild(i); + if (node.title) + return node.title; + } + + return (aDefaultName ? aDefaultName : aURL); +#endif + }, + createBookmark: function (aName, aURL, aCharSet, aDefaultName) { - if (!aName) { - // look up in the history ds to retrieve the name - var rSource = RDF.GetResource(aURL); - var HISTDS = RDF.GetDataSource("rdf:history"); - var nameArc = RDF.GetResource(gNC_NS+"Name"); - var rName = HISTDS.GetTarget(rSource, nameArc, true); - aName = rName ? rName.QueryInterface(kRDFLITIID).Value : aDefaultName; - if (!aName) - aName = aURL; - } + if (!aName) + aName = this.getTitleForURLFromHistory(aURL, aDefaultName); + if (!aCharSet) { var fw = document.commandDispatcher.focusedWindow; if (fw) @@ -1917,21 +1943,6 @@ var BookmarksUtils = { return BMSVC.createBookmark(aName, aURL, null, null, aCharSet, null); }, - createLivemark: function (aName, aURL, aFeedURL, aDefaultName) - { - if (!aName) { - // look up in the history ds to retrieve the name - var rSource = RDF.GetResource(aURL); - var HISTDS = RDF.GetDataSource("rdf:history"); - var nameArc = RDF.GetResource(gNC_NS+"Name"); - var rName = HISTDS.GetTarget(rSource, nameArc, true); - aName = rName ? rName.QueryInterface(kRDFLITIID).Value : aDefaultName; - if (!aName) - aName = aURL; - } - return BMSVC.createLivemark(aName, aURL, aFeedURL, null); - }, - flushDataSource: function () { var remoteDS = BMDS.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);