Grammalecte  Diff

Differences From Artifact [dd49867218]:

To Artifact [5abad65778]:


1
2
3







4
5
6
7
8
9
10
11
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
let xGCEWorker = null;

console.log('[Iframe] Loaded');








/*
    Worker (separate thread to avoid freezing Firefox)
*/
function createSharedWorker (sPath) {
    try {
        xGCEWorker = new SharedWorker(sPath+"gce_sharedworker.js");
    }
    catch (e) {
        console.error(e);
    }

    xGCEWorker.onerror = function(e) {
        console.log('There is an error with your worker!');
        console.log(typeof(e));
        console.log(e);
    }

    xGCEWorker.port.onmessage = function (e) {
        // https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
        try {
            // On retransmet directement le message à la page
            console.log("[Iframe] send from Message Worker");
            window.postMessage({SharedWorker: e.data}, sPath);
        }
        catch (e) {
            console.error(e);
        }
    };
    xGCEWorker.port.start();

    console.log("[Iframe] [worker]");
    console.log(xGCEWorker);

    //xGCEWorker.port.start();
    //console.log("Content script [port started]");

    xGCEWorker.port.postMessage(["init", {sExtensionPath: sPath, sOptions: "", sContext: "Firefox"}]);
    //xGCEWorker.port.postMessage(["parse", {sText: "Vas... J’en aie mare...", sCountry: "FR", bDebug: false, bContext: false}]);
    //xGCEWorker.port.postMessage(["parseAndSpellcheck", {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}]);
    //xGCEWorker.port.postMessage(["getListOfTokens", {sText: oRequest.sText}]);
    //xGCEWorker.port.postMessage(["textToTest", {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}]);
    //xGCEWorker.port.postMessage(["fullTests"]);
}


var sPathOrigin = '';
console.log('[Iframe] Set receivedMessageWeb');
function receivedMessageWeb (oEvent) {
    // Pour être sûr que ça vient bien de notre iframe ;)
    if (!xGCEWorker && typeof oEvent.data.sPath !== "undefined" && typeof oEvent.data.sPage !== "undefined" && oEvent.data.sPage === oEvent.origin) {
        console.log('[Iframe] Create the Sharedworker ', oEvent.origin);
        sPathOrigin = oEvent.origin;
        createSharedWorker(oEvent.data.sPath);
    } else if (xGCEWorker && sPathOrigin === oEvent.origin && typeof oEvent.data.SharedWorker === "undefined") {
        console.log('[Iframe] received (no SharedWorker):', oEvent, oEvent.origin);
        // Les messages reçus maintenant ont un SharedWorker fonctionnel
        // On transmet au SharedWorker uniquement si ça vient de la page web et on s’assure que ce n’est pas une réponse du SharedWorker.
        // TODO: Établir un protocole de communication afin de traiter uniquement les messages utiles
        console.log('[Iframe] exec command with SharedWorker');
        xGCEWorker.port.postMessage(oEvent.data);
        console.log('[Iframe] end send message to worker');
    }
}

window.addEventListener("message", receivedMessageWeb, false);

console.log('[Iframe] END');
|


>
>
>
>
>
>
>




|
<
|
|
<
<
<
<
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|

|
|

|
|

|
|
|
|
|
|
|

<
<



|


<
|





|







1
2
3
4
5
6
7
8
9
10
11
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


console.log('[Iframe] Loaded');
/*console.log(self);
console.log(browser);
console.log(location);
console.log(window.parent.location);*/

var sPathOrigin,
    sPathExtension = browser.extension.getURL("");

/*
    Worker (separate thread to avoid freezing Firefox)
*/
var xGCESharedWorker = xGCESharedWorker || new SharedWorker(browser.extension.getURL("gce_sharedworker.js"), {type:"classic", credentials:"omit", name:"GrammarWorker"});

var xGCEWorker = xGCESharedWorker.port;





xGCESharedWorker.onerror = function(e) {
    console.log('There is an error with your worker!');
    console.log(typeof(e));
    console.log(e);
}

xGCEWorker.onmessage = function (e) {
    // https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
    try {
        // On retransmet directement le message à la page
        console.log("[Iframe] send from Message Worker ",sPathExtension);
        window.postMessage({SharedWorker: e.data}, sPathExtension);
    }
    catch (e) {
        console.error(e);
    }
};
xGCEWorker.start();

console.log("[Iframe] [worker]");
console.log(xGCESharedWorker);

//xGCEWorker.start();
//console.log("Content script [port started]");

xGCEWorker.postMessage(["init", {sExtensionPath: browser.extension.getURL(""), sOptions: "", sContext: "Firefox"}]);
//xGCEWorker.postMessage(["parse", {sText: "Vas... J’en aie mare...", sCountry: "FR", bDebug: false, bContext: false}]);
//xGCEWorker.postMessage(["parseAndSpellcheck", {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}]);
//xGCEWorker.postMessage(["getListOfTokens", {sText: oRequest.sText}]);
//xGCEWorker.postMessage(["textToTest", {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}]);
//xGCEWorker.postMessage(["fullTests"]);




console.log('[Iframe] Set receivedMessageWeb');
function receivedMessageWeb (oEvent) {
    // Pour être sûr que ça vient bien de notre iframe ;)
    if (typeof oEvent.data.sPage !== "undefined" && oEvent.data.sPage === oEvent.origin) {
        console.log('[Iframe] Create the Sharedworker ', oEvent.origin);
        sPathOrigin = oEvent.origin;

    } else if (sPathOrigin === oEvent.origin && typeof oEvent.data.SharedWorker === "undefined") {
        console.log('[Iframe] received (no SharedWorker):', oEvent, oEvent.origin);
        // Les messages reçus maintenant ont un SharedWorker fonctionnel
        // On transmet au SharedWorker uniquement si ça vient de la page web et on s’assure que ce n’est pas une réponse du SharedWorker.
        // TODO: Établir un protocole de communication afin de traiter uniquement les messages utiles
        console.log('[Iframe] exec command with SharedWorker');
        xGCEWorker.postMessage(oEvent.data);
        console.log('[Iframe] end send message to worker');
    }
}

window.addEventListener("message", receivedMessageWeb, false);

console.log('[Iframe] END');