isearch-backspace, isearch-done: docstrings
[conkeror.git] / modules / content-policy.js
blobcb55a905c75cab8cac14a7203405631a37485e4c
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 function content_policy_init () {
9     var xulrunner_version = Cc['@mozilla.org/xre/app-info;1']
10         .getService(Ci.nsIXULAppInfo)
11         .platformVersion;
12     var vc = Cc["@mozilla.org/xpcom/version-comparator;1"]  
13         .getService(Ci.nsIVersionComparator);  
14     var reg = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
15     var file = file_locator_service.get("CurProcD", Ci.nsIFile);
16     if (vc.compare(xulrunner_version, "2.0") >= 0) {
17         file.append("content-policy.manifest");
18     } else {
19         file.append("components");
20         file.append("content-policy.js");
21     }
22     reg.autoRegister(file);
25 content_policy_init();
27 interactive("content-policy-enable",
28     "Enable content-policy processing.",
29     function (I) {
30         if (content_policy_listener.enabled) {
31             I.minibuffer.message("Content-policy already enabled.");
32             return;
33         }
34         content_policy_listener.enabled = true;
35         I.minibuffer.message("Content-policy enabled.");
36     });
38 interactive("content-policy-disable",
39     "Enable content-policy processing.",
40     function (I) {
41         if (! content_policy_listener.enabled) {
42             I.minibuffer.message("Content-policy already disabled.");
43             return;
44         }
45         content_policy_listener.enabled = false;
46         I.minibuffer.message("Content-policy disabled.");
47     });
49 interactive("content-policy-toggle",
50     "Turn the content-policy off if it is on, and on if it is off.",
51     function (I) {
52         content_policy_listener.enabled = !content_policy_listener.enabled;
53         if (content_policy_listener.enabled)
54             I.minibuffer.message("Content-policy enabled.");
55         else
56             I.minibuffer.message("Content-policy disabled.");
57     });
59 const content_policy_accept = Ci.nsIContentPolicy.ACCEPT;
60 const content_policy_reject = Ci.nsIContentPolicy.REJECT_REQUEST;
63  * By Type Filtering
64  */
66 var content_policy_bytype_table = {
67     1: null, get other () { return this[1]; },
68              set other (x) { return this[1] = x; },
69     2: null, get script () { return this[2]; },
70              set script (x) { return this[2] = x; },
71     3: null, get image () { return this[3]; },
72              set image (x) { return this[3] = x; },
73     4: null, get stylesheet () { return this[4]; },
74              set stylesheet (x) { return this[4] = x; },
75     5: null, get object () { return this[5]; },
76              set object (x) { return this[5] = x; },
77     6: null, get document () { return this[6]; },
78              set document (x) { return this[6] = x; },
79     7: null, get subdocument () { return this[7]; },
80              set subdocument (x) { return this[7] = x; },
81     9: null, get xbl () { return this[9]; },
82              set xbl (x) { return this[9] = x; },
83     10: null, get ping () { return this[10]; },
84               set ping (x) { return this[10] = x; },
85     11: null, get xmlhttprequest () { return this[11]; },
86               set xmlhttprequest (x) { return this[11] = x; },
87     12: null, get object_subrequest () { return this[12]; },
88               set object_subrequest (x) { return this[12] = x; },
89     13: null, get dtd () { return this[13]; },
90               set dtd (x) { return this[13] = x; },
91     14: null, get font () { return this[14]; },
92               set font (x) { return this[14] = x; },
93     15: null, get media () { return this[15]; },
94               set media (x) { return this[15] = x; }
97 /**
98  * content_policy_bytype is a function for content_policy_hook, which uses
99  * content_type as the primary key in determining the policy for requests.
100  * its configuration is in content_policy_bytype_table.
101  */
102 function content_policy_bytype (content_type, content_location,
103                                 request_origin, context, mime_type_guess,
104                                 extra) {
105     var rules = content_policy_bytype_table[content_type];
106     if (rules)
107         return rules(content_type, content_location,
108                      request_origin, context, mime_type_guess,
109                      extra);
110     return null;
113 provide("content-policy");