Statistics
| Branch: | Revision:

blinker / firefox.plugin / index.js @ 76dd22bd

History | View | Annotate | Download (14.764 KB)

1
/*
2
 * Copyright 2015 Thies Pfeiffer and Dimitri Heil and Kevin Taron
3
 * Blinker is distributed under the terms of the GNU General Public License
4
 * 
5
 * This file is part of Blinker.
6
 * 
7
 * Blinker is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 * 
12
 * Blinker is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU General Public License for more details.
16
 * 
17
 * You should have received a copy of the GNU General Public License
18
 * along with Blinker. If not, see <http://www.gnu.org/licenses/>.
19
 */
20

    
21

    
22
/****************************************
23
 * Imports 
24
 ****************************************/
25

    
26
var self = require("sdk/self");
27
var panels = require("sdk/panel");
28
var buttons = require('sdk/ui/button/action');
29
var tabs = require("sdk/tabs");
30
var pageMod = require("sdk/page-mod");
31
var pageWorker = require("sdk/page-worker");
32
var settings = require("sdk/simple-prefs");
33
var localstore = require("sdk/simple-storage");
34
var { attach, detach } = require('sdk/content/mod');
35
var { Style } = require('sdk/stylesheet/style');var about_config = require("sdk/preferences/service");
36
var array = require("sdk/util/array");
37
about_config.set("network.websocket.allowInsecureFromHTTPS", true);
38

    
39
var activeTABURL = "no";
40
var pageModWorkers = [];
41
var activeWorker;
42
var calibrationImage = self.data.url('./images/calib.png');
43
var holeImage = self.data.url('./images/hole_200.gif');
44
var currentPort = null;
45

    
46
var arr;
47

    
48
var htmlelements = localstore.storage.htmlelements;
49

    
50
if(htmlelements == null) {
51
  localstore.storage.htmlelements = {
52
    a : {
53
      "data-gaze" : "true",
54
      "data-gaze-type" : "action",
55
      "data-gaze-model" : "onscreen"
56
    },
57
    button : {
58
      "data-gaze" : "true",
59
      "data-gaze-type" : "action",
60
      "data-gaze-model" : "onscreen"
61
    },
62
    img : {
63
      "data-gaze" : "true",
64
      "data-gaze-type" : "action",
65
      "data-gaze-model" : "onscreen"
66
    },
67
    audio: {
68
      "data-gaze" : "true",
69
      "data-gaze-type" : "action",
70
      "data-gaze-model" : "onscreen"
71
    },
72
    video: {
73
      "data-gaze" : "true",
74
      "data-gaze-type" : "action",
75
      "data-gaze-model" : "onscreen"
76
    },
77
    "input\[type=text\]": {
78
      "data-gaze" : "true",
79
      "data-gaze-type" : "text",
80
      "data-gaze-model" : "onscreen"
81
    },
82
    "input\[type=submit\]": {
83
      "data-gaze" : "true",
84
      "data-gaze-type" : "action",
85
      "data-gaze-model" : "onscreen"
86
    },
87
    "input\[type=reset\]": {
88
      "data-gaze" : "true",
89
      "data-gaze-type" : "action",
90
      "data-gaze-model" : "onscreen"
91
    },
92
    "input\[type=email\]": {
93
      "data-gaze" : "true",
94
      "data-gaze-type" : "text",
95
      "data-gaze-model" : "onscreen"
96
    },
97
    "input\[type=password\]": {
98
      "data-gaze" : "true",
99
      "data-gaze-type" : "text",
100
      "data-gaze-model" : "onscreen"
101
    },
102
    "select": {
103
      "data-gaze" : "true",
104
      "data-gaze-type" : "choice",
105
      "data-gaze-model" : "onscreen"
106
    },
107
  };
108
  htmlelements = localstore.storage.htmlelements;
109
}
110

    
111
/****************************************
112
 * Base-Settings 
113
 ****************************************/
114

    
115
tabs.open({
116
    url: self.data.url("tutorial/tutorial-full.html"),
117
    inBackground: false,
118
});
119

    
120
tabs.open({
121
    url: self.data.url("home/start.html"),
122
    inBackground: false,
123
});
124

    
125
// tabs.open({
126
//     url: self.data.url("performancetest/performancetest.html"),
127
//     inBackground: false,
128
// });
129

    
130
// tabs.open({
131
//     url: self.data.url("performancetest/performancetest-comment1.html"),
132
//     inBackground: false,
133
// });
134

    
135
// tabs.open({
136
//     url: self.data.url("tutorial/calibrate.html"),
137
//     inBackground: false,
138
// });
139

    
140
/****************************************
141
 * Settings 
142
 ****************************************/
