| Index: lib/crawler.js |
| diff --git a/lib/crawler.js b/lib/crawler.js |
| index 3445b2f5424fd846e71c3ffe3cb6fe964fc78329..7bc28dbbe75187a1a752583c81d5c638a24c98ca 100644 |
| --- a/lib/crawler.js |
| +++ b/lib/crawler.js |
| @@ -21,7 +21,8 @@ function abprequire(module) |
| } |
| let {RequestNotifier} = abprequire("requestNotifier"); |
| - |
| +let {FilterNotifier} = abprequire("filterNotifier"); |
| +let {FilterStorage} = abprequire("filterStorage"); |
| /** |
| * Creates a pool of tabs and allocates them to tasks on request. |
| @@ -197,13 +198,56 @@ WindowCloser.prototype = { |
| * The browser window we're operating in |
| * @param {String[]} urls |
| * URLs to be crawled |
| - * @param {int} number_of_tabs |
| + * @param {int} timeout |
| + * Load timeout in milliseconds |
| + * @param {int} maxtabs |
| * Maximum number of tabs to be opened |
| * @param {String} targetURL |
| * URL that should receive the results |
| + * @param {Function} onDone |
| + * The callback which is called after finishing of crawling of all URLs. |
| */ |
| function run(window, urls, timeout, maxtabs, targetURL, onDone) |
| { |
| + new Promise((resolve, reject) => |
| + { |
| + if (FilterStorage.subscriptions.length > 0) |
| + { |
| + resolve(); |
| + return; |
| + } |
| + let onFiltersLoaded = (action, item, newValue, oldValue) => |
| + { |
| + if (action == "load") |
| + { |
| + FilterNotifier.removeListener(onFiltersLoaded); |
| + resolve(); |
| + } |
| + }; |
| + FilterNotifier.addListener(onFiltersLoaded); |
| + }).then(() => crawl_urls(window, urls, timeout, maxtabs, targetURL, onDone)) |
| + .catch(reportException); |
| +} |
| +exports.run = run; |
| + |
| +/** |
| + * Spawns a {Task} task to crawl each url from `urls` argument and calls |
| + * `onDone` when all tasks are finished. |
| + * @param {Window} window |
| + * The browser window we're operating in |
| + * @param {String[]} urls |
| + * URLs to be crawled |
| + * @param {int} timeout |
| + * Load timeout in milliseconds |
| + * @param {int} maxtabs |
| + * Maximum number of tabs to be opened |
| + * @param {String} targetURL |
| + * URL that should receive the results |
| + * @param {Function} onDone |
| + * The callback which is called after finishing of all tasks. |
| + */ |
| +function crawl_urls(window, urls, timeout, maxtabs, targetURL, onDone) |
| +{ |
| let tabAllocator = new TabAllocator(window.getBrowser(), maxtabs); |
| let loadListener = new LoadListener(window.getBrowser(), timeout); |
| let running = 0; |
| @@ -245,7 +289,6 @@ function run(window, urls, timeout, maxtabs, targetURL, onDone) |
| }.bind(null, url)); |
| } |
| } |
| -exports.run = run; |
| /** |
| * Crawls a URL. This is a generator meant to be used via a Task object. |