aboutsummaryrefslogtreecommitdiff
path: root/e2e/ambassador/src/content/index.js
blob: fd19136b0b56f7a335b5c315d126911219503585 (plain) (blame)
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
import {
  EVENT_KEYPRESS, EVENT_KEYDOWN, EVENT_KEYUP,
  SCROLL_GET, SCROLL_SET,
} from '../shared/messages';
import * as ipc from './ipc';
import * as events from './events';
import * as scrolls from './scrolls';

ipc.receivePageMessage((message) => {
  return ipc.sendToBackground(message);
});

ipc.receiveBackgroundMesssage((message) => {
  switch (message.type) {
  case EVENT_KEYPRESS:
    events.keypress(message);
    break;
  case EVENT_KEYDOWN:
    events.keydown(message);
    break;
  case EVENT_KEYUP:
    events.keyup(message);
    break;
  case SCROLL_GET:
    return Promise.resolve(scrolls.get());
  case SCROLL_SET:
    return Promise.resolve(scrolls.set(message.x, message.y));
  }
  return Promise.resolve({});
});