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, data
: true, javascript
: true,
21 mailto
: true, "moz-icon": true },
22 "Requests whose scheme is in this structure (with a true value) "+
23 "will be whitelisted before calling content_policy_hook.");
24 this.conkeror
.content_policy_listener
= this;
26 content_policy
.prototype = {
27 QueryInterface
: XPCOMUtils
.generateQI([Ci
.nsIContentPolicy
,
28 Ci
.nsIObserverService
]),
29 contractID
: "@conkeror.org/content-policy-listener;1",
30 classID
: Components
.ID("{2926dd11-4d76-4965-bcdc-4aaad70ada04}"),
31 classDescription
: "content_policy",
33 createInstance: function (outer
, iid
) {
35 throw Cr
.NS_ERROR_NO_AGGREGATION
;
36 if (! content_policy_listener
)
37 content_policy_listener
= new content_policy();
38 return content_policy_listener
;
41 _xpcom_categories
: [{category
: "content-policy"}],
44 shouldLoad: function (content_type
, //unsigned long
45 content_location
, //nsIURI
46 request_origin
, //nsIURI
47 context
, //nsISupports
48 mime_type_guess
, //ACString
52 if (this.conkeror
.content_policy_scheme_whitelist
[content_location
.scheme
])
53 return Ci
.nsIContentPolicy
.ACCEPT
;
54 var action
= this.conkeror
.content_policy_hook
.run(
55 content_type
, content_location
, request_origin
,
56 context
, mime_type_guess
, extra
);
58 return (action
|| Ci
.nsIContentPolicy
.ACCEPT
);
60 shouldProcess: function (content_type
, //unsigned long
61 content_location
, //nsIURI
62 request_origin
, //nsIURI
63 context
, //nsISupports
67 return Ci
.nsIContentPolicy
.ACCEPT
;
71 if (XPCOMUtils
.generateNSGetFactory
)
72 var NSGetFactory
= XPCOMUtils
.generateNSGetFactory([content_policy
]); //XULRunner 2.0
74 var NSGetModule
= XPCOMUtils
.generateNSGetModule([content_policy
]);