2b190e31a098be2d7090f3fc0f32ce936fc13fed — Nathan Hoad 2 years ago b91f467
Remove profile and stylesheet support, which I have never used.
7 files changed, 32 insertions(+), 133 deletions(-)

M README.md
M bin/roland
M roland/api.py
M roland/core.py
M roland/extensions.py
M roland/utils.py
M roland/webextension.py
M README.md => README.md +0 -18
@@ 20,24 20,6 @@ download progress) and an entry field for all other input. Roland aims to have
 NO popup windows of any kind, nothing that is not controllable via the
 keyboard. If you find one, it's a bug.
 
-Profile support
----------------
-
-Roland supports multiple profiles. Specify which profile you want to use with
---profile, e.g. `roland --profile jake` to load the 'jake' profile.
-
-If not specified, the profile is set to 'default'.
-
-This affects history, cookies, session and stylesheet data.
-
-
-User Stylesheets
-----------------
-
-Just like Firefox's chrome.css, this allows you to style pages with your own
-custom CSS. Found at`~/.config/roland/stylesheet.<profile>.css`.
-
-
 Configuration
 -------------
 

M bin/roland => bin/roland +0 -9
@@ 1,8 1,5 @@
 #!/usr/bin/env python3
 
-import argparse
-import sys
-
 import gi
 
 gi.require_version('Gtk', '3.0')


@@ 16,13 13,7 @@ from roland.core import Roland
 
 
 def main():
-    parser = argparse.ArgumentParser('roland')
-    parser.add_argument(
-        '--profile', help='Profile to run under.', default='default')
-    options, unknown = parser.parse_known_args(sys.argv)
-
     roro = Roland()
-    roro.set_profile(options.profile)
 
     gbulb.install(gtk=True)
     loop = gbulb.get_event_loop()

M roland/api.py => roland/api.py +2 -7
@@ 22,18 22,13 @@ class _Lazy:
         return lazy_command
 
 
-def open_window(url, profile='default'):
-    return dbus_execute('open_window', url=url, profile=profile)
-
-
 def dbus_execute(method, *args, profile, **kwargs):
     import dbus
     bus = dbus.SessionBus()
     roland_service = bus.get_object(
-        'com.deschain.roland.{}'.format(profile),
-        '/com/deschain/roland/{}'.format(profile))
+        'com.deschain.roland', '/com/deschain/roland')
     func = roland_service.get_dbus_method(
-        method, 'com.deschain.roland.{}'.format(profile))
+        method, 'com.deschain.roland')
     return func(*args, **kwargs)
 
 

M roland/core.py => roland/core.py +7 -30
@@ 65,12 65,12 @@ def private(func):
 request_counter = itertools.count(1)
 
 
-def message_webprocess(command, *, page_id, profile, callback, **kwargs):
+def message_webprocess(command, *, page_id, callback, **kwargs):
     # FIXME: make this whole thing asyncio friendly, getting rid of callback
     # and everything..
 
     request_id = next(request_counter)
-    p = runtime_path('webprocess.{{}}.{}'.format(page_id), profile)
+    p = runtime_path('webprocess.{}.sock'.format(page_id))
     addr = Gio.UnixSocketAddress.new(p)
     client = Gio.SocketClient.new()
 


