Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

load_rc: allow chrome and file uris

load_rc() will now accept a number of ways to specify the file to
load.  In particular this allows loading from chrome uris on the
command line.  The code tries to produce an nsILocalFile from whatever
it's given so that, for instance, the directory processing works for
chrome uris too.

The subscript loader will refuse to load a non-local uri.

A chrome uri is provided for the test suite, which allows usage like:

  conkeror -q -batch -l chrome://conkeror-test/content/simple

Another usage is to load a module from the contrib area:

  load_rc("chrome://conkeror-contrib/content/mode-line-buttons.js");
  • Loading branch information...
commit 7337b2f87304984cd92cc3cb9e9f7bc5d1391212 1 parent 23a7f62
David Kettler authored
View
1  chrome/chrome.manifest
@@ -6,6 +6,7 @@ locale conkeror-gui en-US file:../locale/en-US/
content conkeror-help file:../help/
content conkeror-contrib file:../contrib/modules/
+content conkeror-test file:../tests/
locale branding en-US file:../branding/
View
2  modules/command-line.js
@@ -96,7 +96,7 @@ command_line_param_handler("f", true, function (command, ctx) {
command_line_param_handler("l", false, function (path, ctx) {
try {
- load_rc(ctx.command_line.resolveFile(path).path);
+ load_rc(path, function(path) ctx.command_line.resolveFile(path));
} catch (e) { dump_error(e); }
});
View
77 modules/rc.js
@@ -9,13 +9,16 @@
function load_rc_file (file) {
try {
- var name;
+ var prefix = "file://";
+ var uri;
if (typeof file == "string")
- name = file;
+ uri = prefix + file;
+ else if (file instanceof Ci.nsIURI)
+ uri = file.spec;
else
- name = file.path;
+ uri = prefix + file.path;
- subscript_loader.loadSubScript("file://" + name, conkeror);
+ subscript_loader.loadSubScript(uri, conkeror);
} catch (e) {
dump_error(e);
}
@@ -47,37 +50,65 @@ function load_rc_directory (file_o) {
/*
- * path_s: string path to load. may be a file, a directory, or null.
- * if it is a file, that file will be loaded. if it is a directory,
- * all `.js' files in that directory will be loaded. if it is null,
- * the preference `conkeror.rcfile' will be read for the default.
+ * The file to load may be specified as an nsILocalFile, an nsIURI or
+ * a string uri or file path or null. If path specifies a directory
+ * all `.js' files in that directory will be loaded. The default,
+ * for a null path, is specified by the preference `conkeror.rcfile'
+ * if it is set, otherwise it is $HOME/.conkerorrc. A uri that is
+ * not of file or chrome scheme will fail.
*/
-function load_rc (path_s) {
- if (! path_s) {
+function load_rc (path, resolve) {
+ var file;
+
+ if (typeof path == "object")
+ file = path;
+ if (typeof path == "string") {
+ try {
+ file = make_uri(path);
+ } catch (e) {
+ if (resolve)
+ file = resolve(path);
+ }
+ }
+ if (file instanceof Ci.nsIURI && file.schemeIs("chrome"))
+ try {
+ file = make_file_from_chrome(file);
+ } catch (e) { /* ignore */ }
+ if (file instanceof Ci.nsIURI && file.schemeIs("file"))
+ file = make_file(file.path);
+
+ if (!path) {
if (pref_has_user_value("conkeror.rcfile")) {
var rcfile = get_pref("conkeror.rcfile");
if (rcfile.length)
- path_s = rcfile;
+ path = rcfile;
else
return;
} else {
- var default_rc = get_home_directory();
- default_rc.appendRelativePath(".conkerorrc");
- if (default_rc.exists())
- path_s = default_rc.path;
- else
+ file = get_home_directory();
+ file.appendRelativePath(".conkerorrc");
+ if (!file.exists())
return;
}
}
- var file_o = Cc["@mozilla.org/file/local;1"]
- .createInstance(Ci.nsILocalFile);
- file_o.initWithPath(path_s);
- if (file_o.isDirectory()) {
- load_rc_directory(file_o);
+ if (!file)
+ file = make_file(path);
+
+ if (file instanceof Ci.nsILocalFile) {
+ path = file.path;
+ if (!file.exists())
+ throw interactive_error("File not found: " + path);
+ }
+ if (file instanceof Ci.nsIURI)
+ path = file.spec;
+
+ if (file instanceof Ci.nsILocalFile && file.isDirectory()) {
+ load_rc_directory(file);
} else {
- load_rc_file(path_s);
+ load_rc_file(file);
}
- return file_o.path;
+
+ return path;
}
View
6 modules/utils.js
@@ -144,6 +144,12 @@ function make_uri (uri, charset, base_uri) {
return io_service.newURI(uri, charset, base_uri);
}
+function make_file_from_chrome (url) {
+ var crs = Cc['@mozilla.org/chrome/chrome-registry;1']
+ .getService(Ci.nsIChromeRegistry);
+ var file = crs.convertChromeURL(make_uri(url));
+ return make_file(file.path);
+}
function get_document_content_disposition (document_o) {
var content_disposition = null;
Please sign in to comment.
Something went wrong with that request. Please try again.