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: Addressed comments Created May 7, 2015, 12:04 a.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/debug.js ('K') | « lib/debug.js ('k') | metadata.gecko » ('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 /*
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
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 let {reportException} = require("debug");
18
19 let baseURL = null;
20
21 /**
22 * Waits for the application to initialize.
23 * @type {Promise}
24 */
25 let applicationReady = (function()
26 {
27 return new Promise((resolve, reject) =>
28 {
29 let observer = {
30 observe: function(subject, topic, data)
31 {
32 Services.obs.removeObserver(this, "sessionstore-windows-restored");
33 resolve();
34 },
35 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakR eference])
36 };
37
38 Services.obs.addObserver(observer, "sessionstore-windows-restored", true);
39 onShutdown.add(() => Services.obs.removeObserver(observer, "sessionstore-win dows-restored"));
40 });
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 }, reportException);
78 }
79
80 /**
81 * Called if requesting parameters failed.
82 *
83 * @param {Event} event
84 */
85 function onParametersFailed(event)
86 {
87 reportException(new Error("Failed loading parameters"));
88 }
OLDNEW
« lib/debug.js ('K') | « lib/debug.js ('k') | metadata.gecko » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld