Grammalecte  Check-in [c262fc885d]

Overview
Comment:[fx] Le SharedWorker ne se partage pas dans toutes les fenêtres... Estce à cause de la bidouille ???
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fx | webext_sharedworker
Files: files | file ages | folders
SHA3-256: c262fc885da821b05cc0235dd19782d60ab4ecec702f031ab6a4f988a15da70f
User & Date: IllusionPerdu on 2017-08-11 10:44:02
Other Links: branch diff | manifest | tags
Context
2017-08-11
16:33
[fx] Pas mal de simplifications dans le code, mais le SharedWorker ne se partage toujours pas... Leaf check-in: d51f7da951 user: IllusionPerdu tags: fx, webext_sharedworker
10:44
[fx] Le SharedWorker ne se partage pas dans toutes les fenêtres... Estce à cause de la bidouille ??? check-in: c262fc885d user: IllusionPerdu tags: fx, webext_sharedworker
09:48
[fx] Simple test of previous commit check-in: acd22b9ea0 user: IllusionPerdu tags: fx, webext_sharedworker
Changes

Modified gc_lang/fr/webext/background.js from [b961377700] to [897ba1cfeb].

1
2
3
4
5
6
7
8
// Background 

"use strict";

function showError (e) {
    console.error(e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
}

|







1
2
3
4
5
6
7
8
// Background

"use strict";

function showError (e) {
    console.error(e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
}

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
                console.log("Unknown command: " + e.data[0]);
        }
    }
    catch (e) {
        showError(e);
    }
};

xGCEWorker.postMessage(["init", {sExtensionPath: browser.extension.getURL("."), sOptions: "", sContext: "Firefox"}]);


/*
    Messages from the extension (not the Worker)
*/
function handleMessage (oRequest, xSender, sendResponse) {







|







55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
                console.log("Unknown command: " + e.data[0]);
        }
    }
    catch (e) {
        showError(e);
    }
};
xGCEWorker.start();
xGCEWorker.postMessage(["init", {sExtensionPath: browser.extension.getURL("."), sOptions: "", sContext: "Firefox"}]);


/*
    Messages from the extension (not the Worker)
*/
function handleMessage (oRequest, xSender, sendResponse) {
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
        case "conjugueur_tab":
            xConjTab = browser.tabs.create({
                url: browser.extension.getURL("panel/conjugueur.html"),
                pinned: true
            });
            xConjTab.then(onCreated, onError);
            break;
    }    
});


async function newwin () {
    console.log("Async on");
    const getActive = browser.tabs.query({ currentWindow: true, active: true, });
    const xWindowInfo = await browser.windows.getLastFocused();







|







156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
        case "conjugueur_tab":
            xConjTab = browser.tabs.create({
                url: browser.extension.getURL("panel/conjugueur.html"),
                pinned: true
            });
            xConjTab.then(onCreated, onError);
            break;
    }
});


async function newwin () {
    console.log("Async on");
    const getActive = browser.tabs.query({ currentWindow: true, active: true, });
    const xWindowInfo = await browser.windows.getLastFocused();

Modified gc_lang/fr/webext/content_scripts/communicate.js from [f425809667] to [dd49867218].

26
27
28
29
30
31
32

33
34
35
36
37
38
39
            console.log("[Iframe] send from Message Worker");
            window.postMessage({SharedWorker: e.data}, sPath);
        }
        catch (e) {
            console.error(e);
        }
    };


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

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








>







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
            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]");

52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
    // 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');







|











53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
    // 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');

Modified gc_lang/fr/webext/gce_sharedworker.js from [72e7a7fc85] to [1348682312].

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
function showError (e) {
    for (let sParam in e) {
        console.log(sParam);
        console.log(e[sParam]);
    }
}

onconnect = function(e) {
    console.log("START CONNECTION");
    xPort = e.ports[0];
    xListPort.push(xPort);

    xPort.onmessage = function (e) {
        console.log("[Sharedworker] ONMESSAGE");
        console.log(e);
        console.log(e.data[0]);
        let oParam = e.data[1];
        switch (e.data[0]) {
            case "init":
                loadGrammarChecker(oParam.sExtensionPath, oParam.sOptions, oParam.sContext);







|



|
<







65
66
67
68
69
70
71
72
73
74
75
76

77
78
79
80
81
82
83
function showError (e) {
    for (let sParam in e) {
        console.log(sParam);
        console.log(e[sParam]);
    }
}

self.addEventListener("connect", function(e){
    console.log("START CONNECTION");
    xPort = e.ports[0];
    xListPort.push(xPort);
    xPort.addEventListener("message", function(e){

        console.log("[Sharedworker] ONMESSAGE");
        console.log(e);
        console.log(e.data[0]);
        let oParam = e.data[1];
        switch (e.data[0]) {
            case "init":
                loadGrammarChecker(oParam.sExtensionPath, oParam.sOptions, oParam.sContext);
110
111
112
113
114
115
116

117
118
119
120

121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
            case "fullTests":
                fullTests();
                break;
            case "getListOfTokens":
                getListOfTokens(oParam.sText);
                break;
            case "other":

                console.log("Message to Other");
                toReply.Other("Message to Other");
                break;
            case "all":

                console.log("Message to All");
                toReply.All("Message to All");
                break;
            default:
                console.log("Unknown command: " + showError(e.data[0]));
        }
    }
    //xPort.start();
}

let toReply = {
    All: function(data){
        xListPort.forEach(function(client){
            client.postMessage(data);
        });
    },







>




>






|
|
|







109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
            case "fullTests":
                fullTests();
                break;
            case "getListOfTokens":
                getListOfTokens(oParam.sText);
                break;
            case "other":
                console.log("[Sharedworker Other] Number of client: "+xListPort.length);
                console.log("Message to Other");
                toReply.Other("Message to Other");
                break;
            case "all":
                console.log("[Sharedworker All] Number of client: "+xListPort.length);
                console.log("Message to All");
                toReply.All("Message to All");
                break;
            default:
                console.log("Unknown command: " + showError(e.data[0]));
        }
    });
    xPort.start();
});

let toReply = {
    All: function(data){
        xListPort.forEach(function(client){
            client.postMessage(data);
        });
    },