From eb888cc8d77cfdba90f85678de223002bdf731c6 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Thu, 25 Jan 2018 13:35:23 -0500 Subject: [PATCH] fix latest change requests --- qutebrowser/browser/browsertab.py | 6 +++-- qutebrowser/browser/commands.py | 2 +- qutebrowser/browser/webengine/webenginetab.py | 16 ++++++------- qutebrowser/browser/webkit/webkittab.py | 24 +++++++------------ tests/end2end/features/history.feature | 2 +- tests/unit/browser/test_tab.py | 2 +- 6 files changed, 23 insertions(+), 29 deletions(-) diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py index 80cdbd5a6..f0015dd47 100644 --- a/qutebrowser/browser/browsertab.py +++ b/qutebrowser/browser/browsertab.py @@ -119,8 +119,10 @@ class AbstractAction: action_class = None action_base = None - def __init__(self): + def __init__(self, tab, win_id): self._widget = None + self._tab = tab + self._win_id = win_id def exit_fullscreen(self): """Exit the fullscreen mode.""" @@ -137,7 +139,7 @@ class AbstractAction: raise WebTabError("{} is not a valid web action!".format(name)) self._widget.triggerPageAction(member) - def show_source(self, win_id, url): + def show_source(self): """Show the source of the current page in a new tab.""" raise NotImplementedError diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 42b7d685e..f7d9bdf73 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1509,7 +1509,7 @@ class CommandDispatcher: if current_url.scheme() == 'view-source': raise cmdexc.CommandError("Already viewing source!") - tab.action.show_source(self._win_id, current_url) + tab.action.show_source() @cmdutils.register(instance='command-dispatcher', scope='window', debug=True) diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index 2b9d9418a..7e2a81af6 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -99,18 +99,16 @@ class WebEngineAction(browsertab.AbstractAction): """Save the current page.""" self._widget.triggerPageAction(QWebEnginePage.SavePage) - def show_source(self, win_id, url): + def show_source(self): try: self._widget.triggerPageAction(QWebEnginePage.ViewSource) except AttributeError: # Qt < 5.8 - # note: it's not possible to build the QUrl object by setting the - # scheme using setScheme('view-source'). - # QUrl does the right thing when URL prefix is "view-source:". - new_url = QUrl('view-source:' + url.toString()) - tabbed_browser = objreg.get('tabbed-browser', scope='window', - window=win_id) - tabbed_browser.tabopen(new_url, background=False, related=True) + url_str = self._tab.url().toString(QUrl.RemoveUserInfo) + new_url = QUrl('view-source:' + url_str) + tb = objreg.get('tabbed-browser', scope='window', + window=self._win_id) + tb.tabopen(new_url, background=False, related=True) class WebEnginePrinting(browsertab.AbstractPrinting): @@ -609,7 +607,7 @@ class WebEngineTab(browsertab.AbstractTab): self.search = WebEngineSearch(parent=self) self.printing = WebEnginePrinting() self.elements = WebEngineElements(self) - self.action = WebEngineAction() + self.action = WebEngineAction(self, win_id) self._set_widget(widget) self._connect_signals() self.backend = usertypes.Backend.QtWebEngine diff --git a/qutebrowser/browser/webkit/webkittab.py b/qutebrowser/browser/webkit/webkittab.py index caaa32738..92820642c 100644 --- a/qutebrowser/browser/webkit/webkittab.py +++ b/qutebrowser/browser/webkit/webkittab.py @@ -54,14 +54,7 @@ class WebKitAction(browsertab.AbstractAction): """Save the current page.""" raise browsertab.UnsupportedOperationError - def show_source(self, win_id, url): - - def format_url(url): - """emulate what WebEnginePage::ViewSource does.""" - s = url.toString() - s = s.split('//')[-1] # strip scheme - s = s.split('@')[-1] # strip userinfo - return s + def show_source(self): def show_source_cb(source): """Show source as soon as it's ready.""" @@ -70,17 +63,18 @@ class WebKitAction(browsertab.AbstractAction): lexer = pygments.lexers.HtmlLexer() formatter = pygments.formatters.HtmlFormatter( full=True, linenos='table', - title='view-source:' + format_url(url)) + title='Source for {}'.format(url_str)) # pylint: enable=no-member highlighted = pygments.highlight(source, lexer, formatter) - base_url = QUrl('view-source:' + url.toString()) - new_tab = tabbed_browser.tabopen(background=False, related=True) + base_url = QUrl('view-source:' + url_str) + tb = objreg.get('tabbed-browser', scope='window', + window=self._win_id) + new_tab = tb.tabopen(background=False, related=True) new_tab.set_html(highlighted, base_url) - tabbed_browser = objreg.get('tabbed-browser', scope='window', - window=win_id) - tabbed_browser.currentWidget().dump_async(show_source_cb) + url_str = self._tab.url().toString(QUrl.RemoveUserInfo) + self._tab.dump_async(show_source_cb) class WebKitPrinting(browsertab.AbstractPrinting): @@ -657,7 +651,7 @@ class WebKitTab(browsertab.AbstractTab): self.search = WebKitSearch(parent=self) self.printing = WebKitPrinting() self.elements = WebKitElements(self) - self.action = WebKitAction() + self.action = WebKitAction(self, win_id) self._set_widget(widget) self._connect_signals() self.backend = usertypes.Backend.QtWebKit diff --git a/tests/end2end/features/history.feature b/tests/end2end/features/history.feature index df6610daf..e9ef56129 100644 --- a/tests/end2end/features/history.feature +++ b/tests/end2end/features/history.feature @@ -69,7 +69,7 @@ Feature: Page history Scenario: History with view-source URL When I open data/title.html And I run :view-source - And I wait for "Changing title for idx * to 'view-source:http://localhost:*/data/title.html'" in the log + And I wait for regex "Changing title for idx \d+ to '(Source for |view-source:)(http://)?localhost:\d+/data/title.html'" in the log Then the history should contain: http://localhost:(port)/data/title.html Test title diff --git a/tests/unit/browser/test_tab.py b/tests/unit/browser/test_tab.py index d67ee4c8f..7ceb9795b 100644 --- a/tests/unit/browser/test_tab.py +++ b/tests/unit/browser/test_tab.py @@ -87,7 +87,7 @@ class Tab(browsertab.AbstractTab): self.search = browsertab.AbstractSearch(parent=self) self.printing = browsertab.AbstractPrinting() self.elements = browsertab.AbstractElements(self) - self.action = browsertab.AbstractAction() + self.action = browsertab.AbstractAction(self, self.win_id) def _install_event_filter(self): pass