Save snapshots via nsIWebBrowserPersist instead of WebPageDump

WPD code hasn't been updated in many years, and there was an issue with
document permissions in 5.0. We'll need to replace nsIWBP in Electron,
but this will do for now.

Attachments are opened using file:// URIs instead of
zotero://attachment, which is what Standalone does anyway. Ancient HTML
annotations and highlights won't be displayed anymore, but I'm not sure
they worked anyway, and it hasn't been possible to create them in years.
We might be able to write out existing annotations to notes.

iframes are skipped during saving, in an attempt to reduce the number of
junk ad files. JS can still cause problems with viewing, so we might
still want to either disable scripts or force the viewed page offline
(if such a thing is possible).

There might be issues with auxiliary filename length/characters during
cross-platform file syncing. (We modified the WPD code to shorten/clean
them.)
This commit is contained in:
Dan Stillman 2016-05-31 18:03:40 -04:00
parent 26b161fce2
commit fcb6e0c068
9 changed files with 85 additions and 1850 deletions

View file

@ -177,6 +177,39 @@ describe("Zotero.Attachments", function() {
})
})
describe("#importFromDocument()", function () {
it("should save a document with embedded files", function* () {
var item = yield createDataObject('item');
var uri = OS.Path.join(getTestDataDirectory().path, "snapshot", "index.html");
var deferred = Zotero.Promise.defer();
win.addEventListener('pageshow', () => deferred.resolve());
win.loadURI(uri);
yield deferred.promise;
var file = getTestDataDirectory();
file.append('test.png');
var attachment = yield Zotero.Attachments.importFromDocument({
document: win.content.document,
parentItemID: item.id
});
assert.equal(attachment.getField('url'), "file://" + uri);
// Check indexing
var matches = yield Zotero.Fulltext.findTextInItems([attachment.id], 'share your research');
assert.lengthOf(matches, 1);
assert.propertyVal(matches[0], 'id', attachment.id);
// Check for embedded files
var storageDir = Zotero.Attachments.getStorageDirectory(attachment).path;
var file = yield attachment.getFilePathAsync();
assert.equal(OS.Path.basename(file), 'index.html');
var filesFolder = OS.Path.join(storageDir, 'index_files');
assert.isTrue(yield OS.File.exists(filesFolder, 'img.gif'));
});
});
describe("#getBaseDirectoryRelativePath()", function () {
it("should convert backslashes to forward slashes", function () {
Zotero.Prefs.set('baseAttachmentPath', "C:\\foo\\bar");