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.
11 let {utils
:Cu
, classes
:Cc
, interfaces
:Ci
, results
:Cr
} = Components
;
13 //////////////////////////////////////////////////////////////////////////////
14 Cu
.import("resource://gre/modules/XPCOMUtils.jsm");
15 Cu
.import("resource://gre/modules/Services.jsm");
17 //////////////////////////////////////////////////////////////////////////////
18 Cu
.import("chrome://k8-imago-code/content/modules/utils.js");
19 Cu
.import(MODULE_PATH
+"debuglog.js");
20 Cu
.import(MODULE_PATH
+"prefs.js");
23 //////////////////////////////////////////////////////////////////////////////
25 // will be called on creating new component
26 //conlog("IMAGO POLICY ctor!");
30 classDescription
: "Imago Policy",
31 classID
: Components
.ID("{085ef727-7222-4ad7-8fe9-653f73d6ee2f}"),
32 contractID
: "@ketmar.no-ip.org/k8imago-policy;1",
34 category
: "content-policy",
35 entry
: "imago-policy",
38 QueryInterface
: XPCOMUtils
.generateQI([Ci
.nsIContentPolicy
, Ci
.nsIFactory
]),
40 createInstance: function (outer
, iid
) {
41 conlog("Policy: createInstance");
42 if (outer
) throw Cr
.NS_ERROR_NO_AGGREGATION
;
43 return this.QueryInterface(iid
);
46 // nsIContentPolicy interface implementation
47 shouldLoad: function (contentType
, contentLocation
, requestOrigin
, node
, mimeTypeGuess
, extra
) {
48 if (contentType
!== Ci
.nsIContentPolicy
.TYPE_IMAGE
) return Ci
.nsIContentPolicy
.ACCEPT
;
50 conlog("shouldLoad: ", contentType, " ",
51 (contentLocation ? contentLocation.spec : "null"), " ",
52 (requestOrigin ? requestOrigin.spec : "null"), " ",
54 mimeTypeGuess, " <", contentType !== Ci.nsIContentPolicy.TYPE_IMAGE, ">");
56 if (!contentLocation
) return Ci
.nsIContentPolicy
.ACCEPT
; // the thing that should not be
58 //conlog("shouldLoad000: ", contentLocation.spec, " ", contentLocation);
59 //if (typeof(contentLocation.host) !== "string") return Ci.nsIContentPolicy.ACCEPT; // some strange things
60 //conlog("shouldLoad001: ", contentLocation.host);
61 if (BLACK_HOSTS
[contentLocation
.host
]) {
62 //TODO: list priorities
63 if (WHITE_HOSTS
[contentLocation
.host
]) return Ci
.nsIContentPolicy
.ACCEPT
;
64 conlog("REJECTED BLACK: ", contentLocation
.host
);
65 return Ci
.nsIContentPolicy
.REJECT
;
68 //conlog("************");
71 //conlog("++++++++++++");
72 return Ci
.nsIContentPolicy
.ACCEPT
;
75 shouldProcess: function (contentType
, contentLocation
, requestOrigin
, node
, mimeTypeGuess
, extra
) {
77 conlog("shouldProcess: ", contentType, " ",
78 (contentLocation ? contentLocation.spec : "null"), " ",
79 (requestOrigin ? requestOrigin.spec : "null"), " ",
83 return Ci
.nsIContentPolicy
.ACCEPT
;
90 if (this._initialized) return;
91 this._initialized = true;
93 conlog("initializing Imago component...");
94 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
95 registrar.registerFactory(this.classID, this.classDescription, this.contractID, this);
97 let catMan = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
98 for each (let xpc in this._xpcom_categories) {
99 //catMan.addCategoryEntry(xpc.category, this.contractID, this.contractID, false, true);
100 catMan.addCategoryEntry(xpc.category, xpc.entry, this.contractID, false, true);
107 //////////////////////////////////////////////////////////////////////////////
108 // dynamic registration: change above to `let Policy = {}`
110 // manifest registration
111 let NSGetFactory
= XPCOMUtils
.generateNSGetFactory([Policy
]);
112 //conlog("IMAGO POLICY1");