Overview
| Comment: | [fx] SharedWorker communicate with intermediate iframe to/from webpage |
|---|---|
| Downloads: | Tarball | ZIP archive | SQL archive |
| Timelines: | family | ancestors | descendants | both | fx | webext_sharedworker |
| Files: | files | file ages | folders |
| SHA3-256: |
4dc627f1b1513c7cd2f6e286b06217b5 |
| User & Date: | IllusionPerdu on 2017-08-10 14:23:50 |
| Other Links: | branch diff | manifest | tags |
Context
|
2017-08-10
| ||
| 15:08 | [fx] Manualy apply change from webext (je me metrise pas les merge de fossil) check-in: 9db066f572 user: IllusionPerdu tags: fx, webext_sharedworker | |
| 14:23 | [fx] SharedWorker communicate with intermediate iframe to/from webpage check-in: 4dc627f1b1 user: IllusionPerdu tags: fx, webext_sharedworker | |
| 14:08 | Create new branch named "webext_sharedworker" check-in: 976290fcbe user: IllusionPerdu tags: webext_sharedworker | |
Changes
Added gc_lang/fr/webext/content_scripts/comunicate.html version [5f977884e2].
> > > > > > | 1 2 3 4 5 6 |
<html>
<head>
<script src="/content_scripts/comunicate.js"></script>
</head>
<body></body>
</html>
|
Added gc_lang/fr/webext/content_scripts/comunicate.js version [a57bb48944].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 72 73 74 75 76 77 78 79 80 81 82 |
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);
for (let sParam in e) {
console.log(sParam);
console.log(e.sParam);
}
}
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);
}
};
console.log("[Iframe] [worker]");
console.log(xGCEWorker);
//xGCEWorker.port.start();
//console.log("Content script [port started]");
//xGCEWorker.port.postMessage(["init", {sExtensionPath: browser.extension.getURL("."), sOptions: "", sContext: "Firefox"}]);
console.log("[Iframe] [worker initialzed]");
//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 savePathExtension = '';
var savePathOrigine = '';
console.log('[Iframe] Set receivedMessageWeb');
function receivedMessageWeb (oEvent) {
console.log('[Iframe] received:', oEvent, savePathExtension, savePathOrigine, oEvent.origin);
//Pour être sure que ca viens bien de notre iframe ;)
if ( !xGCEWorker && typeof oEvent.data.sPath !== "undefined" && typeof oEvent.data.sPage !== "undefined" && oEvent.data.sPage === oEvent.origin ){
console.log('Create the Sharedworker ', oEvent.origin);
savePathExtension = oEvent.data.sPath;
savePathOrigine = oEvent.origin;
//On créer le Shraredworker
createSharedworker(savePathExtension);
//On initialise le Shraredworker
xGCEWorker.port.postMessage(["init", {sExtensionPath: savePathExtension, sOptions: "", sContext: "Firefox"}]);
} else if ( xGCEWorker && savePathOrigine === oEvent.origin) {
//Les messages reçus maintenant on un Sharedworker fonctionnel et donc si ça viens bien de la page on lui transmet
//TODO: Fodrait établir un protocol de communication afin qu'on ne traite vraiment que les messages a transmettre util ;)
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/content_scripts/modify_page.js from [a5f9d0af95] to [649173c95f].
1 2 3 4 | // Modify page "use strict"; | < > > < > < | | < | | < < < | > > > > > > > | > > > > | | < < < < < < < < < < < < | < < < | < < < < < < < < < | < < < < < < < < < | | < < < < | < | | | < > | | < | < | < < < < < | | 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 |
// Modify page
"use strict";
function showError (e) {
console.error(e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
}
console.log("Content script [start]");
/*
* Pour effectuer différent action sur la page en cours
*/
function receivedMessageIframe (oEvent) {
if ( typeof oEvent.data.SharedWorker !== "undefined" ) {
//C'est ici que les action devront être effectuées
console.log('[Web] received (from iframe (Sharedworker)):', oEvent);
}
}
/*
* Creation d'une iframe pour communiquer entre la page visitée et le Shareworker
*/
var iframe = document.createElement('iframe');
iframe.id = "GrammaFrameModule";
iframe.src = browser.extension.getURL('content_scripts/comunicate.html');
iframe.hidden = true;
iframe.onload= function() {
console.log('[Web] Init protocol de communication');
//var iframeContent = iframe.contentWindow;
var iframeContent = document.getElementById("GrammaFrameModule").contentWindow;
iframeContent.addEventListener("message", receivedMessageIframe, false);
try {
//La frame est chargé on envoie l'initialisation du Sharedworker
console.log('[Web] Initialise the worker :s');
console.log('[Web] Domaine ext: '+browser.extension.getURL(''));
iframeContent.postMessage({sPath:browser.extension.getURL(''), sPage:location.origin.trim("/")}, browser.extension.getURL('') );
//Un petit test pour débogage ;)
console.log('[Web] Test the worker :s');
iframeContent.postMessage(["parse", {sText: "Vas... J’en aie mare...", sCountry: "FR", bDebug: false, bContext: false}], browser.extension.getURL(''));
}
catch (e) {
console.error(e);
}
}
document.body.appendChild(iframe);
console.log('[Web] La suite des initialisations');
function wrapTextareas() {;
let lNode = document.getElementsByTagName("textarea");
for (let xNode of lNode) {
createGCButton(xNode);
}
}
|
| ︙ | ︙ |
Modified gc_lang/fr/webext/gce_sharedworker.js from [9a703895dc] to [deea68b2b7].
| ︙ | ︙ | |||
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
/*
Message Event Object
https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
*/
let xPort = null;
onconnect = function(e) {
console.log("START CONNECTION");
xPort = e.ports[0];
xPort.onmessage = function (e) {
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);
break;
| > > > > > > > > | 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 |
/*
Message Event Object
https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
*/
let xPort = null;
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];
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);
break;
|
| ︙ | ︙ | |||
100 101 102 103 104 105 106 |
case "fullTests":
fullTests();
break;
case "getListOfTokens":
getListOfTokens(oParam.sText);
break;
default:
| | | 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
case "fullTests":
fullTests();
break;
case "getListOfTokens":
getListOfTokens(oParam.sText);
break;
default:
console.log("Unknown command: " + showError(e.data[0]));
}
}
//xPort.start();
}
let oDict = null;
|
| ︙ | ︙ | |||
128 129 130 131 132 133 134 |
oDict = gc_engine.getDictionary();
oTest = new TestGrammarChecking(gc_engine, sExtensionPath+"/grammalecte/fr/tests_data.json");
oLxg = new Lexicographe(oDict);
if (sGCOptions !== "") {
gc_engine.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
}
oTokenizer = new Tokenizer("fr");
| | | 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
oDict = gc_engine.getDictionary();
oTest = new TestGrammarChecking(gc_engine, sExtensionPath+"/grammalecte/fr/tests_data.json");
oLxg = new Lexicographe(oDict);
if (sGCOptions !== "") {
gc_engine.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
}
oTokenizer = new Tokenizer("fr");
//tests();
// we always retrieve options from the gc_engine, for setOptions filters obsolete options
xPort.postMessage(["options", gc_engine.getOptions().gl_toString()]);
}
catch (e) {
console.error(e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
xPort.postMessage(["error", e.message]);
}
|
| ︙ | ︙ |
Modified gc_lang/fr/webext/manifest.json from [1400a7a766] to [fb0ccd7853].
| ︙ | ︙ | |||
40 41 42 43 44 45 46 |
}
],
"web_accessible_resources": [
"grammalecte/_dictionaries/French.json",
"grammalecte/fr/conj_data.json",
"grammalecte/fr/mfsp_data.json",
"grammalecte/fr/phonet_data.json",
| | > > | 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
}
],
"web_accessible_resources": [
"grammalecte/_dictionaries/French.json",
"grammalecte/fr/conj_data.json",
"grammalecte/fr/mfsp_data.json",
"grammalecte/fr/phonet_data.json",
"grammalecte/fr/tests_data.json",
"content_scripts/comunicate.html",
"content_scripts/comunicate.js"
],
"permissions": [
"activeTab",
"contextMenus"
],
"chrome_settings_overrides": {
"search_provider": {
|
| ︙ | ︙ |