Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/crawler.js

Issue 8402021: Crawler frontend (Closed)
Patch Set: Fixed issues found in review Created Sept. 24, 2012, 2:10 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« lib/client.js ('K') | « lib/client.js ('k') | lib/main.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 Cu.import("resource://gre/modules/Services.jsm");
2
3 function abprequire(module)
4 {
5 let result = {};
6 result.wrappedJSObject = result;
7 Services.obs.notifyObservers(result, "adblockplus-require", module);
8 return result.exports;
9 }
10
11 let {Storage} = require("storage");
12 let {Client} = require("client");
13
14 let {Policy} = abprequire("contentPolicy");
15 let {Filter} = abprequire("filterClasses");
16
17 let origProcessNode = Policy.processNode;
18
19 let siteTabs;
20 let currentTabs;
21
22 function processNode(wnd, node, contentType, location, collapse)
23 {
24 let result = origProcessNode.apply(this, arguments);
25 let url = (contentType === Policy.type.ELEMHIDE) ? location.text :
26 location.spec;
27 let site = siteTabs[wnd.top.location.href];
28 let filtered = !result;
29 Storage.write([url, site, filtered]);
30 return result;
31 }
32
33 function loadSite(site, window, callback)
34 {
35 if (!site)
36 return;
37
38 let tabbrowser = window.gBrowser;
39 let tab = tabbrowser.addTab(site);
40 let browser = tabbrowser.getBrowserForTab(tab);
41
42 let progressListener = {
43 onStateChange: function(aBrowser, aWebProgress, aRequest, aStateFlags, aStat us)
44 {
45 if (browser !== aBrowser)
46 return;
47
48 if (!(aStateFlags & Ci.nsIWebProgressListener.STATE_STOP))
49 return;
50
51 tabbrowser.removeTabsProgressListener(progressListener);
52 tabbrowser.removeTab(tab);
53 callback();
54 },
55 onLocationChange: function(aBrowser, aWebProgress, aRequest, aLocation, aFla gs)
56 {
57 if (browser === aBrowser)
58 siteTabs[aLocation.spec] = site;
Wladimir Palant 2012/09/25 09:40:39 Taking over comment from previous review: this nee
59 }
60 };
61 tabbrowser.addTabsProgressListener(progressListener);
62 }
63
64 function loadSites(backendUrl, parallelTabs, window, sites, callback)
65 {
66 while (currentTabs < parallelTabs && sites.length)
67 {
68 currentTabs++;
69 let site = sites.shift();
70 loadSite(site, window, function()
71 {
72 currentTabs--;
73 if (!sites.length && !currentTabs)
74 {
75 Storage.finish();
76 let dataFilePath = Storage.dataFile.path;
77 Client.sendCrawlerDataFile(backendUrl, window, dataFilePath, function()
78 {
79 Storage.destroy();
80 callback();
81 });
82 }
83 else
84 loadSites(backendUrl, parallelTabs, window, sites, callback);
85 });
86 }
87 }
88
89 let Crawler = exports.Crawler = {};
90
91 Crawler.crawl = function(backendUrl, parallelTabs, window, callback)
92 {
93 if (Policy.processNode != origProcessNode)
94 return;
95
96 Policy.processNode = processNode;
97
98 siteTabs = {};
99 currentTabs = 0;
100
101 Storage.init();
102
103 Client.fetchCrawlableSites(backendUrl, function(sites)
104 {
105 loadSites(backendUrl, parallelTabs, window, sites, function()
106 {
107 Policy.processNode = origProcessNode;
108 callback();
109 });
110 });
111 };
OLDNEW
« lib/client.js ('K') | « lib/client.js ('k') | lib/main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld