12
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
12
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
+
-
-
+
+
+
+
-
+
-
-
+
-
-
+
+
-
-
+
+
+
-
-
-
+
+
+
-
+
+
+
+
-
+
-
-
-
-
-
+
+
-
+
-
+
-
+
-
+
-
+
-
+
|
//let xGCEWorker = new Worker("gce_worker.js");
let xGCESharedWorker = new SharedWorker(browser.extension.getURL("gce_sharedworker.js"));
let xGCEWorker = xGCESharedWorker.port;
xGCEWorker.onmessage = function (e) {
// https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
try {
let {sActionDone, result, dInfo, bError} = e.data;
switch (e.data[0]) {
case "grammar_errors":
switch (sActionDone) {
case "init":
console.log("INIT DONE");
case "parse":
console.log("GRAMMAR ERRORS");
console.log(e.data[1].aGrammErr);
console.log(result);
browser.runtime.sendMessage({sCommand: "grammar_errors", aGrammErr: e.data[1].aGrammErr});
break;
case "spelling_and_grammar_errors":
case "parseAndSpellcheck":
console.log("SPELLING AND GRAMMAR ERRORS");
console.log(e.data[1].aSpellErr);
console.log(e.data[1].aGrammErr);
console.log(result.aSpellErr);
console.log(result.aGrammErr);
break;
case "text_to_test_result":
browser.runtime.sendMessage({sCommand: "text_to_test_result", sResult: e.data[1]});
case "textToTest":
console.log("TEXT TO TEXT RESULTS");
browser.runtime.sendMessage({sCommand: "textToTest", sResult: result});
break;
case "fulltests_result":
console.log("TESTS RESULTS");
browser.runtime.sendMessage({sCommand: "fulltests_result", sResult: e.data[1]});
case "fullTests":
console.log("FULL TESTS RESULTS");
browser.runtime.sendMessage({sCommand: "fullTests", sResult: result});
break;
case "options":
case "getOptions":
case "getDefaultOptions":
case "setOptions":
case "setOption":
console.log("OPTIONS");
console.log(e.data[1]);
break;
case "tokens":
case "getListOfTokens":
console.log("TOKENS");
console.log(e.data[1]);
let xLxgTab = browser.tabs.create({
url: browser.extension.getURL("panel/lexicographer.html"),
});
xLxgTab.then(onCreated, onError);
break;
break;
case "error":
console.log("ERROR");
console.log(e.data[1]);
break;
default:
console.log("Unknown command: " + e.data[0]);
console.log("Unknown command: " + sActionDone);
console.log(result);
}
}
catch (e) {
showError(e);
}
};
xGCEWorker.postMessage(["init", {sExtensionPath: browser.extension.getURL("."), sOptions: "", sContext: "Firefox"}]);
xGCEWorker.postMessage({sCommand: "init", dParam: {sExtensionPath: browser.extension.getURL("."), sOptions: "", sContext: "Firefox"}, dInfo: {}});
/*
Messages from the extension (not the Worker)
*/
function handleMessage (oRequest, xSender, sendResponse) {
//console.log(xSender);
switch(oRequest.sCommand) {
case "parse":
xGCEWorker.postMessage(["parse", {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}]);
xGCEWorker.postMessage({sCommand: "parse", dParam: {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}, dInfo: {}});
break;
case "parse_and_spellcheck":
xGCEWorker.postMessage(["parseAndSpellcheck", {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}]);
xGCEWorker.postMessage({sCommand: "parseAndSpellcheck", dParam: {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}, dInfo: {}});
break;
case "get_list_of_tokens":
xGCEWorker.postMessage(["getListOfTokens", {sText: oRequest.sText}]);
xGCEWorker.postMessage({sCommand: "getListOfTokens", dParam: {sText: oRequest.sText}, dInfo: {}});
break;
case "text_to_test":
xGCEWorker.postMessage(["textToTest", {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}]);
xGCEWorker.postMessage({sCommand: "textToTest", dParam: {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}, dInfo: {}});
break;
case "fulltests":
xGCEWorker.postMessage(["fullTests"]);
xGCEWorker.postMessage({sCommand: "fullTests", dParam: {}, dInfo: {}});
break;
}
//sendResponse({response: "response from background script"});
}
browser.runtime.onMessage.addListener(handleMessage);
|