# HG changeset patch # User Atul Varma # Date 1238184971 25200 # Node ID fd988ee764083dcb45d7f57a3529cddc9f0d280a # Parent 7ac908bdb3d3c3a191d61490bae6e00b9ecedc68 Added chromeless browsing feed. diff -r 7ac908bdb3d3 -r fd988ee76408 chromeless-browsing/chromeless.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chromeless-browsing/chromeless.js Fri Mar 27 13:16:11 2009 -0700 @@ -0,0 +1,140 @@ +var noun_type_url = { + _name: "url", + _getHistoryLinks: function(partialSearch, onSearchComplete) { + function AutoCompleteInput(aSearches) { + this.searches = aSearches; + } + AutoCompleteInput.prototype = { + constructor: AutoCompleteInput, + searches: null, + minResultsForPopup: 0, + timeout: 10, + searchParam: "", + textValue: "", + disableAutoComplete: false, + completeDefaultIndex: false, + get searchCount() { + return this.searches.length; + }, + getSearchAt: function(aIndex) { + return this.searches[aIndex]; + }, + onSearchBegin: function() {}, + onSearchComplete: function() {}, + popupOpen: false, + popup: { + setSelectedIndex: function(aIndex) {}, + invalidate: function() {}, + // nsISupports implementation + QueryInterface: function(iid) { + if (iid.equals(Ci.nsISupports) || + iid.equals(Ci.nsIAutoCompletePopup)) + return this; + throw Components.results.NS_ERROR_NO_INTERFACE; + } + }, + // nsISupports implementation + QueryInterface: function(iid) { + if (iid.equals(Ci.nsISupports) || + iid.equals(Ci.nsIAutoCompleteInput)) + return this; + throw Components.results.NS_ERROR_NO_INTERFACE; + } + }; + + var controller = Cc["@mozilla.org/autocomplete/controller;1"] + .getService(Ci.nsIAutoCompleteController); + var input = new AutoCompleteInput(["history"]); + controller.input = input; + input.onSearchComplete = function() { + onSearchComplete(controller); + }; + + controller.startSearch(partialSearch); + }, + suggestions: [], + _onSearchComplete: function(controller) { + var suggs = []; + var max_suggs = 5; + for (var i = 0; i < controller.matchCount && i <= max_suggs; i++) { + var result = { + title: controller.getCommentAt(i), + url: controller.getValueAt(i), + image: controller.getImageAt(i), + style: controller.getStyleAt(i) + }; + if (!result.title) + result.title = result.url; + if (result.image.indexOf("moz-anno:favicon:") == 0) + result.image = result.image.slice("moz-anno:favicon:".length); + else + result.image = ""; + suggs.push(CmdUtils.makeSugg(result.title, undefined, result)); + } + noun_type_url.suggestions = suggs; + }, + suggest: function(fragment) { + this._getHistoryLinks(fragment, this._onSearchComplete); + var regexp = /(ftp|http|https):\/\/(\w+:{01}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/; + // Magic words "page" or "url" result in the URL of the current page + if (fragment == "page" || fragment == "url") { + var url = Application.activeWindow.activeTab.document.URL; + this.suggestions.push(CmdUtils.makeSugg(url)); + } + // If it's a valid URL, suggest it back + if (regexp.test(fragment)) { + this.suggestions.push(CmdUtils.makeSugg(fragment)); + } else if (regexp.test("http://" + fragment)) { + this.suggestions.push(CmdUtils.makeSugg("http://" + fragment)); + } + return this.suggestions; + } +}; + +CmdUtils.CreateCommand( + {name: "go", + takes: { + "search terms": noun_type_url + }, + preview: function(pblock, theWords) { + if (theWords.text.length == 0) { + pblock.innerHTML = "Please enter a search term"; + return; + } + var result = ""; + if (theWords.data) { + if (theWords.data.image) + result += (" "); + if (theWords.data.title != theWords.data.url) + result += ("" + + Utils.escapeHtml(theWords.data.title) + + ""); + result += ("

" + + Utils.escapeHtml(theWords.data.url) + + "

"); + } else + result = "Takes you to " + Utils.escapeHtml(theWords.text) + "."; + pblock.innerHTML = result; + }, + execute: function(theWords) { + Utils.openUrlInBrowser(theWords.text); + }} +); + +function cmd_show_tabs() { + var content = context.chromeWindow.document.getElementById("appcontent"); + var browser = content.firstChild; + var tabs = browser.tabContainer; + tabs.style.height = "25px"; + tabs.style.marginTop = "0px"; +} + +function cmd_hide_tabs() { + var content = context.chromeWindow.document.getElementById("appcontent"); + var browser = content.firstChild; + var tabs = browser.tabContainer; + tabs.style.height = "0px"; + tabs.style.marginTop = "-500px"; +} diff -r 7ac908bdb3d3 -r fd988ee76408 chromeless-browsing/index.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chromeless-browsing/index.html Fri Mar 27 13:16:11 2009 -0700 @@ -0,0 +1,12 @@ + + + + + + Atul's Chromeless Browsing Commands + + +This feed contains commands relevant to chromeless browsing. + +