143

    
144
//initiation of the settings panel button
145
var button = buttons.ActionButton({
146
  id: "blickbrowser",
147
  label: "BlickBrowser Settings",
148
  icon: {
149
    "16": "./images/icons/eye-icon.png",
150
    "32": "./images/icons/eye-icon.png",
151
    "64": "./images/icons/eye-icon.png"
152
  },
153
  onClick: showSettings
154
});
155

    
156
/*
157
 *        Is called when the button's state has changed (is it checked or not)
158
 */
159
function showSettings(state) {
160
    panel.port.emit('loadSettings', 'go');
161
    panel.show();
162
}
163

    
164
/*
165
 *        Initiate the settings panel
166
 */
167
var panel = panels.Panel({
168
    contentURL: self.data.url("settings/settings.html"),
169
    contentScriptFile: [
170
      self.data.url("settings/settingsvariables.js"), 
171
      //self.data.url("lib/jquery/jquery-3.1.1.min.js"), 
172
      self.data.url("lib/jquery/jquery-2.2.4.min.js"), 
173
      // self.data.url("lib/jquery/jquery-1.11.1.js"), 
174
      self.data.url("settings/settings.js")
175
    ],
176
    position: button,
177
    //width: 400,
178
    height: 700,
179
});
180

    
181
/*
182
 * Send all blickbrowsersettings to the settings panel on request
183
 */
184
panel.port.on('getAllSettings', function() {
185
    emitAllPrefs(panel.port);
186
    //panel.port.emit('blickBrowserSettings', settings.prefs);
187
});
188

    
189
/*
190
 *        Settings have changed from inside the settings panel - adjust them globally
191
 */
192
panel.port.on("writeSettings", function(settings) {
193
    writeSettings(settings);
194
});
195

    
196
/*
197
 *        Eyetracker calibration has been toggled from settings panel
198
 *        send request to eyetracker
199
 */
200
panel.port.on("toggleCalibrate", function(value) {
201
    if (settings.prefs.eyeTracker == "eyetribe") {
202
        activeWorker.port.emit('startCalibration', 'go');
203
    }
204
});
205

    
206
/*
207
 *        Calibration check is being called from settings panel - hide the panel and tell the pagemod
208
 */
209
panel.port.on("toggleCheckCalibration", function(value) {
210
    if (settings.prefs.eyeTracker == "eyetribe") {
211
        /*tabs.activeTab.reload();*/
212
        panel.hide();
213
        //handleChange();                                
214
        activeWorker.port.emit('checkCalibration', 'go');
215

    
216
    }
217
});
218

    
219

    
220
panel.port.on("openTutorial", function(value) {
221
  tabs.open({
222
    url: self.data.url("tutorial/tutorial-full.html"),
223
    inBackground: false,
224
  });
225
});
226

    
227
panel.port.on("openHTMLSettings", function(value) {
228
  console.log("OpenSettingsPanel");
229
  tabs.open({
230
    url: self.data.url("settings/html-gaze-attr.html"),
231
    inBackground: false,
232
  });
233
});
234

    
235
/*
236
 *        Emit blickbrowsersettings to the panel
237
 */
238
panel.port.emit('loadSettings', 'go');
239

    
240

    
241
/*
242
 *        Is called when the button's state has changed (is it checked or not)
243
 */
244
function handleChange(state) {
245
    if (state.checked) {
246
        panel.port.emit('loadSettings', 'go');
247
        panel.show();
248
    }
249
}
250

    
251
/*
252
 * update settings and send them to the active tab
253
 * @set: The settings array (e.g. blickBrowserSettings)
254
 */
255
function writeSettings(set) {
256
    //console.log("writeSettings()");
257
    for (var name in set) {
258
        settings.prefs[name] = set [name];
259
    }
260
    emitAllPrefs(activeWorker.port);
261
}
262

    
263
/*
264
 *        Update the panel settings button's state when settings panel is being hidden
265
 */
266
function handleHide() {
267
    button.state('window', {
268
        checked: false
269
    });
270
}
271

    
272
/*
273
 * send all settings to the given port
274
 * @port: The port the settings are sent to (e.g. )
275
 */
276
function emitAllPrefs(port) {
277
    port.emit("blickBrowserSettings", settings.prefs);
278
}
279

    
280
/****************************************
281
 * Pageworker 
282
 ****************************************/
