1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 10:17:59 +01:00

Make buffer.UR[LI] nsIURI objects. Fix bug in chrome-data:.

This commit is contained in:
Kris Maglione
2011-01-03 22:00:53 -05:00
parent ec554ac6c9
commit d661d60cb6
11 changed files with 46 additions and 38 deletions

View File

@@ -93,8 +93,14 @@ ChromeData.prototype = {
newChannel: function (uri) { newChannel: function (uri) {
try { try {
if (uri.scheme == this.scheme) if (uri.scheme == this.scheme) {
return makeChannel(uri.spec.replace(/^.*?:\/*(.*)(?:#.*)?/, "data:$1"), uri); let channel = ioService.newChannel(uri.spec.replace(/^.*?:\/*(.*)(?:#.*)?/, "data:$1"),
null, null);
channel.contentCharset = "UTF-8";
channel.owner = systemPrincipal;
channel.originalURI = uri;
return channel;
}
} }
catch (e) {} catch (e) {}
return fakeChannel(uri); return fakeChannel(uri);

View File

@@ -207,7 +207,7 @@ var AutoCommands = Module("autocommands", {
return void dactyl.echomsg("No matching autocommands"); return void dactyl.echomsg("No matching autocommands");
let [event, url] = args; let [event, url] = args;
let defaultURL = url || buffer.URL; let defaultURL = url || buffer.URL.spec;
let validEvents = Object.keys(config.autocommands); let validEvents = Object.keys(config.autocommands);
// TODO: add command validators // TODO: add command validators
@@ -224,7 +224,7 @@ var AutoCommands = Module("autocommands", {
for (let i = 0; i < tabs.count; i++) { for (let i = 0; i < tabs.count; i++) {
tabs.select(i); tabs.select(i);
// if no url arg is specified use the current buffer's URL // if no url arg is specified use the current buffer's URL
autocommands.trigger(event, { url: url || buffer.URL }); autocommands.trigger(event, { url: url || buffer.URL.spec });
} }
tabs.select(current); tabs.select(current);

View File

@@ -62,7 +62,7 @@ var Bookmarks = Module("bookmarks", {
try { try {
let uri = util.createURI(url); let uri = util.createURI(url);
if (!force && this.isBookmarked(uri.spec)) if (!force && this.isBookmarked(uri))
for (var bmark in bookmarkcache) for (var bmark in bookmarkcache)
if (bmark.url == uri.spec) { if (bmark.url == uri.spec) {
if (title) if (title)
@@ -130,7 +130,7 @@ var Bookmarks = Module("bookmarks", {
if (count > 0) if (count > 0)
dactyl.echomsg({ domains: [util.getHost(url)], message: "Removed bookmark: " + url }); dactyl.echomsg({ domains: [util.getHost(url)], message: "Removed bookmark: " + url });
else { else {
let title = buffer.URL == url && buffer.title || url; let title = buffer.URL.spec == url && buffer.title || url;
let extra = ""; let extra = "";
if (title != url) if (title != url)
extra = " (" + title + ")"; extra = " (" + title + ")";
@@ -145,10 +145,12 @@ var Bookmarks = Module("bookmarks", {
* *
* @param {string} url The URL of which to check the bookmarked state. * @param {string} url The URL of which to check the bookmarked state.
*/ */
isBookmarked: function isBookmarked(url) { isBookmarked: function isBookmarked(uri) {
if (isString(uri))
uri = util.newURI(uri);
try { try {
return services.bookmarks return services.bookmarks
.getBookmarkIdsForURI(makeURI(url), {}) .getBookmarkIdsForURI(uri, {})
.some(bookmarkcache.closure.isRegularBookmark); .some(bookmarkcache.closure.isRegularBookmark);
} }
catch (e) { catch (e) {
@@ -442,7 +444,7 @@ var Bookmarks = Module("bookmarks", {
post: args["-post"], post: args["-post"],
tags: args["-tags"] || [], tags: args["-tags"] || [],
title: args["-title"] || (args.length === 0 ? buffer.title : null), title: args["-title"] || (args.length === 0 ? buffer.title : null),
url: args.length === 0 ? buffer.URL : args[0] url: args.length === 0 ? buffer.URL.spec : args[0]
}; };
if (bookmarks.add(opts)) { if (bookmarks.add(opts)) {
@@ -504,7 +506,7 @@ var Bookmarks = Module("bookmarks", {
}); });
else { else {
if (!(args.length || args["-tags"] || args["-keyword"] || args["-title"])) if (!(args.length || args["-tags"] || args["-keyword"] || args["-title"]))
var deletedCount = bookmarks.remove(buffer.URL); var deletedCount = bookmarks.remove(buffer.URL.spec);
else { else {
let context = CompletionContext(args.join(" ")); let context = CompletionContext(args.join(" "));
context.fork("bookmark", 0, completion, "bookmark", context.fork("bookmark", 0, completion, "bookmark",
@@ -536,7 +538,8 @@ var Bookmarks = Module("bookmarks", {
function () { function () {
let options = {}; let options = {};
let bmarks = bookmarks.get(buffer.URL).filter(function (bmark) bmark.url == buffer.URL); let url = buffer.URL.spec;
let bmarks = bookmarks.get(url).filter(function (bmark) bmark.url == url);
if (bmarks.length == 1) { if (bmarks.length == 1) {
let bmark = bmarks[0]; let bmark = bmarks[0];
@@ -548,18 +551,18 @@ var Bookmarks = Module("bookmarks", {
options["-tags"] = bmark.tags.join(", "); options["-tags"] = bmark.tags.join(", ");
} }
else { else {
if (buffer.title != buffer.URL) if (buffer.title != buffer.URL.spec)
options["-title"] = buffer.title; options["-title"] = buffer.title;
} }
commandline.open(":", commandline.open(":",
commands.commandToString({ command: "bmark", options: options, arguments: [buffer.URL] }), commands.commandToString({ command: "bmark", options: options, arguments: [buffer.URL.spec] }),
modes.EX); modes.EX);
}); });
mappings.add(myModes, ["A"], mappings.add(myModes, ["A"],
"Toggle bookmarked state of current URL", "Toggle bookmarked state of current URL",
function () { bookmarks.toggle(buffer.URL); }); function () { bookmarks.toggle(buffer.URL.spec); });
}, },
options: function () { options: function () {
options.add(["defsearch", "ds"], options.add(["defsearch", "ds"],

View File

@@ -14,18 +14,18 @@
var Browser = Module("browser", { var Browser = Module("browser", {
}, { }, {
climbUrlPath: function (count) { climbUrlPath: function (count) {
let url = util.newURI(buffer.URL); let url = buffer.URI;
dactyl.assert(url instanceof Ci.nsIURL); dactyl.assert(url instanceof Ci.nsIURL);
while (count-- && url.path != "/") while (count-- && url.path != "/")
url.path = url.path.replace(/[^\/]+\/*$/, ""); url.path = url.path.replace(/[^\/]+\/*$/, "");
dactyl.assert(url.spec != buffer.URL); dactyl.assert(!url.equals(buffer.URI));
dactyl.open(url.spec); dactyl.open(url.spec);
}, },
incrementURL: function (count) { incrementURL: function (count) {
let matches = buffer.URL.match(/(.*?)(\d+)(\D*)$/); let matches = buffer.URL.spec.match(/(.*?)(\d+)(\D*)$/);
dactyl.assert(matches); dactyl.assert(matches);
let oldNum = matches[2]; let oldNum = matches[2];
@@ -66,7 +66,7 @@ var Browser = Module("browser", {
mappings: function () { mappings: function () {
mappings.add([modes.NORMAL], mappings.add([modes.NORMAL],
["y"], "Yank current location to the clipboard", ["y"], "Yank current location to the clipboard",
function () { dactyl.clipboardWrite(buffer.URL, true); }); function () { dactyl.clipboardWrite(buffer.URL.spec, true); });
// opening websites // opening websites
mappings.add([modes.NORMAL], mappings.add([modes.NORMAL],
@@ -75,7 +75,7 @@ var Browser = Module("browser", {
mappings.add([modes.NORMAL], ["O"], mappings.add([modes.NORMAL], ["O"],
"Open one or more URLs, based on current location", "Open one or more URLs, based on current location",
function () { commandline.open(":", "open " + buffer.URL, modes.EX); }); function () { commandline.open(":", "open " + buffer.URL.spec, modes.EX); });
mappings.add([modes.NORMAL], ["t"], mappings.add([modes.NORMAL], ["t"],
"Open one or more URLs in a new tab", "Open one or more URLs in a new tab",
@@ -83,7 +83,7 @@ var Browser = Module("browser", {
mappings.add([modes.NORMAL], ["T"], mappings.add([modes.NORMAL], ["T"],
"Open one or more URLs in a new tab, based on current location", "Open one or more URLs in a new tab, based on current location",
function () { commandline.open(":", "tabopen " + buffer.URL, modes.EX); }); function () { commandline.open(":", "tabopen " + buffer.URL.spec, modes.EX); });
mappings.add([modes.NORMAL], ["w"], mappings.add([modes.NORMAL], ["w"],
"Open one or more URLs in a new window", "Open one or more URLs in a new window",
@@ -91,7 +91,7 @@ var Browser = Module("browser", {
mappings.add([modes.NORMAL], ["W"], mappings.add([modes.NORMAL], ["W"],
"Open one or more URLs in a new window, based on current location", "Open one or more URLs in a new window, based on current location",
function () { commandline.open(":", "winopen " + buffer.URL, modes.EX); }); function () { commandline.open(":", "winopen " + buffer.URL.spec, modes.EX); });
mappings.add([modes.NORMAL], mappings.add([modes.NORMAL],
["<C-a>"], "Increment last number in URL", ["<C-a>"], "Increment last number in URL",

View File

@@ -383,13 +383,13 @@ var Buffer = Module("buffer", {
/** /**
* @property {string} The current top-level document's URL. * @property {string} The current top-level document's URL.
*/ */
get URL() content.location.href, get URL() util.newURI(content.location.href),
/** /**
* @property {string} The current top-level document's URL, sans any * @property {string} The current top-level document's URL, sans any
* fragment identifier. * fragment identifier.
*/ */
get URI() content.document.documentURI, get URI() let (doc = content.document) doc.documentURIObject || util.newURI(doc.documentURI),
/** /**
* @property {number} The buffer's height in pixels. * @property {number} The buffer's height in pixels.

View File

@@ -2146,7 +2146,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
let rcFile = io.getRCFile("~"); let rcFile = io.getRCFile("~");
if (dactyl.userEval('typeof document') === "undefined") if (dactyl.userEval('typeof document') === "undefined")
jsmodules.__proto__ = (window.XPCSafeJSObjectWrapper || XPCNativeWrapper)(window); jsmodules.__proto__ = XPCSafeJSObjectWrapper(window);
try { try {
if (dactyl.commandLineOptions.rcFile) { if (dactyl.commandLineOptions.rcFile) {

View File

@@ -1267,7 +1267,7 @@ var Events = Module("events", {
"Pass certain keys through directly for the given URLs", "Pass certain keys through directly for the given URLs",
"regexpmap", "", { "regexpmap", "", {
has: function (key) { has: function (key) {
let url = buffer.URI; let url = buffer.URI.spec;
for (let re in values(this.value)) for (let re in values(this.value))
if (re.test(url) && re.result.some(function (k) k === key)) if (re.test(url) && re.result.some(function (k) k === key))
return true; return true;

View File

@@ -145,7 +145,7 @@ var QuickMarks = Module("quickmarks", {
if (!/^[a-zA-Z0-9]$/.test(args[0])) if (!/^[a-zA-Z0-9]$/.test(args[0]))
dactyl.echoerr("E488: Trailing characters"); dactyl.echoerr("E488: Trailing characters");
else if (!args[1]) else if (!args[1])
quickmarks.add(args[0], buffer.URL); quickmarks.add(args[0], buffer.URL.spec);
else else
quickmarks.add(args[0], args[1]); quickmarks.add(args[0], args[1]);
}, },
@@ -204,7 +204,7 @@ var QuickMarks = Module("quickmarks", {
["M"], "Add new QuickMark for current URL", ["M"], "Add new QuickMark for current URL",
function ({ arg }) { function ({ arg }) {
dactyl.assert(/^[a-zA-Z0-9]$/.test(arg)); dactyl.assert(/^[a-zA-Z0-9]$/.test(arg));
quickmarks.add(arg, buffer.URL); quickmarks.add(arg, buffer.URL.spec);
}, },
{ arg: true }); { arg: true });
} }

View File

@@ -143,7 +143,7 @@ var StatusLine = Module("statusline", {
// TODO: this probably needs a more general solution. // TODO: this probably needs a more general solution.
if (url == null) if (url == null)
url = buffer.URL; url = buffer.URL.spec;
// when session information is available, add [+] when we can go // when session information is available, add [+] when we can go
// backwards, [-] when we can go forwards // backwards, [-] when we can go forwards

View File

@@ -21,7 +21,7 @@ if (!JSMLoader)
if (!(prop in this.builtin) && if (!(prop in this.builtin) &&
[this, set].indexOf(Object.getOwnPropertyDescriptor(global, prop).value) < 0 && [this, set].indexOf(Object.getOwnPropertyDescriptor(global, prop).value) < 0 &&
!global.__lookupGetter__(prop)) !global.__lookupGetter__(prop))
global[prop] = null; global[prop] = undefined;
} }
catch (e) { catch (e) {
dump("Deleting property " + prop + " on " + url + ":\n " + e + "\n"); dump("Deleting property " + prop + " on " + url + ":\n " + e + "\n");
@@ -73,6 +73,9 @@ catch (e) {}
let objproto = Object.prototype; let objproto = Object.prototype;
let hasOwnProperty = objproto.hasOwnProperty; let hasOwnProperty = objproto.hasOwnProperty;
if (typeof XPCSafeJSObjectWrapper === "undefined")
var XPCSafeJSObjectWrapper = XPCNativeWrapper;
if (!XPCNativeWrapper.unwrap) if (!XPCNativeWrapper.unwrap)
XPCNativeWrapper.unwrap = function (obj) { XPCNativeWrapper.unwrap = function (obj) {
if (hasOwnProperty.call(obj, "wrappedJSObject")) if (hasOwnProperty.call(obj, "wrappedJSObject"))
@@ -235,12 +238,11 @@ defineModule("base", {
// sed -n 's/^(const|function) ([a-zA-Z0-9_]+).*/ "\2",/p' base.jsm | sort | fmt // sed -n 's/^(const|function) ([a-zA-Z0-9_]+).*/ "\2",/p' base.jsm | sort | fmt
exports: [ exports: [
"ErrorBase", "Cc", "Ci", "Class", "Cr", "Cu", "Module", "JSMLoader", "Object", "Runnable", "ErrorBase", "Cc", "Ci", "Class", "Cr", "Cu", "Module", "JSMLoader", "Object", "Runnable",
"Struct", "StructBase", "Timer", "UTF8", "XPCOM", "XPCOMUtils", "array", "Struct", "StructBase", "Timer", "UTF8", "XPCOM", "XPCOMUtils", "XPCSafeJSObjectWrapper",
"call", "callable", "ctypes", "curry", "debuggerProperties", "defineModule", "array", "call", "callable", "ctypes", "curry", "debuggerProperties", "defineModule",
"deprecated", "endModule", "forEach", "isArray", "isGenerator", "deprecated", "endModule", "forEach", "isArray", "isGenerator", "isinstance", "isObject",
"isinstance", "isObject", "isString", "isSubclass", "iter", "iterAll", "isString", "isSubclass", "iter", "iterAll", "keys", "memoize", "octal", "properties",
"keys", "memoize", "octal", "properties", "require", "set", "update", "require", "set", "update", "values", "withCallerGlobal"
"values", "withCallerGlobal"
], ],
use: ["config", "services", "util"] use: ["config", "services", "util"]
}); });

View File

@@ -4,9 +4,6 @@
// given in the LICENSE.txt file included with this file. // given in the LICENSE.txt file included with this file.
"use strict"; "use strict";
if (this.XPCSafeJSObjectWrapper == null)
this.XPCSafeJSObjectWrapper = XPCNativeWrapper;
var myObject = Object; var myObject = Object;
Components.utils.import("resource://dactyl/base.jsm"); Components.utils.import("resource://dactyl/base.jsm");
defineModule("storage", { defineModule("storage", {