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

- name: Install lynx
  pacman:
    name: lynx
    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
  copy:
    content: ""
    dest: /etc/firejail/firefox.local
    force: false
  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
  copy:
    content: ""
    dest: /etc/firejail/chromium.local
    force: false
  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 Tor browser
  pacman:
    name: torbrowser-launcher
    state: present
  tags:
    - tor-browser

- name: Jail Tor browser
  file:
    src: /usr/bin/firejail
    dest: /usr/local/bin/torbrowser-launcher
    state: link
  tags:
    - tor-browser
    - firejail

- name: Install qutebrowser and dependencies
  pacman:
    name:
      - qutebrowser
      - python-adblock
      - pdfjs
    state: present
  tags:
    - qutebrowser

- name: Jail qutebrowser
  file:
    src: /usr/bin/firejail
    dest: /usr/local/bin/qutebrowser
    state: link
  tags:
    - qutebrowser
    - 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
  copy:
    content: ""
    dest: /etc/xdg/mimeapps.list
    force: false
  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
