LEFT | RIGHT |
1 /* | 1 /* |
2 * This Source Code is subject to the terms of the Mozilla Public License | 2 * This Source Code is subject to the terms of the Mozilla Public License |
3 * version 2.0 (the "License"). You can obtain a copy of the License at | 3 * version 2.0 (the "License"). You can obtain a copy of the License at |
4 * http://mozilla.org/MPL/2.0/. | 4 * http://mozilla.org/MPL/2.0/. |
5 */ | 5 */ |
6 | 6 |
7 const Cc = Components.classes; | 7 const Cc = Components.classes; |
8 const Ci = Components.interfaces; | 8 const Ci = Components.interfaces; |
9 const Cr = Components.results; | 9 const Cr = Components.results; |
10 const Cu = Components.utils; | 10 const Cu = Components.utils; |
11 | 11 |
12 Cu.import("resource://gre/modules/Services.jsm"); | 12 Cu.import("resource://gre/modules/Services.jsm"); |
13 | 13 |
14 function abprequire(module) | 14 function abprequire(module) |
15 { | 15 { |
16 let result = {}; | 16 let result = {}; |
17 result.wrappedJSObject = result; | 17 result.wrappedJSObject = result; |
18 Services.obs.notifyObservers(result, "adblockplus-require", module); | 18 Services.obs.notifyObservers(result, "adblockplus-require", module); |
19 return result.exports; | 19 return result.exports; |
20 } | 20 } |
21 | 21 |
22 let {Policy} = abprequire("contentPolicy"); | 22 let {Policy} = abprequire("contentPolicy"); |
23 let {RequestNotifier} = abprequire("requestNotifier"); | |
24 let {Filter} = abprequire("filterClasses"); | 23 let {Filter} = abprequire("filterClasses"); |
25 | 24 |
26 let origShouldAllow = Policy.shouldAllow; | 25 let origShouldAllow = Policy.shouldAllow; |
27 if (!origShouldAllow) | 26 if (!origShouldAllow) |
28 window.close(); | 27 window.close(); |
29 | 28 |
30 let currentData = null; | |
31 let processingQueue = []; | 29 let processingQueue = []; |
32 let notifier = null; | 30 let notifier = null; |
33 | 31 |
34 // Randomize URI to work around bug 719376 | 32 // Randomize URI to work around bug 719376 |
35 let stringBundle = Services.strings.createBundle("chrome://abpwatcher/locale/glo
bal.properties?" + Math.random()); | 33 let stringBundle = Services.strings.createBundle("chrome://abpwatcher/locale/glo
bal.properties?" + Math.random()); |
36 | 34 |
37 let clipboardHelper = Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.
nsIClipboardHelper); | 35 let clipboardHelper = Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.
nsIClipboardHelper); |
38 | 36 |
39 function init() | 37 function init() |
40 { | 38 { |
41 let list = document.getElementById("list"); | 39 let list = document.getElementById("list"); |
42 list.view = treeView; | 40 list.view = treeView; |
43 list.focus(); | 41 list.focus(); |
44 | 42 |
45 treeView.addObserver(updateProcessingTime); | 43 treeView.addObserver(updateProcessingTime); |
46 updateProcessingTime(treeView, "refresh"); | 44 updateProcessingTime(treeView, "refresh"); |
47 | 45 |
48 // Make sure the tree view has correct filters | 46 // Make sure the tree view has correct filters |
49 document.getElementById("filterText").doCommand(); | 47 document.getElementById("filterText").doCommand(); |
50 | 48 |
51 notifier = new RequestNotifier(null, handleFilterHit); | |
52 | |
53 Policy.shouldAllow = replacementShouldAllow; | 49 Policy.shouldAllow = replacementShouldAllow; |
54 setInterval(processQueue, 200); | 50 setInterval(processQueue, 200); |
55 } | 51 } |
56 | 52 |
57 function E(id) | 53 function E(id) |
58 { | 54 { |
59 return document.getElementById(id); | 55 return document.getElementById(id); |
60 } | 56 } |
61 | 57 |
62 function replacementShouldAllow({contentType, location, frames, isPrivate}) | 58 function replacementShouldAllow({contentType, location, frames, isPrivate}) |
63 { | 59 { |
64 let startTime = null; | 60 let startTime = Date.now(); |
65 try | 61 let currentData = { |
66 { | 62 type: contentType, |
67 currentData = { | 63 location: location, |
68 filters: [], | 64 frames: frames, |
69 type: contentType, | 65 isPrivate: isPrivate |
70 location: location, | 66 }; |
71 frames: frames, | |
72 isPrivate: isPrivate | |
73 }; | |
74 startTime = Date.now(); | |
75 } | |
76 catch(e) | |
77 { | |
78 Cu.reportError(e); | |
79 } | |
80 | |
81 let ret; | 67 let ret; |
| 68 |
82 try | 69 try |
83 { | 70 { |
84 ret = origShouldAllow.apply(this, arguments); | 71 ret = origShouldAllow.apply(this, arguments); |
85 return ret; | 72 return ret; |
86 } | 73 } |
87 finally | 74 finally |
88 { | 75 { |
89 if (startTime !== null) | 76 if (startTime !== null) |
90 { | 77 { |
91 currentData.processingTime = (Date.now() - startTime); | 78 currentData.processingTime = (Date.now() - startTime); |
92 currentData.result = ret; | 79 currentData.result = ret; |
| 80 currentData.filters = ret.hits.filter(h => h.filter).map(h => h.filter); |
93 | 81 |
94 processingQueue.push(currentData); | 82 processingQueue.push(currentData); |
95 currentData = null; | 83 currentData = null; |
96 } | 84 } |
97 } | 85 } |
98 } | 86 } |
99 | 87 |
100 function destroy() | 88 function destroy() |
101 { | 89 { |
102 if (notifier) | |
103 notifier.shutdown(); | |
104 if (origShouldAllow) | 90 if (origShouldAllow) |
105 Policy.shouldAllow = origShouldAllow; | 91 Policy.shouldAllow = origShouldAllow; |
106 } | |
107 | |
108 function handleFilterHit(data) | |
109 { | |
110 if (data.filter && currentData) | |
111 currentData.filters.push(data.filter); | |
112 } | 92 } |
113 | 93 |
114 function processQueue() | 94 function processQueue() |
115 { | 95 { |
116 if (!processingQueue.length) | 96 if (!processingQueue.length) |
117 return; | 97 return; |
118 | 98 |
119 function stringify(value) | 99 function stringify(value) |
120 { | 100 { |
121 if (typeof value == "undefined" || value == null) | 101 if (typeof value == "undefined" || value == null) |
122 return ""; | 102 return ""; |
123 else | 103 else |
124 return String(value); | 104 return String(value); |
125 } | 105 } |
126 | 106 |
127 for each (let entry in processingQueue) | 107 for each (let entry in processingQueue) |
128 { | 108 { |
129 entry.cols = { | 109 entry.cols = { |
130 address: stringify(entry.location), | 110 address: stringify(entry.location), |
131 type: stringify(entry.type), | 111 type: stringify(entry.type), |
132 result: stringBundle.GetStringFromName(entry.result && entry.result.allow
? "decision.allow" : "decision.block"), | 112 result: stringBundle.GetStringFromName(entry.result && entry.result.allow
? "decision.allow" : "decision.block"), |
133 origin: stringify(entry.frames && entry.frames[0] && entry.frames[0].locat
ion), | 113 origin: stringify(entry.frames && entry.frames[0] && entry.frames[0].locat
ion), |
134 filters: stringify(entry.filters && entry.filters.join(", ")), | 114 filter: stringify(entry.filters && entry.filters.join(", ")), |
135 time: stringify(entry.processingTime) | 115 time: stringify(entry.processingTime) |
136 }; | 116 }; |
137 treeView.add(entry); | 117 treeView.add(entry); |
138 } | 118 } |
139 | 119 |
140 processingQueue = []; | 120 processingQueue = []; |
141 } | 121 } |
142 | 122 |
143 function fillInTooltip(event) | 123 function fillInTooltip(event) |
144 { | 124 { |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 for (let i = 0; i < this.observers.length; i++) | 528 for (let i = 0; i < this.observers.length; i++) |
549 if (this.observers[i] == observer) | 529 if (this.observers[i] == observer) |
550 this.observers.splice(i--, 1); | 530 this.observers.splice(i--, 1); |
551 }, | 531 }, |
552 notifyObservers: function(operation, entry) | 532 notifyObservers: function(operation, entry) |
553 { | 533 { |
554 for each (let observer in this.observers) | 534 for each (let observer in this.observers) |
555 observer(this, operation, entry); | 535 observer(this, operation, entry); |
556 } | 536 } |
557 }; | 537 }; |
LEFT | RIGHT |