2 * (C) Copyright 2010 John J. Foerch
4 * Use, modification, and distribution are subject to the terms specified in the
8 const Cc = Components.classes;
9 const Ci = Components.interfaces;
10 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
12 var content_policy_listener;
14 function content_policy () {
15 this.conkeror = Cc["@conkeror.mozdev.org/application;1"]
18 this.conkeror.define_hook("content_policy_hook", "RUN_HOOK_UNTIL_SUCCESS");
19 this.conkeror.define_variable("content_policy_scheme_whitelist",
20 { about: true, chrome: true },
21 "Requests whose scheme is in this structure (with a true value) "+
22 "will be whitelisted before calling content_policy_hook.");
23 this.conkeror.content_policy_listener = this;
25 content_policy.prototype = {
26 QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPolicy,
27 Ci.nsIObserverService]),
28 contractID: "@conkeror.org/content-policy-listener;1",
29 classID: Components.ID("{2926dd11-4d76-4965-bcdc-4aaad70ada04}"),
30 classDescription: "content_policy",
32 createInstance: function (outer, iid) {
34 throw Cr.NS_ERROR_NO_AGGREGATION;
35 if (! content_policy_listener)
36 content_policy_listener = new content_policy();
37 return content_policy_listener;
40 _xpcom_categories: [{category: "content-policy"}],
43 shouldLoad: function (content_type, //unsigned long
44 content_location, //nsIURI
45 request_origin, //nsIURI
46 context, //nsISupports
47 mime_type_guess, //ACString
51 if (this.conkeror.content_policy_scheme_whitelist[content_location.scheme])
52 return Ci.nsIContentPolicy.ACCEPT;
53 var action = this.conkeror.content_policy_hook.run(
54 content_type, content_location, request_origin,
55 context, mime_type_guess, extra);
57 return (action || Ci.nsIContentPolicy.ACCEPT);
59 shouldProcess: function (content_type, //unsigned long
60 content_location, //nsIURI
61 request_origin, //nsIURI
62 context, //nsISupports
66 return Ci.nsIContentPolicy.ACCEPT;
70 if (XPCOMUtils.generateNSGetFactory)
71 var NSGetFactory = XPCOMUtils.generateNSGetFactory([content_policy]); //XULRunner 2.0
73 var NSGetModule = XPCOMUtils.generateNSGetModule([content_policy]);