views:

27

answers:

2

Thanks to everyone in advance -

So I have been banging on this issue for quite a while now and have burned through all my options. My current approach to canceling css requests is with nsIRequest.cancel inside of nsIWebProgressListener.onStateChange. This works most of the time, except when things are a little laggy a few will slip through and jump out of the loadgroup before I can get to them. This is obviously a dirty solution.

I have read through the following links to try and get a better idea of how to disable css before a nsIRequest is created...no dice.

https://developer.mozilla.org/en/Document_Loading_-_From_Load_Start_to_Finding_a_Handler https://developer.mozilla.org/en/The_life_of_an_HTML_HTTP_request https://developer.mozilla.org/en/Bird's_Eye_View_of_the_Mozilla_Framework

How do I disable css via presentation objects/interfaces? Is this possible? Inside of nsIDocShell there are a few attributes that kind of imply you can disable css via the browsers docshell - allowPlugins, allowJavascript, allowMetaRedirects, allowSubframes, allowImages.

Any suggestions?

Thanks,

Sam

A: 

The menu option that disables style sheets uses a function

setStyleDisabled(true)

so you probably can just call this function whenever new browser tab is created. Style sheets are still requested from server, but not applied. This function is not very sophisticated and doesn't mess with nsIRequest, source:

function setStyleDisabled(disabled) {
  getMarkupDocumentViewer().authorStyleDisabled = disabled;
}

Digging in Web Developer Toolbar source code I have noticed that their "disable stylesheets" function loops trough all document.styleSheets and sets the disabled property to true, like:

/* if DOM content is loaded */
var sheets = document.styleSheets;
for(var i in sheets){ sheets[i].disabled = true; }

So if the key is to not apply CSS to pages, one of the above solutions should work. But if you really need to stop style sheets from being downloaded from servers, I'm affraid nsIRequest interception is your only option.

pawel
A: 

Set permissions.default.stylesheet to 2 and voilà!

You can actually use the permissions manager to block or allow stylesheets on a host-by-host basis.

Neil