load_js() will now accept a number of ways to specify the file to
load.  In particular this allows loading from chrome and file uris on
the command line.  The code tries to produce a file object 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 battery of tests can now be run with:

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

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

  load_js("chrome://conkeror-contrib/content/mode-line-buttons.js");

This restores previously available functionality.
---
 modules/command-line.js |    2 +-
 modules/rc.js           |   26 +++++++++++++++++++++++---
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/modules/command-line.js b/modules/command-line.js
index 401a7c6..1765432 100644
--- a/modules/command-line.js
+++ b/modules/command-line.js
@@ -112,7 +112,7 @@ command_line_param_handler("f", true, function (command, 
ctx) {
 
 command_line_param_handler("l", false, function (path, ctx) {
         try {
-            load_js(ctx.command_line.resolveFile(path));
+            load_js(path, function(path) ctx.command_line.resolveFile(path));
         } catch (e) {
             dump_error(e);
         }
diff --git a/modules/rc.js b/modules/rc.js
index 4f60b1b..c4096ed 100644
--- a/modules/rc.js
+++ b/modules/rc.js
@@ -33,10 +33,27 @@ function load_rc () {
     return load_js(path);
 }
 
-function load_js (path) {
+function load_js (path, resolve) {
     var files = [];
     var ret;
-    if (path.isDirectory()) {
+
+    if (typeof path == "string") {
+        try {
+            path = make_uri(path);
+        } catch (e) {
+            if (resolve)
+                path = resolve(path);
+        }
+    }
+
+    if (path instanceof Ci.nsIURI && path.schemeIs("chrome"))
+        try {
+            path = make_file_from_chrome(path);
+        } catch (e) { /* ignore */ }
+    if (path instanceof Ci.nsIURI && path.schemeIs("file"))
+        path = make_file(path.path);
+
+    if (path instanceof Ci.nsIFile && path.isDirectory()) {
         var entries = path.directoryEntries;
         while (entries.hasMoreElements()) {
             var entry = entries.getNext();
@@ -56,7 +73,10 @@ function load_js (path) {
         ret = path.path.substr(0, path.path.length - 1) + "*.js";
     } else {
         files.push(path);
-        ret = path.path;
+        if (path instanceof Ci.nsIURI)
+            ret = path.spec;
+        if (path instanceof Ci.nsIFile)
+            ret = path.path;
     }
     for (var i = 0; files[i]; i++) {
         try {
-- 
1.7.6.3

_______________________________________________
Conkeror mailing list
[email protected]
https://www.mozdev.org/mailman/listinfo/conkeror

Reply via email to