1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-22 10:25:47 +01:00

Update for per-window PBM changes. Closes issue #948.

--HG--
extra : rebase_source : b66c01ca37ebd724b00e454a1ca3b9df32d6937a
This commit is contained in:
Kris Maglione
2013-03-04 19:28:27 -08:00
parent 978abae9f7
commit f5049bbb5e
2 changed files with 44 additions and 12 deletions

View File

@@ -15,6 +15,7 @@ lazyRequire("bookmarkcache", ["bookmarkcache"]);
lazyRequire("io", ["io"]); lazyRequire("io", ["io"]);
lazyRequire("finder", ["RangeFind"]); lazyRequire("finder", ["RangeFind"]);
lazyRequire("overlay", ["overlay"]); lazyRequire("overlay", ["overlay"]);
lazyRequire("sanitizer", ["sanitizer"]);
lazyRequire("storage", ["File", "storage"]); lazyRequire("storage", ["File", "storage"]);
lazyRequire("template", ["template"]); lazyRequire("template", ["template"]);
@@ -615,7 +616,7 @@ var Buffer = Module("Buffer", {
util.assert(false, _("save.invalidDestination", e.name)); util.assert(false, _("save.invalidDestination", e.name));
} }
self.saveURI(uri, file); self.saveURI({ uri: uri, file: file, context: elem });
}, },
completer: function (context) completion.savePage(context, elem) completer: function (context) completion.savePage(context, elem)
@@ -632,25 +633,33 @@ var Buffer = Module("Buffer", {
* @param {nsIURI} uri The URI to save * @param {nsIURI} uri The URI to save
* @param {nsIFile} file The file into which to write the result. * @param {nsIFile} file The file into which to write the result.
*/ */
saveURI: function saveURI(uri, file, callback, self) { saveURI: function saveURI(params) {
if (params instanceof Ci.nsIURI)
// Deprecated?
params = { uri: arguments[0], file: arguments[1],
callback: arguments[2], self: arguments[3] };
var persist = services.Persist(); var persist = services.Persist();
persist.persistFlags = persist.PERSIST_FLAGS_FROM_CACHE persist.persistFlags = persist.PERSIST_FLAGS_FROM_CACHE
| persist.PERSIST_FLAGS_REPLACE_EXISTING_FILES; | persist.PERSIST_FLAGS_REPLACE_EXISTING_FILES;
let window = this.topWindow; let window = this.topWindow;
file = File(file); let privacy = sanitizer.getContext(params.context || this.win);
let file = File(params.file);
if (!file.exists()) if (!file.exists())
file.create(Ci.nsIFile.NORMAL_FILE_TYPE, octal(666)); file.create(Ci.nsIFile.NORMAL_FILE_TYPE, octal(666));
let downloadListener = new window.DownloadListener(window, let downloadListener = new window.DownloadListener(window,
services.Transfer(uri, File(file).URI, "", services.Transfer(params.uri, file.URI, "", null, null, null,
null, null, null, persist)); persist, privacy && privacy.usePrivateBrowsing));
var { callback, self } = params;
if (callback) if (callback)
persist.progressListener = update(Object.create(downloadListener), { persist.progressListener = update(Object.create(downloadListener), {
onStateChange: util.wrapCallback(function onStateChange(progress, request, flags, status) { onStateChange: util.wrapCallback(function onStateChange(progress, request, flags, status) {
if (callback && (flags & Ci.nsIWebProgressListener.STATE_STOP) && status == 0) if (callback && (flags & Ci.nsIWebProgressListener.STATE_STOP) && status == 0)
util.trapErrors(callback, self, uri, file.file, progress, request, flags, status); util.trapErrors(callback, self, params.uri, file.file,
progress, request, flags, status);
return onStateChange.superapply(this, arguments); return onStateChange.superapply(this, arguments);
}) })
@@ -658,7 +667,8 @@ var Buffer = Module("Buffer", {
else else
persist.progressListener = downloadListener; persist.progressListener = downloadListener;
persist.saveURI(uri, null, null, null, null, file.path); persist.saveURI(params.uri, null, null, null, null,
file.file, privacy);
}, },
/** /**
@@ -1040,7 +1050,15 @@ var Buffer = Module("Buffer", {
return true; return true;
}; };
let uri = isString(doc) ? util.newURI(doc) : util.newURI(doc.location.href); if (isString(doc)) {
var privacyContext = null;
var uri = util.newURI(doc);
}
else {
privacyContext = sanitizer.getContext(doc);
uri = util.newURI(doc.location.href);
}
let ext = uri.fileExtension || "txt"; let ext = uri.fileExtension || "txt";
if (doc.contentType) if (doc.contentType)
ext = services.mime.getPrimaryExtension(doc.contentType, ext); ext = services.mime.getPrimaryExtension(doc.contentType, ext);
@@ -1061,7 +1079,8 @@ var Buffer = Module("Buffer", {
var persist = services.Persist(); var persist = services.Persist();
persist.persistFlags = persist.PERSIST_FLAGS_REPLACE_EXISTING_FILES; persist.persistFlags = persist.PERSIST_FLAGS_REPLACE_EXISTING_FILES;
persist.progressListener = this; persist.progressListener = this;
persist.saveURI(uri, null, null, null, null, this.file); persist.saveURI(uri, null, null, null, null, this.file,
privacyContext);
} }
return null; return null;
}, },
@@ -1737,7 +1756,7 @@ var Buffer = Module("Buffer", {
window.internalSave(doc.location.href, doc, null, contentDisposition, window.internalSave(doc.location.href, doc, null, contentDisposition,
doc.contentType, false, null, chosenData, doc.contentType, false, null, chosenData,
doc.referrer ? window.makeURI(doc.referrer) : null, doc.referrer ? window.makeURI(doc.referrer) : null,
true); doc, true);
}, },
{ {
argCount: "?", argCount: "?",

View File

@@ -290,12 +290,25 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
} }
}, },
getContext: function getContext(thing) {
if (!Ci.nsILoadContext)
return null;
if (thing instanceof Ci.nsIDOMNode)
thing = thing.ownerDocument;
if (thing instanceof Ci.nsIDOMDocument)
thing = thing.defaultView;
if (thing instanceof Ci.nsIInterfaceRequestor)
thing = thing.getInterface(Ci.nsIWebNavigation);
return thing.QueryInterface(Ci.nsILoadContext);
},
get ranAtShutdown() config.prefs.get("didSanitizeOnShutdown"), get ranAtShutdown() config.prefs.get("didSanitizeOnShutdown"),
set ranAtShutdown(val) config.prefs.set("didSanitizeOnShutdown", Boolean(val)), set ranAtShutdown(val) config.prefs.set("didSanitizeOnShutdown", Boolean(val)),
get runAtShutdown() prefs.get("privacy.sanitize.sanitizeOnShutdown"), get runAtShutdown() prefs.get("privacy.sanitize.sanitizeOnShutdown"),
set runAtShutdown(val) prefs.set("privacy.sanitize.sanitizeOnShutdown", Boolean(val)), set runAtShutdown(val) prefs.set("privacy.sanitize.sanitizeOnShutdown", Boolean(val)),
sanitize: function (items, range) sanitize: function sanitize(items, range)
this.withSavedValues(["sanitizing"], function () { this.withSavedValues(["sanitizing"], function () {
this.sanitizing = true; this.sanitizing = true;
let errors = this.sanitizeItems(items, range, null); let errors = this.sanitizeItems(items, range, null);
@@ -319,7 +332,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
return errors; return errors;
}), }),
sanitizeItems: function (items, range, host, key) sanitizeItems: function sanitizeItems(items, range, host, key)
this.withSavedValues(["sanitizing"], function () { this.withSavedValues(["sanitizing"], function () {
this.sanitizing = true; this.sanitizing = true;
if (items == null) if (items == null)