283

    
284
/*
285
 * Initiate pageworker (WebSocketServer-Connector)
286
 */
287
var pw = pageWorker.Page({
288
    contentURL: self.data.url("websocket/websocket.html")
289
});
290

    
291

    
292
pw.port.on('getEyeTracker', function() {
293
    worker.port.emit("EyeTracker", eyeTracker);
294
});
295

    
296
/*
297
 * If pageworker
298
 */
299
pw.port.on('getAllSettings', function() {
300
    emitAllPrefs(worker.port);
301
});
302

    
303
/*
304
 *        If message with name: 'eyeTrackerData' is received from pageworker, send it to the according listener
305
 *        inside the active pagemod
306
 */
307
pw.port.on('eyeTrackerData', function(message) {
308
    //console.log("main.js :: pageMod :: port.on.eyeTrackerData" + ", message: " + message);
309
    if (activeWorker !== undefined) {
310
        switch (settings.prefs.eyeTracker) {
311
            case "eyetribe":
312
                activeWorker.port.emit('eyeTrackerData', message);
313
                break;
314
            case "smi":
315
                activeWorker.port.emit('smiData', message);
316
                break;
317
            case "mygaze":
318
                activeWorker.port.emit('myGazeData', message);
319
                break;
320
            default:
321
                break;
322
        }
323
    }
324
});
325

    
326

    
327

    
328
/****************************************
329
 * PageMod 
330
 ****************************************/
331

    
332
/*
333
 *        Initiate pagemod and append listeners
334
 *
335
 */
