mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-14 09:45:46 +01:00
Finish the Great Opening Brace Correction.
This commit is contained in:
@@ -29,10 +29,8 @@ const systemPrincipal = channel.owner;
|
||||
channel.cancel(NS_BINDING_ABORTED);
|
||||
delete channel;
|
||||
|
||||
function dataURL(type, data)
|
||||
"data:" + (type || "application/xml;encoding=UTF-8") + "," + escape(data);
|
||||
function makeChannel(url, orig)
|
||||
{
|
||||
function dataURL(type, data) "data:" + (type || "application/xml;encoding=UTF-8") + "," + escape(data);
|
||||
function makeChannel(url, orig) {
|
||||
if (typeof url == "function")
|
||||
url = dataURL.apply(null, url());
|
||||
let uri = ioService.newURI(url, null, null);
|
||||
@@ -41,10 +39,8 @@ function makeChannel(url, orig)
|
||||
channel.originalURI = orig;
|
||||
return channel;
|
||||
}
|
||||
function fakeChannel(orig)
|
||||
makeChannel("chrome://liberator/content/does/not/exist", orig);
|
||||
function redirect(to, orig)
|
||||
{
|
||||
function fakeChannel(orig) makeChannel("chrome://liberator/content/does/not/exist", orig);
|
||||
function redirect(to, orig) {
|
||||
let html = <html><head><meta http-equiv="Refresh" content={"0;" + to}/></head></html>.toXMLString();
|
||||
return makeChannel(dataURL('text/html', html), ioServices.newURI(to, null, null));
|
||||
}
|
||||
@@ -56,8 +52,7 @@ ChromeData.prototype = {
|
||||
classDescription: "Data URIs with chrome privileges",
|
||||
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIProtocolHandler]),
|
||||
_xpcom_factory: {
|
||||
createInstance: function (outer, iid)
|
||||
{
|
||||
createInstance: function (outer, iid) {
|
||||
if (!ChromeData.instance)
|
||||
ChromeData.instance = new ChromeData();
|
||||
if (outer != null)
|
||||
@@ -73,8 +68,7 @@ ChromeData.prototype = {
|
||||
| nsIProtocolHandler.URI_NOAUTH
|
||||
| nsIProtocolHandler.URI_IS_UI_RESOURCE,
|
||||
|
||||
newURI: function (spec, charset, baseURI)
|
||||
{
|
||||
newURI: function (spec, charset, baseURI) {
|
||||
var uri = Components.classes["@mozilla.org/network/standard-url;1"]
|
||||
.createInstance(Components.interfaces.nsIStandardURL)
|
||||
.QueryInterface(Components.interfaces.nsIURI);
|
||||
@@ -82,10 +76,8 @@ ChromeData.prototype = {
|
||||
return uri;
|
||||
},
|
||||
|
||||
newChannel: function (uri)
|
||||
{
|
||||
try
|
||||
{
|
||||
newChannel: function (uri) {
|
||||
try {
|
||||
if (uri.scheme == this.scheme)
|
||||
return makeChannel(uri.spec.replace(/^.*?:\/*(.*)(?:#.*)?/, "data:$1"), uri);
|
||||
}
|
||||
@@ -94,8 +86,7 @@ ChromeData.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
function Liberator()
|
||||
{
|
||||
function Liberator() {
|
||||
this.wrappedJSObject = this;
|
||||
|
||||
const self = this;
|
||||
@@ -109,8 +100,7 @@ Liberator.prototype = {
|
||||
classDescription: "Liberator utility protocol",
|
||||
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIProtocolHandler]),
|
||||
_xpcom_factory: {
|
||||
createInstance: function (outer, iid)
|
||||
{
|
||||
createInstance: function (outer, iid) {
|
||||
if (!Liberator.instance)
|
||||
Liberator.instance = new Liberator();
|
||||
if (outer != null)
|
||||
@@ -119,10 +109,8 @@ Liberator.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
init: function (obj)
|
||||
{
|
||||
for each (let prop in ["HELP_TAGS", "FILE_MAP", "OVERLAY_MAP"])
|
||||
{
|
||||
init: function (obj) {
|
||||
for each (let prop in ["HELP_TAGS", "FILE_MAP", "OVERLAY_MAP"]) {
|
||||
this[prop] = this[prop].constructor();
|
||||
for (let [k, v] in Iterator(obj[prop] || {}))
|
||||
this[prop][k] = v
|
||||
@@ -136,8 +124,7 @@ Liberator.prototype = {
|
||||
| nsIProtocolHandler.URI_IS_UI_RESOURCE
|
||||
| nsIProtocolHandler.URI_IS_LOCAL_RESOURCE,
|
||||
|
||||
newURI: function (spec, charset, baseURI)
|
||||
{
|
||||
newURI: function (spec, charset, baseURI) {
|
||||
var uri = Components.classes["@mozilla.org/network/standard-url;1"]
|
||||
.createInstance(Components.interfaces.nsIStandardURL)
|
||||
.QueryInterface(Components.interfaces.nsIURI);
|
||||
@@ -145,12 +132,9 @@ Liberator.prototype = {
|
||||
return uri;
|
||||
},
|
||||
|
||||
newChannel: function (uri)
|
||||
{
|
||||
try
|
||||
{
|
||||
switch(uri.host)
|
||||
{
|
||||
newChannel: function (uri) {
|
||||
try {
|
||||
switch(uri.host) {
|
||||
case "help":
|
||||
let url = this.FILE_MAP[uri.path.replace(/^\/|#.*/g, "")];
|
||||
return makeChannel(url, uri);
|
||||
@@ -170,9 +154,6 @@ Liberator.prototype = {
|
||||
|
||||
var components = [ChromeData, Liberator];
|
||||
|
||||
function NSGetModule(compMgr, fileSpec)
|
||||
{
|
||||
return XPCOMUtils.generateModule(components);
|
||||
}
|
||||
function NSGetModule(compMgr, fileSpec) XPCOMUtils.generateModule(components)
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
@@ -355,10 +355,8 @@ const Buffer = Module("buffer", {
|
||||
for (let [, regex] in Iterator(regexes)) {
|
||||
for (let i in util.range(res.snapshotLength, 0, -1)) {
|
||||
let elem = res.snapshotItem(i);
|
||||
if (regex.test(elem.textContent) ||
|
||||
regex.test(elem.title) ||
|
||||
Array.some(elem.childNodes, function (child) regex.test(child.alt)))
|
||||
{
|
||||
if (regex.test(elem.textContent) || regex.test(elem.title) ||
|
||||
Array.some(elem.childNodes, function (child) regex.test(child.alt))) {
|
||||
buffer.followLink(elem, liberator.CURRENT_TAB);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -321,16 +321,15 @@ function Highlights(name, store) {
|
||||
this.loadCSS = function (css) {
|
||||
css.replace(/^(\s*\S*\s+)\{((?:.|\n)*?)\}\s*$/gm, function (_, _1, _2) _1 + " " + _2.replace(/\n\s*/g, " "))
|
||||
.split("\n").filter(function (s) /\S/.test(s))
|
||||
.forEach(function (style)
|
||||
{
|
||||
style = Highlight.apply(Highlight, Array.slice(style.match(/^\s*((?:[^,\s]|\s\S)+)(?:,((?:[^,\s]|\s\S)+)?)?(?:,((?:[^,\s]|\s\S)+))?\s*(.*)$/), 1));
|
||||
if (/^[>+ ]/.test(style.selector))
|
||||
style.selector = self.selector(style.class) + style.selector;
|
||||
.forEach(function (style) {
|
||||
style = Highlight.apply(Highlight, Array.slice(style.match(/^\s*((?:[^,\s]|\s\S)+)(?:,((?:[^,\s]|\s\S)+)?)?(?:,((?:[^,\s]|\s\S)+))?\s*(.*)$/), 1));
|
||||
if (/^[>+ ]/.test(style.selector))
|
||||
style.selector = self.selector(style.class) + style.selector;
|
||||
|
||||
let old = highlight[style.class];
|
||||
highlight[style.class] = style;
|
||||
if (old && old.value != old.default)
|
||||
style.value = old.value;
|
||||
let old = highlight[style.class];
|
||||
highlight[style.class] = style;
|
||||
if (old && old.value != old.default)
|
||||
style.value = old.value;
|
||||
});
|
||||
for (let [class, hl] in Iterator(highlight)) {
|
||||
if (hl.value == hl.default)
|
||||
|
||||
@@ -227,9 +227,7 @@ const Tabs = Module("tabs", {
|
||||
if (getBrowser().mTabs.length > 1)
|
||||
getBrowser().removeTab(tab);
|
||||
else {
|
||||
if (buffer.URL != "about:blank" ||
|
||||
window.getWebNavigation().sessionHistory.count > 0)
|
||||
{
|
||||
if (buffer.URL != "about:blank" || window.getWebNavigation().sessionHistory.count > 0) {
|
||||
liberator.open("about:blank", liberator.NEW_BACKGROUND_TAB);
|
||||
getBrowser().removeTab(tab);
|
||||
}
|
||||
|
||||
@@ -9,8 +9,7 @@ var CommandLineHandler;
|
||||
|
||||
function initCommandLineHandler(Name) {
|
||||
var name = Name.toLowerCase();
|
||||
CommandLineHandler = function CommandLineHandler()
|
||||
{
|
||||
CommandLineHandler = function CommandLineHandler() {
|
||||
this.wrappedJSObject = this;
|
||||
}
|
||||
CommandLineHandler.prototype = {
|
||||
@@ -28,21 +27,18 @@ function initCommandLineHandler(Name) {
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsICommandLineHandler]),
|
||||
|
||||
handle: function (commandLine)
|
||||
{
|
||||
handle: function (commandLine) {
|
||||
// TODO: handle remote launches differently?
|
||||
try
|
||||
{
|
||||
try {
|
||||
this.optionValue = commandLine.handleFlagWithParam(name, false);
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
catch (e) {
|
||||
//"vimperator: option -vimperator requires an argument"
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function NSGetModule(compMgr, fileSpec) XPCOMUtils.generateModule([CommandLineHandler]);
|
||||
function NSGetModule(compMgr, fileSpec) XPCOMUtils.generateModule([CommandLineHandler])
|
||||
|
||||
// vim: set ft=javascript fdm=marker sw=4 ts=4 et:
|
||||
|
||||
@@ -27,29 +27,24 @@ const Ci = Components.interfaces;
|
||||
const Cu = Components.utils;
|
||||
|
||||
// XXX: does not belong here
|
||||
function Timer(minInterval, maxInterval, callback)
|
||||
{
|
||||
function Timer(minInterval, maxInterval, callback) {
|
||||
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
||||
this.doneAt = 0;
|
||||
this.latest = 0;
|
||||
this.notify = function (aTimer)
|
||||
{
|
||||
this.notify = function (aTimer) {
|
||||
timer.cancel();
|
||||
this.latest = 0;
|
||||
// minInterval is the time between the completion of the command and the next firing
|
||||
this.doneAt = Date.now() + minInterval;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
callback(this.arg);
|
||||
}
|
||||
finally
|
||||
{
|
||||
finally {
|
||||
this.doneAt = Date.now() + minInterval;
|
||||
}
|
||||
};
|
||||
this.tell = function (arg)
|
||||
{
|
||||
this.tell = function (arg) {
|
||||
if (arguments.length > 0)
|
||||
this.arg = arg;
|
||||
|
||||
@@ -68,32 +63,27 @@ function Timer(minInterval, maxInterval, callback)
|
||||
timer.initWithCallback(this, Math.max(timeout, 0), timer.TYPE_ONE_SHOT);
|
||||
this.doneAt = -1;
|
||||
};
|
||||
this.reset = function ()
|
||||
{
|
||||
this.reset = function () {
|
||||
timer.cancel();
|
||||
this.doneAt = 0;
|
||||
};
|
||||
this.flush = function ()
|
||||
{
|
||||
this.flush = function () {
|
||||
if (this.doneAt == -1)
|
||||
this.notify();
|
||||
};
|
||||
}
|
||||
|
||||
function getFile(name)
|
||||
{
|
||||
function getFile(name) {
|
||||
let file = storage.infoPath.clone();
|
||||
file.append(name);
|
||||
return file;
|
||||
}
|
||||
|
||||
function readFile(file)
|
||||
{
|
||||
function readFile(file) {
|
||||
let fileStream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
|
||||
let stream = Cc["@mozilla.org/intl/converter-input-stream;1"].createInstance(Ci.nsIConverterInputStream);
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
fileStream.init(file, -1, 0, 0);
|
||||
stream.init(fileStream, "UTF-8", 4096, Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER); // 4096 bytes buffering
|
||||
|
||||
@@ -110,8 +100,7 @@ function readFile(file)
|
||||
catch (e) {}
|
||||
}
|
||||
|
||||
function writeFile(file, data)
|
||||
{
|
||||
function writeFile(file, data) {
|
||||
if (!file.exists())
|
||||
file.create(file.NORMAL_FILE_TYPE, 0600);
|
||||
|
||||
@@ -132,34 +121,28 @@ var prefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPref
|
||||
.getBranch("extensions.liberator.datastore.");
|
||||
var json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
|
||||
|
||||
function getCharPref(name)
|
||||
{
|
||||
try
|
||||
{
|
||||
function getCharPref(name) {
|
||||
try {
|
||||
return prefService.getComplexValue(name, Ci.nsISupportsString).data;
|
||||
}
|
||||
catch (e) {}
|
||||
}
|
||||
|
||||
function setCharPref(name, value)
|
||||
{
|
||||
function setCharPref(name, value) {
|
||||
var str = Cc['@mozilla.org/supports-string;1'].createInstance(Ci.nsISupportsString);
|
||||
str.data = value;
|
||||
return prefService.setComplexValue(name, Ci.nsISupportsString, str);
|
||||
}
|
||||
|
||||
function loadPref(name, store, type)
|
||||
{
|
||||
try
|
||||
{
|
||||
function loadPref(name, store, type) {
|
||||
try {
|
||||
if (store)
|
||||
var pref = getCharPref(name);
|
||||
if (!pref && storage.infoPath)
|
||||
var file = readFile(getFile(name));
|
||||
if (pref || file)
|
||||
var result = json.decode(pref || file);
|
||||
if (pref)
|
||||
{
|
||||
if (pref) {
|
||||
prefService.clearUserPref(name);
|
||||
savePref({ name: name, store: true, serial: pref });
|
||||
}
|
||||
@@ -169,8 +152,7 @@ function loadPref(name, store, type)
|
||||
catch (e) {}
|
||||
}
|
||||
|
||||
function savePref(obj)
|
||||
{
|
||||
function savePref(obj) {
|
||||
if (obj.privateData && storage.privateMode)
|
||||
return;
|
||||
if (obj.store && storage.infoPath)
|
||||
@@ -181,8 +163,7 @@ var prototype = {
|
||||
OPTIONS: ["privateData"],
|
||||
fireEvent: function (event, arg) { storage.fireEvent(this.name, event, arg); },
|
||||
save: function () { savePref(this); },
|
||||
init: function (name, store, data, options)
|
||||
{
|
||||
init: function (name, store, data, options) {
|
||||
this.__defineGetter__("store", function () store);
|
||||
this.__defineGetter__("name", function () name);
|
||||
for (let [k, v] in Iterator(options))
|
||||
@@ -192,12 +173,10 @@ var prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
function ObjectStore(name, store, load, options)
|
||||
{
|
||||
function ObjectStore(name, store, load, options) {
|
||||
var object = {};
|
||||
|
||||
this.reload = function reload()
|
||||
{
|
||||
this.reload = function reload() {
|
||||
object = load() || {};
|
||||
this.fireEvent("change", null);
|
||||
};
|
||||
@@ -205,8 +184,7 @@ function ObjectStore(name, store, load, options)
|
||||
this.init.apply(this, arguments);
|
||||
this.__defineGetter__("serial", function () json.encode(object));
|
||||
|
||||
this.set = function set(key, val)
|
||||
{
|
||||
this.set = function set(key, val) {
|
||||
var defined = key in object;
|
||||
var orig = object[key];
|
||||
object[key] = val;
|
||||
@@ -216,8 +194,7 @@ function ObjectStore(name, store, load, options)
|
||||
this.fireEvent("change", key);
|
||||
};
|
||||
|
||||
this.remove = function remove(key)
|
||||
{
|
||||
this.remove = function remove(key) {
|
||||
var ret = object[key];
|
||||
delete object[key];
|
||||
this.fireEvent("remove", key);
|
||||
@@ -226,8 +203,7 @@ function ObjectStore(name, store, load, options)
|
||||
|
||||
this.get = function get(val) object[val];
|
||||
|
||||
this.clear = function ()
|
||||
{
|
||||
this.clear = function () {
|
||||
object = {};
|
||||
};
|
||||
|
||||
@@ -235,12 +211,10 @@ function ObjectStore(name, store, load, options)
|
||||
}
|
||||
ObjectStore.prototype = prototype;
|
||||
|
||||
function ArrayStore(name, store, load, options)
|
||||
{
|
||||
function ArrayStore(name, store, load, options) {
|
||||
var array = [];
|
||||
|
||||
this.reload = function reload()
|
||||
{
|
||||
this.reload = function reload() {
|
||||
array = load() || [];
|
||||
this.fireEvent("change", null);
|
||||
};
|
||||
@@ -249,31 +223,26 @@ function ArrayStore(name, store, load, options)
|
||||
this.__defineGetter__("serial", function () json.encode(array));
|
||||
this.__defineGetter__("length", function () array.length);
|
||||
|
||||
this.set = function set(index, value)
|
||||
{
|
||||
this.set = function set(index, value) {
|
||||
var orig = array[index];
|
||||
array[index] = value;
|
||||
this.fireEvent("change", index);
|
||||
};
|
||||
|
||||
this.push = function push(value)
|
||||
{
|
||||
this.push = function push(value) {
|
||||
array.push(value);
|
||||
this.fireEvent("push", array.length);
|
||||
};
|
||||
|
||||
this.pop = function pop(value)
|
||||
{
|
||||
this.pop = function pop(value) {
|
||||
var ret = array.pop();
|
||||
this.fireEvent("pop", array.length);
|
||||
return ret;
|
||||
};
|
||||
|
||||
this.truncate = function truncate(length, fromEnd)
|
||||
{
|
||||
this.truncate = function truncate(length, fromEnd) {
|
||||
var ret = array.length;
|
||||
if (array.length > length)
|
||||
{
|
||||
if (array.length > length) {
|
||||
if (fromEnd)
|
||||
array.splice(0, array.length - length);
|
||||
array.length = length;
|
||||
@@ -283,16 +252,14 @@ function ArrayStore(name, store, load, options)
|
||||
};
|
||||
|
||||
// XXX: Awkward.
|
||||
this.mutate = function mutate(aFuncName)
|
||||
{
|
||||
this.mutate = function mutate(aFuncName) {
|
||||
var funcName = aFuncName;
|
||||
arguments[0] = array;
|
||||
array = Array[funcName].apply(Array, arguments);
|
||||
this.fireEvent("change", null);
|
||||
};
|
||||
|
||||
this.get = function get(index)
|
||||
{
|
||||
this.get = function get(index) {
|
||||
return index >= 0 ? array[index] : array[array.length + index];
|
||||
};
|
||||
|
||||
@@ -306,10 +273,8 @@ var timers = {};
|
||||
|
||||
var storage = {
|
||||
alwaysReload: {},
|
||||
newObject: function newObject(key, constructor, params)
|
||||
{
|
||||
if (!(key in keys) || params.reload || this.alwaysReload[key])
|
||||
{
|
||||
newObject: function newObject(key, constructor, params) {
|
||||
if (!(key in keys) || params.reload || this.alwaysReload[key]) {
|
||||
if (key in this && !(params.reload || this.alwaysReload[key]))
|
||||
throw Error();
|
||||
let load = function () loadPref(key, params.store, params.type || Object);
|
||||
@@ -320,27 +285,22 @@ var storage = {
|
||||
return keys[key];
|
||||
},
|
||||
|
||||
newMap: function newMap(key, options)
|
||||
{
|
||||
newMap: function newMap(key, options) {
|
||||
return this.newObject(key, ObjectStore, options);
|
||||
},
|
||||
|
||||
newArray: function newArray(key, options)
|
||||
{
|
||||
newArray: function newArray(key, options) {
|
||||
return this.newObject(key, ArrayStore, { type: Array, __proto__: options });
|
||||
},
|
||||
|
||||
addObserver: function addObserver(key, callback, ref)
|
||||
{
|
||||
if (ref)
|
||||
{
|
||||
addObserver: function addObserver(key, callback, ref) {
|
||||
if (ref) {
|
||||
if (!ref.liberatorStorageRefs)
|
||||
ref.liberatorStorageRefs = [];
|
||||
ref.liberatorStorageRefs.push(callback);
|
||||
var callbackRef = Cu.getWeakReference(callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
callbackRef = { get: function () callback };
|
||||
}
|
||||
this.removeDeadObservers();
|
||||
@@ -350,8 +310,7 @@ var storage = {
|
||||
observers[key].push({ ref: ref && Cu.getWeakReference(ref), callback: callbackRef });
|
||||
},
|
||||
|
||||
removeObserver: function (key, callback)
|
||||
{
|
||||
removeObserver: function (key, callback) {
|
||||
this.removeDeadObservers();
|
||||
if (!(key in observers))
|
||||
return;
|
||||
@@ -360,10 +319,8 @@ var storage = {
|
||||
delete obsevers[key];
|
||||
},
|
||||
|
||||
removeDeadObservers: function ()
|
||||
{
|
||||
for (let [key, ary] in Iterator(observers))
|
||||
{
|
||||
removeDeadObservers: function () {
|
||||
for (let [key, ary] in Iterator(observers)) {
|
||||
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];
|
||||
@@ -372,8 +329,7 @@ var storage = {
|
||||
|
||||
get observers() observers,
|
||||
|
||||
fireEvent: function fireEvent(key, event, arg)
|
||||
{
|
||||
fireEvent: function fireEvent(key, event, arg) {
|
||||
if (!(key in this))
|
||||
return;
|
||||
this.removeDeadObservers();
|
||||
@@ -383,27 +339,23 @@ var storage = {
|
||||
timers[key].tell();
|
||||
},
|
||||
|
||||
load: function load(key)
|
||||
{
|
||||
load: function load(key) {
|
||||
if (this[key].store && this[key].reload)
|
||||
this[key].reload();
|
||||
},
|
||||
|
||||
save: function save(key)
|
||||
{
|
||||
save: function save(key) {
|
||||
savePref(keys[key]);
|
||||
},
|
||||
|
||||
saveAll: function storeAll()
|
||||
{
|
||||
saveAll: function storeAll() {
|
||||
for each (let obj in keys)
|
||||
savePref(obj);
|
||||
},
|
||||
|
||||
_privateMode: false,
|
||||
get privateMode() this._privateMode,
|
||||
set privateMode(val)
|
||||
{
|
||||
set privateMode(val) {
|
||||
if (!val && this._privateMode)
|
||||
for (let key in keys)
|
||||
this.load(key);
|
||||
|
||||
Reference in New Issue
Block a user