Created
October 20, 2011 10:42
-
-
Save Gozala/1300867 to your computer and use it in GitHub Desktop.
Example of defining content policies.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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