Refuse to serialize chrome:// and view-source:// tabs

Fixes #2289
This commit is contained in:
Florian Bruhin 2017-02-08 11:38:39 +01:00
parent 580648da32
commit 7c08444c37
5 changed files with 37 additions and 4 deletions

View File

@ -62,6 +62,7 @@ Fixed
- When downloading files with QtWebKit, a User-Agent header is set when possible.
- Fixed showing of keybindings in the :help completion
- Worked around a segfault when opening a URL after a QtWebEngine renderer process crash
- Using :undo or :tab-clone with a view-source:// or chrome:// tab is now prevented, as it segfaults
v0.9.1
------

View File

@ -427,6 +427,11 @@ class CommandDispatcher:
cmdutils.check_exclusive((bg, window), 'bw')
curtab = self._current_widget()
cur_title = self._tabbed_browser.page_title(self._current_index())
try:
history = curtab.history.serialize()
except browsertab.WebTabError as e:
raise cmdexc.CommandError(e)
# The new tab could be in a new tabbed_browser (e.g. because of
# tabs-are-windows being set)
if window:
@ -437,13 +442,15 @@ class CommandDispatcher:
new_tabbed_browser = objreg.get('tabbed-browser', scope='window',
window=newtab.win_id)
idx = new_tabbed_browser.indexOf(newtab)
new_tabbed_browser.set_page_title(idx, cur_title)
if config.get('tabs', 'show-favicons'):
new_tabbed_browser.setTabIcon(idx, curtab.icon())
if config.get('tabs', 'tabs-are-windows'):
new_tabbed_browser.window().setWindowIcon(curtab.icon())
newtab.data.keep_icon = True
newtab.history.deserialize(curtab.history.serialize())
newtab.history.deserialize(history)
newtab.zoom.set_factor(curtab.zoom.factor())
return newtab

View File

@ -384,6 +384,11 @@ class WebEngineHistory(browsertab.AbstractHistory):
return self._history.canGoForward()
def serialize(self):
# WORKAROUND for https://github.com/qutebrowser/qutebrowser/issues/2289
# FIXME:qtwebengine can we get rid of this with Qt 5.8.1?
scheme = self._history.currentItem().url().scheme()
if scheme in ['view-source', 'chrome']:
raise browsertab.WebTabError("Can't serialize special URL!")
return qtutils.serialize(self._history)
def deserialize(self, data):

View File

@ -268,9 +268,12 @@ class TabbedBrowser(tabwidget.TabWidget):
window=self._win_id):
objreg.delete('last-focused-tab', scope='window',
window=self._win_id)
if tab.url().isValid():
history_data = tab.history.serialize()
if add_undo:
if tab.url().isValid() and add_undo:
try:
history_data = tab.history.serialize()
except browsertab.WebTabError:
pass # special URL
else:
entry = UndoEntry(tab.url(), history_data, idx)
self._undo_stack.append(entry)
elif tab.url().isEmpty():

View File

@ -604,6 +604,12 @@ Feature: Tab management
- url: http://localhost:*/data/title.html
title: Test title
# https://github.com/qutebrowser/qutebrowser/issues/2289
Scenario: Cloning a tab with a special URL
When I open chrome://gpu
And I run :tab-clone
Then the error "Can't serialize special URL!" should be shown
# :tab-detach
Scenario: Detaching a tab
@ -759,6 +765,17 @@ Feature: Tab management
- data/numbers/2.txt
- data/numbers/3.txt
# https://github.com/qutebrowser/qutebrowser/issues/2289
Scenario: Undoing a tab with a special URL
Given I have a fresh instance
When I open data/numbers/1.txt
And I open chrome://gpu in a new tab
And I run :tab-close
And I run :undo
Then the error "Nothing to undo!" should be shown
And the following tabs should be open:
- data/numbers/1.txt (active)
# last-close
# FIXME:qtwebengine