aboutsummaryrefslogtreecommitdiff
path: root/src/content/components/top-content/index.js
blob: 1aaef1b54041568ed9728d579c70e404b65a2875 (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
31
32
33
34
35
36
37
38
39
40
41
import CommonComponent from '../common';
import FollowController from './follow-controller';
import FindComponent from './find';
import * as consoleFrames from '../../console-frames';
import messages from 'shared/messages';
import * as scrolls from 'content/scrolls';

export default class TopContent {

  constructor(win, store) {
    this.win = win;
    this.store = store;

    new CommonComponent(win, store); // eslint-disable-line no-new
    new FollowController(win, store); // eslint-disable-line no-new
    new FindComponent(win, store); // eslint-disable-line no-new

    // TODO make component
    consoleFrames.initialize(this.win.document);

    messages.onMessage(this.onMessage.bind(this));
  }

  onMessage(message) {
    let addonState = this.store.getState().addon;

    switch (message.type) {
    case messages.CONSOLE_UNFOCUS:
      this.win.focus();
      consoleFrames.blur(window.document);
      return Promise.resolve();
    case messages.ADDON_ENABLED_QUERY:
      return Promise.resolve({
        type: messages.ADDON_ENABLED_RESPONSE,
        enabled: addonState.enabled,
      });
    case messages.TAB_SCROLL_TO:
      return scrolls.scrollTo(message.x, message.y, false);
    }
  }
}