content-policy-enable/disable: two new commands
[conkeror.git] / modules / content-policy.js
blobe70322850de5efe2a33c2ff9bfdc33bcb6222f6f
1 /**
2  * (C) Copyright 2010 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 content_policy_listener.enabled = true;
12 interactive("content-policy-enable",
13     "Enable content-policy processing.",
14     function (I) {
15         if (content_policy_listener.enabled) {
16             I.minibuffer.message("Content-policy already enabled.");
17             return;
18         }
19         content_policy_listener.enabled = true;
20         I.minibuffer.message("Content-policy enabled.");
21     });
23 interactive("content-policy-disable",
24     "Enable content-policy processing.",
25     function (I) {
26         if (! content_policy_listener.enabled) {
27             I.minibuffer.message("Content-policy already disabled.");
28             return;
29         }
30         content_policy_listener.enabled = false;
31         I.minibuffer.message("Content-policy disabled.");
32     });
34 const REJECT_REQUEST = Ci.nsIContentPolicy.REJECT_REQUEST;
35 const REJECT_TYPE = Ci.nsIContentPolicy.REJECT_TYPE;
36 const REJECT_SERVER = Ci.nsIContentPolicy.REJECT_SERVER;
37 const REJECT_OTHER = Ci.nsIContentPolicy.REJECT_OTHER;
38 const ACCEPT = Ci.nsIContentPolicy.ACCEPT;
41  * By Type Filtering
42  */
44 var content_policy_bytype_table = {
45     1: null, get other () { return this[1]; },
46              set other (x) { return this[1] = x; },
47     2: null, get script () { return this[2]; },
48              set script (x) { return this[2] = x; },
49     3: null, get image () { return this[3]; },
50              set image (x) { return this[3] = x; },
51     4: null, get stylesheet () { return this[4]; },
52              set stylesheet (x) { return this[4] = x; },
53     5: null, get object () { return this[5]; },
54              set object (x) { return this[5] = x; },
55     6: null, get document () { return this[6]; },
56              set document (x) { return this[6] = x; },
57     7: null, get subdocument () { return this[7]; },
58              set subdocument (x) { return this[7] = x; },
59     8: null, get refresh () { return this[8]; },
60              set refresh (x) { return this[8] = x; },
61     9: null, get xbl () { return this[9]; },
62              set xbl (x) { return this[9] = x; },
63     10: null, get ping () { return this[10]; },
64               set ping (x) { return this[10] = x; },
65     11: null, get xmlhttprequest () { return this[11]; },
66               set xmlhttprequest (x) { return this[11] = x; },
67     12: null, get object_subrequest () { return this[12]; },
68               set object_subrequest (x) { return this[12] = x; },
69     13: null, get dtd () { return this[13]; },
70               set dtd (x) { return this[13] = x; },
71     14: null, get font () { return this[14]; },
72               set font (x) { return this[14] = x; },
73     15: null, get media () { return this[15]; },
74               set media (x) { return this[15] = x; }
77 /**
78  * content_policy_bytype is a function for content_policy_hook, which uses
79  * content_type as the primary key in determining the policy for requests.
80  * its configuration is in content_policy_bytype_table.
81  */
82 function content_policy_bytype (content_type, content_location,
83                                 request_origin, context, mime_type_guess,
84                                 extra) {
85     var rules = content_policy_bytype_table[content_type];
86     if (rules)
87         return rules(content_type, content_location,
88                      request_origin, context, mime_type_guess,
89                      extra);
90     return null;
93 provide("content-policy");