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

Side by Side Diff: lib/main.js

Issue 5288886037118976: Adblock Plus Crawler rewrite (Closed)
Patch Set: Created April 24, 2015, 3:38 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
OLDNEW
(Empty)
1 /*
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
4 * http://mozilla.org/MPL/2.0/.
5 */
6
7 /**
8 * @module main
saroyanm 2015/05/04 18:13:43 I think this should be file overview, maybe smth l
Wladimir Palant 2015/05/07 00:04:59 As Sebastian noted elsewhere, @module is actually
9 */
10
11 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
12 Cu.import("resource://gre/modules/Services.jsm");
13 Cu.import("resource://gre/modules/Promise.jsm");
14
15 require("commandLine");
16 let {run} = require("crawler");
17
18 let baseURL = null;
19
20 /**
21 * Waits for the application to initialize.
22 * @type {Promise}
23 */
24 let applicationReady = (function()
25 {
26 let deferred = Promise.defer();
saroyanm 2015/05/04 18:13:43 As mentioned in crawler.js please also don't use D
Wladimir Palant 2015/05/07 00:04:59 Done.
27
28 let observer = {
29 observe: function(subject, topic, data)
30 {
31 Services.obs.removeObserver(this, "sessionstore-windows-restored");
32 deferred.resolve();
33 },
34 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakRef erence])
35 };
36
37 Services.obs.addObserver(observer, "sessionstore-windows-restored", true);
38 onShutdown.add(() => Services.obs.removeObserver(observer, "sessionstore-windo ws-restored"));
39
40 return deferred.promise;
41 })();
42
43 /**
44 * Startup function, called from command line handler.
45 *
46 * @param {int} port Port to communicate with
47 */
48 function startup(port)
49 {
50 baseURL = "http://localhost:" + port + "/";
51
52 let request = new XMLHttpRequest();
53 request.open("GET", baseURL + "parameters");
54 request.addEventListener("load", onParametersLoaded, false);
55 request.addEventListener("error", onParametersFailed, false);
56 request.responseType = "json";
57 request.send();
58 }
59 exports.startup = startup;
60
61 /**
62 * Called if parameters loaded succesfully.
63 *
64 * @param {Event} event
65 */
66 function onParametersLoaded(event)
67 {
68 let {urls, timeout, maxtabs} = event.target.response;
69
70 applicationReady.then(function()
71 {
72 let window = Services.wm.getMostRecentWindow("navigator:browser");
73 run(window, urls, timeout, maxtabs, baseURL + "save", function()
74 {
75 Services.startup.quit(Services.startup.eAttemptQuit);
76 });
77 }, function(exception)
78 {
79 Cu.reportError(exception);
80 dump(exception + "\n")
81 });
82 }
83
84 /**
85 * Called if requesting parameters failed.
86 *
87 * @param {Event} event
88 */
89 function onParametersFailed(event)
90 {
91 Cu.reportError("Failed loading parameters");
saroyanm 2015/05/04 18:13:43 Maybe also make sense to print the message in the
Wladimir Palant 2015/05/07 00:04:59 Done.
92 }
OLDNEW

Powered by Google App Engine
This is Rietveld