Left: | ||
Right: |
OLD | NEW |
---|---|
1 Cu.import("resource://gre/modules/Services.jsm"); | 1 Cu.import("resource://gre/modules/Services.jsm"); |
2 | 2 |
3 function abprequire(module) | 3 function abprequire(module) |
4 { | 4 { |
5 let result = {}; | 5 let result = {}; |
6 result.wrappedJSObject = result; | 6 result.wrappedJSObject = result; |
7 Services.obs.notifyObservers(result, "adblockplus-require", module); | 7 Services.obs.notifyObservers(result, "adblockplus-require", module); |
8 return result.exports; | 8 return result.exports; |
9 } | 9 } |
10 | 10 |
11 let {Storage} = require("storage"); | 11 let {Storage} = require("storage"); |
12 let {Client} = require("client"); | 12 let {Client} = require("client"); |
13 | 13 |
14 let {Policy} = abprequire("contentPolicy"); | 14 let {Policy} = abprequire("contentPolicy"); |
15 let {RequestNotifier} = abprequire("requestNotifier"); | |
15 let {Filter} = abprequire("filterClasses"); | 16 let {Filter} = abprequire("filterClasses"); |
16 let {Utils} = abprequire("utils"); | 17 let {Utils} = abprequire("utils"); |
17 | 18 |
18 let origProcessNode = Policy.processNode; | 19 let origProcessNode = Policy.processNode; |
19 | 20 |
21 let requestNotifier; | |
20 let siteTabs; | 22 let siteTabs; |
21 let currentTabs; | 23 let currentTabs; |
24 let currentFilter; | |
Wladimir Palant
2012/12/13 16:14:01
Initialize with null?
Felix Dahlke
2012/12/14 10:11:58
I'd rather keep it undefined, like currentTabs etc
| |
22 | 25 |
23 function processNode(wnd, node, contentType, location, collapse) | 26 function processNode(wnd, node, contentType, location, collapse) |
24 { | 27 { |
25 let result = origProcessNode.apply(this, arguments); | 28 let result = origProcessNode.apply(this, arguments); |
26 let url = (contentType === Policy.type.ELEMHIDE) ? location.text : | 29 let url = (contentType === Policy.type.ELEMHIDE) ? location.text : |
27 location.spec; | 30 location.spec; |
28 | 31 |
29 let topWindow = wnd.top; | 32 let topWindow = wnd.top; |
30 if (!topWindow.document) | 33 if (!topWindow.document) |
31 { | 34 { |
(...skipping 10 matching lines...) Expand all Loading... | |
42 | 45 |
43 let browser = tabbrowser.getBrowserForDocument(topWindow.document); | 46 let browser = tabbrowser.getBrowserForDocument(topWindow.document); |
44 if (!browser) | 47 if (!browser) |
45 { | 48 { |
46 Cu.reportError("Unable to get browser for the tab"); | 49 Cu.reportError("Unable to get browser for the tab"); |
47 return result; | 50 return result; |
48 } | 51 } |
49 | 52 |
50 let site = siteTabs.get(browser); | 53 let site = siteTabs.get(browser); |
51 let filtered = !result; | 54 let filtered = !result; |
52 Storage.write([url, site, filtered]); | 55 let data = [url, site, filtered]; |
56 if (currentFilter) { | |
Wladimir Palant
2012/12/14 16:43:01
Missed on the first pass - bracket should be on ne
| |
57 data.push(currentFilter); | |
58 currentFilter = null; | |
59 } | |
60 Storage.write(data); | |
53 return result; | 61 return result; |
54 } | 62 } |
55 | 63 |
64 function handleFilterHit(wnd, node, data) | |
65 { | |
66 if (data.filter) | |
67 currentFilter = data.filter.text; | |
68 } | |
69 | |
70 function prepare() | |
71 { | |
72 if (Policy.processNode != origProcessNode) | |
73 return false; | |
74 | |
75 Policy.processNode = processNode; | |
76 | |
77 requestNotifier = new RequestNotifier(null, handleFilterHit); | |
78 siteTabs = new WeakMap(); | |
79 currentTabs = 0; | |
80 | |
81 Storage.init(); | |
82 | |
83 return true; | |
84 } | |
85 | |
56 function loadSite(site, window, callback) | 86 function loadSite(site, window, callback) |
57 { | 87 { |
58 if (!site) | 88 if (!site) |
59 return; | 89 return; |
60 | 90 |
61 let tabbrowser = window.gBrowser; | 91 let tabbrowser = window.gBrowser; |
62 let tab = tabbrowser.addTab(site); | 92 let tab = tabbrowser.addTab(site); |
63 let browser = tabbrowser.getBrowserForTab(tab); | 93 let browser = tabbrowser.getBrowserForTab(tab); |
64 | 94 |
65 siteTabs.set(browser, site); | 95 siteTabs.set(browser, site); |
(...skipping 20 matching lines...) Expand all Loading... | |
86 while (currentTabs < parallelTabs && sites.length) | 116 while (currentTabs < parallelTabs && sites.length) |
87 { | 117 { |
88 currentTabs++; | 118 currentTabs++; |
89 let site = sites.shift(); | 119 let site = sites.shift(); |
90 loadSite(site, window, function() | 120 loadSite(site, window, function() |
91 { | 121 { |
92 currentTabs--; | 122 currentTabs--; |
93 if (!sites.length && !currentTabs) | 123 if (!sites.length && !currentTabs) |
94 { | 124 { |
95 Storage.finish(); | 125 Storage.finish(); |
96 let dataFilePath = Storage.dataFile.path; | 126 let requestsFilePath = Storage.requestsFile.path; |
97 Client.sendCrawlerDataFile(backendUrl, dataFilePath, function() | 127 Client.sendRequestsFile(backendUrl, requestsFilePath, function() |
98 { | 128 { |
99 Storage.destroy(); | 129 Storage.destroy(); |
100 callback(); | 130 callback(); |
101 }); | 131 }); |
102 } | 132 } |
103 else | 133 else |
104 loadSites(backendUrl, parallelTabs, window, sites, callback); | 134 loadSites(backendUrl, parallelTabs, window, sites, callback); |
105 }); | 135 }); |
106 } | 136 } |
107 } | 137 } |
108 | 138 |
139 function cleanUp() | |
140 { | |
141 Policy.processNode = origProcessNode; | |
142 siteTabs = null; | |
143 } | |
144 | |
109 let Crawler = exports.Crawler = {}; | 145 let Crawler = exports.Crawler = {}; |
110 | 146 |
111 Crawler.crawl = function(backendUrl, parallelTabs, window, callback) | 147 Crawler.crawl = function(backendUrl, parallelTabs, window, callback) |
112 { | 148 { |
113 if (Policy.processNode != origProcessNode) | 149 if (!prepare()) |
114 return; | 150 return; |
115 | 151 |
116 Policy.processNode = processNode; | |
117 | |
118 siteTabs = new WeakMap(); | |
119 currentTabs = 0; | |
120 | |
121 Storage.init(); | |
122 | |
123 Client.fetchCrawlableSites(backendUrl, function(sites) | 152 Client.fetchCrawlableSites(backendUrl, function(sites) |
124 { | 153 { |
125 loadSites(backendUrl, parallelTabs, window, sites, function() | 154 loadSites(backendUrl, parallelTabs, window, sites, function() |
126 { | 155 { |
127 Policy.processNode = origProcessNode; | 156 cleanUp(); |
128 siteTabs = null; | |
129 callback(); | 157 callback(); |
130 }); | 158 }); |
131 }); | 159 }); |
132 }; | 160 }; |
OLD | NEW |