On Tuesday, February 26, 2013 3:46:35 PM UTC+1, Boris Zbarsky wrote:
> I thought you were implementing a custom protocol handler?  If you are, 
> then you can just use whatever channel you want.
> 
> If you're not, of course, messing with the channel won't help anything.

I am, but that wouldn't help the fundamental problem with DOMWindowCreated not 
being fired. But (with your help) I found a much better solution anyway (see 
below).

> > I added URI_INHERITS_SECURITY_CONTEXT to my protocolFlags and now it works.
> I really hope your protocol is not loadable from the web at large....

This is a good point. Our framework makes it possible to use Chrome extensions 
in Firefox, and since they moved to manifest v2 they have a new config property 
called web_accessible_resources that specifies exactly which files can be 
accessed from content. This is needed since in some cases you'll want to inject 
some HTML into a webpage and have it load e.g. stylesheets or images from the 
extension.

As per your suggestion, I implemented a wrapper for the normal nsIFileChannel 
that overrides the stream listener's onStartRequest and throws 
NS_ERROR_DOM_SECURITY_ERR if the URL isn't whitelisted. I think I really have 
to use URI_LOADABLE_BY_ANYONE in my protocolFlags, so this mitigates the 
security risk.

As an aside, it took me a full day to figure out how to wrap the 
nsIFileChannel. Turns out you *must* override the 
nsIStreamListener/nsIRequestObserver methods as well so that they are called 
with the wrapper, not the underlying channel as the request, otherwise XHR 
doesn't start the request (see 
http://mxr.mozilla.org/mozilla-central/source/content/base/src/nsXMLHttpRequest.cpp#2016).

If anyone is interested, feel free to use my ChannelWrapper 
(https://github.com/salsita/ancho/blob/develop/firefox/js/channelWrapper.js). I 
had to wrap IWritablePropertyBag2 and friends as well.

> > Shall I file a bug
> Please do!

https://bugzilla.mozilla.org/show_bug.cgi?id=845780

Matt
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to