336
pageMod.PageMod({
337
    include: ["*", "file://*", "resource://*"],
338
    contentScriptFile: [
339
      // Basic Libs
340
      self.data.url("lib/jquery/jquery-2.2.4.min.js"), 
341
      self.data.url("lib/notify.js"), 
342
      self.data.url("lib/jquery-ui/jquery-ui.js"), 
343
      self.data.url("lib/jquery.knob.js"), 
344
      self.data.url("lib/jquery.nearest.js"),
345
      self.data.url("lib/withinViewport.js"), 
346
      self.data.url("lib/jquery.withinViewport.js"), 
347
      self.data.url("lib/circle-progress.js"), 
348

    
349
      // Eyetracker Configs
350
      self.data.url("eyetracker/eyetribe/eyeTribe.js"), 
351

    
352
      // Custom Scripts
353
      self.data.url("scripts/helpers.js"), 
354
      self.data.url("scripts/functions.js"), 
355
      self.data.url("scripts/types/types.js"), 
356
      self.data.url("scripts/gazePosition.js"), 
357
      self.data.url("scripts/emulation.js"),
358
      self.data.url("scripts/myscript.js"),
359

    
360
      // Models
361
      self.data.url("scripts/models/dwell.js"), 
362
      self.data.url("scripts/models/onScreen.js"), 
363
      self.data.url("scripts/models/piemenu.js"), 
364

    
365
      // Modules
366
      self.data.url("scripts/text/keyboard.js"), 
367
      self.data.url("scripts/text/pieKeyboard.js"), 
368
      self.data.url("scripts/modules/piemenuOption.js"), 
369
      self.data.url("scripts/modules/onscreenOption.js"), 
370

    
371
      // Actions
372
      self.data.url("scripts/actions/actions.js"), 
373
      self.data.url("scripts/actions/multimedia.js"), 
374

    
375
      // Choices
376
      self.data.url("scripts/choices/choice.js"), 
377
      self.data.url("scripts/choices/checkbox.js"), 
378
      self.data.url("scripts/choices/select.js"), 
379
      self.data.url("scripts/choices/radio.js"), 
380
      self.data.url("scripts/choices/range.js"), 
381
    ],
382
    contentStyleFile: [
383
      self.data.url("style/style.css"), 
384
      self.data.url("lib/jquery-ui/jquiery-ui.css"), 
385
      self.data.url("style/fonts/font-awesome.css"),
386

    
387
      // Modules
388
      self.data.url("style/text/keyboard.css"), 
389
      self.data.url("style/text/piemenukeyboard.css"), 
390
      self.data.url("style/modules/piemenu.css"), 
391
      self.data.url("style/modules/onscreen.css"), 
392
    ],
393
    attachTo: ["top"],
394
    onAttach: function(worker) {
395

    
396
        //set global activeworker to current pagemod
397
        activeWorker = worker;
398

    
399
        worker.port.emit("activeEmulation", true);
400

    
401
        /*
402
         *        if page tab / page is (re)-activated - reset the eyetribes configuration settings and refresh the
403
         *        blickBrowserSettings, that might have changed in another tab
404
         */
405
        worker.tab.on('activate', function() {
406
            activeWorker = worker;
407
            activeWorker.port.emit("initializeEyeTribe", "");
408
            emitAllPrefs(activeWorker.port);
409
        });
410
        /*
411
         *        if page tab / page is (re)-activated - reset the eyetribes configuration settings and refresh the
412
         *        blickBrowserSettings, that might have changed in another tab
413
         */
414
        worker.on('pageshow', function() {
415
            activeWorker = worker;
416
            activeWorker.port.emit("initializeEyeTribe", "");
417
            array.add(pageModWorkers, this);
418
            emitAllPrefs(activeWorker.port);
419
        });
420

    
421
        /*
422
         *        if page tab / page is minimized, remove the actual worker from pagemodworkers
423
         */
424
        worker.on('pagehide', function() {
425
            array.remove(pageModWorkers, this);
426
        });
427

    
428
        /*
429
         *        if page tab / page is closed, remove the actual worker from pagemodworkers
430
         */
431
        worker.on('detach', function() {
432
            console.log("worker detached.");
433
            array.remove(pageModWorkers, this);
434
        });
435

    
436
        /*
437
         *        ################################################################
438
         *        #################### PAGEMOD PORT LISTENERS ####################
439
         *        ################################################################
440
         */
441

    
442
        /*
443
         *        Redirect message from pagemod to pageworker
444
         */
445
        worker.port.on("sendToTracker", function(message) {
446
            pw.port.emit("toEyetracker", message);
447
        });
448

    
449

    
450
        /*
451
         *        Set panel button icon color
452
         */
453
        worker.port.on('setIconGreen', function() {
454
            button.icon = "./images/icons/eye-icon_green.png";
455
        });
456
        worker.port.on('setIconRed', function() {
457
            button.icon = "./images/icons/eye-icon_red.png";
458
        });
459

    
460

    
461
        worker.port.on('blickBrowserMode', function(value) {
462
            settings.prefs.blickBrowserMode = value;
463
            emitAllPrefs(activeWorker.port);
464
        });  
465

    
466
        worker.port.on('openHomepage', function() {
467
          tabs.open({
468
              url: self.data.url("home/start.html"),
469
              inBackground: false,
470
          });
471
        });
472

    
473
        /*
474
         *        Settings have changed from inside the pagemod - adjust them globally
475
         */
476
        worker.port.on("writeSettings", function(settings) {
477
            writeSettings(settings);
478
        });
479

    
480
        /*
481
         *        ################################################################
482
         *        #################### PAGEMOD PORT EMITTERS #####################
483
         *        ################################################################
484
         */
485

    
486
        /*
487
         *        Send calibration image file to pagemod
488
         */
489
        worker.port.emit("calibrationImage", calibrationImage);
490

    
491
        /*
492
         *        Send privacy image file to pagemod
493
         */
494
        worker.port.emit("holeImage", holeImage);
495

    
496

    
497
    }
498
});
499

    
500
pageMod.PageMod({
501
  include: ["*", "file://*", "resource://*"],
502
  contentScriptFile: [
503
      // Basic Libs
504
      self.data.url("lib/jquery/jquery-2.2.4.min.js"), 
505
      // Custom Scripts
506
      self.data.url("scripts/htmlElements.js"),
507
  ],
508
  onAttach: function(worker) {
509
    worker.port.emit("getElements", htmlelements);
510
  }
511
});
512

    
513

    
514
pageMod.PageMod({
515
  include: ["resource://*"],
516
  contentScriptFile: [
517
      // Basic Libs
518
      self.data.url("lib/jquery/jquery-2.2.4.min.js"), 
519
      self.data.url("lib/notify.js"), 
520
      // Custom Scripts
521
      self.data.url("settings/html-gaze-attr.js"),
522
  ],
523
  onAttach: function(worker) {
524
    worker.port.emit("getElements", htmlelements);
525

    
526
    worker.port.on("setElements", function(value) { 
527
      htmlelements = value;
528
      localstore.storage.htmlelements = value;
529
    });
530

    
531
    worker.port.on("docChange", function() { 
532
      worker.port.emit("getElements", htmlelements);
533
    });
534
  }
535
});