mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 22:22:27 +01:00
Cache favicons
This commit is contained in:
@@ -40,11 +40,13 @@ liberator.Bookmarks = function () //{{{
|
|||||||
.getService(Components.interfaces.nsIBrowserSearchService);
|
.getService(Components.interfaces.nsIBrowserSearchService);
|
||||||
const ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
const ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||||
.getService(Components.interfaces.nsIIOService);
|
.getService(Components.interfaces.nsIIOService);
|
||||||
|
const faviconService = Components.classes["@mozilla.org/browser/favicon-service;1"]
|
||||||
|
.getService(Components.interfaces.nsIFaviconService);
|
||||||
|
|
||||||
const storage = liberator.storage;
|
const storage = liberator.storage;
|
||||||
function Cache(name, store, serial)
|
function Cache(name, store, serial)
|
||||||
{
|
{
|
||||||
const properties = { uri: 0, title: 1, keyword: 2, tags: 3, id: 4 };
|
const properties = { uri: 0, title: 1, keyword: 2, tags: 3, id: 4, icon: 5 };
|
||||||
const rootFolders = [bookmarksService.toolbarFolder, bookmarksService.bookmarksMenuFolder, bookmarksService.unfiledBookmarksFolder];
|
const rootFolders = [bookmarksService.toolbarFolder, bookmarksService.bookmarksMenuFolder, bookmarksService.unfiledBookmarksFolder];
|
||||||
|
|
||||||
var bookmarks = [];
|
var bookmarks = [];
|
||||||
@@ -55,15 +57,17 @@ liberator.Bookmarks = function () //{{{
|
|||||||
this.__defineGetter__("bookmarks", function () { this.load(); return bookmarks; });
|
this.__defineGetter__("bookmarks", function () { this.load(); return bookmarks; });
|
||||||
|
|
||||||
this.__defineGetter__("keywords",
|
this.__defineGetter__("keywords",
|
||||||
function () [[k[2], k[1], k[0]] for each (k in self.bookmarks) if (k[2])]);
|
function () [[k[2], k[1], k[0], k[5]] for each (k in self.bookmarks) if (k[2])]);
|
||||||
|
|
||||||
this.__iterator__ = function () (val for each (val in self.bookmarks));
|
this.__iterator__ = function () (val for each (val in self.bookmarks));
|
||||||
|
|
||||||
function loadBookmark(node)
|
function loadBookmark(node)
|
||||||
{
|
{
|
||||||
var keyword = bookmarksService.getKeywordForBookmark(node.itemId);
|
let uri = ioService.newURI(node.uri, null, null);
|
||||||
var tags = taggingService.getTagsForURI(ioService.newURI(node.uri, null, null), {});
|
let keyword = bookmarksService.getKeywordForBookmark(node.itemId);
|
||||||
bookmarks.push([node.uri, node.title, keyword, tags, node.itemId]);
|
let tags = taggingService.getTagsForURI(uri, {}) || [];
|
||||||
|
let icon = faviconService.getFaviconImageForPage(uri).spec;
|
||||||
|
bookmarks.push([node.uri, node.title, keyword, tags, node.itemId, icon]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function readBookmark(id)
|
function readBookmark(id)
|
||||||
@@ -502,8 +506,8 @@ liberator.Bookmarks = function () //{{{
|
|||||||
{
|
{
|
||||||
url: item[0],
|
url: item[0],
|
||||||
title: item[1],
|
title: item[1],
|
||||||
extra: [['keyword', item[2], "hl-Keyword"],
|
extra: [['keyword', item[2], "hl-Keyword"],
|
||||||
['tags', (item[3]||[]).join(', '), "hl-Tag"]].filter(function (i) i[1])
|
['tags', item[3].join(', '), "hl-Tag"]].filter(function (i) i[1])
|
||||||
} for each (item in items)));
|
} for each (item in items)));
|
||||||
liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
|
liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
|
||||||
},
|
},
|
||||||
@@ -519,6 +523,14 @@ liberator.History = function () //{{{
|
|||||||
|
|
||||||
const historyService = Components.classes["@mozilla.org/browser/nav-history-service;1"]
|
const historyService = Components.classes["@mozilla.org/browser/nav-history-service;1"]
|
||||||
.getService(Components.interfaces.nsINavHistoryService);
|
.getService(Components.interfaces.nsINavHistoryService);
|
||||||
|
const ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||||
|
.getService(Components.interfaces.nsIIOService);
|
||||||
|
const faviconService = Components.classes["@mozilla.org/browser/favicon-service;1"]
|
||||||
|
.getService(Components.interfaces.nsIFaviconService);
|
||||||
|
function getIcon(uri)
|
||||||
|
{
|
||||||
|
return faviconService.getFaviconImageForPage(ioService.newURI(uri, null, null)).spec;
|
||||||
|
}
|
||||||
|
|
||||||
var history = [];
|
var history = [];
|
||||||
var cachedHistory = []; // add pages here after loading the initial Places history
|
var cachedHistory = []; // add pages here after loading the initial Places history
|
||||||
@@ -545,7 +557,7 @@ liberator.History = function () //{{{
|
|||||||
var node = rootNode.getChild(i);
|
var node = rootNode.getChild(i);
|
||||||
//liberator.dump("History child " + node.itemId + ": " + node.title + " - " + node.type + "\n");
|
//liberator.dump("History child " + node.itemId + ": " + node.title + " - " + node.type + "\n");
|
||||||
if (node.type == node.RESULT_TYPE_URI) // just make sure it's a bookmark
|
if (node.type == node.RESULT_TYPE_URI) // just make sure it's a bookmark
|
||||||
history.push([node.uri, node.title || "[No title]"]);
|
history.push([node.uri, node.title || "[No title]", getIcon(node.uri)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// close a container after using it!
|
// close a container after using it!
|
||||||
@@ -717,7 +729,7 @@ liberator.History = function () //{{{
|
|||||||
else
|
else
|
||||||
cachedHistory = cachedHistory.filter(function (elem) elem[0] != url);
|
cachedHistory = cachedHistory.filter(function (elem) elem[0] != url);
|
||||||
|
|
||||||
cachedHistory.unshift([url, title || "[No title]"]);
|
cachedHistory.unshift([url, title || "[No title]", getIcon(url)]);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -54,19 +54,6 @@ liberator.Completion = function () //{{{
|
|||||||
liberator.commandline.setCompletions(completionCache.concat(historyCache));
|
liberator.commandline.setCompletions(completionCache.concat(historyCache));
|
||||||
});
|
});
|
||||||
|
|
||||||
const faviconService = Components.classes["@mozilla.org/browser/favicon-service;1"]
|
|
||||||
.getService(Components.interfaces.nsIFaviconService);
|
|
||||||
const ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
|
||||||
.getService(Components.interfaces.nsIIOService);
|
|
||||||
function getIcon(uri)
|
|
||||||
{
|
|
||||||
return function () faviconService.getFaviconImageForPage(ioService.newURI(uri, null, null)).spec;
|
|
||||||
}
|
|
||||||
function addIcon(elem)
|
|
||||||
{
|
|
||||||
return [elem[0], elem[1], getIcon(elem[0])];
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildSubstrings(str, filter)
|
function buildSubstrings(str, filter)
|
||||||
{
|
{
|
||||||
if (filter == "")
|
if (filter == "")
|
||||||
@@ -286,8 +273,7 @@ liberator.Completion = function () //{{{
|
|||||||
}
|
}
|
||||||
|
|
||||||
mapped = files.map(function (file) [tail ? file.leafName : (dir + file.leafName),
|
mapped = files.map(function (file) [tail ? file.leafName : (dir + file.leafName),
|
||||||
file.isDirectory() ? "Directory" : "File",
|
file.isDirectory() ? "Directory" : "File"]);
|
||||||
getIcon("file://" + file.path)]);
|
|
||||||
}
|
}
|
||||||
catch (e)
|
catch (e)
|
||||||
{
|
{
|
||||||
@@ -387,7 +373,7 @@ liberator.Completion = function () //{{{
|
|||||||
|
|
||||||
search: function (filter)
|
search: function (filter)
|
||||||
{
|
{
|
||||||
var keywords = [[k[0], k[1], getIcon(k[2])] for each (k in liberator.bookmarks.getKeywords())];
|
var keywords = [[k[0], k[1], k[3]] for each (k in liberator.bookmarks.getKeywords())];
|
||||||
var engines = liberator.bookmarks.getSearchEngines();
|
var engines = liberator.bookmarks.getSearchEngines();
|
||||||
return [0, this.filter(engines.concat(keywords), filter, false, true)];
|
return [0, this.filter(engines.concat(keywords), filter, false, true)];
|
||||||
},
|
},
|
||||||
@@ -492,9 +478,9 @@ liberator.Completion = function () //{{{
|
|||||||
else if (c == "S")
|
else if (c == "S")
|
||||||
completions.push(this.searchEngineSuggest(filter, suggestEngineAlias)[1]);
|
completions.push(this.searchEngineSuggest(filter, suggestEngineAlias)[1]);
|
||||||
else if (c == "b" && !autoCompletions)
|
else if (c == "b" && !autoCompletions)
|
||||||
completions.push(liberator.bookmarks.get(filter).map(addIcon));
|
completions.push(liberator.bookmarks.get(filter).map(function (a) [a[0], a[1], a[5]]));
|
||||||
else if (c == "h" && !autoCompletions)
|
else if (c == "h" && !autoCompletions)
|
||||||
completions.push(liberator.history.get(filter).map(addIcon));
|
completions.push(liberator.history.get(filter));
|
||||||
else if (c == "l") // add completions like Firefox's smart location bar
|
else if (c == "l") // add completions like Firefox's smart location bar
|
||||||
{
|
{
|
||||||
completionService.startSearch(filter, "", historyResult, {
|
completionService.startSearch(filter, "", historyResult, {
|
||||||
|
|||||||
Reference in New Issue
Block a user