diff --git a/qutebrowser/utils/objreg.py b/qutebrowser/utils/objreg.py index e6af97aea..8b2e5a2b8 100644 --- a/qutebrowser/utils/objreg.py +++ b/qutebrowser/utils/objreg.py @@ -36,6 +36,13 @@ class UnsetObject: __slots__ = () +class RegistryUnavailableError(Exception): + + """Exception raised when a certain registry does not exist yet.""" + + pass + + _UNSET = UnsetObject() @@ -81,6 +88,11 @@ def _get_registry(scope): """Get the correct registry for a given scope.""" if scope == 'global': return global_registry + elif scope == 'tab': + widget = get('tabbed-browser').currentWidget() + if widget is None: + raise RegistryUnavailableError(scope) + return widget.registry else: raise ValueError("Invalid scope '{}'!".format(scope)) diff --git a/qutebrowser/widgets/webview.py b/qutebrowser/widgets/webview.py index decb87c65..4dce57f63 100644 --- a/qutebrowser/widgets/webview.py +++ b/qutebrowser/widgets/webview.py @@ -51,6 +51,7 @@ class WebView(QWebView): open_target: Where to open the next tab ("normal", "tab", "tab_bg") viewing_source: Whether the webview is currently displaying source code. + registry: The ObjectRegistry associated with this tab. _cur_url: The current URL (accessed via cur_url property). _has_ssl_errors: Whether SSL errors occured during loading. _zoom: A NeighborList with the zoom levels. @@ -89,6 +90,8 @@ class WebView(QWebView): self._cur_url = None self.cur_url = QUrl() self.progress = 0 + self.registry = objreg.ObjectRegistry() + objreg.register('webview', self, registry=self.registry) page = webpage.BrowserPage(self) self.setPage(page) self.hintmanager = hints.HintManager(self)