View previous topic :: View next topic |
Author |
Message |
devhed
Joined: 22 Apr 2006 Posts: 3
|
Posted: Sat Apr 22, 2006 Post subject: How does AdBlock intercept URL requests? |
|
|
I hope you don't mind me asking this question here as it is to help me build another filtering extension (based on an entirely different mechanism).
I unpacked adblock.rar but I couldn't pinpoint where adblack attaches to FireFox's URI requests...
I thought it might have something to do with
http://www.xulplanet.com/references/xpcomref/ifaces/nsIRequestObserver.html
any help would be greatly appreciated. |
|
Back to top |
|
 |
mcm_ham

Joined: 17 Dec 2004 Posts: 310
|
Posted: Mon Apr 24, 2006 Post subject: |
|
|
It actually hooks into Firefox's content policy which all images are checked against to see if they are allowed to load. You can see how Adblock hooks into this service in the nsAdblock.js file under the components directory. The shouldLoad function is implemented at the top of the component.js file.
http://www.xulplanet.com/references/xpcomref/comps/c_layoutcontentpolicy1.html |
|
Back to top |
|
 |
devhed
Joined: 22 Apr 2006 Posts: 3
|
Posted: Tue Apr 25, 2006 Post subject: thanks! |
|
|
Thanks muchly for the pointer. It's a great place for me to start my investigations. nsIContentPolicy looks straight forward enough, but I have no experience with comonents in general. This will be interesting...
Looks like I can learn a lot from AdBlock. |
|
Back to top |
|
 |
devhed
Joined: 22 Apr 2006 Posts: 3
|
Posted: Tue Apr 25, 2006 Post subject: #10 ??? |
|
|
In the object definition below, I'm puzzled by the #10 assignments and #10# references. I've never seen this before, what does it mean?
Code: |
<snip>
// nsIContentPolicy (placeholder)
policy: {
count: 0,
loadFromProfile: #10=function(){
if (typeof policy == 'undefined') {
try{
var SubScriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"].createInstance(Components.interfaces.mozIJSSubScriptLoader);
SubScriptLoader.loadSubScript("chrome://adblock/content/component.js");
this.shouldLoad = policy.shouldLoad, this.shouldProcess=policy.shouldProcess;
}catch(e){
//if (++this.count<10||(100%this.count==0 && this.count<2000))
// module.log('typeof policy: '+(typeof(policy))+" -> "+this.count+"\n"+e+'\n\ncaller: '+arguments.callee.caller);
}
}
return 1;
},
shouldLoad: #10#, shouldProcess: #10#,
QueryInterface: function(iid) {
return (typeof policy !='undefined') ? policy : this;
}
},
</snip>
|
|
|
Back to top |
|
 |
|