Refactor bookmarks code a bit from upstream

Proper fix for #627

Adds some initial work for displaying symbolic icons for bookmarks (like
in the sidebar) but no actual implementation yet.