@@ 187,7 187,6 @@ class BrowserCommands:
 
             message_webprocess(
                 'form_fill',
-                profile=self.roland.profile,
                 page_id=self.webview.get_page_id(),
                 callback=None,
                 **{k.decode('utf8'): v for (k, v) in form.items()}


@@ 225,7 224,6 @@ class BrowserCommands:
             message_webprocess(
                 'serialise_form',
                 form_id=form_id,
-                profile=self.roland.profile,
                 page_id=self.webview.get_page_id(),
                 callback=serialised_form,
             )


@@ 233,7 231,6 @@ class BrowserCommands:
         message_webprocess(
             'highlight',
             selector='form',
-            profile=self.roland.profile,
             page_id=self.webview.get_page_id(),
             callback=display_choices,
         )


@@ 276,7 273,6 @@ class BrowserCommands:
 
         message_webprocess(
             'form_fill',
-            profile=self.roland.profile,
             page_id=self.webview.get_page_id(),
             callback=None,
             **{k.decode('utf8'): v for (k, v) in form_data.items()}


@@ 507,7 503,6 @@ class BrowserCommands:
 
         message_webprocess(
             'get_source',
-            profile=self.roland.profile,
             page_id=self.webview.get_page_id(),
             callback=have_source
         )


@@ 516,7 511,6 @@ class BrowserCommands:
     def remove_overlay(self):
         message_webprocess(
             'remove_overlay',
-            profile=self.roland.profile,
             page_id=self.webview.get_page_id(),
             callback=None,
         )


@@ 533,7 527,6 @@ class BrowserCommands:
                 message_webprocess(
                     'yank',
                     yank_id=yank_id,
-                    profile=self.roland.profile,
                     page_id=self.webview.get_page_id(),
                     callback=None
                 )


@@ 552,7 545,6 @@ class BrowserCommands:
                     'click',
                     click_id=click_id,
                     new_window=new_window,
-                    profile=self.roland.profile,
                     page_id=self.webview.get_page_id(),
                     callback=None
                 )


@@ 583,7 575,6 @@ class BrowserCommands:
         message_webprocess(
             'highlight',
             selector=selector,
-            profile=self.roland.profile,
             page_id=self.webview.get_page_id(),
             callback=display_choices,
         )


@@ 1686,7 1677,6 @@ class BrowserTab(BrowserView, Gtk.VBox):
 class Roland(RolandConfigBase, Gtk.Application):
     __gsignals__ = {
         'new_browser': (GObject.SIGNAL_RUN_LAST, None, (str, str, str, bool, bool, str, str)),
-        'profile_set': (GObject.SIGNAL_RUN_LAST, None, (str,)),
     }
 
     browser_view = BrowserTab


@@ 1760,13 1750,7 @@ class Roland(RolandConfigBase, Gtk.Application):
             notebook.set_show_tabs(True)
 
     def new_webview(self):
-        user_content_manager = self.get_extension('UserContentManager')
-
-        if user_content_manager is not None:
-            webview = WebKit2.WebView.new_with_user_content_manager(user_content_manager.manager)
-        else:
-            webview = WebKit2.WebView()
-        return webview
+        return WebKit2.WebView()
 
     def before_run(self):
         for ext in self.extensions:


@@ 1823,11 1807,6 @@ class Roland(RolandConfigBase, Gtk.Application):
             if previous_uri != 'about:blank':
                 self.new_window(previous_uri, session=previous_session)
 
-    def set_profile(self, profile):
-        self.profile = profile
-        self.set_application_id('{}.{}'.format('deschain.roland', profile))
-        self.emit('profile-set', profile)
-
     def load_config(self):
         super().load_config()
         init_logging()


@@ 1839,8 1818,7 @@ class Roland(RolandConfigBase, Gtk.Application):
 
         self.browser_view = getattr(self.config, 'browser_view', self.browser_view)
 
-        if self.config.enable_disk_cache:
-            self.connect('profile-set', self.set_disk_cache)
+        self.set_disk_cache()
 
         font = getattr(self.config, 'font', '')
 


@@ 1874,17 1852,17 @@ class Roland(RolandConfigBase, Gtk.Application):
 
         self.font_style_provider.load_from_data('* {{ font: {} "{}"; }}'.format(size, font).encode('utf8'))
 
-    def set_disk_cache(self, roland, profile):
+    def set_disk_cache(self):
         context = WebKit2.WebContext.get_default()
 
-        disk_cache = cache_path('{}/web/'.format(self.profile))
+        disk_cache = cache_path('web/')
         try:
             os.makedirs(disk_cache)
         except FileExistsError:
             pass
         context.set_disk_cache_directory(disk_cache)
 
-        favicon_cache = cache_path('{}/favicon/'.format(self.profile))
+        favicon_cache = cache_path('favicon/')
         try:
             os.makedirs(favicon_cache)
         except FileExistsError:


@@ 1892,7 1870,6 @@ class Roland(RolandConfigBase, Gtk.Application):
         context.set_favicon_database_directory(favicon_cache)
 
     def set_web_extensions_info(self, context):
-        context.set_web_extensions_initialization_user_data(GLib.Variant.new_string(self.profile))
         context.set_web_extensions_directory(config_path('webextensions/'))
 
     def setup(self):

M roland/extensions.py => roland/extensions.py +13 -52
@@ 87,7 87,7 @@ class HistoryManager(Extension):
         conn.close()
 
     def get_history_db(self):
-        return sqlite3.connect(config_path('history.{}.db', self.roland.profile))
+        return sqlite3.connect(config_path('history.db'))
 
     def update(self, url):
         if url == 'about:blank':


@@ 169,7 169,7 @@ class DownloadManager(Extension):
 
 class CookieManager(Extension):
     def setup(self):
-        cookiejar_path = config_path('cookies.{}.db', self.roland.profile)
+        cookiejar_path = config_path('cookies.db')
 
         cookiejar = WebKit2.WebContext.get_default().get_cookie_manager()
 


@@ 186,7 186,7 @@ class SessionManager(Extension):
 
     def setup(self):
         try:
-            with open(config_path('session.{}.json', self.roland.profile), 'r') as f:
+            with open(config_path('session.json'), 'r') as f:
                 session = json.load(f)
         except FileNotFoundError:
             pass


@@ 230,21 230,20 @@ class SessionManager(Extension):
                 'session': single_session,
             })
 
