Skip to content

Instantly share code, notes, and snippets.

@Gozala
Created October 20, 2011 10:42
Show Gist options
  • Save Gozala/1300867 to your computer and use it in GitHub Desktop.
Save Gozala/1300867 to your computer and use it in GitHub Desktop.
Example of defining content policies.
// For details see:
// https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIContentPolicy
// https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsICategoryManager
const { Ci } = require('chrome')
const xpcom = require('api-utils/xpcom')
const policy = {
contractID: '@lduros.net/PreventImage-policy',
name: 'Implements content policy to prevent images from being loaded',
QueryInterface: xpcom.utils.generateQI([ 'nsIContentPolicy' ]),
create: function create() {
console.log('create an instance')
return policy // Make it a singleton
},
shouldLoad: function (contType, contLoc, reqOrig, ctx, typeGuess, extra) {
console.log('checking type')
if (contType === 3) {
console.log('detected an image')
return Ci.nsIContentPolicy.REJECT_OTHER
} else {
return Ci.nsIContentPolicy.ACCEPT
}
},
shouldProcess: function (contType, contLoc, reqOrig, ctx, mimeType, extra) {
return Ci.nsIContentPolicy.ACCEPT
}
}
xpcom.register(policy)
xpcom.utils.categoryManager.addCategoryEntry('content-policy', policy.name, policy.contractID, false, true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment