3 const nav_history_service = Cc["@mozilla.org/browser/nav-history-service;1"]
4 .getService(Ci.nsINavHistoryService);
6 define_keywords("$use_webjumps", "$use_history", "$use_bookmarks");
7 function history_completer() {
9 var use_history = arguments.$use_history;
10 var use_bookmarks = arguments.$use_bookmarks;
11 return function (input, pos, conservative) {
12 if (conservative && input.length == 0)
14 var query = nav_history_service.getNewQuery();
15 query.searchTerms = input;
17 query.onlyBookmarked = true;
18 var options = nav_history_service.getNewQueryOptions();
19 options.sortingMode = options.SORT_BY_VISITCOUNT_DESCENDING;
20 var root = nav_history_service.executeQuery(query, options).root;
21 root.containerOpen = true;
22 var history_count = root.childCount;
23 return {count: history_count,
24 get_string: function (i) {
25 return root.getChild(i).uri;
27 get_description: function (i) {
28 return root.getChild(i).title;
30 apply: function (i, m) {
31 apply_completion_string(root.getChild(i).uri, m);
33 destroy: function () { root.containerOpen = false; }
38 function webjump_completer() {
39 return prefix_completer(
40 $completions = function(visitor) {
41 for (var i in webjumps)
42 visitor([i,webjumps[i]]);
44 $get_string = function (x) x[0] + " ",
45 $get_description = function (x) "");
48 function url_completer() {
50 var use_webjumps = arguments.$use_webjumps;
51 var use_history = arguments.$use_history;
52 var use_bookmarks = arguments.$use_bookmarks;
54 completers.push(file_path_completer());
56 completers.push(webjump_completer());
58 if(use_history || use_bookmarks) {
59 completers.push(history_completer($use_history = use_history,
60 $use_bookmarks = use_bookmarks));
62 return merge_completers(completers);
65 const nav_bookmarks_service = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Ci.nsINavBookmarksService);
67 function add_bookmark(url, title) {
68 nav_bookmarks_service.insertBookmark(nav_bookmarks_service.unfiledBookmarksFolder,
69 makeURL(url), -1, title);
72 function get_element_bookmark_info(elem) {
75 if (elem instanceof Ci.nsIDOMWindow)
77 else if (elem instanceof Ci.nsIDOMHTMLFrameElement || Ci.nsIDOMHTMLIFrameElement)
78 doc = elem.contentDocument;
79 else if (elem instanceof Ci.nsIDOMHTMLAnchorElement) {
80 uri = elem.getAttribute("href");
81 let t = elem.getAttribute("title");
85 title = elem.textContent;
87 throw interactive_error("Invalid element");
90 uri = doc.location.href;