-        with open(config_path('session.{}.json', self.roland.profile), 'w') as f:
+        with open(config_path('session.json'), 'w') as f:
             json.dump(session, f, indent=4)
 
 
 class TLSErrorByPassExtension(Extension):
     def setup(self):
-        cert_bypass_path = config_path(
-            'tls.{}/bypass/'.format(self.roland.profile))
+        cert_bypass_path = config_path('tls/bypass/')
         try:
             os.makedirs(cert_bypass_path)
         except FileExistsError:
             pass
 
         try:
-            os.makedirs(config_path('tls.{}/error/'.format(self.roland.profile)))
+            os.makedirs(config_path('tls/error/'))
         except FileExistsError:
             pass
 


@@ 257,10 256,8 @@ class TLSErrorByPassExtension(Extension):
             context.allow_tls_certificate_for_host(certificate, host)
 
     def bypass(self, host):
-        cert_error_path = config_path(
-            'tls.{}/error/{}'.format(self.roland.profile, host))
-        cert_bypass_path = config_path(
-            'tls.{}/bypass/{}'.format(self.roland.profile, host))
+        cert_error_path = config_path('tls/error/{}'.format(host))
+        cert_bypass_path = config_path('tls/bypass/{}'.format(host))
 
         context = WebKit2.WebContext.get_default()
         try:


@@ 340,7 337,7 @@ class HSTSExtension(Extension):
             conn.commit()
 
     def get_hsts_db(self):
-        return sqlite3.connect(config_path('hsts.{}.db', self.roland.profile), detect_types=sqlite3.PARSE_DECLTYPES)
+        return sqlite3.connect(config_path('hsts.db'), detect_types=sqlite3.PARSE_DECLTYPES)
 
     def add_entry(self, uri, hsts_header):
         parsed = parse_dict_header(hsts_header)


@@ 396,43 393,6 @@ class HSTSExtension(Extension):
         return False
 
 
-class UserContentManager(Extension):
-    def setup(self):
-        path = config_path('stylesheet.{}.css', self.roland.profile)
-        try:
-            with open(path) as f:
-                stylesheet = f.read()
-        except FileNotFoundError:
-            stylesheet = ''
-
-        path = config_path('script.{}.js', self.roland.profile)
-        try:
-            with open(path) as f:
-                script = f.read()
-        except FileNotFoundError:
-            script = ''
-
-        self.script = WebKit2.UserScript.new(
-            script,
-            WebKit2.UserContentInjectedFrames.ALL_FRAMES,
-            WebKit2.UserScriptInjectionTime.END,
-            None,
-            None
-        )
-
-        self.stylesheet = WebKit2.UserStyleSheet.new(
-            stylesheet,
-            WebKit2.UserContentInjectedFrames.ALL_FRAMES,
-            WebKit2.UserStyleLevel.USER,
-            None,
-            None
-        )
-
-        self.manager = WebKit2.UserContentManager.new()
-        self.manager.add_script(self.script)
-        self.manager.add_style_sheet(self.stylesheet)
-
-
 class DBusManager(Extension):
     def before_run(self):
         try:


@@ 449,14 409,15 @@ class DBusManager(Extension):
         import dbus
         import dbus.service
 
