better temp blacklister (earlier abort)
[k8imago.git] / code / modules / imago-policy.js
blob8f051d28ee4b89f80ea8ce692bba87c392417935
1 /* coded by Ketmar // Invisible Vector (psyc://ketmar.no-ip.org/~Ketmar)
2 * Understanding is not required. Only obedience.
4 * This program is free software. It comes without any warranty, to
5 * the extent permitted by applicable law. You can redistribute it
6 * and/or modify it under the terms of the Do What The Fuck You Want
7 * To Public License, Version 2, as published by Sam Hocevar. See
8 * http://www.wtfpl.net/txt/copying/ for more details.
9 */
10 // http observer
11 let EXPORTED_SYMBOLS = [
14 const {utils:Cu, classes:Cc, interfaces:Ci, results:Cr} = Components;
16 //////////////////////////////////////////////////////////////////////////////
17 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
18 Cu.import("resource://gre/modules/Services.jsm");
20 //////////////////////////////////////////////////////////////////////////////
21 Cu.import("chrome://k8-imago-code/content/modules/utils.js");
22 Cu.import(MODULE_PATH+"debuglog.js");
23 Cu.import(MODULE_PATH+"prefs.js");
26 //////////////////////////////////////////////////////////////////////////////
27 let policy = {
28 _initialized: false,
29 classDescription: "Test content policy",
30 classID: Components.ID("{085ef727-7222-4ad7-8fe9-653f73d6ee2f}"),
31 contractID: "@ketmar.no-ip.org/k8imago;1",
32 xpcom_categories: ["content-policy"],
34 init: function () {
35 if (this._initialized) return;
36 this._initialized = true;
38 conlog("initializing Imago component...");
39 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
40 registrar.registerFactory(this.classID, this.classDescription, this.contractID, this);
42 let catMan = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
43 for each (let category in this.xpcom_categories) {
44 catMan.addCategoryEntry(category, this.contractID, this.contractID, false, true);
48 onShutdown.add((function() {
49 for each (let category in this.xpcom_categories)
50 catMan.deleteCategoryEntry(category, this.contractID, false);
52 // This needs to run asynchronously, see bug 753687
53 Services.tm.currentThread.dispatch(function()
55 registrar.unregisterFactory(this.classID, this);
56 }.bind(this), Ci.nsIEventTarget.DISPATCH_NORMAL);
57 }).bind(this));
59 conlog("Imago component initialized OK");
62 deinit: function () {
65 // nsIContentPolicy interface implementation
66 shouldLoad: function (contentType, contentLocation, requestOrigin, node, mimeTypeGuess, extra) {
67 if (contentType !== Ci.nsIContentPolicy.TYPE_IMAGE) return Ci.nsIContentPolicy.ACCEPT;
69 conlog("shouldLoad: ", contentType, " ",
70 (contentLocation ? contentLocation.spec : "null"), " ",
71 (requestOrigin ? requestOrigin.spec : "null"), " ",
72 node, " ",
73 mimeTypeGuess, " <", contentType !== Ci.nsIContentPolicy.TYPE_IMAGE, ">");
75 if (!contentLocation) return Ci.nsIContentPolicy.ACCEPT; // the thing that should not be
76 try {
77 //conlog("shouldLoad000: ", contentLocation.spec, " ", contentLocation);
78 //if (typeof(contentLocation.host) !== "string") return Ci.nsIContentPolicy.ACCEPT; // some strange things
79 //conlog("shouldLoad001: ", contentLocation.host);
80 if (BLACK_HOSTS[contentLocation.host]) {
81 //TODO: list priorities
82 if (WHITE_HOSTS[contentLocation.host]) return Ci.nsIContentPolicy.ACCEPT;
83 conlog("REJECTED BLACK: ", contentLocation.host);
84 return Ci.nsIContentPolicy.REJECT;
86 } catch (e) {
87 //conlog("************");
88 //Cu.reportError(e);
90 //conlog("++++++++++++");
91 return Ci.nsIContentPolicy.ACCEPT;
94 shouldProcess: function (contentType, contentLocation, requestOrigin, node, mimeTypeGuess, extra) {
96 conlog("shouldProcess: ", contentType, " ",
97 (contentLocation ? contentLocation.spec : "null"), " ",
98 (requestOrigin ? requestOrigin.spec : "null"), " ",
99 node, " ",
100 mimeTypeGuess);
102 return Ci.nsIContentPolicy.ACCEPT;
105 // nsIFactory interface implementation
106 createInstance: function (outer, iid) {
107 if (outer) throw Cr.NS_ERROR_NO_AGGREGATION;
108 return this.QueryInterface(iid);
111 // nsISupports interface implementation
112 QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPolicy, Ci.nsIFactory])
116 //////////////////////////////////////////////////////////////////////////////
117 policy.init();