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         -// Background 
            1  +// Background
     2      2   
     3      3   "use strict";
     4      4   
     5      5   function showError (e) {
     6      6       console.error(e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
     7      7   }
     8      8   
................................................................................
    55     55                   console.log("Unknown command: " + e.data[0]);
    56     56           }
    57     57       }
    58     58       catch (e) {
    59     59           showError(e);
    60     60       }
    61     61   };
    62         -
           62  +xGCEWorker.start();
    63     63   xGCEWorker.postMessage(["init", {sExtensionPath: browser.extension.getURL("."), sOptions: "", sContext: "Firefox"}]);
    64     64   
    65     65   
    66     66   /*
    67     67       Messages from the extension (not the Worker)
    68     68   */
    69     69   function handleMessage (oRequest, xSender, sendResponse) {
................................................................................
   156    156           case "conjugueur_tab":
   157    157               xConjTab = browser.tabs.create({
   158    158                   url: browser.extension.getURL("panel/conjugueur.html"),
   159    159                   pinned: true
   160    160               });
   161    161               xConjTab.then(onCreated, onError);
   162    162               break;
   163         -    }    
          163  +    }
   164    164   });
   165    165   
   166    166   
   167    167   async function newwin () {
   168    168       console.log("Async on");
   169    169       const getActive = browser.tabs.query({ currentWindow: true, active: true, });
   170    170       const xWindowInfo = await browser.windows.getLastFocused();

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

    26     26               console.log("[Iframe] send from Message Worker");
    27     27               window.postMessage({SharedWorker: e.data}, sPath);
    28     28           }
    29     29           catch (e) {
    30     30               console.error(e);
    31     31           }
    32     32       };
           33  +    xGCEWorker.port.start();
    33     34   
    34     35       console.log("[Iframe] [worker]");
    35     36       console.log(xGCEWorker);
    36     37   
    37     38       //xGCEWorker.port.start();
    38     39       //console.log("Content script [port started]");
    39     40   
................................................................................
    52     53       // Pour être sûr que ça vient bien de notre iframe ;)
    53     54       if (!xGCEWorker && typeof oEvent.data.sPath !== "undefined" && typeof oEvent.data.sPage !== "undefined" && oEvent.data.sPage === oEvent.origin) {
    54     55           console.log('[Iframe] Create the Sharedworker ', oEvent.origin);
    55     56           sPathOrigin = oEvent.origin;
    56     57           createSharedWorker(oEvent.data.sPath);
    57     58       } else if (xGCEWorker && sPathOrigin === oEvent.origin && typeof oEvent.data.SharedWorker === "undefined") {
    58     59           console.log('[Iframe] received (no SharedWorker):', oEvent, oEvent.origin);
    59         -        // Les messages reçus maintenant ont un SharedWorker fonctionnel 
           60  +        // Les messages reçus maintenant ont un SharedWorker fonctionnel
    60     61           // 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.
    61     62           // TODO: Établir un protocole de communication afin de traiter uniquement les messages utiles
    62     63           console.log('[Iframe] exec command with SharedWorker');
    63     64           xGCEWorker.port.postMessage(oEvent.data);
    64     65           console.log('[Iframe] end send message to worker');
    65     66       }
    66     67   }
    67     68   
    68     69   window.addEventListener("message", receivedMessageWeb, false);
    69     70   
    70     71   console.log('[Iframe] END');

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

    65     65   function showError (e) {
    66     66       for (let sParam in e) {
    67     67           console.log(sParam);
    68     68           console.log(e[sParam]);
    69     69       }
    70     70   }
    71     71   
    72         -onconnect = function(e) {
           72  +self.addEventListener("connect", function(e){
    73     73       console.log("START CONNECTION");
    74     74       xPort = e.ports[0];
    75     75       xListPort.push(xPort);
    76         -
    77         -    xPort.onmessage = function (e) {
           76  +    xPort.addEventListener("message", function(e){
    78     77           console.log("[Sharedworker] ONMESSAGE");
    79     78           console.log(e);
    80     79           console.log(e.data[0]);
    81     80           let oParam = e.data[1];
    82     81           switch (e.data[0]) {
    83     82               case "init":
    84     83                   loadGrammarChecker(oParam.sExtensionPath, oParam.sOptions, oParam.sContext);
................................................................................
   110    109               case "fullTests":
   111    110                   fullTests();
   112    111                   break;
   113    112               case "getListOfTokens":
   114    113                   getListOfTokens(oParam.sText);
   115    114                   break;
   116    115               case "other":
          116  +                console.log("[Sharedworker Other] Number of client: "+xListPort.length);
   117    117                   console.log("Message to Other");
   118    118                   toReply.Other("Message to Other");
   119    119                   break;
   120    120               case "all":
          121  +                console.log("[Sharedworker All] Number of client: "+xListPort.length);
   121    122                   console.log("Message to All");
   122    123                   toReply.All("Message to All");
   123    124                   break;
   124    125               default:
   125    126                   console.log("Unknown command: " + showError(e.data[0]));
   126    127           }
   127         -    }
   128         -    //xPort.start();
   129         -}
          128  +    });
          129  +    xPort.start();
          130  +});
   130    131   
   131    132   let toReply = {
   132    133       All: function(data){
   133    134           xListPort.forEach(function(client){
   134    135               client.postMessage(data);
   135    136           });
   136    137       },