Debian package: lpbugnr webjump added
[conkeror.git] / components / content-policy.js
blob79e248446d516ac9d30f183fd6c9fbd01129ed2a
1 /**
2 * (C) Copyright 2010 John J. Foerch
4 * Use, modification, and distribution are subject to the terms specified in the
5 * COPYING file.
6 **/
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"]
16 .getService()
17 .wrappedJSObject;
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",
32 _xpcom_factory: {
33 createInstance: function (outer, iid) {
34 if (outer)
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"}],
43 enabled: true,
44 shouldLoad: function (content_type, //unsigned long
45 content_location, //nsIURI
46 request_origin, //nsIURI
47 context, //nsISupports
48 mime_type_guess, //ACString
49 extra) //nsISupports
51 if (this.enabled) {
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
64 mime_type, //ACString
65 extra) //nsISupports
67 return Ci.nsIContentPolicy.ACCEPT;
71 if (XPCOMUtils.generateNSGetFactory)
72 var NSGetFactory = XPCOMUtils.generateNSGetFactory([content_policy]); //XULRunner 2.0
73 else
74 var NSGetModule = XPCOMUtils.generateNSGetModule([content_policy]);