From 8b7b290e65f2c874a5327b3edddc0e8f8c721de2 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Fri, 9 Oct 2009 00:17:57 -0400 Subject: [PATCH] Don't report live bookmark items as bookmarked. --- common/content/bookmarks.js | 42 +++++++++++++++++++------------------ common/content/liberator.js | 4 ++-- common/content/services.js | 1 + common/modules/storage.jsm | 6 +++--- 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/common/content/bookmarks.js b/common/content/bookmarks.js index 038313e1..34f6c246 100644 --- a/common/content/bookmarks.js +++ b/common/content/bookmarks.js @@ -39,6 +39,7 @@ function Bookmarks() //{{{ const bookmarksService = PlacesUtils.bookmarks; const taggingService = PlacesUtils.tagging; const faviconService = services.get("favicon"); + const livemarkService = services.get("livemark"); // XXX for strange Firefox bug :( // Error: [Exception... "Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsIObserverService.addObserver]" @@ -114,6 +115,18 @@ function Bookmarks() //{{{ this.isBookmark = function (id) rootFolders.indexOf(self.findRoot(id)) >= 0; + this.isRegularBookmark = function findRoot(id) + { + do + { + var root = id; + if (livemarkService && livemarkService.isLivemark(id)) + return false; + id = bookmarksService.getFolderIdForItem(id); + } while (id != bookmarksService.placesRoot && id != root); + return rootFolders.indexOf(root) >= 0; + } + // since we don't use a threaded bookmark loading (by set preload) // anymore, is this loading synchronization still needed? --mst let loading = false; @@ -389,11 +402,10 @@ function Bookmarks() //{{{ if (args.bang) { commandline.input("This will delete all bookmarks. Would you like to continue? (yes/[no]) ", - function (resp) - { + function (resp) { if (resp && resp.match(/^y(es)?$/i)) { - bookmarks.get("").forEach(function (bmark) { bookmarks.remove(bmark.url); }); + cache.bookmarks.forEach(function (bmark) { bookmarksService.removeItem(bmark.id); }); liberator.echomsg("All bookmarks deleted", 1, commandline.FORCE_SINGLELINE); } }); @@ -403,7 +415,7 @@ function Bookmarks() //{{{ let url = args.string || buffer.URL; let deletedCount = bookmarks.remove(url); - liberator.echomsg(deletedCount + " bookmark(s) with url `" + url + "' deleted", 1, commandline.FORCE_SINGLELINE); + liberator.echomsg(deletedCount + " bookmark(s) with url " + url.quote() + " deleted", 1, commandline.FORCE_SINGLELINE); } }, @@ -587,7 +599,7 @@ function Bookmarks() //{{{ try { return bookmarksService.getBookmarkIdsForURI(makeURI(url), {}) - .some(cache.isBookmark); + .some(cache.isRegularBookmark); } catch (e) { @@ -598,29 +610,19 @@ function Bookmarks() //{{{ // returns number of deleted bookmarks remove: function remove(url) { - if (!url) - return 0; - - let i = 0; try { let uri = util.newURI(url); - var count = {}; - let bmarks = bookmarksService.getBookmarkIdsForURI(uri, count); - - for (; i < bmarks.length; i++) - bookmarksService.removeItem(bmarks[i]); + let bmarks = bookmarksService.getBookmarkIdsForURI(uri, {}) + .filter(cache.isRegularBookmark); + bmarks.forEach(bookmarksService.removeItem); + return bmarks.length; } catch (e) { liberator.log(e, 0); - return i; + return 0; } - - // update the display of our "bookmarked" symbol - statusline.updateUrl(); - - return count.value; }, getFavicon: function (url) getFavicon(url), diff --git a/common/content/liberator.js b/common/content/liberator.js index 10b6afeb..6b026f63 100644 --- a/common/content/liberator.js +++ b/common/content/liberator.js @@ -1661,7 +1661,7 @@ const liberator = (function () //{{{ { let obj = { toString: function () error.toString(), - stack: <>{error.stack.replace(/^/mg, "\t")} + stack: <>{(error.stack || Error().stack).replace(/^/mg, "\t")} }; for (let [k, v] in Iterator(error)) { @@ -1671,7 +1671,7 @@ const liberator = (function () //{{{ liberator.dump(obj); liberator.dump(""); } - catch (e) {} + catch (e) { window.dump(e) } }, /** diff --git a/common/content/services.js b/common/content/services.js index 778c250e..ee8cd78a 100644 --- a/common/content/services.js +++ b/common/content/services.js @@ -97,6 +97,7 @@ function Services() self.add("extensionManager", "@mozilla.org/extensions/manager;1", Ci.nsIExtensionManager); self.add("favicon", "@mozilla.org/browser/favicon-service;1", Ci.nsIFaviconService); self.add("json", "@mozilla.org/dom/json;1", Ci.nsIJSON, "createInstance"); + self.add("livemark", "@mozilla.org/browser/livemark-service;2", Ci.nsILivemarkService); self.add("observer", "@mozilla.org/observer-service;1", Ci.nsIObserverService); self.add("io", "@mozilla.org/network/io-service;1", Ci.nsIIOService); self.add("pref", "@mozilla.org/preferences-service;1", [Ci.nsIPrefService, Ci.nsIPrefBranch, Ci.nsIPrefBranch2]); diff --git a/common/modules/storage.jsm b/common/modules/storage.jsm index f5489735..47fad206 100755 --- a/common/modules/storage.jsm +++ b/common/modules/storage.jsm @@ -308,10 +308,10 @@ var storage = { alwaysReload: {}, newObject: function newObject(key, constructor, store, type, options, reload) { - if (!(key in keys) || reload || key in this.alwaysReload) + if (!(key in keys) || reload || this.alwaysReload[key]) { - if (key in this && !reload) - throw Error; + if (key in this && !(reload || this.alwaysReload[key])) + throw Error(); let load = function () loadPref(key, store, type || Object); keys[key] = new constructor(key, store, load, options || {}); timers[key] = new Timer(1000, 10000, function () storage.save(key));