From 1a78e1c0a92080e9bc728862ef1401706c1a845b Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sun, 21 Dec 2008 17:26:45 -0500 Subject: [PATCH 01/31] Remove @class='s' from default hinttags --- common/content/hints.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/content/hints.js b/common/content/hints.js index 3b2f3bd1..35b81fd4 100644 --- a/common/content/hints.js +++ b/common/content/hints.js @@ -527,7 +527,7 @@ function Hints() //{{{ ////////////////////// OPTIONS ///////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - const DEFAULT_HINTTAGS = "//*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @class='s' or @role='link'] | " + + const DEFAULT_HINTTAGS = "//*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @role='link'] | " + "//input[not(@type='hidden')] | //a | //area | //iframe | //textarea | //button | //select | " + "//xhtml:input[not(@type='hidden')] | //xhtml:a | //xhtml:area | //xhtml:iframe | //xhtml:textarea | //xhtml:button | //xhtml:select"; From d7b20e26f5a6be769add6472ceee3e8314b5094c Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sun, 21 Dec 2008 17:36:55 -0500 Subject: [PATCH 02/31] Blur focused element on return to NORMAL mode. --- common/content/commands.js | 3 ++- common/content/modes.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/common/content/commands.js b/common/content/commands.js index d2682d54..5df3818e 100644 --- a/common/content/commands.js +++ b/common/content/commands.js @@ -923,7 +923,8 @@ function Commands() //{{{ [["-bang"], commandManager.OPTION_NOARG], [["-count"], commandManager.OPTION_NOARG], [["-complete"], commandManager.OPTION_STRING, - function (arg) arg in completeOptionMap || /custom,\w+/.test(arg)] + function (arg) arg in completeOptionMap || /custom,\w+/.test(arg), + function (context) [[k, ''] for ([k, v] in Iterator(completeOptionMap))]] ], literal: 1, serial: function () [ diff --git a/common/content/modes.js b/common/content/modes.js index fc4195c5..4f5d3de9 100644 --- a/common/content/modes.js +++ b/common/content/modes.js @@ -118,7 +118,7 @@ const modes = (function () //{{{ options.setPref("accessibility.browsewithcaret", false); statusline.updateUrl(); - liberator.focusContent(false); + liberator.focusContent(true); } } From fc0a35e83382a693e352ba0aacd4593f7d9be20e Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sun, 21 Dec 2008 18:39:09 -0500 Subject: [PATCH 03/31] =?UTF-8?q?Fix=20liberator.callAsync=20(thanks=20?= =?UTF-8?q?=E7=BD=97=E6=98=A5=E9=9B=B7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/content/liberator.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/content/liberator.js b/common/content/liberator.js index 35a71efb..fd795a06 100644 --- a/common/content/liberator.js +++ b/common/content/liberator.js @@ -688,8 +688,8 @@ const liberator = (function () //{{{ callAsync: function (thread, self, func) { - hread = thread || service["threadManager"].newThread(0); - thread.dispatch(new Runnable(self, func, Array.slice(arguments, 2)), thread.DISPATCH_NORMAL); + thread = thread || service["threadManager"].newThread(0); + thread.dispatch(new Runnable(self, func, Array.slice(arguments, 3)), thread.DISPATCH_NORMAL); }, // be sure to call GUI related methods like alert() or dump() ONLY in the main thread From 348226998025ebe75217553e6ae2ff3c270432f8 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sun, 21 Dec 2008 18:56:56 -0500 Subject: [PATCH 04/31] Fix storage observer weak ref stuff (Gecko is a strange beast) --- common/content/options.js | 2 +- common/modules/storage.jsm | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/common/content/options.js b/common/content/options.js index c20882db..9128b492 100644 --- a/common/content/options.js +++ b/common/content/options.js @@ -96,7 +96,7 @@ Option.prototype = { }, get values() this.parseValues(this.value), - set values(values) this.setValues(this.scope, values), + set values(values) this.setValues(values, this.scope), getValues: function (scope) this.parseValues(this.get(scope)), diff --git a/common/modules/storage.jsm b/common/modules/storage.jsm index 22b89605..c48a0c40 100644 --- a/common/modules/storage.jsm +++ b/common/modules/storage.jsm @@ -311,11 +311,22 @@ var storage = { addObserver: function addObserver(key, callback, ref) { + if (ref) + { + if (!ref.liberatorStorageRefs) + ref.liberatorStorageRefs = []; + ref.liberatorStorageRefs.push(callback); + var callbackRef = Cu.getWeakReference(callback); + } + else + { + callbackRef = { get: function () callback }; + } this.removeDeadObservers(); if (!(key in observers)) observers[key] = []; - if (observers[key].indexOf(callback) == -1) - observers[key].push({ ref: ref && Cu.getWeakReference(ref), callback: callback }); + if (!observers[key].some(function (o) o.callback.get() == callback)) + observers[key].push({ ref: ref && Cu.getWeakReference(ref), callback: callbackRef }); }, removeObserver: function (key, callback) @@ -323,7 +334,7 @@ var storage = { this.removeDeadObservers(); if (!(key in observers)) return; - observers[key] = observers[key].filter(function (elem) elem.callback != callback); + observers[key] = observers[key].filter(function (elem) elem.callback.get() != callback); if (observers[key].length == 0) delete obsevers[key]; }, @@ -332,18 +343,20 @@ var storage = { { for (let [key, ary] in Iterator(observers)) { - observers[key] = ary = ary.filter(function (o) !o.ref || o.ref.get()); + observers[key] = ary = ary.filter(function (o) o.callback.get() && (!o.ref || o.ref.get() && o.ref.get().liberatorStorageRefs)) if (!ary.length) delete observers[key]; } }, + get observers() observers, + fireEvent: function fireEvent(key, event, arg) { this.removeDeadObservers(); // Safe, since we have our own Array object here. for each (let observer in observers[key]) - observer.callback(key, event, arg); + observer.callback.get()(key, event, arg); timers[key].tell(); }, From db0fa4bc5b7f68218477acdec244d857a661523f Mon Sep 17 00:00:00 2001 From: Martin Stubenschrott Date: Mon, 22 Dec 2008 13:15:05 +0100 Subject: [PATCH 05/31] Fixed ctrl-a/x with 0003-style urls, thanks hogelog --- vimperator/content/config.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/vimperator/content/config.js b/vimperator/content/config.js index bfde7c86..812497e1 100644 --- a/vimperator/content/config.js +++ b/vimperator/content/config.js @@ -127,26 +127,28 @@ const config = { //{{{ init: function () { - // TODO: support 'nrformats'? + // TODO: support 'nrformats'? -> probably not worth it --mst function incrementURL(count) { let matches = buffer.URL.match(/(.*?)(\d+)(\D*)$/); - if (!matches) + return liberator.beep(); + + let [, pre, number, post] = matches; + let newNumber = parseInt(number, 10) + count; + let newNumberStr = String(newNumber > 0 ? newNumber : 0); + if (number.match(/^0/)) // add 0009 should become 0010 { - liberator.beep(); - return; + while(newNumberStr.length < number.length) + newNumberStr = "0" + newNumberStr; } - [, pre, number, post] = matches; - let newNumber = parseInt(number, 10) + count; - - liberator.open(pre + (newNumber > 0 ? newNumber : 0) + post); + liberator.open(pre + newNumberStr + post); } // load Vimperator specific modules // FIXME: Why aren't these listed in config.scripts? - // FIXME: Why isn't this automatic? + // FIXME: Why isn't this automatic? -> how would one know which classes to load where? --mst liberator.loadModule("search", Search); liberator.loadModule("bookmarks", Bookmarks); liberator.loadModule("history", History); From f96b522ec1bf7fb360e9a11ed434fa0ff61b6025 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Tue, 23 Dec 2008 00:16:34 +1100 Subject: [PATCH 06/31] Handle the silly exception thrown from options.resetPref. --- common/content/options.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/common/content/options.js b/common/content/options.js index 9128b492..1e7b215e 100644 --- a/common/content/options.js +++ b/common/content/options.js @@ -986,7 +986,14 @@ function Options() //{{{ resetPref: function (name) { - return service["pref"].clearUserPref(name); + try + { + return service["pref"].clearUserPref(name); + } + catch (e) + { + // ignore - thrown if not a user set value + } }, // this works only for booleans From cd9715fc6bb177e7bcc7fb1c05fb87350c5ed263 Mon Sep 17 00:00:00 2001 From: anekos Date: Tue, 23 Dec 2008 07:57:27 +0900 Subject: [PATCH 07/31] Fix: bookmarks.js loading error. liberator.modules.options has not been defined when bookmarks.js is loading. --- vimperator/content/bookmarks.js | 36 ++++++++++++++++----------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/vimperator/content/bookmarks.js b/vimperator/content/bookmarks.js index 277b5ccd..299589a5 100644 --- a/vimperator/content/bookmarks.js +++ b/vimperator/content/bookmarks.js @@ -28,26 +28,26 @@ the terms of any one of the MPL, the GPL or the LGPL. const DEFAULT_FAVICON = "chrome://mozapps/skin/places/defaultFavicon.png"; -if (liberator.options.getPref("extensions.vimperator.commandline_cmd_history")) -{ - // Try to import older command line history, quick marks, etc. - liberator.registerObserver("load_options", function () { - let store = liberator.storage["history-command"]; - let pref = liberator.options.getPref("extensions.vimperator.commandline_cmd_history"); - for (let [k, v] in Iterator(pref.split("\n"))) - store.push(v); +// Try to import older command line history, quick marks, etc. +liberator.registerObserver("load_options", function () { + if (!liberator.modules.options.getPref("extensions.vimperator.commandline_cmd_history")) + return; - store = liberator.storage["quickmarks"]; - pref = liberator.options.getPref("extensions.vimperator.quickmarks") - .split("\n"); - while (pref.length > 0) - store.set(pref.shift(), pref.shift()); + let store = liberator.storage["history-command"]; + let pref = liberator.options.getPref("extensions.vimperator.commandline_cmd_history"); + for (let [k, v] in Iterator(pref.split("\n"))) + store.push(v); - liberator.options.resetPref("extensions.vimperator.commandline_cmd_history"); - liberator.options.resetPref("extensions.vimperator.commandline_search_history"); - liberator.options.resetPref("extensions.vimperator.quickmarks"); - }); -} + store = liberator.storage["quickmarks"]; + pref = liberator.options.getPref("extensions.vimperator.quickmarks") + .split("\n"); + while (pref.length > 0) + store.set(pref.shift(), pref.shift()); + + liberator.options.resetPref("extensions.vimperator.commandline_cmd_history"); + liberator.options.resetPref("extensions.vimperator.commandline_search_history"); + liberator.options.resetPref("extensions.vimperator.quickmarks"); +}); // also includes methods for dealing with keywords and search engines function Bookmarks() //{{{ From c64a3507a09172ce3795393dabae9e6c546ca48d Mon Sep 17 00:00:00 2001 From: anekos Date: Tue, 23 Dec 2008 08:01:50 +0900 Subject: [PATCH 08/31] More fix -> 6875dacf74649253574a9bd444cec86a0087f31a --- vimperator/content/bookmarks.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/vimperator/content/bookmarks.js b/vimperator/content/bookmarks.js index 299589a5..6c2546b0 100644 --- a/vimperator/content/bookmarks.js +++ b/vimperator/content/bookmarks.js @@ -33,20 +33,20 @@ liberator.registerObserver("load_options", function () { if (!liberator.modules.options.getPref("extensions.vimperator.commandline_cmd_history")) return; - let store = liberator.storage["history-command"]; - let pref = liberator.options.getPref("extensions.vimperator.commandline_cmd_history"); + let store = liberator.modules.storage["history-command"]; + let pref = liberator.modules.options.getPref("extensions.vimperator.commandline_cmd_history"); for (let [k, v] in Iterator(pref.split("\n"))) store.push(v); - store = liberator.storage["quickmarks"]; - pref = liberator.options.getPref("extensions.vimperator.quickmarks") + store = liberator.modules.storage["quickmarks"]; + pref = liberator.modules.options.getPref("extensions.vimperator.quickmarks") .split("\n"); while (pref.length > 0) store.set(pref.shift(), pref.shift()); - liberator.options.resetPref("extensions.vimperator.commandline_cmd_history"); - liberator.options.resetPref("extensions.vimperator.commandline_search_history"); - liberator.options.resetPref("extensions.vimperator.quickmarks"); + liberator.modules.options.resetPref("extensions.vimperator.commandline_cmd_history"); + liberator.modules.options.resetPref("extensions.vimperator.commandline_search_history"); + liberator.modules.options.resetPref("extensions.vimperator.quickmarks"); }); // also includes methods for dealing with keywords and search engines From db87ca56f807c1ff9f1ec071830a0c4e335f25ec Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Mon, 22 Dec 2008 19:42:38 -0500 Subject: [PATCH 09/31] Fix multiline-input --- common/content/ui.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/common/content/ui.js b/common/content/ui.js index d7fdc3b1..3f817e4c 100644 --- a/common/content/ui.js +++ b/common/content/ui.js @@ -518,8 +518,7 @@ function CommandLine() //{{{ // Whether the command line must be open. function commandShown() modes.main == modes.COMMAND_LINE && - !(modes.extended & modes.INPUT_MULTILINE) && - !(modes.extended & modes.OUTPUT_MULTILINE); + !(modes.extended & (modes.INPUT_MULTILINE | modes.OUTPUT_MULTILINE)); // sets the prompt - for example, : or / function setPrompt(val, highlightGroup) @@ -603,7 +602,7 @@ function CommandLine() //{{{ { let lines = multilineInputWidget.value.split("\n").length - 1; - multilineInputWidget.setAttribute("rows", Math.min(lines, 1)); + multilineInputWidget.setAttribute("rows", Math.max(lines, 1)); } // used for the :echo[err] commands @@ -1036,8 +1035,11 @@ function CommandLine() //{{{ // @param untilRegexp inputMultiline: function inputMultiline(untilRegexp, callbackFunc) { - // save the mode, because we need to restore it + // Kludge. + let cmd = !commandWidget.collapsed && this.command; modes.push(modes.COMMAND_LINE, modes.INPUT_MULTILINE); + if (cmd != false) + echoLine(cmd, this.HL_NORMAL); // save the arguments, they are needed in the event handler onEvent multilineRegexp = untilRegexp; From 352fc252b12bcf1637a6cc5ffc8dc280a18e2d33 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Mon, 22 Dec 2008 19:46:29 -0500 Subject: [PATCH 10/31] s/liberator.modules.// --- vimperator/content/bookmarks.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/vimperator/content/bookmarks.js b/vimperator/content/bookmarks.js index 6c2546b0..30747f9c 100644 --- a/vimperator/content/bookmarks.js +++ b/vimperator/content/bookmarks.js @@ -30,23 +30,23 @@ const DEFAULT_FAVICON = "chrome://mozapps/skin/places/defaultFavicon.png"; // Try to import older command line history, quick marks, etc. liberator.registerObserver("load_options", function () { - if (!liberator.modules.options.getPref("extensions.vimperator.commandline_cmd_history")) + if (!options.getPref("extensions.vimperator.commandline_cmd_history")) return; - let store = liberator.modules.storage["history-command"]; - let pref = liberator.modules.options.getPref("extensions.vimperator.commandline_cmd_history"); + let store = storage["history-command"]; + let pref = options.getPref("extensions.vimperator.commandline_cmd_history"); for (let [k, v] in Iterator(pref.split("\n"))) store.push(v); - store = liberator.modules.storage["quickmarks"]; - pref = liberator.modules.options.getPref("extensions.vimperator.quickmarks") + store = storage["quickmarks"]; + pref = options.getPref("extensions.vimperator.quickmarks") .split("\n"); while (pref.length > 0) store.set(pref.shift(), pref.shift()); - liberator.modules.options.resetPref("extensions.vimperator.commandline_cmd_history"); - liberator.modules.options.resetPref("extensions.vimperator.commandline_search_history"); - liberator.modules.options.resetPref("extensions.vimperator.quickmarks"); + options.resetPref("extensions.vimperator.commandline_cmd_history"); + options.resetPref("extensions.vimperator.commandline_search_history"); + options.resetPref("extensions.vimperator.quickmarks"); }); // also includes methods for dealing with keywords and search engines From 90d7eb0d1724e17a5502ad439ee6b4aa6650e36b Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Mon, 22 Dec 2008 19:53:16 -0500 Subject: [PATCH 11/31] Respond to "how would one knwo which classes to load where?" --- vimperator/content/config.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/vimperator/content/config.js b/vimperator/content/config.js index 812497e1..a2baffe4 100644 --- a/vimperator/content/config.js +++ b/vimperator/content/config.js @@ -149,6 +149,13 @@ const config = { //{{{ // load Vimperator specific modules // FIXME: Why aren't these listed in config.scripts? // FIXME: Why isn't this automatic? -> how would one know which classes to load where? --mst + // Something like: + // liberator.addModule("search", function Search() { ... + // for all modules, or something similar. For modules which + // require other modules, well, there's addObserver("load_foo", + // or we could just make sure that they're all sourced in order. + // The scripts could even just instantiate them themselves. + // --Kris liberator.loadModule("search", Search); liberator.loadModule("bookmarks", Bookmarks); liberator.loadModule("history", History); From feeccb23d2e1e5680effd7540ff6efde61ac57d9 Mon Sep 17 00:00:00 2001 From: Martin Stubenschrott Date: Tue, 23 Dec 2008 03:10:01 +0100 Subject: [PATCH 12/31] Undo certain parts from the unfortunate "service" commit, to unbreak Muttator. @Kris: Please try not to commit unconnected things at once, as it's much harder to revert such commits :( I'll have to revert the service -> Cc/Ci manually now, as I got lots of conflicts in reverting, and if i didn't, i wouldn't want to undo the other parts of that commit (like VIMPERATOR_RUNTIME or the added comments) --- common/content/completion.js | 4 ++- common/content/events.js | 5 ++-- common/content/io.js | 3 ++- common/content/liberator.js | 3 ++- common/content/options.js | 42 +++++++++++++++--------------- common/content/service.js | 45 ++++++++++++++++----------------- common/content/style.js | 4 +-- common/content/util.js | 6 +++++ vimperator/content/bookmarks.js | 11 ++++---- vimperator/content/config.js | 8 +++--- 10 files changed, 72 insertions(+), 59 deletions(-) diff --git a/common/content/completion.js b/common/content/completion.js index 60dc0af6..c3f349be 100644 --- a/common/content/completion.js +++ b/common/content/completion.js @@ -1651,7 +1651,9 @@ function Completion() //{{{ context.anchored = false; context.title = ["Firefox Preference", "Value"]; context.keys = { text: function (item) item, description: function (item) options.getPref(item) }; - context.completions = service["pref"].getChildList("", { value: 0 }); + context.completions = Cc["@mozilla.org/preferences-service;1"] + .getService(Ci.nsIPrefBranch) + .getChildList("", { value: 0 }); }, search: function search(context, noSuggest) diff --git a/common/content/events.js b/common/content/events.js index 7c7d486d..226d4483 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -1644,8 +1644,9 @@ function Events() //{{{ prefObserver: { register: function () { - this._branch = service["pref"].getBranch("") // better way to monitor all changes? - .QueryInterface(Ci.nsIPrefBranch2); + const prefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService); + this._branch = prefService.getBranch(""); // better way to monitor all changes? + this._branch.QueryInterface(Ci.nsIPrefBranch2); this._branch.addObserver("", this, false); }, diff --git a/common/content/io.js b/common/content/io.js index de7eb73e..1b7135e0 100644 --- a/common/content/io.js +++ b/common/content/io.js @@ -67,6 +67,7 @@ function IO() //{{{ const EXTENSION_NAME = config.name.toLowerCase(); // "vimperator" or "muttator" const downloadManager = Cc["@mozilla.org/download-manager;1"].createInstance(Ci.nsIDownloadManager); + const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); var processDir = service["directory"].get("CurWorkD", Ci.nsIFile); var cwd = processDir; @@ -777,7 +778,7 @@ lookup: liberator.echomsg("sourcing " + filename.quote(), 2); let str = ioManager.readFile(file); - let uri = service["io"].newFileURI(file); + let uri = ioService.newFileURI(file); // handle pure javascript files specially if (/\.js$/.test(filename)) diff --git a/common/content/liberator.js b/common/content/liberator.js index fd795a06..d3c6e5d3 100644 --- a/common/content/liberator.js +++ b/common/content/liberator.js @@ -1053,7 +1053,8 @@ const liberator = (function () //{{{ if (typeof msg == "object") msg = util.objectToString(msg, false); - service["console"].logStringMessage(config.name.toLowerCase() + ": " + msg); + const consoleService = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService); + consoleService.logStringMessage(config.name.toLowerCase() + ": " + msg); }, // open one or more URLs diff --git a/common/content/options.js b/common/content/options.js index 1e7b215e..48862381 100644 --- a/common/content/options.js +++ b/common/content/options.js @@ -303,6 +303,8 @@ function Options() //{{{ //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ + + const prefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); const SAVED = "liberator.saved."; @@ -330,27 +332,27 @@ function Options() //{{{ prefContexts[prefContexts.length - 1][name] = val; } - let type = service["pref"].getPrefType(name); + let type = prefService.getPrefType(name); switch (typeof value) { case "string": - if (type == service["pref"].PREF_INVALID || type == service["pref"].PREF_STRING) - service["pref"].setCharPref(name, value); - else if (type == service["pref"].PREF_INT) + if (type == prefService.PREF_INVALID || type == prefService.PREF_STRING) + prefService.setCharPref(name, value); + else if (type == prefService.PREF_INT) liberator.echoerr("E521: Number required after =: " + name + "=" + value); else liberator.echoerr("E474: Invalid argument: " + name + "=" + value); break; case "number": - if (type == service["pref"].PREF_INVALID || type == service["pref"].PREF_INT) - service["pref"].setIntPref(name, value); + if (type == prefService.PREF_INVALID || type == prefService.PREF_INT) + prefService.setIntPref(name, value); else liberator.echoerr("E474: Invalid argument: " + name + "=" + value); break; case "boolean": - if (type == service["pref"].PREF_INVALID || type == service["pref"].PREF_BOOL) - service["pref"].setBoolPref(name, value); - else if (type == service["pref"].PREF_INT) + if (type == prefService.PREF_INVALID || type == prefService.PREF_BOOL) + prefService.setBoolPref(name, value); + else if (type == prefService.PREF_INT) liberator.echoerr("E521: Number required after =: " + name + "=" + value); else liberator.echoerr("E474: Invalid argument: " + name + "=" + value); @@ -366,22 +368,22 @@ function Options() //{{{ if (forcedDefault != null) // this argument sets defaults for non-user settable options (like extensions.history.comp_history) defaultValue = forcedDefault; - let branch = defaultBranch ? service["pref"].getDefaultBranch("") : service["pref"]; - let type = service["pref"].getPrefType(name); + let branch = defaultBranch ? prefService.getDefaultBranch("") : prefService; + let type = prefService.getPrefType(name); try { switch (type) { - case service["pref"].PREF_STRING: + case prefService.PREF_STRING: let value = branch.getComplexValue(name, Ci.nsISupportsString).data; // try in case it's a localized string (will throw an exception if not) - if (!service["pref"].prefIsLocked(name) && !service["pref"].prefHasUserValue(name) && + if (!prefService.prefIsLocked(name) && !prefService.prefHasUserValue(name) && /^chrome:\/\/.+\/locale\/.+\.properties/.test(value)) value = branch.getComplexValue(name, Ci.nsIPrefLocalizedString).data; return value; - case service["pref"].PREF_INT: + case prefService.PREF_INT: return branch.getIntPref(name); - case service["pref"].PREF_BOOL: + case prefService.PREF_BOOL: return branch.getBoolPref(name); default: return defaultValue; @@ -786,7 +788,7 @@ function Options() //{{{ { completion.setFunctionCompleter(options.get, [function () ([o.name, o.description] for (o in options))]); completion.setFunctionCompleter([options.getPref, options.safeSetPref, options.setPref, options.resetPref, options.invertPref], - [function () service["pref"].getChildList("", { value: 0 }) + [function () prefService.getChildList("", { value: 0 }) .map(function (pref) [pref, ""])]); }); @@ -888,12 +890,12 @@ function Options() //{{{ if (!filter) filter = ""; - let prefArray = service["pref"].getChildList("", { value: 0 }); + let prefArray = prefService.getChildList("", { value: 0 }); prefArray.sort(); let prefs = function () { for each (let pref in prefArray) { - let userValue = service["pref"].prefHasUserValue(pref); + let userValue = prefService.prefHasUserValue(pref); if (onlyNonDefault && !userValue || pref.indexOf(filter) == -1) continue; @@ -988,7 +990,7 @@ function Options() //{{{ { try { - return service["pref"].clearUserPref(name); + return prefService.clearUserPref(name); } catch (e) { @@ -999,7 +1001,7 @@ function Options() //{{{ // this works only for booleans invertPref: function (name) { - if (service["pref"].getPrefType(name) == service["pref"].PREF_BOOL) + if (prefService.getPrefType(name) == prefService.PREF_BOOL) this.setPref(name, !this.getPref(name)); else liberator.echoerr("E488: Trailing characters: " + name + "!"); diff --git a/common/content/service.js b/common/content/service.js index 084a72b5..26fd1ab6 100644 --- a/common/content/service.js +++ b/common/content/service.js @@ -1,35 +1,34 @@ /** @scope modules */ -let (cc = function (class, iface, meth) { try { return Cc[class][meth || "getService"](iface) } catch (e) {} }) +let (cc = function (class, iface, meth) { try { return Components.classes[class][meth || "getService"](iface) } catch (e) {} }) { + // var Ci = Components.interfaces; // quick fix for muttator, will change/remove service.js anyway after the vacation + /** * Cached XPCOM services and instances. * * @singleton */ const service = { - appStartup: cc("@mozilla.org/toolkit/app-startup;1", Ci.nsIAppStartup), - autoCompleteSearch: cc("@mozilla.org/browser/global-history;2", Ci.nsIAutoCompleteSearch), - browserSearch: cc("@mozilla.org/browser/search-service;1", Ci.nsIBrowserSearchService), - cache: cc("@mozilla.org/network/cache-service;1", Ci.nsICacheService), - console: cc("@mozilla.org/consoleservice;1", Ci.nsIConsoleService), - directory: cc("@mozilla.org/file/directory_service;1", Ci.nsIProperties), - environment: cc("@mozilla.org/process/environment;1", Ci.nsIEnvironment), - extensionManager: cc("@mozilla.org/extensions/manager;1", Ci.nsIExtensionManager), - io: cc("@mozilla.org/network/io-service;1", Ci.nsIIOService).QueryInterface(Ci.nsIIOService2), - json: cc("@mozilla.org/dom/json;1", Ci.nsIJSON, "createInstance"), - observer: cc("@mozilla.org/observer-service;1", Ci.nsIObserverService), - profile: cc("@mozilla.org/toolkit/profile-service;1", Ci.nsIToolkitProfileService), - pref: cc("@mozilla.org/preferences-service;1", Ci.nsIPrefService) - .QueryInterface(Ci.nsIPrefBranch).QueryInterface(Ci.nsIPrefBranch2), - sessionStore: cc("@mozilla.org/browser/sessionstore;1", Ci.nsISessionStore), - subscriptLoader: cc("@mozilla.org/moz/jssubscript-loader;1", Ci.mozIJSSubScriptLoader), - threadManager: cc("@mozilla.org/thread-manager;1", Ci.nsIThreadManager), - windowMediator: cc("@mozilla.org/appshell/window-mediator;1", Ci.nsIWindowMediator), - windowWatcher: cc("@mozilla.org/embedcomp/window-watcher;1", Ci.nsIWindowWatcher), - getFile: function () Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile), - getFind: function () Cc["@mozilla.org/embedcomp/rangefind;1"].createInstance(Ci.nsIFind), - getProcess: function () Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess) + appStartup: cc("@mozilla.org/toolkit/app-startup;1", Components.interfaces.nsIAppStartup), + autoCompleteSearch: cc("@mozilla.org/browser/global-history;2", Components.interfaces.nsIAutoCompleteSearch), + browserSearch: cc("@mozilla.org/browser/search-service;1", Components.interfaces.nsIBrowserSearchService), + cache: cc("@mozilla.org/network/cache-service;1", Components.interfaces.nsICacheService), + console: cc("@mozilla.org/consoleservice;1", Components.interfaces.nsIConsoleService), + directory: cc("@mozilla.org/file/directory_service;1", Components.interfaces.nsIProperties), + environment: cc("@mozilla.org/process/environment;1", Components.interfaces.nsIEnvironment), + extensionManager: cc("@mozilla.org/extensions/manager;1", Components.interfaces.nsIExtensionManager), + json: cc("@mozilla.org/dom/json;1", Components.interfaces.nsIJSON, "createInstance"), + observer: cc("@mozilla.org/observer-service;1", Components.interfaces.nsIObserverService), + profile: cc("@mozilla.org/toolkit/profile-service;1", Components.interfaces.nsIToolkitProfileService), + sessionStore: cc("@mozilla.org/browser/sessionstore;1", Components.interfaces.nsISessionStore), + subscriptLoader: cc("@mozilla.org/moz/jssubscript-loader;1", Components.interfaces.mozIJSSubScriptLoader), + threadManager: cc("@mozilla.org/thread-manager;1", Components.interfaces.nsIThreadManager), + windowMediator: cc("@mozilla.org/appshell/window-mediator;1", Components.interfaces.nsIWindowMediator), + windowWatcher: cc("@mozilla.org/embedcomp/window-watcher;1", Components.interfaces.nsIWindowWatcher), + getFile: function () Cc["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile), + getFind: function () Cc["@mozilla.org/embedcomp/rangefind;1"].createInstance(Components.interfaces.nsIFind), + getProcess: function () Cc["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess) }; }; diff --git a/common/content/style.js b/common/content/style.js index 2459dbb4..6bdcf232 100644 --- a/common/content/style.js +++ b/common/content/style.js @@ -248,8 +248,8 @@ function Styles(name, store, serial) const util = modules.util; const sleep = liberator.sleep; const storage = modules.storage; - const consoleService = service["console"]; - const ios = service["io"]; + const consoleService = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService); + const ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); const sss = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService); const namespace = '@namespace html "' + XHTML + '";\n' + '@namespace xul "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";\n' + diff --git a/common/content/util.js b/common/content/util.js index 41b9d3f3..b6cf22f4 100644 --- a/common/content/util.js +++ b/common/content/util.js @@ -335,6 +335,12 @@ const util = { //{{{ return ary; }, + newURI: function (url) + { + const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); + return ioService.newURI(url, null, null); + }, + // if color = true it uses HTML markup to color certain items objectToString: function objectToString(object, color) { diff --git a/vimperator/content/bookmarks.js b/vimperator/content/bookmarks.js index 30747f9c..e0d525ee 100644 --- a/vimperator/content/bookmarks.js +++ b/vimperator/content/bookmarks.js @@ -60,7 +60,6 @@ function Bookmarks() //{{{ const bookmarksService = PlacesUtils.bookmarks; const taggingService = PlacesUtils.tagging; const searchService = service.browserSearch; - const ioService = service.io; const faviconService = Cc["@mozilla.org/browser/favicon-service;1"].getService(Ci.nsIFaviconService); const Bookmark = new Struct("url", "title", "icon", "keyword", "tags", "id"); @@ -91,7 +90,7 @@ function Bookmarks() //{{{ function loadBookmark(node) { - let uri = ioService.newURI(node.uri, null, null); + let uri = util.newURI(node.uri); let keyword = bookmarksService.getKeywordForBookmark(node.itemId); let tags = taggingService.getTagsForURI(uri, {}) || []; @@ -199,7 +198,7 @@ function Bookmarks() //{{{ if (bookmark) { if (property == "tags") - value = taggingService.getTagsForURI(ioService.newURI(bookmark.url, null, null), {}); + value = taggingService.getTagsForURI(util.newURI(bookmark.url), {}); if (property in bookmark) bookmark[property] = value; storage.fireEvent(name, "change", itemId); @@ -220,7 +219,7 @@ function Bookmarks() //{{{ { try { - return faviconService.getFaviconImageForPage(ioService.newURI(uri, null, null)).spec; + return faviconService.getFaviconImageForPage(util.newURI(uri)).spec; } catch (e) { @@ -487,7 +486,7 @@ function Bookmarks() //{{{ { try { - var uri = ioService.newURI(url, null, null); + var uri = util.newURI(url); return (bookmarksService.getBookmarkedURIFor(uri) != null); } catch (e) @@ -505,7 +504,7 @@ function Bookmarks() //{{{ var i = 0; try { - var uri = ioService.newURI(url, null, null); + var uri = util.newURI(url); var count = {}; var bmarks = bookmarksService.getBookmarkIdsForURI(uri, count); diff --git a/vimperator/content/config.js b/vimperator/content/config.js index a2baffe4..e69b2eec 100644 --- a/vimperator/content/config.js +++ b/vimperator/content/config.js @@ -427,13 +427,15 @@ const config = { //{{{ { setter: function (value) { - service.io.offline = !value; - gPrefService.setBoolPref("browser.offline", service.io.offline); + const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService2); + ioService.offline = !value; + gPrefService.setBoolPref("browser.offline", ioService.offline); return value; }, getter: function () { - return service.io.offline; + const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService2); + return ioService.offline; } }); From dba08286e822337520c607bd4e8cbf79c4c3b483 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Tue, 23 Dec 2008 01:30:33 +1100 Subject: [PATCH 13/31] Prefer let over var in Highlights and Bookmarks. --- common/content/style.js | 6 +-- vimperator/content/bookmarks.js | 70 ++++++++++++++++----------------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/common/content/style.js b/common/content/style.js index 6bdcf232..6388aadd 100644 --- a/common/content/style.js +++ b/common/content/style.js @@ -135,9 +135,9 @@ Highlights.prototype.CSS = 0) { commandline.echo("Removed bookmark: " + url, commandline.HL_NORMAL, commandline.FORCE_SINGLELINE); } else { - var title = buffer.title || url; - var extra = ""; + let title = buffer.title || url; + let extra = ""; if (title != url) extra = " (" + title + ")"; this.add(true, title, url); @@ -486,7 +486,7 @@ function Bookmarks() //{{{ { try { - var uri = util.newURI(url); + let uri = util.newURI(url); return (bookmarksService.getBookmarkedURIFor(uri) != null); } catch (e) @@ -501,12 +501,12 @@ function Bookmarks() //{{{ if (!url) return 0; - var i = 0; + let i = 0; try { - var uri = util.newURI(url); + let uri = util.newURI(url); var count = {}; - var bmarks = bookmarksService.getBookmarkIdsForURI(uri, count); + let bmarks = bookmarksService.getBookmarkIdsForURI(uri, count); for (; i < bmarks.length; i++) bookmarksService.removeItem(bmarks[i]); @@ -529,18 +529,18 @@ function Bookmarks() //{{{ // also ensures that each search engine has a Vimperator-friendly alias getSearchEngines: function getSearchEngines() { - var searchEngines = []; - var firefoxEngines = searchService.getVisibleEngines({}); + let searchEngines = []; + let firefoxEngines = searchService.getVisibleEngines({}); for (let [,engine] in Iterator(firefoxEngines)) { - var alias = engine.alias; + let alias = engine.alias; if (!alias || !/^[a-z0-9_-]+$/.test(alias)) alias = engine.name.replace(/^\W*([a-zA-Z_-]+).*/, "$1").toLowerCase(); if (!alias) alias = "search"; // for search engines which we can't find a suitable alias // make sure we can use search engines which would have the same alias (add numbers at the end) - var newAlias = alias; + let newAlias = alias; for (let j = 1; j <= 10; j++) // <=10 is intentional { if (!searchEngines.some(function (item) item[0] == newAlias)) @@ -603,9 +603,9 @@ function Bookmarks() //{{{ // if the search also requires a postData, [url, postData] is returned getSearchURL: function getSearchURL(text, useDefsearch) { - var url = null; - var aPostDataRef = {}; - var searchString = (useDefsearch ? options["defsearch"] + " " : "") + text; + let url = null; + let aPostDataRef = {}; + let searchString = (useDefsearch ? options["defsearch"] + " " : "") + text; // we need to make sure our custom alias have been set, even if the user // did not :open once before @@ -702,7 +702,7 @@ function History() //{{{ { if (args) { - var sh = window.getWebNavigation().sessionHistory; + let sh = window.getWebNavigation().sessionHistory; for (let i = sh.index - 1; i >= 0; i--) { if (sh.getEntryAtIndex(i, false).URI.spec == args) @@ -748,7 +748,7 @@ function History() //{{{ { if (args) { - var sh = window.getWebNavigation().sessionHistory; + let sh = window.getWebNavigation().sessionHistory; for (let i in util.range(sh.index + 1, sh.count)) { if (sh.getEntryAtIndex(i, false).URI.spec == args) @@ -961,7 +961,7 @@ function QuickMarks() //{{{ "Mark a URL with a letter for quick access", function (args) { - var matches = args.string.match(/^([a-zA-Z0-9])(?:\s+(.+))?$/); + let matches = args.string.match(/^([a-zA-Z0-9])(?:\s+(.+))?$/); if (!matches) liberator.echoerr("E488: Trailing characters"); else if (!matches[2]) @@ -984,7 +984,7 @@ function QuickMarks() //{{{ return; } - var filter = args.replace(/[^a-zA-Z0-9]/g, ""); + let filter = args.replace(/[^a-zA-Z0-9]/g, ""); quickmarks.list(filter); }); @@ -1002,7 +1002,7 @@ function QuickMarks() //{{{ remove: function remove(filter) { - var pattern = RegExp("[" + filter.replace(/\s+/g, "") + "]"); + let pattern = RegExp("[" + filter.replace(/\s+/g, "") + "]"); for (let [qmark,] in qmarks) { @@ -1018,7 +1018,7 @@ function QuickMarks() //{{{ jumpTo: function jumpTo(qmark, where) { - var url = qmarks.get(qmark); + let url = qmarks.get(qmark); if (url) liberator.open(url, where); @@ -1028,11 +1028,11 @@ function QuickMarks() //{{{ list: function list(filter) { - var marks = [key for ([key, val] in qmarks)]; + let marks = [key for ([key, val] in qmarks)]; // This was a lot nicer without the lambda... - var lowercaseMarks = marks.filter(function (x) /[a-z]/.test(x)).sort(); - var uppercaseMarks = marks.filter(function (x) /[A-Z]/.test(x)).sort(); - var numberMarks = marks.filter(function (x) /[0-9]/.test(x)).sort(); + let lowercaseMarks = marks.filter(function (x) /[a-z]/.test(x)).sort(); + let uppercaseMarks = marks.filter(function (x) /[A-Z]/.test(x)).sort(); + let numberMarks = marks.filter(function (x) /[0-9]/.test(x)).sort(); marks = Array.concat(lowercaseMarks, uppercaseMarks, numberMarks); From 483b3f4b008c5950b064a04279563af288e93409 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Tue, 23 Dec 2008 01:30:52 +1100 Subject: [PATCH 14/31] Document return value of util.cloneObject. --- common/content/util.js | 1 + 1 file changed, 1 insertion(+) diff --git a/common/content/util.js b/common/content/util.js index b6cf22f4..ac63871e 100644 --- a/common/content/util.js +++ b/common/content/util.js @@ -121,6 +121,7 @@ const util = { //{{{ * Returns a shallow copy of obj. * * @param {Object} obj + * @returns {Object} */ cloneObject: function cloneObject(obj) { From 68a28b7e14cb6ec248f994303cf0ad36513de63c Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Tue, 23 Dec 2008 01:31:55 +1100 Subject: [PATCH 15/31] Fix return signature of buffer.{followLink,focusElement}. --- common/content/buffer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/content/buffer.js b/common/content/buffer.js index d773b842..9cbab80d 100644 --- a/common/content/buffer.js +++ b/common/content/buffer.js @@ -1008,7 +1008,7 @@ function Buffer() //{{{ if (elemTagName == "frame" || elemTagName == "iframe") { elem.contentWindow.focus(); - return false; + return; } elem.focus(); @@ -1109,7 +1109,7 @@ function Buffer() //{{{ if (localName == "frame" || localName == "iframe") // broken? { elem.contentWindow.focus(); - return false; + return; } else if (localName == "area") // for imagemap { From 253346dbc3605583fa81411b86ae045d5a628a55 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Tue, 23 Dec 2008 01:32:24 +1100 Subject: [PATCH 16/31] Remove trailing commas from object initializers. --- common/content/hints.js | 2 +- common/content/options.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common/content/hints.js b/common/content/hints.js index 35b81fd4..edca3fb6 100644 --- a/common/content/hints.js +++ b/common/content/hints.js @@ -80,7 +80,7 @@ function Hints() //{{{ T: Mode("Open new tab based on hint", function (elem, loc) commandline.open(":", "tabopen " + loc, modes.EX)), W: Mode("Open new window based on hint", function (elem, loc) commandline.open(":", "winopen " + loc, modes.EX)), y: Mode("Yank hint location", function (elem, loc) util.copyToClipboard(loc, true)), - Y: Mode("Yank hint description", function (elem) util.copyToClipboard(elem.textContent || "", true), extended), + Y: Mode("Yank hint description", function (elem) util.copyToClipboard(elem.textContent || "", true), extended) }; // reset all important variables diff --git a/common/content/options.js b/common/content/options.js index 48862381..43c17d62 100644 --- a/common/content/options.js +++ b/common/content/options.js @@ -1029,7 +1029,7 @@ function Options() //{{{ { this.popContext(); } - }, + } }; //}}} }; //}}} From 99384f1dadf55cd6999739254b3c0bfdaf6b91b2 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Tue, 23 Dec 2008 01:42:27 +1100 Subject: [PATCH 17/31] Fix return signature of tabs.tabStrip and showtabline's completer. --- common/content/tabs.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/common/content/tabs.js b/common/content/tabs.js index 64b47a02..3341a0ac 100644 --- a/common/content/tabs.js +++ b/common/content/tabs.js @@ -123,7 +123,7 @@ function Tabs() //{{{ let tabStrip = tabs.tabStrip; if (!tabStrip) - return; + return options['showtabline']; // XXX if (value == 0) { @@ -689,10 +689,14 @@ function Tabs() //{{{ get tabStrip() { + let tabStrip = null; + if (config.hostApplication == "Firefox") - return getBrowser().mStrip.getElementsByClassName("tabbrowser-tabs")[0]; + tabStrip = getBrowser().mStrip.getElementsByClassName("tabbrowser-tabs")[0]; else if (config.hostApplication == "Thunderbird") - return getBrowser().mStrip; + tabStrip = getBrowser().mStrip; + + return tabStrip; }, // @returns the index of the currently selected tab starting with 0 From f859d73149a103d331e2edf0fe72f5604b5e4c8e Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Tue, 23 Dec 2008 22:30:55 +1100 Subject: [PATCH 18/31] Fix return signature of incrementURL. --- vimperator/content/config.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/vimperator/content/config.js b/vimperator/content/config.js index e69b2eec..7a49393c 100644 --- a/vimperator/content/config.js +++ b/vimperator/content/config.js @@ -132,14 +132,17 @@ const config = { //{{{ { let matches = buffer.URL.match(/(.*?)(\d+)(\D*)$/); if (!matches) - return liberator.beep(); + { + liberator.beep(); + return; + } let [, pre, number, post] = matches; let newNumber = parseInt(number, 10) + count; let newNumberStr = String(newNumber > 0 ? newNumber : 0); if (number.match(/^0/)) // add 0009 should become 0010 { - while(newNumberStr.length < number.length) + while (newNumberStr.length < number.length) newNumberStr = "0" + newNumberStr; } From cf9cb136fc3954675ace7da85144782d436c2893 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Tue, 23 Dec 2008 22:33:06 +1100 Subject: [PATCH 19/31] Whitespace fixes. --- common/content/commands.js | 4 ++-- common/content/completion.js | 6 +++--- common/content/options.js | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/common/content/commands.js b/common/content/commands.js index 5df3818e..6e74f680 100644 --- a/common/content/commands.js +++ b/common/content/commands.js @@ -149,7 +149,7 @@ Command.prototype = { * executed with a trailing !. * @param {number} count @deprecated Whether this command was * executed a leading count. - * @param modifiers Any modifiers to be passed to + * @param modifiers Any modifiers to be passed to * {@link action} */ execute: function (args, bang, count, modifiers) @@ -856,7 +856,7 @@ function Commands() //{{{ return completer.apply(this, Array.slice(arguments)); } } - else + else { completeFunc = function () completion[completeOptionMap[completeOpt]].apply(this, Array.slice(arguments)); } diff --git a/common/content/completion.js b/common/content/completion.js index c3f349be..a6bea8f0 100644 --- a/common/content/completion.js +++ b/common/content/completion.js @@ -28,7 +28,7 @@ the terms of any one of the MPL, the GPL or the LGPL. /** @scope modules */ -/** +/** * Creates a new completion context. * * @class A class to provide contexts for command completion. @@ -65,7 +65,7 @@ function CompletionContext(editor, name, offset) //{{{ else self.contexts[name] = this; - /** + /** * @property {CompletionContext} This context's parent. {null} when this is a top-level context. */ self.parent = parent; @@ -497,7 +497,7 @@ CompletionContext.prototype = { * advanced to match. If {@link #quote} is non-null, its prefix and suffix * are set to the null-string. * - * This function is still imperfect for quoted strings. When + * This function is still imperfect for quoted strings. When * {@link #quote} is non-null, it adjusts the count based on the quoted * size of the count-character substring of the filter, which is * accurate so long as unquoting and quoting a string will always map to diff --git a/common/content/options.js b/common/content/options.js index 43c17d62..b9aa8d66 100644 --- a/common/content/options.js +++ b/common/content/options.js @@ -303,7 +303,7 @@ function Options() //{{{ //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - + const prefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); const SAVED = "liberator.saved."; From 19b5905c9857612cbf2f7889baf83176e45d13ba Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Tue, 23 Dec 2008 22:50:53 +1100 Subject: [PATCH 20/31] Fix BookmarkAdd autocommand keyword expansion. --- vimperator/content/bookmarks.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vimperator/content/bookmarks.js b/vimperator/content/bookmarks.js index ac466975..31d861f7 100644 --- a/vimperator/content/bookmarks.js +++ b/vimperator/content/bookmarks.js @@ -93,8 +93,11 @@ function Bookmarks() //{{{ let uri = util.newURI(node.uri); let keyword = bookmarksService.getKeywordForBookmark(node.itemId); let tags = taggingService.getTagsForURI(uri, {}) || []; + let bmark = new Bookmark(node.uri, node.title, node.icon && node.icon.spec, keyword, tags, node.itemId); - return bookmarks.push(new Bookmark(node.uri, node.title, node.icon && node.icon.spec, keyword, tags, node.itemId)); + bookmarks.push(bmark); + + return bmark; } function readBookmark(id) From 0bfda57eff69439b4e294ddae01c08385447a52c Mon Sep 17 00:00:00 2001 From: anekos Date: Tue, 23 Dec 2008 21:07:51 +0900 Subject: [PATCH 21/31] Fix: getSearchEngines raise a error, if iconURI of a engine has not been defined. --- vimperator/content/bookmarks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vimperator/content/bookmarks.js b/vimperator/content/bookmarks.js index 31d861f7..69a7edb0 100644 --- a/vimperator/content/bookmarks.js +++ b/vimperator/content/bookmarks.js @@ -555,7 +555,7 @@ function Bookmarks() //{{{ if (engine.alias != newAlias) engine.alias = newAlias; - searchEngines.push([engine.alias, engine.description, engine.iconURI.spec]); + searchEngines.push([engine.alias, engine.description, engine.iconURI && engine.iconURI.spec]); } return searchEngines; From 89743f543536b3d5aafd6cc0d8fcf9b1f0ffbf68 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Tue, 23 Dec 2008 23:32:56 +1100 Subject: [PATCH 22/31] Fix missing vimperator help logo. --- vimperator/content/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vimperator/content/config.js b/vimperator/content/config.js index 7a49393c..8a531367 100644 --- a/vimperator/content/config.js +++ b/vimperator/content/config.js @@ -174,7 +174,7 @@ const config = { //{{{ let img = Image(); img.src = "chrome://vimperator/content/vimperator.png"; img.onload = function () { - styles.addSheet("logo", "chrome://liberator/locale/*", + styles.addSheet(true, "logo", "chrome://liberator/locale/*", ".vimperator-logo {" + <> display: inline-block; background: url({img.src}); From d225b8908be820b256d81d4a8b29c2222d249dd6 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Tue, 23 Dec 2008 14:12:08 -0500 Subject: [PATCH 23/31] Fix :h --- common/content/liberator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/content/liberator.js b/common/content/liberator.js index d3c6e5d3..e6470186 100644 --- a/common/content/liberator.js +++ b/common/content/liberator.js @@ -950,7 +950,7 @@ const liberator = (function () //{{{ { if (item[0] == topic) return format(item); - else if (partialMatch == -1 && item[0].indexOf(topic) > -1) + else if (!partialMatch && item[0].indexOf(topic) > -1) { partialMatch = item; } From 1969caca06e6d9254384fccbee3212f558765fb2 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Tue, 23 Dec 2008 14:15:14 -0500 Subject: [PATCH 24/31] Handle bad help tag links better --- common/content/help.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/content/help.js b/common/content/help.js index 3ae6d96e..c2ee6b87 100644 --- a/common/content/help.js +++ b/common/content/help.js @@ -5,7 +5,7 @@ const win = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] const liberator = win.liberator; let page = liberator.findHelp(decodeURIComponent(document.location.search.substr(1))); -let url = "chrome://liberator/locale/" + page; +let url = page ? "chrome://liberator/locale/" + page : content.history.previous; win.getBrowser().loadURIWithFlags(url, Components.interfaces.nsIWebNavigation.LOAD_FLAGS_REPLACE_HISTORY, null, null, null); From aa27e686c8732361d86490117a8ad69fb7ba0ee5 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Tue, 23 Dec 2008 14:17:15 -0500 Subject: [PATCH 25/31] Fix :mkv for options with white space --- common/content/options.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/content/options.js b/common/content/options.js index b9aa8d66..558bedc6 100644 --- a/common/content/options.js +++ b/common/content/options.js @@ -743,8 +743,8 @@ function Options() //{{{ serial: function () [ { command: this.name, - literalArg: opt.type == "boolean" ? (opt.value ? "" : "no") + opt.name - : opt.name + "=" + opt.value + arguments: [opt.type == "boolean" ? (opt.value ? "" : "no") + opt.name + : opt.name + "=" + opt.value] } for (opt in options) if (!opt.getter && opt.value != opt.defaultValue && (opt.scope & options.OPTION_SCOPE_GLOBAL)) From 89698e3e050feb9876adaf01db6c7b6dee4697e3 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Tue, 23 Dec 2008 15:07:48 -0500 Subject: [PATCH 26/31] s/service[(".*?")]/services.get(\1)/g; s/service.get(\w+)/'services.create("' + lcfirst($1) + '")'/ge --- common/content/buffer.js | 4 +- common/content/completion.js | 14 +++--- common/content/events.js | 5 +- common/content/find.js | 2 +- common/content/io.js | 28 +++++------ common/content/liberator-overlay.js | 2 +- common/content/liberator.js | 47 +++++++++---------- common/content/options.js | 49 ++++++++++--------- common/content/service.js | 34 -------------- common/content/services.js | 73 +++++++++++++++++++++++++++++ common/content/tabs.js | 8 ++-- common/content/ui.js | 4 +- vimperator/content/bookmarks.js | 9 ++-- 13 files changed, 153 insertions(+), 126 deletions(-) delete mode 100644 common/content/service.js create mode 100644 common/content/services.js diff --git a/common/content/buffer.js b/common/content/buffer.js index 9cbab80d..fd750f6e 100644 --- a/common/content/buffer.js +++ b/common/content/buffer.js @@ -751,8 +751,8 @@ function Buffer() //{{{ { try { - var cacheEntryDescriptor = service["cache"].createSession(proto, 0, true) - .openCacheEntry(cacheKey, ACCESS_READ, false); + var cacheEntryDescriptor = services.get("cache").createSession(proto, 0, true) + .openCacheEntry(cacheKey, ACCESS_READ, false); break; } catch (e) {} diff --git a/common/content/completion.js b/common/content/completion.js index a6bea8f0..fd465199 100644 --- a/common/content/completion.js +++ b/common/content/completion.js @@ -1551,7 +1551,7 @@ function Completion() //{{{ location: function location(context) { - if (!service["autoCompleteSearch"]) + if (!services.get("autoCompleteSearch")) return context.anchored = false; context.title = ["Smart Completions"]; @@ -1567,8 +1567,8 @@ function Completion() //{{{ for (i in util.range(0, result.matchCount)) ]; }); - service["autoCompleteSearch"].stopSearch(); - service["autoCompleteSearch"].startSearch(context.filter, "", context.result, { + services.get("autoCompleteSearch").stopSearch(); + services.get("autoCompleteSearch").startSearch(context.filter, "", context.result, { onSearchResult: function onSearchResult(search, result) { context.result = result; @@ -1651,9 +1651,7 @@ function Completion() //{{{ context.anchored = false; context.title = ["Firefox Preference", "Value"]; context.keys = { text: function (item) item, description: function (item) options.getPref(item) }; - context.completions = Cc["@mozilla.org/preferences-service;1"] - .getService(Ci.nsIPrefBranch) - .getChildList("", { value: 0 }); + context.completions = services.get("pref").getChildList("", { value: 0 }); }, search: function search(context, noSuggest) @@ -1704,7 +1702,7 @@ function Completion() //{{{ let completions = []; engineList.forEach(function (name) { - let engine = service["browserSearch"].getEngineByAlias(name); + let engine = services.get("browserSearch").getEngineByAlias(name); if (!engine) return; let [,word] = /^\s*(\S+)/.exec(context.filter) || []; @@ -1727,7 +1725,7 @@ function Completion() //{{{ context.title = ["Shell Command", "Path"]; context.generate = function () { - let dirNames = service["environment"].get("PATH").split(RegExp(liberator.has("Win32") ? ";" : ":")); + let dirNames = services.get("environment").get("PATH").split(RegExp(liberator.has("Win32") ? ";" : ":")); let commands = []; for (let [,dirName] in Iterator(dirNames)) diff --git a/common/content/events.js b/common/content/events.js index 226d4483..630de130 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -1644,9 +1644,8 @@ function Events() //{{{ prefObserver: { register: function () { - const prefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService); - this._branch = prefService.getBranch(""); // better way to monitor all changes? - this._branch.QueryInterface(Ci.nsIPrefBranch2); + // better way to monitor all changes? + this._branch = services.get("pref").getBranch("").QueryInterface(Ci.nsIPrefBranch2); this._branch.addObserver("", this, false); }, diff --git a/common/content/find.js b/common/content/find.js index 09f02a43..8e67fbb4 100644 --- a/common/content/find.js +++ b/common/content/find.js @@ -138,7 +138,7 @@ function Search() //{{{ var highlightObj = { search: function (aWord, matchCase) { - var finder = service.getFind(); + var finder = services.create("find"); if (matchCase !== undefined) finder.caseSensitive = matchCase; diff --git a/common/content/io.js b/common/content/io.js index 1b7135e0..8254151d 100644 --- a/common/content/io.js +++ b/common/content/io.js @@ -69,7 +69,7 @@ function IO() //{{{ const downloadManager = Cc["@mozilla.org/download-manager;1"].createInstance(Ci.nsIDownloadManager); const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); - var processDir = service["directory"].get("CurWorkD", Ci.nsIFile); + var processDir = services.get("directory").get("CurWorkD", Ci.nsIFile); var cwd = processDir; var oldcwd = null; @@ -77,7 +77,7 @@ function IO() //{{{ var scriptNames = []; // default option values - var cdpath = "," + (service["environment"].get("CDPATH").replace(/[:;]/g, ",") || ","); + var cdpath = "," + (services.get("environment").get("CDPATH").replace(/[:;]/g, ",") || ","); var shell, shellcmdflag; if (WINDOWS) @@ -89,7 +89,7 @@ function IO() //{{{ } else { - shell = service["environment"].get("SHELL") || "sh"; + shell = services.get("environment").get("SHELL") || "sh"; shellcmdflag = "-c"; } @@ -132,7 +132,7 @@ function IO() //{{{ { try { - service.getFile().initWithPath(path); + services.create("file").initWithPath(path); return true; } catch (e) @@ -480,7 +480,7 @@ function IO() //{{{ // also expands relative paths getFile: function (path, noCheckPWD) { - let file = service.getFile(); + let file = services.create("file"); if (/file:\/\//.test(path)) { @@ -521,7 +521,7 @@ function IO() //{{{ break; } - let file = service["directory"].get("TmpD", Ci.nsIFile); + let file = services.get("directory").get("TmpD", Ci.nsIFile); file.append(tmpName); file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0600); @@ -627,7 +627,7 @@ function IO() //{{{ } else { - let dirs = service["environment"].get("PATH").split(WINDOWS ? ";" : ":"); + let dirs = services.get("environment").get("PATH").split(WINDOWS ? ";" : ":"); // Windows tries the cwd first TODO: desirable? if (WINDOWS) dirs = [io.getCurrentDirectory().path].concat(dirs); @@ -645,7 +645,7 @@ lookup: // automatically try to add the executable path extensions on windows if (WINDOWS) { - let extensions = service["environment"].get("PATHEXT").split(";"); + let extensions = services.get("environment").get("PATHEXT").split(";"); for (let [,extension] in Iterator(extensions)) { file = joinPaths(dir, program + extension); @@ -664,7 +664,7 @@ lookup: return -1; } - let process = service.getProcess(); + let process = services.create("process"); process.init(file); process.run(blocking, args, args.length); @@ -922,7 +922,7 @@ lookup: }; //}}} -IO.__defineGetter__("runtimePath", function () service["environment"].get(config.name.toUpperCase() + "_RUNTIME") || +IO.__defineGetter__("runtimePath", function () services.get("environment").get(config.name.toUpperCase() + "_RUNTIME") || "~/" + (liberator.has("Win32") ? "" : ".") + config.name.toLowerCase()); IO.expandPath = function (path, relative) @@ -939,7 +939,7 @@ IO.expandPath = function (path, relative) function expand(path) path.replace( !WINDOWS ? /\$(\w+)\b|\${(\w+)}/g : /\$(\w+)\b|\${(\w+)}|%(\w+)%/g, - function (m, n1, n2, n3) service["environment"].get(n1 || n2 || n3) || m + function (m, n1, n2, n3) services.get("environment").get(n1 || n2 || n3) || m ); path = expand(path); @@ -947,12 +947,12 @@ IO.expandPath = function (path, relative) if (!relative && (WINDOWS ? /^~(?:$|\\)/ : /^~(?:$|\/)/).test(path)) { // Try $HOME first, on all systems - let home = service["environment"].get("HOME"); + let home = services.get("environment").get("HOME"); // Windows has its own ideosyncratic $HOME variables. if (!home && WINDOWS) - home = service["environment"].get("USERPROFILE") || - service["environment"].get("HOMEDRIVE") + service["environment"].get("HOMEPATH"); + home = services.get("environment").get("USERPROFILE") || + services.get("environment").get("HOMEDRIVE") + services.get("environment").get("HOMEPATH"); path = home + path.substr(1); } diff --git a/common/content/liberator-overlay.js b/common/content/liberator-overlay.js index eb60e48f..73431da4 100644 --- a/common/content/liberator-overlay.js +++ b/common/content/liberator-overlay.js @@ -31,7 +31,7 @@ let prefix = [BASE]; - ["service.js", + ["services.js", "liberator.js", "config.js", "util.js", diff --git a/common/content/liberator.js b/common/content/liberator.js index e6470186..27ec275c 100644 --- a/common/content/liberator.js +++ b/common/content/liberator.js @@ -28,11 +28,6 @@ the terms of any one of the MPL, the GPL or the LGPL. /** @scope modules */ -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cr = Components.results; -const Cu = Components.utils; - Cu.import("resource://gre/modules/XPCOMUtils.jsm"); const plugins = {}; @@ -684,18 +679,18 @@ const liberator = (function () //{{{ return false; // so you can do: if (...) return liberator.beep(); }, - newThread: function () service["threadManager"].newThread(0), + newThread: function () services.get("threadManager").newThread(0), callAsync: function (thread, self, func) { - thread = thread || service["threadManager"].newThread(0); + thread = thread || services.get("threadManager").newThread(0); thread.dispatch(new Runnable(self, func, Array.slice(arguments, 3)), thread.DISPATCH_NORMAL); }, // be sure to call GUI related methods like alert() or dump() ONLY in the main thread callFunctionInThread: function (thread, func) { - thread = thread || service["threadManager"].newThread(0); + thread = thread || services.get("threadManager").newThread(0); // DISPATCH_SYNC is necessary, otherwise strange things will happen thread.dispatch(new Runnable(null, func, Array.slice(arguments, 2)), thread.DISPATCH_SYNC); @@ -767,7 +762,7 @@ const liberator = (function () //{{{ loadScript: function (uri, context) { - service["subscriptLoader"].loadSubScript(uri, context); + services.get("subscriptLoader").loadSubScript(uri, context); }, eval: function (str, context) @@ -901,7 +896,7 @@ const liberator = (function () //{{{ // if clearFocusedElement, also blur a focused link focusContent: function (clearFocusedElement) { - if (window != service["windowWatcher"].activeWindow) + if (window != services.get("windowWatcher").activeWindow) return; let elem = config.mainWidget || window.content; @@ -934,7 +929,7 @@ const liberator = (function () //{{{ hasExtension: function (name) { - let extensions = service["extensionManager"].getItemList(Ci.nsIUpdateItem.TYPE_EXTENSION, {}); + let extensions = services.get("extensionManager").getItemList(Ci.nsIUpdateItem.TYPE_EXTENSION, {}); return extensions.some(function (e) e.name == name); }, @@ -1112,8 +1107,8 @@ const liberator = (function () //{{{ case liberator.NEW_WINDOW: window.open(); - service["windowMediator"].getMostRecentWindow("navigator:browser") - .loadURI(url, null, postdata); + services.get("windowMediator").getMostRecentWindow("navigator:browser") + .loadURI(url, null, postdata); break; default: @@ -1154,7 +1149,7 @@ const liberator = (function () //{{{ options.setPref("browser.startup.page", 1); // start with default homepage session if (force) - service["appStartup"].quit(Ci.nsIAppStartup.eForceQuit); + services.get("appStartup").quit(Ci.nsIAppStartup.eForceQuit); else window.goQuitApplication(); }, @@ -1184,24 +1179,24 @@ const liberator = (function () //{{{ { // notify all windows that an application quit has been requested. var cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool); - service["observer"].notifyObservers(cancelQuit, "quit-application-requested", null); + services.get("observer").notifyObservers(cancelQuit, "quit-application-requested", null); // something aborted the quit process. if (cancelQuit.data) return; // notify all windows that an application quit has been granted. - service["observer"].notifyObservers(null, "quit-application-granted", null); + services.get("observer").notifyObservers(null, "quit-application-granted", null); // enumerate all windows and call shutdown handlers - let windows = service["windowMediator"].getEnumerator(null); + let windows = services.get("windowMediator").getEnumerator(null); while (windows.hasMoreElements()) { let win = windows.getNext(); if (("tryToClose" in win) && !win.tryToClose()) return; } - service["appStartup"].quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit); + services.get("appStartup").quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit); }, // TODO: move to {muttator,vimperator,...}.js @@ -1228,10 +1223,10 @@ const liberator = (function () //{{{ try { - let infoPath = service.getFile(); + let infoPath = services.create("file"); infoPath.initWithPath(IO.expandPath(IO.runtimePath.replace(/,.*/, ""))); infoPath.append("info"); - infoPath.append(service["profile"].selectedProfile.name); + infoPath.append(services.get("profile").selectedProfile.name); storage.infoPath = infoPath; } catch (e) @@ -1280,7 +1275,7 @@ const liberator = (function () //{{{ // make sourcing asynchronous, otherwise commands that open new tabs won't work setTimeout(function () { - let init = service["environment"].get(config.name.toUpperCase() + "_INIT"); + let init = services.get("environment").get(config.name.toUpperCase() + "_INIT"); if (init) liberator.execute(init); else @@ -1337,7 +1332,7 @@ const liberator = (function () //{{{ sleep: function (delay) { - let mainThread = service["threadManager"].mainThread; + let mainThread = services.get("threadManager").mainThread; let end = Date.now() + delay; while (Date.now() < end) @@ -1347,8 +1342,8 @@ const liberator = (function () //{{{ callInMainThread: function (callback, self) { - let mainThread = service["threadManager"].mainThread; - if (!service["threadManager"].isMainThread) + let mainThread = services.get("threadManager").mainThread; + if (!services.get("threadManager").isMainThread) mainThread.dispatch({ run: callback.call(self) }, mainThread.DISPATCH_NORMAL); else callback.call(self); @@ -1356,7 +1351,7 @@ const liberator = (function () //{{{ threadYield: function (flush, interruptable) { - let mainThread = service["threadManager"].mainThread; + let mainThread = services.get("threadManager").mainThread; liberator.interrupted = false; do { @@ -1396,7 +1391,7 @@ const liberator = (function () //{{{ get windows() { let windows = []; - let enumerator = service["windowMediator"].getEnumerator("navigator:browser"); + let enumerator = services.get("windowMediator").getEnumerator("navigator:browser"); while (enumerator.hasMoreElements()) windows.push(enumerator.getNext()); diff --git a/common/content/options.js b/common/content/options.js index 558bedc6..9877c741 100644 --- a/common/content/options.js +++ b/common/content/options.js @@ -304,8 +304,6 @@ function Options() //{{{ ////////////////////// PRIVATE SECTION ///////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - const prefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); - const SAVED = "liberator.saved."; const optionHash = {}; @@ -332,27 +330,27 @@ function Options() //{{{ prefContexts[prefContexts.length - 1][name] = val; } - let type = prefService.getPrefType(name); + let type = services.get("pref").getPrefType(name); switch (typeof value) { case "string": - if (type == prefService.PREF_INVALID || type == prefService.PREF_STRING) - prefService.setCharPref(name, value); - else if (type == prefService.PREF_INT) + if (type == Ci.nsIPrefBranch.PREF_INVALID || type == Ci.nsIPrefBranch.PREF_STRING) + services.get("pref").setCharPref(name, value); + else if (type == Ci.nsIPrefBranch.PREF_INT) liberator.echoerr("E521: Number required after =: " + name + "=" + value); else liberator.echoerr("E474: Invalid argument: " + name + "=" + value); break; case "number": - if (type == prefService.PREF_INVALID || type == prefService.PREF_INT) - prefService.setIntPref(name, value); + if (type == Ci.nsIPrefBranch.PREF_INVALID || type == Ci.nsIPrefBranch.PREF_INT) + services.get("pref").setIntPref(name, value); else liberator.echoerr("E474: Invalid argument: " + name + "=" + value); break; case "boolean": - if (type == prefService.PREF_INVALID || type == prefService.PREF_BOOL) - prefService.setBoolPref(name, value); - else if (type == prefService.PREF_INT) + if (type == Ci.nsIPrefBranch.PREF_INVALID || type == Ci.nsIPrefBranch.PREF_BOOL) + services.get("pref").setBoolPref(name, value); + else if (type == Ci.nsIPrefBranch.PREF_INT) liberator.echoerr("E521: Number required after =: " + name + "=" + value); else liberator.echoerr("E474: Invalid argument: " + name + "=" + value); @@ -368,22 +366,22 @@ function Options() //{{{ if (forcedDefault != null) // this argument sets defaults for non-user settable options (like extensions.history.comp_history) defaultValue = forcedDefault; - let branch = defaultBranch ? prefService.getDefaultBranch("") : prefService; - let type = prefService.getPrefType(name); + let branch = defaultBranch ? services.get("pref").getDefaultBranch("") : services.get("pref"); + let type = services.get("pref").getPrefType(name); try { switch (type) { - case prefService.PREF_STRING: + case Ci.nsIPrefBranch.PREF_STRING: let value = branch.getComplexValue(name, Ci.nsISupportsString).data; // try in case it's a localized string (will throw an exception if not) - if (!prefService.prefIsLocked(name) && !prefService.prefHasUserValue(name) && - /^chrome:\/\/.+\/locale\/.+\.properties/.test(value)) + if (!services.get("pref").prefIsLocked(name) && !services.get("pref").prefHasUserValue(name) && + RegExp("chrome://.+/locale/.+\\.properties").test(value)) value = branch.getComplexValue(name, Ci.nsIPrefLocalizedString).data; return value; - case prefService.PREF_INT: + case Ci.nsIPrefBranch.PREF_INT: return branch.getIntPref(name); - case prefService.PREF_BOOL: + case Ci.nsIPrefBranch.PREF_BOOL: return branch.getBoolPref(name); default: return defaultValue; @@ -788,8 +786,9 @@ function Options() //{{{ { completion.setFunctionCompleter(options.get, [function () ([o.name, o.description] for (o in options))]); completion.setFunctionCompleter([options.getPref, options.safeSetPref, options.setPref, options.resetPref, options.invertPref], - [function () prefService.getChildList("", { value: 0 }) - .map(function (pref) [pref, ""])]); + [function () services.get("pref") + .getChildList("", { value: 0 }) + .map(function (pref) [pref, ""])]); }); return { @@ -890,12 +889,12 @@ function Options() //{{{ if (!filter) filter = ""; - let prefArray = prefService.getChildList("", { value: 0 }); + let prefArray = services.get("pref").getChildList("", { value: 0 }); prefArray.sort(); let prefs = function () { - for each (let pref in prefArray) + for (let [,pref] in Iterator(prefArray)) { - let userValue = prefService.prefHasUserValue(pref); + let userValue = services.get("pref").prefHasUserValue(pref); if (onlyNonDefault && !userValue || pref.indexOf(filter) == -1) continue; @@ -990,7 +989,7 @@ function Options() //{{{ { try { - return prefService.clearUserPref(name); + return services.get("pref").clearUserPref(name); } catch (e) { @@ -1001,7 +1000,7 @@ function Options() //{{{ // this works only for booleans invertPref: function (name) { - if (prefService.getPrefType(name) == prefService.PREF_BOOL) + if (services.get("pref").getPrefType(name) == Ci.nsIPrefBranch.PREF_BOOL) this.setPref(name, !this.getPref(name)); else liberator.echoerr("E488: Trailing characters: " + name + "!"); diff --git a/common/content/service.js b/common/content/service.js deleted file mode 100644 index 26fd1ab6..00000000 --- a/common/content/service.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @scope modules */ - -let (cc = function (class, iface, meth) { try { return Components.classes[class][meth || "getService"](iface) } catch (e) {} }) -{ - // var Ci = Components.interfaces; // quick fix for muttator, will change/remove service.js anyway after the vacation - - /** - * Cached XPCOM services and instances. - * - * @singleton - */ - const service = { - appStartup: cc("@mozilla.org/toolkit/app-startup;1", Components.interfaces.nsIAppStartup), - autoCompleteSearch: cc("@mozilla.org/browser/global-history;2", Components.interfaces.nsIAutoCompleteSearch), - browserSearch: cc("@mozilla.org/browser/search-service;1", Components.interfaces.nsIBrowserSearchService), - cache: cc("@mozilla.org/network/cache-service;1", Components.interfaces.nsICacheService), - console: cc("@mozilla.org/consoleservice;1", Components.interfaces.nsIConsoleService), - directory: cc("@mozilla.org/file/directory_service;1", Components.interfaces.nsIProperties), - environment: cc("@mozilla.org/process/environment;1", Components.interfaces.nsIEnvironment), - extensionManager: cc("@mozilla.org/extensions/manager;1", Components.interfaces.nsIExtensionManager), - json: cc("@mozilla.org/dom/json;1", Components.interfaces.nsIJSON, "createInstance"), - observer: cc("@mozilla.org/observer-service;1", Components.interfaces.nsIObserverService), - profile: cc("@mozilla.org/toolkit/profile-service;1", Components.interfaces.nsIToolkitProfileService), - sessionStore: cc("@mozilla.org/browser/sessionstore;1", Components.interfaces.nsISessionStore), - subscriptLoader: cc("@mozilla.org/moz/jssubscript-loader;1", Components.interfaces.mozIJSSubScriptLoader), - threadManager: cc("@mozilla.org/thread-manager;1", Components.interfaces.nsIThreadManager), - windowMediator: cc("@mozilla.org/appshell/window-mediator;1", Components.interfaces.nsIWindowMediator), - windowWatcher: cc("@mozilla.org/embedcomp/window-watcher;1", Components.interfaces.nsIWindowWatcher), - getFile: function () Cc["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile), - getFind: function () Cc["@mozilla.org/embedcomp/rangefind;1"].createInstance(Components.interfaces.nsIFind), - getProcess: function () Cc["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess) - }; -}; - diff --git a/common/content/services.js b/common/content/services.js new file mode 100644 index 00000000..2b22c702 --- /dev/null +++ b/common/content/services.js @@ -0,0 +1,73 @@ +/***** BEGIN LICENSE BLOCK ***** {{{ + ©2008 Kris Maglione + Distributable under the terms of the MIT license, which allows + for sublicensing under any compatible license, including the MPL, + GPL, and MPL. Anyone who changes this file is welcome to relicense + it under any or all of those licenseses. +}}} ***** END LICENSE BLOCK *****/ + +/** @scope modules */ + +const Cc = Components.classes; +const Ci = Components.interfaces; +const Cr = Components.results; +const Cu = Components.utils; + +/** + * Cached XPCOM services and instances. + * + * @constructor + */ +function Services() +{ + const classes = {}; + const services = {}; + function create(classes, ifaces, meth) + { + ifaces = Array.concat(ifaces); + try + { + let res = Cc[classes][meth || "getService"](ifaces.shift()) + ifaces.forEach(function (iface) res.QueryInterface(iface)); + return res; + } + catch (e) {} + } + const self = { + add: function (name, class, ifaces, meth) + { + return services[name] = create(class, ifaces, meth); + }, + addClass: function (name, class, ifaces) + { + return classes[name] = function () create(class, ifaces, "createInstance"); + }, + get: function (name) services[name], + create: function (name) classes[name]() + }; + self.add("appStartup", "@mozilla.org/toolkit/app-startup;1", Ci.nsIAppStartup); + self.add("autoCompleteSearch", "@mozilla.org/browser/global-history;2", Ci.nsIAutoCompleteSearch); + self.add("browserSearch", "@mozilla.org/browser/search-service;1", Ci.nsIBrowserSearchService); + self.add("cache", "@mozilla.org/network/cache-service;1", Ci.nsICacheService); + self.add("console", "@mozilla.org/consoleservice;1", Ci.nsIConsoleService); + self.add("directory", "@mozilla.org/file/directory_service;1", Ci.nsIProperties); + self.add("environment", "@mozilla.org/process/environment;1", Ci.nsIEnvironment); + self.add("extensionManager", "@mozilla.org/extensions/manager;1", Ci.nsIExtensionManager); + self.add("json", "@mozilla.org/dom/json;1", Ci.nsIJSON, "createInstance"); + self.add("observer", "@mozilla.org/observer-service;1", Ci.nsIObserverService); + self.add("pref", "@mozilla.org/preferences-service;1", [Ci.nsIPrefService, Ci.nsIPrefBranch, Ci.nsIPrefBranch2]); + self.add("profile", "@mozilla.org/toolkit/profile-service;1", Ci.nsIToolkitProfileService); + self.add("sessionStore", "@mozilla.org/browser/sessionstore;1", Ci.nsISessionStore); + self.add("subscriptLoader", "@mozilla.org/moz/jssubscript-loader;1", Ci.mozIJSSubScriptLoader); + self.add("threadManager", "@mozilla.org/thread-manager;1", Ci.nsIThreadManager); + self.add("windowMediator", "@mozilla.org/appshell/window-mediator;1", Ci.nsIWindowMediator); + self.add("windowWatcher", "@mozilla.org/embedcomp/window-watcher;1", Ci.nsIWindowWatcher); + + self.addClass("file", "@mozilla.org/file/local;1", Ci.nsILocalFile); + self.addClass("find", "@mozilla.org/embedcomp/rangefind;1", Ci.nsIFind); + self.addClass("process", "@mozilla.org/process/util;1", Ci.nsIProcess); + return self; +}; + +var services = Services(); + diff --git a/common/content/tabs.js b/common/content/tabs.js index 3341a0ac..4e33b942 100644 --- a/common/content/tabs.js +++ b/common/content/tabs.js @@ -102,8 +102,8 @@ function Tabs() //{{{ if (!from) from = getBrowser().mTabContainer.selectedItem; - let tabState = service["sessionStore"].getTabState(from); - service["sessionStore"].setTabState(to, tabState); + let tabState = services.get("sessionStore").getTabState(from); + services.get("sessionStore").setTabState(to, tabState); } // hide tabs initially @@ -743,7 +743,7 @@ function Tabs() //{{{ get closedTabs() { - return service["json"].decode(service["sessionStore"].getClosedTabData(window)); + return services.get("json").decode(services.get("sessionStore").getClosedTabData(window)); }, list: function (filter) @@ -970,7 +970,7 @@ function Tabs() //{{{ tab = getBrowser().mTabContainer.selectedItem; window.open(); - let win = service["windowMediator"].getMostRecentWindow("navigator:browser"); + let win = services.get("windowMediator").getMostRecentWindow("navigator:browser"); copyTab(win.getBrowser().mCurrentTab, tab); this.remove(tab, 1, false, 1); diff --git a/common/content/ui.js b/common/content/ui.js index 3f817e4c..458a353a 100644 --- a/common/content/ui.js +++ b/common/content/ui.js @@ -659,8 +659,8 @@ function CommandLine() //{{{ { completer: function completer(value) { - let engines = service["browserSearch"].getEngines({}) - .filter(function (engine) engine.supportsResponseType("application/x-suggestions+json")); + let engines = services.get("browserSearch").getEngines({}) + .filter(function (engine) engine.supportsResponseType("application/x-suggestions+json")); return engines.map(function (engine) [engine.alias, engine.description]); }, diff --git a/vimperator/content/bookmarks.js b/vimperator/content/bookmarks.js index 69a7edb0..af0dbb94 100644 --- a/vimperator/content/bookmarks.js +++ b/vimperator/content/bookmarks.js @@ -59,7 +59,6 @@ function Bookmarks() //{{{ const historyService = PlacesUtils.history; const bookmarksService = PlacesUtils.bookmarks; const taggingService = PlacesUtils.tagging; - const searchService = service.browserSearch; const faviconService = Cc["@mozilla.org/browser/favicon-service;1"].getService(Ci.nsIFaviconService); const Bookmark = new Struct("url", "title", "icon", "keyword", "tags", "id"); @@ -533,7 +532,7 @@ function Bookmarks() //{{{ getSearchEngines: function getSearchEngines() { let searchEngines = []; - let firefoxEngines = searchService.getVisibleEngines({}); + let firefoxEngines = services.get("browserSearch").getVisibleEngines({}); for (let [,engine] in Iterator(firefoxEngines)) { let alias = engine.alias; @@ -563,10 +562,9 @@ function Bookmarks() //{{{ getSuggestions: function getSuggestions(engineName, query, callback) { - let ss = service.browserSearch; const responseType = "application/x-suggestions+json"; - let engine = ss.getEngineByAlias(engineName); + let engine = services.get("browserSearch").getEngineByAlias(engineName); if (engine && engine.supportsResponseType(responseType)) var queryURI = engine.getSubmission(query, responseType).uri.spec; if (!queryURI) @@ -574,11 +572,10 @@ function Bookmarks() //{{{ function process(resp) { - const json = service.json; let results = []; try { - results = json.decode(resp.responseText)[1]; + results = services.get("json").decode(resp.responseText)[1]; results = [[item, ""] for ([k, item] in Iterator(results)) if (typeof item == "string")]; } catch (e) {} From d2fea07fbd19cc72953fef3b755707d50fa1c4b8 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Tue, 23 Dec 2008 17:25:08 -0500 Subject: [PATCH 27/31] Don't echo commands executed from sourced files. --- common/content/io.js | 2 +- common/content/liberator.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/common/content/io.js b/common/content/io.js index 8254151d..1d63684d 100644 --- a/common/content/io.js +++ b/common/content/io.js @@ -870,7 +870,7 @@ lookup: else { // execute a normal liberator command - liberator.execute(line); + liberator.execute(line, null, true); } } } diff --git a/common/content/liberator.js b/common/content/liberator.js index 27ec275c..62f150f9 100644 --- a/common/content/liberator.js +++ b/common/content/liberator.js @@ -856,7 +856,7 @@ const liberator = (function () //{{{ }, // Execute an Ex command like str=":zoom 300" - execute: function (str, modifiers) + execute: function (str, modifiers, silent) { // skip comments and blank lines if (/^\s*("|$)/.test(str)) @@ -888,7 +888,8 @@ const liberator = (function () //{{{ if (err) return liberator.echoerr(err); - commandline.command = str.replace(/^\s*:\s*/, ""); + if (!silent) + commandline.command = str.replace(/^\s*:\s*/, ""); command.execute(args, special, count, modifiers); }, From aba49d9ce4316fc6fa13ab3b8f497cf942176366 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Thu, 25 Dec 2008 02:36:43 +1100 Subject: [PATCH 28/31] Fix #88 (:buffer! is broken). --- common/content/tabs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/content/tabs.js b/common/content/tabs.js index 4e33b942..50d791bb 100644 --- a/common/content/tabs.js +++ b/common/content/tabs.js @@ -463,7 +463,7 @@ function Tabs() //{{{ "Switch to a buffer", function (args) { - let special = args.special; + let special = args.bang; let count = args.count; let arg = args.literalArg; From 3acf6873407453265bdb51cf9cc3aea0573e173e Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Wed, 24 Dec 2008 12:57:59 -0500 Subject: [PATCH 29/31] Fix stupid MS/Mac urlbar focus bug again (again) --- common/content/events.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/content/events.js b/common/content/events.js index 630de130..35a4fada 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -1143,7 +1143,7 @@ function Events() //{{{ } urlbar = document.getElementById("urlbar"); - if (focus == null && urlbar && urlbar.inputField == lastFocus) + if (elem == null && urlbar && urlbar.inputField == lastFocus) liberator.threadYield(true); if (liberator.mode & (modes.INSERT | modes.TEXTAREA | modes.MESSAGE | modes.VISUAL)) From deaba40c8f1ac9ab1b24c1e2e0f2a39673d15722 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Wed, 24 Dec 2008 13:07:36 -0500 Subject: [PATCH 30/31] Fix IO.expandPath quirk on MS --- common/content/io.js | 9 +++++---- common/content/liberator.js | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/common/content/io.js b/common/content/io.js index 1d63684d..0c10eae0 100644 --- a/common/content/io.js +++ b/common/content/io.js @@ -944,7 +944,7 @@ IO.expandPath = function (path, relative) path = expand(path); // expand ~ - if (!relative && (WINDOWS ? /^~(?:$|\\)/ : /^~(?:$|\/)/).test(path)) + if (!relative && (WINDOWS ? /^~(?:$|[\\\/])/ : /^~(?:$|\/)/).test(path)) { // Try $HOME first, on all systems let home = services.get("environment").get("HOME"); @@ -961,9 +961,10 @@ IO.expandPath = function (path, relative) // after, but doesn't document it. Is this just a bug? --Kris path = expand(path); - // FIXME: Should we be doing this here? I think it should be done - // by the arg parser or nowhere. --Kris - return path.replace("\\ ", " ", "g"); + if (WINDOWS) + path = path.replace("/", "\\", "g"); + + return path; }; // vim: set fdm=marker sw=4 ts=4 et: diff --git a/common/content/liberator.js b/common/content/liberator.js index 62f150f9..113a0c58 100644 --- a/common/content/liberator.js +++ b/common/content/liberator.js @@ -1225,6 +1225,7 @@ const liberator = (function () //{{{ try { let infoPath = services.create("file"); + liberator.dump("'rtp': " + IO.expandPath(IO.runtimePath.replace(/,.*/, ""))); infoPath.initWithPath(IO.expandPath(IO.runtimePath.replace(/,.*/, ""))); infoPath.append("info"); infoPath.append(services.get("profile").selectedProfile.name); From 8294df5e81329b243b51c81e4b0a000fecc2f84b Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Wed, 24 Dec 2008 13:18:08 -0500 Subject: [PATCH 31/31] Remove dump line --- common/content/liberator.js | 1 - 1 file changed, 1 deletion(-) diff --git a/common/content/liberator.js b/common/content/liberator.js index 113a0c58..62f150f9 100644 --- a/common/content/liberator.js +++ b/common/content/liberator.js @@ -1225,7 +1225,6 @@ const liberator = (function () //{{{ try { let infoPath = services.create("file"); - liberator.dump("'rtp': " + IO.expandPath(IO.runtimePath.replace(/,.*/, ""))); infoPath.initWithPath(IO.expandPath(IO.runtimePath.replace(/,.*/, ""))); infoPath.append("info"); infoPath.append(services.get("profile").selectedProfile.name);