Debian package: Support xulrunner 9+10 in debian/conkeror.bin, drop support for unver...
[conkeror.git] / modules / content-policy.js
blobb467630f0e1fe7abdb294ef579b7c5d9e9505545
1 /**
2  * (C) Copyright 2010-2011 John J. Foerch
3  *
4  * Use, modification, and distribution are subject to the terms specified in the
5  * COPYING file.
6 **/
8 in_module(null);
10 function content_policy_init () {
11     var xulrunner_version = Cc['@mozilla.org/xre/app-info;1']
12         .getService(Ci.nsIXULAppInfo)
13         .platformVersion;
14     var vc = Cc["@mozilla.org/xpcom/version-comparator;1"]  
15         .getService(Ci.nsIVersionComparator);  
16     var reg = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
17     var file = file_locator_service.get("CurProcD", Ci.nsIFile);
18     if (vc.compare(xulrunner_version, "2.0") >= 0) {
19         file.append("content-policy.manifest");
20     } else {
21         file.append("components");
22         file.append("content-policy.js");
23     }
24     reg.autoRegister(file);
27 content_policy_init();
29 interactive("content-policy-enable",
30     "Enable content-policy processing.",
31     function (I) {
32         if (content_policy_listener.enabled) {
33             I.minibuffer.message("Content-policy already enabled.");
34             return;
35         }
36         content_policy_listener.enabled = true;
37         I.minibuffer.message("Content-policy enabled.");
38     });
40 interactive("content-policy-disable",
41     "Enable content-policy processing.",
42     function (I) {
43         if (! content_policy_listener.enabled) {
44             I.minibuffer.message("Content-policy already disabled.");
45             return;
46         }
47         content_policy_listener.enabled = false;
48         I.minibuffer.message("Content-policy disabled.");
49     });
51 interactive("content-policy-toggle",
52     "Turn the content-policy off if it is on, and on if it is off.",
53     function (I) {
54         content_policy_listener.enabled = !content_policy_listener.enabled;
55         if (content_policy_listener.enabled)
56             I.minibuffer.message("Content-policy enabled.");
57         else
58             I.minibuffer.message("Content-policy disabled.");
59     });
61 const content_policy_accept = Ci.nsIContentPolicy.ACCEPT;
62 const content_policy_reject = Ci.nsIContentPolicy.REJECT_REQUEST;
65  * By Type Filtering
66  */
68 var content_policy_bytype_table = {
69     1: null, get other () { return this[1]; },
70              set other (x) { return this[1] = x; },
71     2: null, get script () { return this[2]; },
72              set script (x) { return this[2] = x; },
73     3: null, get image () { return this[3]; },
74              set image (x) { return this[3] = x; },
75     4: null, get stylesheet () { return this[4]; },
76              set stylesheet (x) { return this[4] = x; },
77     5: null, get object () { return this[5]; },
78              set object (x) { return this[5] = x; },
79     6: null, get document () { return this[6]; },
80              set document (x) { return this[6] = x; },
81     7: null, get subdocument () { return this[7]; },
82              set subdocument (x) { return this[7] = x; },
83     9: null, get xbl () { return this[9]; },
84              set xbl (x) { return this[9] = x; },
85     10: null, get ping () { return this[10]; },
86               set ping (x) { return this[10] = x; },
87     11: null, get xmlhttprequest () { return this[11]; },
88               set xmlhttprequest (x) { return this[11] = x; },
89     12: null, get object_subrequest () { return this[12]; },
90               set object_subrequest (x) { return this[12] = x; },
91     13: null, get dtd () { return this[13]; },
92               set dtd (x) { return this[13] = x; },
93     14: null, get font () { return this[14]; },
94               set font (x) { return this[14] = x; },
95     15: null, get media () { return this[15]; },
96               set media (x) { return this[15] = x; }
99 /**
100  * content_policy_bytype is a function for content_policy_hook, which uses
101  * content_type as the primary key in determining the policy for requests.
102  * its configuration is in content_policy_bytype_table.
103  */
104 function content_policy_bytype (content_type, content_location,
105                                 request_origin, context, mime_type_guess,
106                                 extra) {
107     var rules = content_policy_bytype_table[content_type];
108     if (rules)
109         return rules(content_type, content_location,
110                      request_origin, context, mime_type_guess,
111                      extra);
112     return null;
115 provide("content-policy");