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 const Cu
= Components
.utils
;
11 Cu
.import("resource://gre/modules/XPCOMUtils.jsm");
13 var content_policy_listener
;
15 function content_policy () {
16 this.conkeror
= Cc
["@conkeror.mozdev.org/application;1"]
19 this.conkeror
.define_hook("content_policy_hook", "RUN_HOOK_UNTIL_SUCCESS");
20 this.conkeror
.define_variable("content_policy_scheme_whitelist",
21 { about
: true, chrome
: true, data
: true, javascript
: true,
22 mailto
: true, "moz-icon": true },
23 "Requests whose scheme is in this structure (with a true value) "+
24 "will be whitelisted before calling content_policy_hook.");
25 this.conkeror
.content_policy_listener
= this;
27 content_policy
.prototype = {
28 QueryInterface
: XPCOMUtils
.generateQI([Ci
.nsIContentPolicy
,
29 Ci
.nsIObserverService
]),
30 contractID
: "@conkeror.org/content-policy-listener;1",
31 classID
: Components
.ID("{2926dd11-4d76-4965-bcdc-4aaad70ada04}"),
32 classDescription
: "content_policy",
34 createInstance: function (outer
, iid
) {
36 throw Cr
.NS_ERROR_NO_AGGREGATION
;
37 if (! content_policy_listener
)
38 content_policy_listener
= new content_policy();
39 return content_policy_listener
;
42 _xpcom_categories
: [{category
: "content-policy"}],
45 shouldLoad: function (content_type
, //unsigned long
46 content_location
, //nsIURI
47 request_origin
, //nsIURI
48 context
, //nsISupports
49 mime_type_guess
, //ACString
53 if (this.conkeror
.content_policy_scheme_whitelist
[content_location
.scheme
])
54 return Ci
.nsIContentPolicy
.ACCEPT
;
55 var action
= this.conkeror
.content_policy_hook
.run(
56 content_type
, content_location
, request_origin
,
57 context
, mime_type_guess
, extra
);
59 return (action
|| Ci
.nsIContentPolicy
.ACCEPT
);
61 shouldProcess: function (content_type
, //unsigned long
62 content_location
, //nsIURI
63 request_origin
, //nsIURI
64 context
, //nsISupports
68 return Ci
.nsIContentPolicy
.ACCEPT
;
72 if (XPCOMUtils
.generateNSGetFactory
)
73 var NSGetFactory
= XPCOMUtils
.generateNSGetFactory([content_policy
]); //XULRunner 2.0
75 var NSGetModule
= XPCOMUtils
.generateNSGetModule([content_policy
]);