Grammalecte  Check-in [1938527edc]

Overview
Comment:[fx] use objects for communication with Worker (normalization)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fx | webext2
Files: files | file ages | folders
SHA3-256: 1938527edce5a6f5de0941409cfe9cd6f09c217f05971614b11e64396368d58a
User & Date: olr on 2017-08-11 12:38:23
Other Links: branch diff | manifest | tags
Context
2017-08-11
12:48
[fx] use objects for communication with SharedWorker (normalization) (may be useful one day) check-in: e22cada231 user: olr tags: fx, webext2
12:38
[fx] use objects for communication with Worker (normalization) check-in: 1938527edc user: olr tags: fx, webext2
2017-08-10
09:59
[fx] content-script interface + remove SharedWorker check-in: e026bff1c5 user: olr tags: fx, webext2
Changes

Modified gc_lang/fr/webext/background.js from [eb2f1b3278] to [fcd118d7b1].

    10     10       Worker (separate thread to avoid freezing Firefox)
    11     11   */
    12     12   let xGCEWorker = new Worker("gce_worker.js");
    13     13   
    14     14   xGCEWorker.onmessage = function (e) {
    15     15       // https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
    16     16       try {
    17         -        switch (e.data[0]) {
    18         -            case "grammar_errors":
           17  +        let {sActionDone, result, dInfo, bError} = e.data;
           18  +        switch (sActionDone) {
           19  +            case "init":
           20  +                console.log("INIT DONE");
           21  +                break;
           22  +            case "parse":
    19     23                   console.log("GRAMMAR ERRORS");
    20         -                console.log(e.data[1].aGrammErr);
    21         -                browser.runtime.sendMessage({sCommand: "grammar_errors", aGrammErr: e.data[1].aGrammErr});
           24  +                console.log(result);
    22     25                   break;
    23         -            case "spelling_and_grammar_errors":
           26  +            case "parseAndSpellcheck":
    24     27                   console.log("SPELLING AND GRAMMAR ERRORS");
    25         -                console.log(e.data[1].aSpellErr);
    26         -                console.log(e.data[1].aGrammErr);
           28  +                console.log(result.aSpellErr);
           29  +                console.log(result.aGrammErr);
           30  +                break;
           31  +            case "textToTest":
           32  +                console.log("TEXT TO TEXT RESULTS");
           33  +                browser.runtime.sendMessage({sCommand: "text_to_test_result", sResult: result});
    27     34                   break;
    28         -            case "text_to_test_result":
    29         -                browser.runtime.sendMessage({sCommand: "text_to_test_result", sResult: e.data[1]});
           35  +            case "fullTests":
           36  +                console.log("FULL TESTS RESULTS");
           37  +                browser.runtime.sendMessage({sCommand: "fulltests_result", sResult: result});
    30     38                   break;
    31         -            case "fulltests_result":
    32         -                console.log("TESTS RESULTS");
    33         -                browser.runtime.sendMessage({sCommand: "fulltests_result", sResult: e.data[1]});
    34         -                break;
    35         -            case "options":
           39  +            case "getOptions":
           40  +            case "getDefaultOptions":
           41  +            case "setOptions":
           42  +            case "setOption":
    36     43                   console.log("OPTIONS");
    37     44                   console.log(e.data[1]);
    38     45                   break;
    39         -            case "tokens":
           46  +            case "getListOfTokens":
    40     47                   console.log("TOKENS");
    41     48                   console.log(e.data[1]);
    42     49                   let xLxgTab = browser.tabs.create({
    43     50                       url: browser.extension.getURL("panel/lexicographer.html"),
    44     51                   });
    45     52                   xLxgTab.then(onCreated, onError);
    46     53                   break;
    47     54                   break;
    48         -            case "error":
    49         -                console.log("ERROR");
    50         -                console.log(e.data[1]);
    51         -                break;
    52     55               default:
    53         -                console.log("Unknown command: " + e.data[0]);
           56  +                console.log("Unknown command: " + sActionDone);
           57  +                console.log(result);
    54     58           }
    55     59       }
    56     60       catch (e) {
    57     61           showError(e);
    58     62       }
    59     63   };
    60     64   
    61         -xGCEWorker.postMessage(["init", {sExtensionPath: browser.extension.getURL("."), sOptions: "", sContext: "Firefox"}]);
           65  +
           66  +xGCEWorker.postMessage({sCommand: "init", dParam: {sExtensionPath: browser.extension.getURL("."), sOptions: "", sContext: "Firefox"}, dInfo: {}});
    62     67   
    63     68   
    64     69   /*
    65     70       Messages from the extension (not the Worker)
    66     71   */
    67     72   function handleMessage (oRequest, xSender, sendResponse) {
    68     73       //console.log(xSender);
    69     74       switch(oRequest.sCommand) {
    70     75           case "parse":
    71         -            xGCEWorker.postMessage(["parse", {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}]);
           76  +            xGCEWorker.postMessage({sCommand: "parse", dParam: {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}, dInfo: {}});
    72     77               break;
    73     78           case "parse_and_spellcheck":
    74         -            xGCEWorker.postMessage(["parseAndSpellcheck", {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}]);
           79  +            xGCEWorker.postMessage({sCommand: "parseAndSpellcheck", dParam: {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}, dInfo: {}});
    75     80               break;
    76     81           case "get_list_of_tokens":
    77         -            xGCEWorker.postMessage(["getListOfTokens", {sText: oRequest.sText}]);
           82  +            xGCEWorker.postMessage({sCommand: "getListOfTokens", dParam: {sText: oRequest.sText}, dInfo: {}});
    78     83               break;
    79     84           case "text_to_test":
    80         -            xGCEWorker.postMessage(["textToTest", {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}]);
           85  +            xGCEWorker.postMessage({sCommand: "textToTest", dParam: {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}, dInfo: {}});
    81     86               break;
    82     87           case "fulltests":
    83         -            xGCEWorker.postMessage(["fullTests"]);
           88  +            xGCEWorker.postMessage({sCommand: "fullTests", dParam: {}, dInfo: {}});
    84     89               break;
    85     90       }
    86     91       //sendResponse({response: "response from background script"});
    87     92   }
    88     93   
    89     94   browser.runtime.onMessage.addListener(handleMessage);
    90     95   
................................................................................
   112    117   browser.contextMenus.create({
   113    118       id: "conjugueur_tab",
   114    119       title: "Conjugueur [onglet]",
   115    120       contexts: ["all"]
   116    121   });
   117    122   
   118    123   function onCreated(windowInfo) {
   119         -  console.log(`Created window: ${windowInfo.id}`);
          124  +    console.log(`Created window: ${windowInfo.id}`);
   120    125   }
   121    126   
   122    127   function onError(error) {
   123         -  console.log(`Error: ${error}`);
          128  +    console.log(`Error: ${error}`);
   124    129   }
   125    130   
   126    131   let xConjWindow = null;
   127    132   let xConjTab = null;
   128    133   
   129    134   browser.contextMenus.onClicked.addListener(function (xInfo, xTab) {
   130    135       // xInfo = https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/contextMenus/OnClickData
................................................................................
   159    164               xConjTab.then(onCreated, onError);
   160    165               break;
   161    166       }    
   162    167   });
   163    168   
   164    169   
   165    170   async function newwin () {
          171  +    // test for popup window-like, which doesn’t close when losing the focus
   166    172       console.log("Async on");
   167    173       const getActive = browser.tabs.query({ currentWindow: true, active: true, });
   168    174       const xWindowInfo = await browser.windows.getLastFocused();
   169         -    // the pop-up will not resize itself as the panel would, so the dimensions can be passed as query params 'w' and 'h'
   170    175       const width = 710, height = 980; // the maximum size for panels is somewhere around 700x800. Firefox needs some additional pixels: 14x42 for FF54 on Win 10 with dpi 1.25
   171    176       const left = Math.round(xWindowInfo.left + xWindowInfo.width - width - 25);
   172    177       const top = Math.round(xWindowInfo.top + 74); // the actual frame height of the main window varies, but 74px should place the pop-up at the bottom if the button
   173    178       const xWin = await browser.windows.create({
   174    179           type: 'panel', url: browser.extension.getURL("panel/conjugueur.html"), top: top, left: left, width: width, height: height,
   175    180       });
   176    181       browser.windows.update(xWin.id, { top:top, left:left, }); // firefox currently ignores top and left in .create(), so move it here
   177    182       console.log("Async done");
   178    183   }
   179    184   
   180    185   //newwin();
   181         -
   182         -
   183         -/*
   184         -    Worker (separate thread to avoid freezing Firefox)
   185         -*/
   186         -/*
   187         -let xGCESharedWorker = new SharedWorker("gce_sharedworker.js");
   188         -
   189         -xGCESharedWorker.port.onmessage = function (e) {
   190         -    // https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
   191         -    try {
   192         -        switch (e.data[0]) {
   193         -            case "grammar_errors":
   194         -                console.log("GRAMMAR ERRORS (SHARE)");
   195         -                console.log(e.data[1].aGrammErr);
   196         -                //browser.runtime.sendMessage({sCommand: "grammar_errors", aGrammErr: e.data[1].aGrammErr});
   197         -                break;
   198         -            case "spelling_and_grammar_errors":
   199         -                console.log("SPELLING AND GRAMMAR ERRORS (SHARE)");
   200         -                console.log(e.data[1].aSpellErr);
   201         -                console.log(e.data[1].aGrammErr);
   202         -                break;
   203         -            case "text_to_test_result":
   204         -                console.log("TESTS RESULTS (SHARE)");
   205         -                console.log(e.data[1]);
   206         -                break;
   207         -            case "fulltests_result":
   208         -                console.log("TESTS RESULTS (SHARE)");
   209         -                console.log(e.data[1]);
   210         -                break;
   211         -            case "options":
   212         -                console.log("OPTIONS (SHARE)");
   213         -                console.log(e.data[1]);
   214         -                break;
   215         -            case "tokens":
   216         -                console.log("TOKENS (SHARE)");
   217         -                console.log(e.data[1]);
   218         -                let xLxgTab = browser.tabs.create({
   219         -                    url: browser.extension.getURL("panel/lexicographer.html"),
   220         -                });
   221         -                xLxgTab.then(onCreated, onError);
   222         -                break;
   223         -            case "error":
   224         -                console.log("ERROR (SHARE)");
   225         -                console.log(e.data[1]);
   226         -                break;
   227         -            default:
   228         -                console.log("Unknown command (SHARE): " + e.data[0]);
   229         -        }
   230         -    }
   231         -    catch (e) {
   232         -        showError(e);
   233         -    }
   234         -};
   235         -
   236         -console.log("Content script [worker]");
   237         -console.log(xGCESharedWorker);
   238         -
   239         -
   240         -//xGCESharedWorker.port.start();
   241         -//console.log("Content script [port started]");
   242         -
   243         -xGCESharedWorker.port.postMessage(["init", {sExtensionPath: browser.extension.getURL("."), sOptions: "", sContext: "Firefox"}]);
   244         -
   245         -console.log("Content script [worker initialzed]");
   246         -
   247         -xGCESharedWorker.port.postMessage(["parse", {sText: "Vas... J’en aie mare...", sCountry: "FR", bDebug: false, bContext: false}]);
   248         -//xGCESharedWorker.port.postMessage(["parseAndSpellcheck", {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}]);
   249         -//xGCESharedWorker.port.postMessage(["getListOfTokens", {sText: oRequest.sText}]);
   250         -//xGCESharedWorker.port.postMessage(["textToTest", {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}]);
   251         -//xGCESharedWorker.port.postMessage(["fullTests"]);
   252         -
   253         -
   254         -*/

