Skip to content

Instantly share code, notes, and snippets.

@lduros
Created January 22, 2013 19:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lduros/4597791 to your computer and use it in GitHub Desktop.
Save lduros/4597791 to your computer and use it in GitHub Desktop.
ochameau's nsIContentPolicy in addon-sdk module
const { Cc, Ci } = require("chrome");
const xpcom = require("xpcom");
const { Class } = require("api-utils/heritage");
exports.preventCrossRequest = Class({
extends: xpcom.Unknown,
interfaces: ["nsIContentPolicy"],
shouldLoad: function (contType, contLoc, reqOrig, ctx, typeGuess, extra) {
return Ci.nsIContentPolicy.REJECT;
},
shouldProcess: function (contType, contLoc, reqOrig, ctx, mimeType, extra) {
return Ci.nsIContentPolicy.ACCEPT;
}
});
let factory = xpcom.Factory({
Component: exports.preventCrossRequest,
description: "Implements content policy to prevent cross requests",
contract: "@lduros.net/PreventCrossRequest-policy"
});
var catman = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
catman.addCategoryEntry("content-policy", "prevent-cross-request.preventCrossRequest", factory.contract, false, true);
@jiacai2050
Copy link

hi Lduros :
I have some kind of problem:
In shouldLoad method, contLoc is where resource will be loaded, there is any possiblities to redirect this?
for example, contLoc is A.js and I want to load B.js.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment