出于测试目的,我尝试使用XPCOM组件阻止图像,但shouldLoad方法仅调用内部资源(例如chrome://global/skin/global.css,crome: //browser/skin/tabbrowser/xxx.png,about:blank等...),永远不会为内联内容调用它。可能是什么问题?
内容-policy.js
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
function MyContentPolicyComponent() {}
MyContentPolicyComponent.prototype = {
classDescription: "My Content Policy Component",
classID: Components.ID("{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}"),
contractID: "@mycontractid/content-policy;1",
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIContentPolicy]),
_xpcom_categories: [{category: "content-policy"}],
shouldLoad: function(aContentType, aContentLocation, aRequestOrigin, aContext, aMimeTypeGuess, aExtra, aRequestPrincipal) {
// dump(aContentLocation.spec + "\n");
if (aContentType === Components.interfaces.nsIContentPolicy.TYPE_IMAGE)
return Components.interfaces.nsIContentPolicy.REJECT;
return Components.interfaces.nsIContentPolicy.ACCEPT;
},
shouldProcess: function(aContentType, aContentLocation, aRequestOrigin, aContext, aMimeType, aExtra, aRequestPrincipal) {
return Components.interfaces.nsIContentPolicy.ACCEPT;
}
};
var NSGetFactory = XPCOMUtils.generateNSGetFactory([MyContentPolicyComponent]);
chrome.manifest用于
...
component {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} components/content-policy.js
contract @mycontractid/content-policy;1 {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
category content-policy MyContentPolicyComponent @mycontractid/content-policy;1