Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /*
2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/licenses/publicdomain/
4 */
6 importScripts("onLine_worker_head.js");
8 var N_CHILDREN = 3;
9 var children = [];
10 var finishedChildrenCount = 0;
11 var lastTest = false;
13 for (var event of ["online", "offline"]) {
14 addEventListener(event,
15 makeHandler(
16 "addEventListener('%1', ..., false)",
17 event, 1, "Parent Worker"),
18 false);
19 }
21 onmessage = function(e) {
22 if (e.data === 'lastTest') {
23 children.forEach(function(w) {
24 w.postMessage({ type: 'lastTest' });
25 });
26 lastTest = true;
27 }
28 }
30 function setupChildren(cb) {
31 var readyCount = 0;
32 for (var i = 0; i < N_CHILDREN; ++i) {
33 var w = new Worker("onLine_worker_child.js");
34 children.push(w);
36 w.onerror = function(e) {
37 info("Error creating child " + e.message);
38 }
40 w.onmessage = function(e) {
41 if (e.data.type === 'ready') {
42 info("Got ready from child");
43 readyCount++;
44 if (readyCount === N_CHILDREN) {
45 cb();
46 }
47 } else if (e.data.type === 'finished') {
48 finishedChildrenCount++;
50 if (lastTest && finishedChildrenCount === N_CHILDREN) {
51 postMessage({ type: 'finished' });
52 children = [];
53 close();
54 }
55 } else if (e.data.type === 'ok') {
56 // Pass on test to page.
57 postMessage(e.data);
58 }
59 }
60 }
61 }
63 setupChildren(function() {
64 postMessage({ type: 'ready' });
65 });