Opened 10 years ago

Closed 8 years ago

#564 closed enhancement (fixed)

use zotero:// protocol handler to load snapshots

Reported by: simon Owned by: dstillman
Priority: major Milestone:
Component: data layer Version: 1.5
Keywords: Cc:

Description

is this easy to do?

Change History (5)

comment:1 Changed 9 years ago by dstillman

  • Milestone 1.0 Final deleted
  • Version changed from 1.0 to 1.5

Probably, though not necessarily efficient.

comment:2 Changed 9 years ago by dstillman

From http://developer.mozilla.org/en/docs/The_data_URL_scheme#Converting_an_nsIFile_to_a_data_URI:

function generateDataURI(file) {
  var contentType = Components.classes["@mozilla.org/mime;1"]
                              .getService(Components.interfaces.nsIMIMEService)
                              .getTypeFromFile(file);
  var inputStream = Components.classes["@mozilla.org/network/file-input-stream;1"]
                              .createInstance(Components.interfaces.nsIFileInputStream);
  inputStream.init(file, 0x01, 0600, 0);
  var stream = Components.classes["@mozilla.org/binaryinputstream;1"]
                         .createInstance(Components.interfaces.nsIBinaryInputStream);
  stream.setInputStream(inputStream);
  var encoded = btoa(stream.readBytes(stream.available()));
  return "data:" + contentType + ";base64," + encoded;
}

comment:3 Changed 9 years ago by simon

In your protocol handler component, it looks like you're just returning channels, correct? So why not just use Components.interfaces.nsIIOService.newChannelFromURI()?

comment:4 Changed 9 years ago by dstillman

Yeah, good call. I just threw the above function on here because I saw it in passing, but passing a channel with a file:/// URL would be much better if it works.

comment:5 Changed 8 years ago by dstillman

  • Resolution set to fixed
  • Status changed from new to closed

(In [2997]) Closes #564, use zotero:// protocol handler to load snapshots
Fixes #1056, Annotation icons aren't displayed

May be some glitches loading attachments this way, but it seems to work, and it fixes the annotation icons (though they're now misaligned).

Can use zotero://snapshot/ instead of zotero://annotation/ if people think it'd be better.

Note: See TracTickets for help on using tickets.