13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
xGCEWorker.onmessage = function (e) {
// https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
try {
let {sActionDone, result, dInfo} = e.data;
switch (sActionDone) {
case "init":
console.log("INIT DONE");
break;
case "parse":
case "parseAndSpellcheck":
case "parseAndSpellcheck1":
case "getListOfTokens":
console.log("Action done: " + sActionDone);
if (typeof(dInfo.iReturnPort) === "number") {
let xPort = dConnx.get(dInfo.iReturnPort);
xPort.postMessage(e.data);
} else {
console.log("[background] don’t know where to send results");
console.log(e.data);
}
break;
case "textToTest":
console.log("TEXT TO TEXT RESULTS");
browser.runtime.sendMessage({sCommand: "text_to_test_result", sResult: result});
break;
case "fullTests":
console.log("FULL TESTS RESULTS");
browser.runtime.sendMessage({sCommand: "fulltests_result", sResult: result});
break;
case "getOptions":
case "getDefaultOptions":
case "setOptions":
case "setOption":
console.log("OPTIONS");
|
<
<
<
<
|
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
xGCEWorker.onmessage = function (e) {
// https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
try {
let {sActionDone, result, dInfo} = e.data;
switch (sActionDone) {
case "init":
break;
case "parse":
case "parseAndSpellcheck":
case "parseAndSpellcheck1":
case "getListOfTokens":
if (typeof(dInfo.iReturnPort) === "number") {
let xPort = dConnx.get(dInfo.iReturnPort);
xPort.postMessage(e.data);
} else {
console.log("[background] don’t know where to send results");
console.log(e.data);
}
break;
case "textToTest":
browser.runtime.sendMessage({sCommand: "text_to_test_result", sResult: result});
break;
case "fullTests":
browser.runtime.sendMessage({sCommand: "fulltests_result", sResult: result});
break;
case "getOptions":
case "getDefaultOptions":
case "setOptions":
case "setOption":
console.log("OPTIONS");
|
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/*
Messages from the extension (not the Worker)
*/
function handleMessage (oRequest, xSender, sendResponse) {
//console.log(xSender);
console.log("[background] received:");
console.log(oRequest);
switch (oRequest.sCommand) {
case "parse":
case "parseAndSpellcheck":
case "parseAndSpellcheck1":
case "getListOfTokens":
case "textToTest":
case "getOptions":
|
<
<
|
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/*
Messages from the extension (not the Worker)
*/
function handleMessage (oRequest, xSender, sendResponse) {
//console.log(xSender);
switch (oRequest.sCommand) {
case "parse":
case "parseAndSpellcheck":
case "parseAndSpellcheck1":
case "getListOfTokens":
case "textToTest":
case "getOptions":
|
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
}
browser.runtime.onMessage.addListener(handleMessage);
function handleConnexion (xPort) {
let iPortId = xPort.sender.tab.id; // identifier for the port: each port can be found at dConnx[iPortId]
console.log("tab_id: " + iPortId);
dConnx.set(iPortId, xPort);
xPort.onMessage.addListener(function (oRequest) {
console.log("[background] message via connexion:");
console.log(oRequest);
switch (oRequest.sCommand) {
case "parse":
case "parseAndSpellcheck":
case "parseAndSpellcheck1":
case "getListOfTokens":
oRequest.dInfo.iReturnPort = iPortId; // we pass the id of the return port to receive answer
console.log(oRequest);
xGCEWorker.postMessage(oRequest);
break;
default:
console.log("[background] Unknown command: " + oRequest.sCommand);
console.log(oRequest);
}
});
|
<
<
<
<
|
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
}
browser.runtime.onMessage.addListener(handleMessage);
function handleConnexion (xPort) {
let iPortId = xPort.sender.tab.id; // identifier for the port: each port can be found at dConnx[iPortId]
dConnx.set(iPortId, xPort);
xPort.onMessage.addListener(function (oRequest) {
switch (oRequest.sCommand) {
case "parse":
case "parseAndSpellcheck":
case "parseAndSpellcheck1":
case "getListOfTokens":
oRequest.dInfo.iReturnPort = iPortId; // we pass the id of the return port to receive answer
xGCEWorker.postMessage(oRequest);
break;
default:
console.log("[background] Unknown command: " + oRequest.sCommand);
console.log(oRequest);
}
});
|