---
- name: Install w3m
  pacman: name=w3m state=present

- name: Install Firefox
  pacman: name=firefox state=present
  tags:
    - firefox

- name: Jail Firefox
  file: src=/usr/bin/firejail
        dest=/usr/local/bin/firefox
        state=link
  tags:
    - firefox
    - firejail

- name: Verify Firefox firejail local profile exists
  file: path=/etc/firejail/firefox.local state=touch
  tags:
    - firefox
    - firejail

- name: Restrict Firefox access to /etc
  lineinfile:
    dest: /etc/firejail/firefox.local
    regexp: "^private-etc"
    line: "private-etc firejail,passwd,group,hostname,hosts,nsswitch.conf,resolv.conf,gtk-2.0,gtk-3.0,fonts,mime.types,asound.conf,pulse,localtime"
  tags:
    - firefox
    - firejail

- name: Install Chromium
  pacman: name=chromium state=present
  tags:
    - chromium

- name: Jail Chromium
  file: src=/usr/bin/firejail
        dest=/usr/local/bin/chromium
        state=link
  tags:
    - chromium
    - firejail

- name: Verify Chromium firejail local profile exists
  file: path=/etc/firejail/chromium.local state=touch
  tags:
    - chromium
    - firejail

- name: Restrict Chromium access to /etc
  lineinfile:
    dest: /etc/firejail/chromium.local
    regexp: "^private-etc"
    line: "private-etc firejail,passwd,group,hostname,hosts,nsswitch.conf,resolv.conf,gtk-2.0,gtk-3.0,fonts,mime.types,asound.conf,pulse,localtime"
  tags:
    - chromium
    - firejail

- name: Install Pepper Flash
  pacman: name=pepper-flash state=present
  tags:
    - chromium

- name: Install tor-browser-en
  aur: name=tor-browser-en user={{ user.name }} skip_pgp=yes
  tags:
    - tor-browser
    - aur

- name: Jail tor-browser-en
  file: src=/usr/bin/firejail
        dest=/usr/local/bin/tor-browser-en
        state=link
  tags:
    - tor-browser
    - firejail

- name: Push rofi browser chooser
  template: src=browser.sh.j2 dest=/usr/local/bin/browser mode=0755
  tags:
    - rofi
    - chooser

- name: Create local desktop application dir
  file: path=/usr/local/share/applications state=directory
  tags:
    - rofi
    - chooser

- name: Push rofi browser chooser desktop file
  copy: src=browser.desktop dest=/usr/local/share/applications/browser.desktop
  tags:
    - rofi
    - chooser

- name: Verify mimeapps.list exists
  file: path=/etc/xdg/mimeapps.list state=touch
  tags:
    - rofi
    - chooser

- name: Set rofi browser chooser as default application for relevant mimetypes
  lineinfile:
    dest: /etc/xdg/mimeapps.list
    regexp: "{{ item.regexp }}"
    line: "{{ item.line }}"
  with_items:
    - { regexp: '^text/html=', line: 'text/html=browser.desktop' }
    - { regexp: '^text/xml=', line: 'text/xml=browser.desktop' }
    - { regexp: '^text/mml=', line: 'text/mml=browser.desktop' }
    - { regexp: '^application/xhtml\+xml=', line: 'application/xhtml+xml=browser.desktop' }
    - { regexp: '^application/xml=', line: 'application/xml=browser.desktop' }
    - { regexp: '^x-scheme-handler/http=', line: 'x-scheme-handler/http=browser.desktop' }
    - { regexp: '^x-scheme-handler/https=', line: 'x-scheme-handler/https=browser.desktop' }
  tags:
    - rofi
    - chooser

- name: Install surfraw
  pacman: name=surfraw state=present
  tags:
    - surfraw

- name: Configure surfraw browser
  lineinfile:
    dest: /etc/xdg/surfraw/conf
    regexp: '^def   SURFRAW_graphical_browser	'
    line: 'def   SURFRAW_graphical_browser	/usr/local/bin/browser'
  tags:
    - surfraw
    - chooser

- name: Push surfraw-rofi script
  copy: src=surfraw-rofi dest=/usr/local/bin/surfraw-rofi mode=0755
  tags:
    - surfraw
    - rofi
