2

For testing purposes I'm trying to block images using an XPCOM component, but the shouldLoad method is only called for internal resources (e.g. chrome://global/skin/global.css, chrome://browser/skin/tabbrowser/xxx.png, about:blank, etc...), it is never called for inline content. What could be the problem?

content-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
Maxime
  • 93
  • 5

0 Answers0