whitespace
[conkeror.git] / modules / content-policy.js
blob606cec47b7da3c3dea33f9b2e92e45151ce664c2
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 interactive("content-policy-toggle",
35     "Turn the content-policy off if it is on, and on if it is off.",
36     function (I) {
37         content_policy_listener.enabled = !content_policy_listener.enabled;
38         if (content_policy_listener.enabled)
39             I.minibuffer.message("Content-policy enabled.");
40         else
41             I.minibuffer.message("Content-policy disabled.");
42     });
44 const content_policy_accept = Ci.nsIContentPolicy.ACCEPT;
45 const content_policy_reject = Ci.nsIContentPolicy.REJECT_REQUEST;
48  * By Type Filtering
49  */
51 var content_policy_bytype_table = {
52     1: null, get other () { return this[1]; },
53              set other (x) { return this[1] = x; },
54     2: null, get script () { return this[2]; },
55              set script (x) { return this[2] = x; },
56     3: null, get image () { return this[3]; },
57              set image (x) { return this[3] = x; },
58     4: null, get stylesheet () { return this[4]; },
59              set stylesheet (x) { return this[4] = x; },
60     5: null, get object () { return this[5]; },
61              set object (x) { return this[5] = x; },
62     6: null, get document () { return this[6]; },
63              set document (x) { return this[6] = x; },
64     7: null, get subdocument () { return this[7]; },
65              set subdocument (x) { return this[7] = x; },
66     9: null, get xbl () { return this[9]; },
67              set xbl (x) { return this[9] = x; },
68     10: null, get ping () { return this[10]; },
69               set ping (x) { return this[10] = x; },
70     11: null, get xmlhttprequest () { return this[11]; },
71               set xmlhttprequest (x) { return this[11] = x; },
72     12: null, get object_subrequest () { return this[12]; },
73               set object_subrequest (x) { return this[12] = x; },
74     13: null, get dtd () { return this[13]; },
75               set dtd (x) { return this[13] = x; },
76     14: null, get font () { return this[14]; },
77               set font (x) { return this[14] = x; },
78     15: null, get media () { return this[15]; },
79               set media (x) { return this[15] = x; }
82 /**
83  * content_policy_bytype is a function for content_policy_hook, which uses
84  * content_type as the primary key in determining the policy for requests.
85  * its configuration is in content_policy_bytype_table.
86  */
87 function content_policy_bytype (content_type, content_location,
88                                 request_origin, context, mime_type_guess,
89                                 extra) {
90     var rules = content_policy_bytype_table[content_type];
91     if (rules)
92         return rules(content_type, content_location,
93                      request_origin, context, mime_type_guess,
94                      extra);
95     return null;
98 provide("content-policy");