mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-16 15:25:47 +01:00
Add 'const service'
This commit is contained in:
@@ -526,17 +526,10 @@ function Completion() //{{{
|
|||||||
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////{{{
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var completionService = Cc["@mozilla.org/browser/global-history;2"].getService(Ci.nsIAutoCompleteSearch);
|
|
||||||
}
|
|
||||||
catch (e) {}
|
|
||||||
|
|
||||||
const EVAL_TMP = "__liberator_eval_tmp";
|
const EVAL_TMP = "__liberator_eval_tmp";
|
||||||
|
|
||||||
function Javascript()
|
function Javascript()
|
||||||
{
|
{
|
||||||
let json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
|
|
||||||
const OFFSET = 0, CHAR = 1, STATEMENTS = 2, DOTS = 3, FULL_STATEMENTS = 4, COMMA = 5, FUNCTIONS = 6;
|
const OFFSET = 0, CHAR = 1, STATEMENTS = 2, DOTS = 3, FULL_STATEMENTS = 4, COMMA = 5, FUNCTIONS = 6;
|
||||||
let stack = [];
|
let stack = [];
|
||||||
let functions = [];
|
let functions = [];
|
||||||
@@ -1406,7 +1399,7 @@ function Completion() //{{{
|
|||||||
|
|
||||||
location: function location(context)
|
location: function location(context)
|
||||||
{
|
{
|
||||||
if (!completionService)
|
if (!service.autoCompleteSearch)
|
||||||
return
|
return
|
||||||
context.anchored = false;
|
context.anchored = false;
|
||||||
context.title = ["Smart Completions"];
|
context.title = ["Smart Completions"];
|
||||||
@@ -1422,8 +1415,8 @@ function Completion() //{{{
|
|||||||
for (i in util.range(0, result.matchCount))
|
for (i in util.range(0, result.matchCount))
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
completionService.stopSearch();
|
service.autoCompleteSearch.stopSearch();
|
||||||
completionService.startSearch(context.filter, "", context.result, {
|
service.autoCompleteSearch.startSearch(context.filter, "", context.result, {
|
||||||
onSearchResult: function onSearchResult(search, result) {
|
onSearchResult: function onSearchResult(search, result) {
|
||||||
context.result = result;
|
context.result = result;
|
||||||
timer.tell(result);
|
timer.tell(result);
|
||||||
@@ -1502,11 +1495,10 @@ function Completion() //{{{
|
|||||||
|
|
||||||
preference: function preference(context)
|
preference: function preference(context)
|
||||||
{
|
{
|
||||||
let prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
|
|
||||||
context.anchored = false;
|
context.anchored = false;
|
||||||
context.title = ["Firefox Preference", "Value"];
|
context.title = ["Firefox Preference", "Value"];
|
||||||
context.keys = { text: function (item) item, description: function (item) options.getPref(item) };
|
context.keys = { text: function (item) item, description: function (item) options.getPref(item) };
|
||||||
context.completions = prefs.getChildList("", { value: 0 });
|
context.completions = service.prefs.getChildList("", { value: 0 });
|
||||||
},
|
},
|
||||||
|
|
||||||
search: function search(context, noSuggest)
|
search: function search(context, noSuggest)
|
||||||
@@ -1553,12 +1545,11 @@ function Completion() //{{{
|
|||||||
if (!context.filter)
|
if (!context.filter)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
let ss = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService);
|
|
||||||
let engineList = (engineAliases || options["suggestengines"] || "google").split(",");
|
let engineList = (engineAliases || options["suggestengines"] || "google").split(",");
|
||||||
|
|
||||||
let completions = [];
|
let completions = [];
|
||||||
engineList.forEach(function (name) {
|
engineList.forEach(function (name) {
|
||||||
let engine = ss.getEngineByAlias(name);
|
let engine = service.browserSearch.getEngineByAlias(name);
|
||||||
if (!engine)
|
if (!engine)
|
||||||
return;
|
return;
|
||||||
let [,word] = /^\s*(\S+)/.exec(context.filter) || [];
|
let [,word] = /^\s*(\S+)/.exec(context.filter) || [];
|
||||||
@@ -1581,9 +1572,7 @@ function Completion() //{{{
|
|||||||
context.title = ["Shell Command", "Path"];
|
context.title = ["Shell Command", "Path"];
|
||||||
context.generate = function ()
|
context.generate = function ()
|
||||||
{
|
{
|
||||||
const environmentService = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
|
let dirNames = service.environment.get("PATH").split(RegExp(liberator.has("Win32") ? ";" : ":"));
|
||||||
|
|
||||||
let dirNames = environmentService.get("PATH").split(RegExp(liberator.has("Win32") ? ";" : ":"));
|
|
||||||
let commands = [];
|
let commands = [];
|
||||||
|
|
||||||
for (let [,dirName] in Iterator(dirNames))
|
for (let [,dirName] in Iterator(dirNames))
|
||||||
|
|||||||
@@ -1541,10 +1541,9 @@ function Events() //{{{
|
|||||||
// XXX: function may later be needed to detect a canceled synchronous openURL()
|
// XXX: function may later be needed to detect a canceled synchronous openURL()
|
||||||
onStateChange: function (webProgress, request, flags, status)
|
onStateChange: function (webProgress, request, flags, status)
|
||||||
{
|
{
|
||||||
const nsIWebProgressListener = Ci.nsIWebProgressListener;
|
|
||||||
// STATE_IS_DOCUMENT | STATE_IS_WINDOW is important, because we also
|
// STATE_IS_DOCUMENT | STATE_IS_WINDOW is important, because we also
|
||||||
// receive statechange events for loading images and other parts of the web page
|
// receive statechange events for loading images and other parts of the web page
|
||||||
if (flags & (nsIWebProgressListener.STATE_IS_DOCUMENT | nsIWebProgressListener.STATE_IS_WINDOW))
|
if (flags & (Ci.nsIWebProgressListener.STATE_IS_DOCUMENT | Ci.nsIWebProgressListener.STATE_IS_WINDOW))
|
||||||
{
|
{
|
||||||
// This fires when the load event is initiated
|
// This fires when the load event is initiated
|
||||||
// only thrown for the current tab, not when another tab changes
|
// only thrown for the current tab, not when another tab changes
|
||||||
@@ -1573,12 +1572,11 @@ function Events() //{{{
|
|||||||
// for notifying the user about secure web pages
|
// for notifying the user about secure web pages
|
||||||
onSecurityChange: function (webProgress, aRequest, aState)
|
onSecurityChange: function (webProgress, aRequest, aState)
|
||||||
{
|
{
|
||||||
const nsIWebProgressListener = Ci.nsIWebProgressListener;
|
if (aState & Ci.nsIWebProgressListener.STATE_IS_INSECURE)
|
||||||
if (aState & nsIWebProgressListener.STATE_IS_INSECURE)
|
|
||||||
statusline.setClass("insecure");
|
statusline.setClass("insecure");
|
||||||
else if (aState & nsIWebProgressListener.STATE_IS_BROKEN)
|
else if (aState & Ci.nsIWebProgressListener.STATE_IS_BROKEN)
|
||||||
statusline.setClass("broken");
|
statusline.setClass("broken");
|
||||||
else if (aState & nsIWebProgressListener.STATE_IS_SECURE)
|
else if (aState & Ci.nsIWebProgressListener.STATE_IS_SECURE)
|
||||||
statusline.setClass("secure");
|
statusline.setClass("secure");
|
||||||
},
|
},
|
||||||
onStatusChange: function (webProgress, request, status, message)
|
onStatusChange: function (webProgress, request, status, message)
|
||||||
@@ -1638,9 +1636,8 @@ function Events() //{{{
|
|||||||
prefObserver: {
|
prefObserver: {
|
||||||
register: function ()
|
register: function ()
|
||||||
{
|
{
|
||||||
const prefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService);
|
this._branch = service.pref.getBranch("") // better way to monitor all changes?
|
||||||
this._branch = prefService.getBranch(""); // better way to monitor all changes?
|
.QueryInterface(Ci.nsIPrefBranch2);
|
||||||
this._branch.QueryInterface(Ci.nsIPrefBranch2);
|
|
||||||
this._branch.addObserver("", this, false);
|
this._branch.addObserver("", this, false);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -133,9 +133,7 @@ function Search() //{{{
|
|||||||
var highlightObj = {
|
var highlightObj = {
|
||||||
search: function (aWord, matchCase)
|
search: function (aWord, matchCase)
|
||||||
{
|
{
|
||||||
var finder = Cc["@mozilla.org/embedcomp/rangefind;1"]
|
var finder = Cc["@mozilla.org/embedcomp/rangefind;1"].createInstance(Ci.nsIFind);
|
||||||
.createInstance()
|
|
||||||
.QueryInterface(Ci.nsIFind);
|
|
||||||
if (matchCase !== undefined)
|
if (matchCase !== undefined)
|
||||||
finder.caseSensitive = matchCase;
|
finder.caseSensitive = matchCase;
|
||||||
|
|
||||||
|
|||||||
@@ -61,12 +61,9 @@ function IO() //{{{
|
|||||||
const WINDOWS = liberator.has("Win32");
|
const WINDOWS = liberator.has("Win32");
|
||||||
const EXTENSION_NAME = config.name.toLowerCase(); // "vimperator" or "muttator"
|
const EXTENSION_NAME = config.name.toLowerCase(); // "vimperator" or "muttator"
|
||||||
|
|
||||||
const ioService = Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService);
|
|
||||||
const environmentService = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
|
|
||||||
const directoryService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
|
|
||||||
const downloadManager = Cc["@mozilla.org/download-manager;1"].createInstance(Ci.nsIDownloadManager);
|
const downloadManager = Cc["@mozilla.org/download-manager;1"].createInstance(Ci.nsIDownloadManager);
|
||||||
|
|
||||||
var processDir = directoryService.get("CurWorkD", Ci.nsIFile);
|
var processDir = service.directory.get("CurWorkD", Ci.nsIFile);
|
||||||
var cwd = processDir;
|
var cwd = processDir;
|
||||||
var oldcwd = null;
|
var oldcwd = null;
|
||||||
|
|
||||||
@@ -74,7 +71,7 @@ function IO() //{{{
|
|||||||
var scriptNames = [];
|
var scriptNames = [];
|
||||||
|
|
||||||
// default option values
|
// default option values
|
||||||
var cdpath = "," + (environmentService.get("CDPATH").replace(/[:;]/g, ",") || ",");
|
var cdpath = "," + (service.environment.get("CDPATH").replace(/[:;]/g, ",") || ",");
|
||||||
var runtimepath = "~/" + (WINDOWS ? "" : ".") + EXTENSION_NAME;
|
var runtimepath = "~/" + (WINDOWS ? "" : ".") + EXTENSION_NAME;
|
||||||
var shell, shellcmdflag;
|
var shell, shellcmdflag;
|
||||||
|
|
||||||
@@ -87,7 +84,7 @@ function IO() //{{{
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
shell = environmentService.get("SHELL") || "sh";
|
shell = service.environment.get("SHELL") || "sh";
|
||||||
shellcmdflag = "-c";
|
shellcmdflag = "-c";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,13 +113,13 @@ function IO() //{{{
|
|||||||
let path = ioManager.getFile(head);
|
let path = ioManager.getFile(head);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
path.appendRelativePath(ioManager.expandPath(tail)); // FIXME: should only expand env vars and normalise path separators
|
path.appendRelativePath(ioManager.expandPath(tail, true)); // FIXME: should only expand env vars and normalise path separators
|
||||||
if (path.exists())
|
if (path.exists())
|
||||||
path.normalize();
|
path.normalize();
|
||||||
}
|
}
|
||||||
catch(e)
|
catch(e)
|
||||||
{
|
{
|
||||||
return { exists: function () false };
|
return { exists: function () false, __noSuchMethod__: function () { throw e } };
|
||||||
}
|
}
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
@@ -131,7 +128,7 @@ function IO() //{{{
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile)
|
service.localFile
|
||||||
.initWithPath(path);
|
.initWithPath(path);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -407,7 +404,7 @@ function IO() //{{{
|
|||||||
|
|
||||||
pathSeparator: WINDOWS ? "\\" : "/",
|
pathSeparator: WINDOWS ? "\\" : "/",
|
||||||
|
|
||||||
expandPath: function (path)
|
expandPath: function (path, relative)
|
||||||
{
|
{
|
||||||
// TODO: proper pathname separator translation like Vim - this should be done elsewhere
|
// TODO: proper pathname separator translation like Vim - this should be done elsewhere
|
||||||
if (WINDOWS)
|
if (WINDOWS)
|
||||||
@@ -420,21 +417,21 @@ function IO() //{{{
|
|||||||
function expand(path) path.replace(
|
function expand(path) path.replace(
|
||||||
!WINDOWS ? /\$(\w+)\b|\${(\w+)}/g
|
!WINDOWS ? /\$(\w+)\b|\${(\w+)}/g
|
||||||
: /\$(\w+)\b|\${(\w+)}|%(\w+)%/g,
|
: /\$(\w+)\b|\${(\w+)}|%(\w+)%/g,
|
||||||
function (m, n1, n2, n3) environmentService.get(n1 || n2 || n3) || m
|
function (m, n1, n2, n3) service.environment.get(n1 || n2 || n3) || m
|
||||||
);
|
);
|
||||||
path = expand(path);
|
path = expand(path);
|
||||||
|
|
||||||
// expand ~
|
// expand ~
|
||||||
if ((WINDOWS ? /^~(?:$|\\)/ : /^~(?:$|\/)/).test(path))
|
if (!relative && (WINDOWS ? /^~(?:$|\\)/ : /^~(?:$|\/)/).test(path))
|
||||||
{
|
{
|
||||||
// Try $(VIMPERATOR|MUTTATOR)_HOME || $HOME first, on all systems
|
// Try $(VIMPERATOR|MUTTATOR)_HOME || $HOME first, on all systems
|
||||||
let home = environmentService.get(config.name.toUpperCase() + "_HOME") ||
|
let home = service.environment.get(config.name.toUpperCase() + "_HOME") ||
|
||||||
environmentService.get("HOME");
|
service.environment.get("HOME");
|
||||||
|
|
||||||
// Windows has its own ideosynchratic $HOME variables.
|
// Windows has its own ideosyncratic $HOME variables.
|
||||||
if (!home && WINDOWS)
|
if (!home && WINDOWS)
|
||||||
home = environmentService.get("USERPROFILE") ||
|
home = service.environment.get("USERPROFILE") ||
|
||||||
environmentService.get("HOMEDRIVE") + environmentService.get("HOMEPATH");
|
service.environment.get("HOMEDRIVE") + service.environment.get("HOMEPATH");
|
||||||
|
|
||||||
path = home + path.substr(1);
|
path = home + path.substr(1);
|
||||||
}
|
}
|
||||||
@@ -560,7 +557,7 @@ function IO() //{{{
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let file = directoryService.get("TmpD", Ci.nsIFile);
|
let file = service.directory.get("TmpD", Ci.nsIFile);
|
||||||
file.append(tmpName);
|
file.append(tmpName);
|
||||||
file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0600);
|
file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0600);
|
||||||
|
|
||||||
@@ -667,7 +664,7 @@ function IO() //{{{
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
let dirs = environmentService.get("PATH").split(WINDOWS ? ";" : ":");
|
let dirs = service.environment.get("PATH").split(WINDOWS ? ";" : ":");
|
||||||
// Windows tries the cwd first TODO: desirable?
|
// Windows tries the cwd first TODO: desirable?
|
||||||
if (WINDOWS)
|
if (WINDOWS)
|
||||||
dirs = [io.getCurrentDirectory().path].concat(dirs);
|
dirs = [io.getCurrentDirectory().path].concat(dirs);
|
||||||
@@ -685,7 +682,7 @@ lookup:
|
|||||||
// automatically try to add the executable path extensions on windows
|
// automatically try to add the executable path extensions on windows
|
||||||
if (WINDOWS)
|
if (WINDOWS)
|
||||||
{
|
{
|
||||||
let extensions = environmentService.get("PATHEXT").split(";");
|
let extensions = service.environment.get("PATHEXT").split(";");
|
||||||
for (let [,extension] in Iterator(extensions))
|
for (let [,extension] in Iterator(extensions))
|
||||||
{
|
{
|
||||||
file = joinPaths(dir, program + extension);
|
file = joinPaths(dir, program + extension);
|
||||||
@@ -830,7 +827,7 @@ lookup:
|
|||||||
liberator.echomsg("sourcing " + filename.quote(), 2);
|
liberator.echomsg("sourcing " + filename.quote(), 2);
|
||||||
|
|
||||||
let str = ioManager.readFile(file);
|
let str = ioManager.readFile(file);
|
||||||
let uri = ioService.newFileURI(file);
|
let uri = service.io.newFileURI(file);
|
||||||
|
|
||||||
// handle pure javascript files specially
|
// handle pure javascript files specially
|
||||||
if (/\.js$/.test(filename))
|
if (/\.js$/.test(filename))
|
||||||
|
|||||||
@@ -43,13 +43,33 @@ const userContext = {
|
|||||||
__proto__: modules
|
__proto__: modules
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let (cc = function (class, meth, iface) { try { return Cc[class][meth](iface) } catch (e) {} })
|
||||||
|
{
|
||||||
|
const service = {
|
||||||
|
appStartup: cc("@mozilla.org/toolkit/app-startup;1", "getService", Ci.nsIAppStartup),
|
||||||
|
autoCompleteSearch: cc("@mozilla.org/browser/global-history;2", "getService", Ci.nsIAutoCompleteSearch),
|
||||||
|
browserSearch: cc("@mozilla.org/browser/search-service;1", "getService", Ci.nsIBrowserSearchService),
|
||||||
|
console: cc("@mozilla.org/consoleservice;1", "getService", Ci.nsIConsoleService),
|
||||||
|
directory: cc("@mozilla.org/file/directory_service;1", "getService", Ci.nsIProperties),
|
||||||
|
environment: cc("@mozilla.org/process/environment;1", "getService", Ci.nsIEnvironment),
|
||||||
|
io: cc("@mozilla.org/network/io-service;1", "getService", Ci.nsIIOService).QueryInterface(Ci.nsIIOService2),
|
||||||
|
json: cc("@mozilla.org/dom/json;1", "createInstance", Ci.nsIJSON),
|
||||||
|
observer: cc("@mozilla.org/observer-service;1", "getService", Ci.nsIObserverService),
|
||||||
|
pref: cc("@mozilla.org/preferences-service;1", "getService", Ci.nsIPrefService)
|
||||||
|
.QueryInterface(Ci.nsIPrefBranch).QueryInterface(nsIPrefBranch2),
|
||||||
|
sessionStore: cc("@mozilla.org/browser/sessionstore;1", "getService", Ci.nsISessionStore),
|
||||||
|
subscriptLoader: cc("@mozilla.org/moz/jssubscript-loader;1", "getService", Ci.mozIJSSubScriptLoader),
|
||||||
|
threadManager: cc("@mozilla.org/thread-manager;1", "getService", Ci.nsIThreadManager),
|
||||||
|
windowMediator: cc("@mozilla.org/appshell/window-mediator;1", "getService", Ci.nsIWindowMediator),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const liberator = (function () //{{{
|
const liberator = (function () //{{{
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////{{{
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
|
|
||||||
const threadManager = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
|
|
||||||
function Runnable(self, func, args)
|
function Runnable(self, func, args)
|
||||||
{
|
{
|
||||||
this.self = self;
|
this.self = self;
|
||||||
@@ -678,18 +698,18 @@ const liberator = (function () //{{{
|
|||||||
return false; // so you can do: if (...) return liberator.beep();
|
return false; // so you can do: if (...) return liberator.beep();
|
||||||
},
|
},
|
||||||
|
|
||||||
newThread: function () threadManager.newThread(0),
|
newThread: function () service.threadManager.newThread(0),
|
||||||
|
|
||||||
callAsync: function (thread, self, func)
|
callAsync: function (thread, self, func)
|
||||||
{
|
{
|
||||||
hread = thread || threadManager.newThread(0);
|
hread = thread || service.threadManager.newThread(0);
|
||||||
thread.dispatch(new Runnable(self, func, Array.slice(arguments, 2)), thread.DISPATCH_NORMAL);
|
thread.dispatch(new Runnable(self, func, Array.slice(arguments, 2)), thread.DISPATCH_NORMAL);
|
||||||
},
|
},
|
||||||
|
|
||||||
// be sure to call GUI related methods like alert() or dump() ONLY in the main thread
|
// be sure to call GUI related methods like alert() or dump() ONLY in the main thread
|
||||||
callFunctionInThread: function (thread, func)
|
callFunctionInThread: function (thread, func)
|
||||||
{
|
{
|
||||||
thread = thread || threadManager.newThread(0);
|
thread = thread || service.threadManager.newThread(0);
|
||||||
|
|
||||||
// DISPATCH_SYNC is necessary, otherwise strange things will happen
|
// DISPATCH_SYNC is necessary, otherwise strange things will happen
|
||||||
thread.dispatch(new Runnable(null, func, Array.slice(arguments, 2)), thread.DISPATCH_SYNC);
|
thread.dispatch(new Runnable(null, func, Array.slice(arguments, 2)), thread.DISPATCH_SYNC);
|
||||||
@@ -761,8 +781,7 @@ const liberator = (function () //{{{
|
|||||||
|
|
||||||
loadScript: function (uri, context)
|
loadScript: function (uri, context)
|
||||||
{
|
{
|
||||||
let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader);
|
service.subscriptLoader.loadSubScript(uri, context);
|
||||||
loader.loadSubScript(uri, context);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
eval: function (str, context)
|
eval: function (str, context)
|
||||||
@@ -1047,8 +1066,7 @@ const liberator = (function () //{{{
|
|||||||
if (typeof msg == "object")
|
if (typeof msg == "object")
|
||||||
msg = util.objectToString(msg, false);
|
msg = util.objectToString(msg, false);
|
||||||
|
|
||||||
var consoleService = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);
|
service.console.logStringMessage(config.name.toLowerCase() + ": " + msg);
|
||||||
consoleService.logStringMessage(config.name.toLowerCase() + ": " + msg);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// open one or more URLs
|
// open one or more URLs
|
||||||
@@ -1085,7 +1103,6 @@ const liberator = (function () //{{{
|
|||||||
{
|
{
|
||||||
let url = Array.concat(urls)[0];
|
let url = Array.concat(urls)[0];
|
||||||
let postdata = Array.concat(urls)[1];
|
let postdata = Array.concat(urls)[1];
|
||||||
let whichwindow = window;
|
|
||||||
|
|
||||||
// decide where to load the first url
|
// decide where to load the first url
|
||||||
switch (where)
|
switch (where)
|
||||||
@@ -1105,10 +1122,9 @@ const liberator = (function () //{{{
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case liberator.NEW_WINDOW:
|
case liberator.NEW_WINDOW:
|
||||||
const wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
|
|
||||||
window.open();
|
window.open();
|
||||||
whichwindow = wm.getMostRecentWindow("navigator:browser");
|
service.windowMediator.getMostRecentWindow("navigator:browser")
|
||||||
whichwindow.loadURI(url, null, postdata);
|
.loadURI(url, null, postdata);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -1150,11 +1166,8 @@ const liberator = (function () //{{{
|
|||||||
else
|
else
|
||||||
options.setPref("browser.startup.page", 1); // start with default homepage session
|
options.setPref("browser.startup.page", 1); // start with default homepage session
|
||||||
|
|
||||||
const nsIAppStartup = Ci.nsIAppStartup;
|
|
||||||
if (force)
|
if (force)
|
||||||
Cc["@mozilla.org/toolkit/app-startup;1"]
|
service.appStartup.quit(Ci.nsIAppStartup.eForceQuit);
|
||||||
.getService(nsIAppStartup)
|
|
||||||
.quit(nsIAppStartup.eForceQuit);
|
|
||||||
else
|
else
|
||||||
window.goQuitApplication();
|
window.goQuitApplication();
|
||||||
},
|
},
|
||||||
@@ -1182,32 +1195,26 @@ const liberator = (function () //{{{
|
|||||||
|
|
||||||
restart: function ()
|
restart: function ()
|
||||||
{
|
{
|
||||||
const nsIAppStartup = Ci.nsIAppStartup;
|
|
||||||
|
|
||||||
// notify all windows that an application quit has been requested.
|
// notify all windows that an application quit has been requested.
|
||||||
var os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
|
|
||||||
var cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
|
var cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
|
||||||
os.notifyObservers(cancelQuit, "quit-application-requested", null);
|
service.observer.notifyObservers(cancelQuit, "quit-application-requested", null);
|
||||||
|
|
||||||
// something aborted the quit process.
|
// something aborted the quit process.
|
||||||
if (cancelQuit.data)
|
if (cancelQuit.data)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// notify all windows that an application quit has been granted.
|
// notify all windows that an application quit has been granted.
|
||||||
os.notifyObservers(null, "quit-application-granted", null);
|
service.observer.notifyObservers(null, "quit-application-granted", null);
|
||||||
|
|
||||||
// enumerate all windows and call shutdown handlers
|
// enumerate all windows and call shutdown handlers
|
||||||
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
|
var windows = service.windowMediator.getEnumerator(null);
|
||||||
var windows = wm.getEnumerator(null);
|
|
||||||
while (windows.hasMoreElements())
|
while (windows.hasMoreElements())
|
||||||
{
|
{
|
||||||
var win = windows.getNext();
|
var win = windows.getNext();
|
||||||
if (("tryToClose" in win) && !win.tryToClose())
|
if (("tryToClose" in win) && !win.tryToClose())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Cc["@mozilla.org/toolkit/app-startup;1"]
|
service.appStartup.quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit);
|
||||||
.getService(nsIAppStartup)
|
|
||||||
.quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// TODO: move to {muttator,vimperator,...}.js
|
// TODO: move to {muttator,vimperator,...}.js
|
||||||
@@ -1324,7 +1331,7 @@ const liberator = (function () //{{{
|
|||||||
|
|
||||||
sleep: function (delay)
|
sleep: function (delay)
|
||||||
{
|
{
|
||||||
let mainThread = threadManager.mainThread;
|
let mainThread = service.threadManager.mainThread;
|
||||||
|
|
||||||
let end = Date.now() + delay;
|
let end = Date.now() + delay;
|
||||||
while (Date.now() < end)
|
while (Date.now() < end)
|
||||||
@@ -1334,8 +1341,8 @@ const liberator = (function () //{{{
|
|||||||
|
|
||||||
callInMainThread: function (callback, self)
|
callInMainThread: function (callback, self)
|
||||||
{
|
{
|
||||||
let mainThread = threadManager.mainThread;
|
let mainThread = service.threadManager.mainThread;
|
||||||
if (!threadManager.isMainThread)
|
if (!service.threadManager.isMainThread)
|
||||||
mainThread.dispatch({ run: callback.call(self) }, mainThread.DISPATCH_NORMAL);
|
mainThread.dispatch({ run: callback.call(self) }, mainThread.DISPATCH_NORMAL);
|
||||||
else
|
else
|
||||||
callback.call(self);
|
callback.call(self);
|
||||||
@@ -1343,7 +1350,7 @@ const liberator = (function () //{{{
|
|||||||
|
|
||||||
threadYield: function (flush, interruptable)
|
threadYield: function (flush, interruptable)
|
||||||
{
|
{
|
||||||
let mainThread = threadManager.mainThread;
|
let mainThread = service.threadManager.mainThread;
|
||||||
liberator.interrupted = false;
|
liberator.interrupted = false;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@@ -1382,9 +1389,8 @@ const liberator = (function () //{{{
|
|||||||
|
|
||||||
get windows()
|
get windows()
|
||||||
{
|
{
|
||||||
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
|
|
||||||
var wa = [];
|
var wa = [];
|
||||||
var enumerator = wm.getEnumerator("navigator:browser");
|
var enumerator = service.windowMediator.getEnumerator("navigator:browser");
|
||||||
while (enumerator.hasMoreElements())
|
while (enumerator.hasMoreElements())
|
||||||
wa.push(enumerator.getNext());
|
wa.push(enumerator.getNext());
|
||||||
return wa;
|
return wa;
|
||||||
|
|||||||
@@ -301,7 +301,6 @@ function Options() //{{{
|
|||||||
|
|
||||||
const SAVED = "liberator.saved.";
|
const SAVED = "liberator.saved.";
|
||||||
|
|
||||||
const prefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
|
|
||||||
var optionHash = {};
|
var optionHash = {};
|
||||||
|
|
||||||
function optionObserver(key, event, option)
|
function optionObserver(key, event, option)
|
||||||
@@ -320,27 +319,27 @@ function Options() //{{{
|
|||||||
|
|
||||||
function storePreference(name, value)
|
function storePreference(name, value)
|
||||||
{
|
{
|
||||||
var type = prefService.getPrefType(name);
|
var type = service.prefBranch.getPrefType(name);
|
||||||
switch (typeof value)
|
switch (typeof value)
|
||||||
{
|
{
|
||||||
case "string":
|
case "string":
|
||||||
if (type == prefService.PREF_INVALID || type == prefService.PREF_STRING)
|
if (type == service.prefBranch.PREF_INVALID || type == service.prefBranch.PREF_STRING)
|
||||||
prefService.setCharPref(name, value);
|
service.pref.setCharPref(name, value);
|
||||||
else if (type == prefService.PREF_INT)
|
else if (type == service.pref.PREF_INT)
|
||||||
liberator.echoerr("E521: Number required after =: " + name + "=" + value);
|
liberator.echoerr("E521: Number required after =: " + name + "=" + value);
|
||||||
else
|
else
|
||||||
liberator.echoerr("E474: Invalid argument: " + name + "=" + value);
|
liberator.echoerr("E474: Invalid argument: " + name + "=" + value);
|
||||||
break;
|
break;
|
||||||
case "number":
|
case "number":
|
||||||
if (type == prefService.PREF_INVALID || type == prefService.PREF_INT)
|
if (type == service.pref.PREF_INVALID || type == service.pref.PREF_INT)
|
||||||
prefService.setIntPref(name, value);
|
service.pref.setIntPref(name, value);
|
||||||
else
|
else
|
||||||
liberator.echoerr("E474: Invalid argument: " + name + "=" + value);
|
liberator.echoerr("E474: Invalid argument: " + name + "=" + value);
|
||||||
break;
|
break;
|
||||||
case "boolean":
|
case "boolean":
|
||||||
if (type == prefService.PREF_INVALID || type == prefService.PREF_BOOL)
|
if (type == service.pref.PREF_INVALID || type == service.pref.PREF_BOOL)
|
||||||
prefService.setBoolPref(name, value);
|
service.pref.setBoolPref(name, value);
|
||||||
else if (type == prefService.PREF_INT)
|
else if (type == service.pref.PREF_INT)
|
||||||
liberator.echoerr("E521: Number required after =: " + name + "=" + value);
|
liberator.echoerr("E521: Number required after =: " + name + "=" + value);
|
||||||
else
|
else
|
||||||
liberator.echoerr("E474: Invalid argument: " + name + "=" + value);
|
liberator.echoerr("E474: Invalid argument: " + name + "=" + value);
|
||||||
@@ -356,22 +355,22 @@ function Options() //{{{
|
|||||||
if (forcedDefault != null) // this argument sets defaults for non-user settable options (like extensions.history.comp_history)
|
if (forcedDefault != null) // this argument sets defaults for non-user settable options (like extensions.history.comp_history)
|
||||||
defaultValue = forcedDefault;
|
defaultValue = forcedDefault;
|
||||||
|
|
||||||
let branch = defaultBranch ? prefService.getDefaultBranch("") : prefService;
|
let branch = defaultBranch ? service.pref.getDefaultBranch("") : service.pref;
|
||||||
let type = prefService.getPrefType(name);
|
let type = service.pref.getPrefType(name);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case prefService.PREF_STRING:
|
case service.pref.PREF_STRING:
|
||||||
let value = branch.getComplexValue(name, Ci.nsISupportsString).data;
|
let value = branch.getComplexValue(name, Ci.nsISupportsString).data;
|
||||||
// try in case it's a localized string (will throw an exception if not)
|
// try in case it's a localized string (will throw an exception if not)
|
||||||
if (!prefService.prefIsLocked(name) && !prefService.prefHasUserValue(name) &&
|
if (!service.pref.prefIsLocked(name) && !service.pref.prefHasUserValue(name) &&
|
||||||
/^chrome:\/\/.+\/locale\/.+\.properties/.test(value))
|
/^chrome:\/\/.+\/locale\/.+\.properties/.test(value))
|
||||||
value = branch.getComplexValue(name, Ci.nsIPrefLocalizedString).data;
|
value = branch.getComplexValue(name, Ci.nsIPrefLocalizedString).data;
|
||||||
return value;
|
return value;
|
||||||
case prefService.PREF_INT:
|
case service.pref.PREF_INT:
|
||||||
return branch.getIntPref(name);
|
return branch.getIntPref(name);
|
||||||
case prefService.PREF_BOOL:
|
case service.pref.PREF_BOOL:
|
||||||
return branch.getBoolPref(name);
|
return branch.getBoolPref(name);
|
||||||
default:
|
default:
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
@@ -777,7 +776,7 @@ function Options() //{{{
|
|||||||
{
|
{
|
||||||
completion.setFunctionCompleter(options.get, [function () ([o.name, o.description] for (o in 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],
|
completion.setFunctionCompleter([options.getPref, options.safeSetPref, options.setPref, options.resetPref, options.invertPref],
|
||||||
[function () Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch)
|
[function () service.prefBranch
|
||||||
.getChildList("", { value: 0 })
|
.getChildList("", { value: 0 })
|
||||||
.map(function (pref) [pref, ""])]);
|
.map(function (pref) [pref, ""])]);
|
||||||
});
|
});
|
||||||
@@ -880,12 +879,12 @@ function Options() //{{{
|
|||||||
if (!filter)
|
if (!filter)
|
||||||
filter = "";
|
filter = "";
|
||||||
|
|
||||||
var prefArray = prefService.getChildList("", { value: 0 });
|
var prefArray = service.pref.getChildList("", { value: 0 });
|
||||||
prefArray.sort();
|
prefArray.sort();
|
||||||
let prefs = function () {
|
let prefs = function () {
|
||||||
for each (let pref in prefArray)
|
for each (let pref in prefArray)
|
||||||
{
|
{
|
||||||
let userValue = prefService.prefHasUserValue(pref);
|
let userValue = service.pref.prefHasUserValue(pref);
|
||||||
if (onlyNonDefault && !userValue || pref.indexOf(filter) == -1)
|
if (onlyNonDefault && !userValue || pref.indexOf(filter) == -1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -978,13 +977,13 @@ function Options() //{{{
|
|||||||
|
|
||||||
resetPref: function (name)
|
resetPref: function (name)
|
||||||
{
|
{
|
||||||
return prefService.clearUserPref(name);
|
return service.pref.clearUserPref(name);
|
||||||
},
|
},
|
||||||
|
|
||||||
// this works only for booleans
|
// this works only for booleans
|
||||||
invertPref: function (name)
|
invertPref: function (name)
|
||||||
{
|
{
|
||||||
if (prefService.getPrefType(name) == prefService.PREF_BOOL)
|
if (service.pref.getPrefType(name) == service.pref.PREF_BOOL)
|
||||||
this.setPref(name, !this.getPref(name));
|
this.setPref(name, !this.getPref(name));
|
||||||
else
|
else
|
||||||
liberator.echoerr("E488: Trailing characters: " + name + "!");
|
liberator.echoerr("E488: Trailing characters: " + name + "!");
|
||||||
|
|||||||
@@ -212,8 +212,8 @@ function Styles(name, store, serial)
|
|||||||
const util = modules.util;
|
const util = modules.util;
|
||||||
const sleep = liberator.sleep;
|
const sleep = liberator.sleep;
|
||||||
const storage = modules.storage;
|
const storage = modules.storage;
|
||||||
const consoleService = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);
|
const consoleService = service.console;
|
||||||
const ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
const ios = service.io;
|
||||||
const sss = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService);
|
const sss = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService);
|
||||||
const namespace = '@namespace html "' + XHTML + '";\n' +
|
const namespace = '@namespace html "' + XHTML + '";\n' +
|
||||||
'@namespace xul "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";\n' +
|
'@namespace xul "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";\n' +
|
||||||
|
|||||||
@@ -97,13 +97,11 @@ function Tabs() //{{{
|
|||||||
|
|
||||||
function copyTab(to, from)
|
function copyTab(to, from)
|
||||||
{
|
{
|
||||||
const ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
|
|
||||||
|
|
||||||
if (!from)
|
if (!from)
|
||||||
from = getBrowser().mTabContainer.selectedItem;
|
from = getBrowser().mTabContainer.selectedItem;
|
||||||
|
|
||||||
let tabState = ss.getTabState(from);
|
let tabState = service.sessionStore.getTabState(from);
|
||||||
ss.setTabState(to, tabState);
|
service.sessionStore.setTabState(to, tabState);
|
||||||
}
|
}
|
||||||
|
|
||||||
// hide tabs initially
|
// hide tabs initially
|
||||||
@@ -263,12 +261,12 @@ function Tabs() //{{{
|
|||||||
|
|
||||||
mappings.add([modes.NORMAL], ["d"],
|
mappings.add([modes.NORMAL], ["d"],
|
||||||
"Delete current buffer",
|
"Delete current buffer",
|
||||||
function (count) { tabs.remove(getBrowser().mCurrentTab, count, false, 0); },
|
function (count) { tabs.remove(tabs.getTab(), count, false, 0); },
|
||||||
{ flags: Mappings.flags.COUNT });
|
{ flags: Mappings.flags.COUNT });
|
||||||
|
|
||||||
mappings.add([modes.NORMAL], ["D"],
|
mappings.add([modes.NORMAL], ["D"],
|
||||||
"Delete current buffer, focus tab to the left",
|
"Delete current buffer, focus tab to the left",
|
||||||
function (count) { tabs.remove(getBrowser().mCurrentTab, count, true, 0); },
|
function (count) { tabs.remove(tabs.getTab(), count, true, 0); },
|
||||||
{ flags: Mappings.flags.COUNT });
|
{ flags: Mappings.flags.COUNT });
|
||||||
|
|
||||||
mappings.add([modes.NORMAL], ["gb"],
|
mappings.add([modes.NORMAL], ["gb"],
|
||||||
@@ -345,7 +343,7 @@ function Tabs() //{{{
|
|||||||
liberator.echoerr("E94: No matching tab for " + arg);
|
liberator.echoerr("E94: No matching tab for " + arg);
|
||||||
}
|
}
|
||||||
else // just remove the current tab
|
else // just remove the current tab
|
||||||
tabs.remove(getBrowser().mCurrentTab, count > 0 ? count : 1, special, 0);
|
tabs.remove(tabs.getTab(), count > 0 ? count : 1, special, 0);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
argCount: "?",
|
argCount: "?",
|
||||||
@@ -733,14 +731,12 @@ function Tabs() //{{{
|
|||||||
if (index != undefined)
|
if (index != undefined)
|
||||||
return getBrowser().mTabs[index];
|
return getBrowser().mTabs[index];
|
||||||
|
|
||||||
return getBrowser().mTabContainer.selectedItem;
|
return getBrowser().mCurrentTab;
|
||||||
},
|
},
|
||||||
|
|
||||||
get closedTabs()
|
get closedTabs()
|
||||||
{
|
{
|
||||||
const json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
|
return service.json.decode(service.sessionStore.getClosedTabData(window));
|
||||||
const ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
|
|
||||||
return json.decode(ss.getClosedTabData(window));
|
|
||||||
},
|
},
|
||||||
|
|
||||||
list: function (filter)
|
list: function (filter)
|
||||||
@@ -843,8 +839,7 @@ function Tabs() //{{{
|
|||||||
{
|
{
|
||||||
if (bypassCache)
|
if (bypassCache)
|
||||||
{
|
{
|
||||||
const nsIWebNavigation = Ci.nsIWebNavigation;
|
const flags = Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_PROXY | Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE;
|
||||||
const flags = nsIWebNavigation.LOAD_FLAGS_BYPASS_PROXY | nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE;
|
|
||||||
getBrowser().getBrowserForTab(tab).reloadWithFlags(flags);
|
getBrowser().getBrowserForTab(tab).reloadWithFlags(flags);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -968,8 +963,7 @@ function Tabs() //{{{
|
|||||||
tab = getBrowser().mTabContainer.selectedItem;
|
tab = getBrowser().mTabContainer.selectedItem;
|
||||||
|
|
||||||
window.open();
|
window.open();
|
||||||
const wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
|
let win = service.windowMediator.getMostRecentWindow("navigator:browser");
|
||||||
let win = wm.getMostRecentWindow("navigator:browser");
|
|
||||||
|
|
||||||
copyTab(win.getBrowser().mCurrentTab, tab);
|
copyTab(win.getBrowser().mCurrentTab, tab);
|
||||||
this.remove(tab, 1, false, 1);
|
this.remove(tab, 1, false, 1);
|
||||||
|
|||||||
@@ -659,9 +659,8 @@ function CommandLine() //{{{
|
|||||||
{
|
{
|
||||||
completer: function completer(value)
|
completer: function completer(value)
|
||||||
{
|
{
|
||||||
let ss = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService);
|
let engines = service.browserSearch.getEngines({})
|
||||||
let engines = ss.getEngines({})
|
.filter(function (engine) engine.supportsResponseType("application/x-suggestions+json"));
|
||||||
.filter(function (engine) engine.supportsResponseType("application/x-suggestions+json"));
|
|
||||||
|
|
||||||
return engines.map(function (engine) [engine.alias, engine.description]);
|
return engines.map(function (engine) [engine.alias, engine.description]);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -81,60 +81,6 @@ const util = { //{{{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// TODO: class could have better variable names/documentation
|
|
||||||
Timer: 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)
|
|
||||||
{
|
|
||||||
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
|
|
||||||
{
|
|
||||||
callback(this.arg);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
this.doneAt = Date.now() + minInterval;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.tell = function (arg)
|
|
||||||
{
|
|
||||||
if (arg !== undefined)
|
|
||||||
this.arg = arg;
|
|
||||||
|
|
||||||
let now = Date.now();
|
|
||||||
if (this.doneAt == -1)
|
|
||||||
timer.cancel();
|
|
||||||
|
|
||||||
let timeout = minInterval;
|
|
||||||
if (now > this.doneAt && this.doneAt > -1)
|
|
||||||
timeout = 0;
|
|
||||||
else if (this.latest)
|
|
||||||
timeout = Math.min(timeout, this.latest - now);
|
|
||||||
else
|
|
||||||
this.latest = now + maxInterval;
|
|
||||||
|
|
||||||
timer.initWithCallback(this, Math.max(timeout, 0), timer.TYPE_ONE_SHOT);
|
|
||||||
this.doneAt = -1;
|
|
||||||
};
|
|
||||||
this.reset = function ()
|
|
||||||
{
|
|
||||||
timer.cancel();
|
|
||||||
this.doneAt = 0;
|
|
||||||
};
|
|
||||||
this.flush = function ()
|
|
||||||
{
|
|
||||||
if (this.latest)
|
|
||||||
this.notify();
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
cloneObject: function cloneObject(obj)
|
cloneObject: function cloneObject(obj)
|
||||||
{
|
{
|
||||||
if (obj instanceof Array)
|
if (obj instanceof Array)
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ function Bookmarks() //{{{
|
|||||||
const historyService = PlacesUtils.history;
|
const historyService = PlacesUtils.history;
|
||||||
const bookmarksService = PlacesUtils.bookmarks;
|
const bookmarksService = PlacesUtils.bookmarks;
|
||||||
const taggingService = PlacesUtils.tagging;
|
const taggingService = PlacesUtils.tagging;
|
||||||
const searchService = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService);
|
const searchService = service.browserSearch;
|
||||||
const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
const ioService = service.io;
|
||||||
const faviconService = Cc["@mozilla.org/browser/favicon-service;1"].getService(Ci.nsIFaviconService);
|
const faviconService = Cc["@mozilla.org/browser/favicon-service;1"].getService(Ci.nsIFaviconService);
|
||||||
|
|
||||||
const Bookmark = new Struct("url", "title", "icon", "keyword", "tags", "id");
|
const Bookmark = new Struct("url", "title", "icon", "keyword", "tags", "id");
|
||||||
@@ -533,7 +533,7 @@ function Bookmarks() //{{{
|
|||||||
|
|
||||||
getSuggestions: function getSuggestions(engine, query, callback)
|
getSuggestions: function getSuggestions(engine, query, callback)
|
||||||
{
|
{
|
||||||
let ss = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService);
|
let ss = service.browserSearch;
|
||||||
const responseType = "application/x-suggestions+json";
|
const responseType = "application/x-suggestions+json";
|
||||||
|
|
||||||
let engine = ss.getEngineByAlias(engine);
|
let engine = ss.getEngineByAlias(engine);
|
||||||
@@ -544,7 +544,7 @@ function Bookmarks() //{{{
|
|||||||
|
|
||||||
function process(resp)
|
function process(resp)
|
||||||
{
|
{
|
||||||
const json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
|
const json = service.json;
|
||||||
let results = [];
|
let results = [];
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -418,16 +418,13 @@ const config = { //{{{
|
|||||||
{
|
{
|
||||||
setter: function (value)
|
setter: function (value)
|
||||||
{
|
{
|
||||||
const ioService = Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService2);
|
|
||||||
|
|
||||||
ioService.offline = !value;
|
ioService.offline = !value;
|
||||||
gPrefService.setBoolPref("browser.offline", ioService.offline);
|
gPrefService.setBoolPref("browser.offline", service.io.offline);
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
},
|
},
|
||||||
getter: function ()
|
getter: function ()
|
||||||
{
|
{
|
||||||
return Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService2).offline;
|
return service.io.offline;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user