-        name = 'com.deschain.roland.{}'.format(self.roland.profile)
+        name = 'com.deschain.roland'
 
         roland = self.roland
 
         class DBusAPI(dbus.service.Object):
             def __init__(self):
                 bus_name = dbus.service.BusName(name, bus=dbus.SessionBus())
-                dbus.service.Object.__init__(self, bus_name, '/com/deschain/roland/{}'.format(roland.profile))
+                dbus.service.Object.__init__(
+                    self, bus_name, '/com/deschain/roland')
 
             @dbus.service.method(name)
             def open_window(self, url, related_id=None):


@@ 614,7 575,7 @@ class PasswordManagerExtension(Extension):
             db.commit()
 
     def get_password_db(self):
-        return sqlite3.connect(config_path('passwords.{}.db', self.roland.profile), detect_types=sqlite3.PARSE_DECLTYPES)
+        return sqlite3.connect(config_path('passwords.db'), detect_types=sqlite3.PARSE_DECLTYPES)
 
     def update_last_used(self, record_id):
         with self.get_password_db() as db:

M roland/utils.py => roland/utils.py +5 -9
@@ 11,21 11,18 @@ def get_pretty_size(bytecount):
     return '%d%s' % (size, suffix)
 
 
-def config_path(t, profile=''):
+def config_path(t):
     from gi.repository import GLib
-    t = t.format(profile)
     return os.path.join(GLib.get_user_config_dir(), 'roland', t)
 
 
-def runtime_path(t, profile=''):
+def runtime_path(t):
     from gi.repository import GLib
-    t = t.format(profile)
     return os.path.join(GLib.get_user_runtime_dir(), 'roland', t)
 
 
-def cache_path(t, profile=''):
+def cache_path(t):
     from gi.repository import GLib
-    t = t.format(profile)
     return os.path.join(GLib.get_user_cache_dir(), 'roland', t)
 
 


@@ 138,14 135,13 @@ def load_config():
 
     from roland.extensions import (
         CookieManager, DBusManager, DownloadManager, HistoryManager,
-        SessionManager, TLSErrorByPassExtension, HSTSExtension, UserContentManager,
+        SessionManager, TLSErrorByPassExtension, HSTSExtension,
         PasswordManagerExtension, NotificationManager, ClipboardManager)
 
     default_extensions = [
         CookieManager, DBusManager, DownloadManager, HistoryManager,
         SessionManager, TLSErrorByPassExtension, HSTSExtension,
-        UserContentManager, PasswordManagerExtension, NotificationManager,
-        ClipboardManager]
+        PasswordManagerExtension, NotificationManager, ClipboardManager]
     config.extensions = getattr(config, 'extensions', default_extensions)
 
     # DBusManager, as of the WebKit2 port, is essentially required

M roland/webextension.py => roland/webextension.py +5 -8
@@ 19,10 19,9 @@ Highlight = namedtuple('Highlight', 'nodes node_lists')
 
 
 class RolandWebExtension(RolandConfigBase):
-    def __init__(self, profile):
+    def __init__(self):
         gbulb.install(gtk=False)
 
-        self.profile = profile
         try:
             self.loop = asyncio.get_event_loop()
         except RuntimeError:


@@ 75,7 74,7 @@ class RolandWebExtension(RolandConfigBase):
         if new_window:
             url = node.get_href()
             from roland.api import dbus_execute
-            dbus_execute('open_window', url, page_id, profile=self.profile)
+            dbus_execute('open_window', url, page_id)
         else:
             node.click()
             node.focus()


@@ 288,7 287,7 @@ class RolandWebExtension(RolandConfigBase):
         log.info("Starting page server for {}", page_id)
         self.pages[page_id] = web_page
 
-        path = runtime_path('webprocess.{}.{}'.format(self.profile, page_id))
+        path = runtime_path('webprocess.{}.sock'.format(page_id))
 
         try:
             os.unlink(path)


@@ 340,12 339,10 @@ class RolandWebExtension(RolandConfigBase):
 
 
 def initialize(extension, arguments):
-    profile = arguments.unpack()
-
     init_logging()
-    log.info("Plugin initialized for {}", profile)
+    log.info("Plugin initialized")
 
-    roland = RolandWebExtension(profile)
+    roland = RolandWebExtension()
 
     extension.connect('page-created', roland.on_page_created)