MozillaZine

"Content-Disposition: attachment" and nsIURIContentListener

Discuss building things with or for the Mozilla Platform.
open_mind_core2
 
Posts: 3
Joined: January 4th, 2011, 10:22 pm

Post Posted January 4th, 2011, 10:33 pm

HI All,

I am creating a plugin/addon for firefox, which will monitor/log/prevent the url of the files that are being downloaded.

I could successfully implement nsIURIContentListener and register it with nsiuriloader and successfully receiving events like IsPreffered, canHandleContent, doContent for downloads like http://download.sysinternals.com/Files/ ... onitor.zip

However, it does not receive such notification when the header has "Content-Disposition: attachment"

https://developer.mozilla.org/en/Docume ... uided_Tour says that for "Content-Disposition: attachment", nsiuricontentlistener will be bypassed. I have spent quite a lot of time searching for solution on this without success.

Can you anyone please direct me how I can intercept the download through firefox addon/plugin when header has "Content-Disposition: attachment"?

Thank you,
Karan

Torisugari
 
Posts: 1634
Joined: November 4th, 2002, 8:34 pm
Location: Kyoto, Nippon (GMT +9)

Post Posted January 5th, 2011, 6:38 am

Maybe it's impossible for an extension, not to mention a plugin.

The flag |forceExternalHandling| is having content listeners skipped. So anyway ExternalHelperAppService will be called.
http://mxr.mozilla.org/mozilla-central/ ... er.cpp#438

open_mind_core2
 
Posts: 3
Joined: January 4th, 2011, 10:22 pm

Post Posted January 5th, 2011, 7:23 am

Thanks Torisugari,

My requirement is to cancel the download based on few conditions such as domain or file type.
ExternalHelperAppService will pop-up save as dialog. I need to intercept this even before it reaches to ExternalHelperAppService and cancel the request.

Thanks,
Karan

open_mind_core2
 
Posts: 3
Joined: January 4th, 2011, 10:22 pm

Post Posted January 5th, 2011, 7:31 am

And also, in nsDocumentOpenInfo::DispatchContent -> nsDocumentOpenInfo tries to get interface for nsiuricontentlistner from the window context. Is it possible to hook my nsiuricontentlistener to it?

~Karan

lithopsian
 
Posts: 3664
Joined: September 15th, 2010, 9:03 am

Post Posted March 27th, 2013, 10:45 am

Old, but deserves an answer.

Content disposition "attachment" forces the Firefox download file dialog before any content handlers are queries. To prevent this you need to intercept http responses and change the header to inline, using an http-on-examine-response observer. This will cause that response to be routed through the normal content handling. Probably you only want to do this for certain responses relevant to your addon. You should take care that your observer acts very quickly to pass on any responses it isn't interested in since every incoming http message will be stuck in your code until it returns.

Return to Mozilla Development


Who is online

Users browsing this forum: No registered users and 3 guests