Modified gc_lang/fr/webext/gce_worker.js from [3fc4168020] to [63b4c024ea].

    25     25       https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
    26     26       https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export
    27     27   */
    28     28   
    29     29   "use strict";
    30     30   
    31     31   
    32         -console.log("GC Engine Worker [start]");
           32  +console.log("[Worker] GC Engine Worker [start]");
    33     33   //console.log(self);
    34     34   
    35     35   importScripts("grammalecte/helpers.js");
    36     36   importScripts("grammalecte/str_transform.js");
    37     37   importScripts("grammalecte/ibdawg.js");
    38     38   importScripts("grammalecte/text.js");
    39     39   importScripts("grammalecte/tokenizer.js");
................................................................................
    49     49   /*
    50     50       Warning.
    51     51       Initialization can’t be completed at startup of the worker,
    52     52       for we need the path of the extension to load data stored in JSON files.
    53     53       This path is retrieved in background.js and passed with the event “init”.
    54     54   */
    55     55   
           56  +
           57  +function createResponse (sActionDone, result, dInfo, bError=false) {
           58  +    return {
           59  +        "sActionDone": sActionDone,
           60  +        "result": result, // can be of any type
           61  +        "dInfo": dInfo,
           62  +        "bError": bError
           63  +    };
           64  +}
           65  +
           66  +function createErrorResult (e, sDescr="no description") {
           67  +    return {
           68  +        "sType": "error",
           69  +        "sDescription": sDescr,
           70  +        "sMessage": e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message
           71  +    };
           72  +}
           73  +
           74  +function showData (e) {
           75  +    for (let sParam in e) {
           76  +        console.log(sParam);
           77  +        console.log(e[sParam]);
           78  +    }
           79  +}
           80  +
    56     81   
    57     82   /*
    58     83       Message Event Object
    59     84       https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
    60     85   */
    61     86   onmessage = function (e) {
    62         -    let oParam = e.data[1];
    63         -    switch (e.data[0]) {
           87  +    console.log("[Worker] message received");
           88  +    let {sCommand, dParam, dInfo} = e.data;
           89  +    switch (sCommand) {
    64     90           case "init":
    65         -            loadGrammarChecker(oParam.sExtensionPath, oParam.sOptions, oParam.sContext);
           91  +            init(dParam.sExtensionPath, dParam.sOptions, dParam.sContext, dInfo);
    66     92               break;
    67     93           case "parse":
    68         -            parse(oParam.sText, oParam.sCountry, oParam.bDebug, oParam.bContext);
           94  +            parse(dParam.sText, dParam.sCountry, dParam.bDebug, dParam.bContext, dInfo);
    69     95               break;
    70     96           case "parseAndSpellcheck":
    71         -            parseAndSpellcheck(oParam.sText, oParam.sCountry, oParam.bDebug, oParam.bContext);
           97  +            parseAndSpellcheck(dParam.sText, dParam.sCountry, dParam.bDebug, dParam.bContext, dInfo);
    72     98               break;
    73     99           case "getOptions":
    74         -            getOptions();
          100  +            getOptions(dInfo);
    75    101               break;
    76    102           case "getDefaultOptions":
    77         -            getDefaultOptions();
          103  +            getDefaultOptions(dInfo);
    78    104               break;
    79    105           case "setOptions":
    80         -            setOptions(oParam.sOptions);
          106  +            setOptions(dParam.sOptions, dInfo);
    81    107               break;
    82    108           case "setOption":
    83         -            setOption(oParam.sOptName, oParam.bValue);
          109  +            setOption(dParam.sOptName, dParam.bValue, dInfo);
    84    110               break;
    85    111           case "resetOptions":
    86         -            resetOptions();
          112  +            resetOptions(dInfo);
    87    113               break;
    88    114           case "textToTest":
    89         -            textToTest(oParam.sText, oParam.sCountry, oParam.bDebug, oParam.bContext);
          115  +            textToTest(dParam.sText, dParam.sCountry, dParam.bDebug, dParam.bContext, dInfo);
    90    116               break;
    91    117           case "fullTests":
    92         -            fullTests();
          118  +            fullTests('{"nbsp":true, "esp":true, "unit":true, "num":true}', dInfo);
    93    119               break;
    94    120           case "getListOfTokens":
    95         -            getListOfTokens(oParam.sText);
          121  +            getListOfTokens(dParam.sText, dInfo);
    96    122               break;
    97    123           default:
    98         -            console.log("Unknown command: " + e.data[0]);
          124  +            console.log("Unknown command: " + sCommand);
          125  +            showData(e.data);
    99    126       }
   100    127   }
   101    128   
   102    129   
          130  +
          131  +let bInitDone = false;
          132  +
   103    133   let oDict = null;
   104    134   let oTokenizer = null;
   105    135   let oLxg = null;
   106    136   let oTest = null;
   107    137   
   108    138   
   109         -function loadGrammarChecker (sExtensionPath, sGCOptions="", sContext="JavaScript") {
          139  +function init (sExtensionPath, sGCOptions="", sContext="JavaScript", dInfo={}) {
   110    140       try {
   111         -        console.log("Loading… Extension path: " + sExtensionPath);
   112         -        conj.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/conj_data.json"));
   113         -        phonet.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/phonet_data.json"));
   114         -        mfsp.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/mfsp_data.json"));
   115         -        console.log("Modules have been initialized…");
   116         -        gc_engine.load(sContext, sExtensionPath+"grammalecte/_dictionaries");
   117         -        oDict = gc_engine.getDictionary();
   118         -        oTest = new TestGrammarChecking(gc_engine, sExtensionPath+"/grammalecte/fr/tests_data.json");
   119         -        oLxg = new Lexicographe(oDict);
   120         -        if (sGCOptions !== "") {
   121         -            gc_engine.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
          141  +        if (!bInitDone) {
          142  +            console.log("[Worker] Loading… Extension path: " + sExtensionPath);
          143  +            conj.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/conj_data.json"));
          144  +            phonet.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/phonet_data.json"));
          145  +            mfsp.init(helpers.loadFile(sExtensionPath + "/grammalecte/fr/mfsp_data.json"));
          146  +            console.log("[Worker] Modules have been initialized…");
          147  +            gc_engine.load(sContext, sExtensionPath+"grammalecte/_dictionaries");
          148  +            oDict = gc_engine.getDictionary();
          149  +            oTest = new TestGrammarChecking(gc_engine, sExtensionPath+"/grammalecte/fr/tests_data.json");
          150  +            oLxg = new Lexicographe(oDict);
          151  +            if (sGCOptions !== "") {
          152  +                gc_engine.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
          153  +            }
          154  +            oTokenizer = new Tokenizer("fr");
          155  +            tests();
          156  +            bInitDone = true;
          157  +        } else {
          158  +            console.log("[Worker] Already initialized…")
   122    159           }
   123         -        oTokenizer = new Tokenizer("fr");
   124         -        tests();
   125    160           // we always retrieve options from the gc_engine, for setOptions filters obsolete options
   126         -        postMessage(["options", gc_engine.getOptions().gl_toString()]);
          161  +        postMessage(createResponse("init", gc_engine.getOptions().gl_toString(), dInfo));
   127    162       }
   128    163       catch (e) {
   129         -        console.error(e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
   130         -        postMessage(["error", e.message]);
          164  +        helpers.logerror(e);
          165  +        postMessage(createResponse("init", createErrorResult(e, "init failed"), dInfo, true));
   131    166       }
   132    167   }
   133    168   
   134         -function parse (sText, sCountry, bDebug, bContext) {
          169  +
          170  +function parse (sText, sCountry, bDebug, bContext, dInfo={}) {
   135    171       let aGrammErr = gc_engine.parse(sText, sCountry, bDebug, bContext);
   136         -    postMessage(["grammar_errors", {aGrammErr: aGrammErr}]);
          172  +    postMessage({sActionDone: "parse", result: aGrammErr, dInfo: dInfo});
   137    173   }
   138    174   
   139         -function parseAndSpellcheck (sText, sCountry, bDebug, bContext) {
          175  +function parseAndSpellcheck (sText, sCountry, bDebug, bContext, dInfo={}) {
   140    176       let aGrammErr = gc_engine.parse(sText, sCountry, bDebug, bContext);
   141    177       let aSpellErr = oTokenizer.getSpellingErrors(sText, oDict);
   142         -    postMessage(["spelling_and_grammar_errors", {aGrammErr: aGrammErr, aSpellErr: aSpellErr}]);
          178  +    postMessage(createResponse("parseAndSpellcheck", {aGrammErr: aGrammErr, aSpellErr: aSpellErr}, dInfo));
          179  +}
          180  +
          181  +function getOptions (dInfo={}) {
          182  +    postMessage(createResponse("getOptions", gc_engine.getOptions().gl_toString(), dInfo));
   143    183   }
   144    184   
   145         -function getOptions () {
   146         -    postMessage(["options", gc_engine.getOptions().gl_toString()]);
          185  +function getDefaultOptions (dInfo={}) {
          186  +    postMessage(createResponse("getDefaultOptions", gc_engine.getDefaultOptions().gl_toString(), dInfo));
   147    187   }
   148    188   
   149         -function getDefaultOptions () {
   150         -    postMessage(["options", gc_engine.getDefaultOptions().gl_toString()]);
          189  +function setOptions (sGCOptions, dInfo={}) {
          190  +    gc_engine.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
          191  +    postMessage(createResponse("setOptions", gc_engine.getOptions().gl_toString(), dInfo));
   151    192   }
   152    193   
   153         -function setOptions (sGCOptions) {
   154         -    gc_engine.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
   155         -    postMessage(["options", gc_engine.getOptions().gl_toString()]);
          194  +function setOption (sOptName, bValue, dInfo={}) {
          195  +    gc_engine.setOptions(new Map([ [sOptName, bValue] ]));
          196  +    postMessage(createResponse("setOption", gc_engine.getOptions().gl_toString(), dInfo));
   156    197   }
   157    198   
   158         -function setOption (sOptName, bValue) {
   159         -    gc_engine.setOptions(new Map([ [sOptName, bValue] ]));
   160         -    postMessage(["options", gc_engine.getOptions().gl_toString()]);
   161         -}
   162         -
   163         -function resetOptions () {
          199  +function resetOptions (dInfo={}) {
   164    200       gc_engine.resetOptions();
   165         -    postMessage(["options", gc_engine.getOptions().gl_toString()]);
          201  +    postMessage(createResponse("resetOptions", gc_engine.getOptions().gl_toString(), dInfo));
   166    202   }
   167    203   
   168    204   function tests () {
   169    205       console.log(conj.getConj("devenir", ":E", ":2s"));
   170    206       console.log(mfsp.getMasForm("emmerdeuse", true));
   171    207       console.log(mfsp.getMasForm("pointilleuse", false));
   172    208       console.log(phonet.getSimil("est"));
   173    209       let aRes = gc_engine.parse("Je suit...");
   174    210       for (let oErr of aRes) {
   175    211           console.log(text.getReadableError(oErr));
   176    212       }
   177    213   }
   178    214   
   179         -function textToTest (sText, sCountry, bDebug, bContext) {
          215  +function textToTest (sText, sCountry, bDebug, bContext, dInfo={}) {
   180    216       if (!gc_engine || !oDict) {
   181         -        postMessage(["error", "# Error: grammar checker or dictionary not loaded."]);
          217  +        postMessage(createResponse("textToTest", "# Grammar checker or dictionary not loaded.", dInfo));
   182    218           return;
   183    219       }
   184    220       let aGrammErr = gc_engine.parse(sText, sCountry, bDebug, bContext);
   185    221       let sMsg = "";
   186    222       for (let oErr of aGrammErr) {
   187    223           sMsg += text.getReadableError(oErr) + "\n";
   188    224       }
   189         -    postMessage(["text_to_test_result", sMsg]);
          225  +    postMessage(createResponse("textToTest", sMsg, dInfo));
   190    226   }
   191    227   
   192         -function fullTests (sGCOptions='{"nbsp":true, "esp":true, "unit":true, "num":true}') {
          228  +function fullTests (sGCOptions="", dInfo={}) {
   193    229       if (!gc_engine || !oDict) {
   194         -        postMessage(["error", "# Error: grammar checker or dictionary not loaded."]);
          230  +        postMessage(createResponse("fullTests", "# Grammar checker or dictionary not loaded.", dInfo));
   195    231           return;
   196    232       }
   197    233       let dMemoOptions = gc_engine.getOptions();
   198    234       if (sGCOptions) {
   199    235           gc_engine.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
   200    236       }
   201    237       let sMsg = "";
   202    238       for (let sRes of oTest.testParse()) {
   203    239           sMsg += sRes + "\n";
   204    240           console.log(sRes);
   205    241       }
   206    242       gc_engine.setOptions(dMemoOptions);
   207         -    postMessage(["fulltests_result", sMsg]);
          243  +    postMessage(createResponse("fullTests", sMsg, dInfo));
   208    244   }
          245  +
   209    246   
   210    247   
   211    248   // Lexicographer
   212    249   
   213         -function getListOfTokens (sText) {
          250  +function getListOfTokens (sText, dInfo={}) {
   214    251       try {
   215    252           let aElem = [];
   216    253           let aRes = null;
   217    254           for (let oToken of oTokenizer.genTokens(sText)) {
   218    255               aRes = oLxg.getInfoForToken(oToken);
   219    256               if (aRes) {
   220    257                   aElem.push(aRes);
   221    258               }
   222    259           }
   223         -        postMessage(["tokens", aElem]);
          260  +        postMessage(createResponse("getListOfTokens", aElem, dInfo));
   224    261       }
   225    262       catch (e) {
   226    263           helpers.logerror(e);
   227         -        postMessage(["error", e.message]);
          264  +        postMessage(createResponse("getListOfTokens", createErrorResult(e, "no tokens"), dInfo, true));
   228    265       }
   229    266   }

Modified gc_lang/fr/webext/panel/main.html from [152e200e98] to [d1a2ec127f].

    13     13           <nav>
    14     14             <header id="logo">
    15     15               <img src="../img/logo-32.png">
    16     16             </header>
    17     17             <ul>
    18     18               <li class="select" data-page="home_page"><i class="fa fa-home icon"></i> 1.</li>
    19     19               <li class="select" data-page="tf_page"><i class="fa fa-photo icon"></i> TF</li>
    20         -            <li class="select" data-page="gc_page"><i class="fa fa-question-circle icon"></i> CG</li>
    21     20               <li class="select" data-page="gc_options_page"><i class="fa fa-coffee icon"></i> OP1</li>
    22     21               <li class="select" data-page="sc_options_page"><i class="fa fa-keyboard-o icon"></i> OP2</li>
    23     22               <li class="select" data-page="test_page"><i class="fa fa-keyboard-o icon"></i> TST</li>
    24     23             </ul>
    25     24           </nav>
    26     25         </header> <!-- #left -->
    27     26   
................................................................................
    36     35   
    37     36         <div id="page">
    38     37   
    39     38           <section id="home_page" class="page">
    40     39             <h1>GRAMMALECTE</h1>
    41     40           </section>
    42     41   
    43         -        <section id="gc_page" class="page">
    44         -          <h1>CORRECTEUR GRAMMATICAL</h1>
    45         -          <div id="paragraphs_list"></div>
    46         -        </section>
    47         -
    48     42           <section id="gc_options_page" class="page">
    49     43             <h1>OPTIONS GRAMMATICALES</h1>
    50     44           </section>
    51     45   
    52     46           <section id="sc_options_page" class="page">
    53     47             <h1>OPTIONS ORTHOGRAPHIQUES</h1>
    54     48           </section>