Don't save the original URL for redirected pages

See #1345
This commit is contained in:
Florian Bruhin 2016-06-08 17:15:08 +02:00
parent 263b5680c7
commit e08c6cb059
3 changed files with 16 additions and 11 deletions

View File

@ -39,17 +39,20 @@ class HistoryEntry:
atime: The time the page was accessed. atime: The time the page was accessed.
url: The URL which was accessed as QUrl. url: The URL which was accessed as QUrl.
url_string: The URL which was accessed as string. url_string: The URL which was accessed as string.
hidden: If True, don't save this entry to disk
""" """
def __init__(self, atime, url, title): def __init__(self, atime, url, title, hidden=False):
self.atime = float(atime) self.atime = float(atime)
self.url = QUrl(url) self.url = QUrl(url)
self.url_string = url self.url_string = url
self.title = title self.title = title
self.hidden = hidden
def __repr__(self): def __repr__(self):
return utils.get_repr(self, constructor=True, atime=self.atime, return utils.get_repr(self, constructor=True, atime=self.atime,
url=self.url.toDisplayString(), title=self.title) url=self.url.toDisplayString(), title=self.title,
hidden=self.hidden)
def __str__(self): def __str__(self):
return '{} {} {}'.format(int(self.atime), self.url_string, self.title) return '{} {} {}'.format(int(self.atime), self.url_string, self.title)
@ -154,8 +157,9 @@ class WebHistory(QWebHistoryInterface):
self.async_read_done.emit() self.async_read_done.emit()
for url, entry in self._temp_history.items(): for url, entry in self._temp_history.items():
self._new_history.append(entry)
self._add_entry(entry) self._add_entry(entry)
if not entry.hidden:
self._new_history.append(entry)
self.add_completion_item.emit(entry) self.add_completion_item.emit(entry)
def _add_entry(self, entry, target=None): def _add_entry(self, entry, target=None):
@ -196,21 +200,23 @@ class WebHistory(QWebHistoryInterface):
"""Required for a QWebHistoryInterface impl, obsoleted by add_url.""" """Required for a QWebHistoryInterface impl, obsoleted by add_url."""
pass pass
def add_url(self, url_string, title=""): def add_url(self, url_string, title="", hidden=False):
"""Called by WebKit when an URL should be added to the history. """Called by WebKit when an URL should be added to the history.
Args: Args:
url_string: An url as string to add to the history. url_string: An url as string to add to the history.
hidden: Whether to hide the entry from the on-disk history
""" """
if not url_string: if not url_string:
return return
if config.get('general', 'private-browsing'): if config.get('general', 'private-browsing'):
return return
entry = HistoryEntry(time.time(), url_string, title) entry = HistoryEntry(time.time(), url_string, title, hidden=hidden)
if self._initial_read_done: if self._initial_read_done:
self._add_entry(entry)
if not entry.hidden:
self.add_completion_item.emit(entry) self.add_completion_item.emit(entry)
self._new_history.append(entry) self._new_history.append(entry)
self._add_entry(entry)
self.item_added.emit(entry) self.item_added.emit(entry)
else: else:
self._add_entry(entry, target=self._temp_history) self._add_entry(entry, target=self._temp_history)

View File

@ -156,7 +156,7 @@ class WebView(QWebView):
# originally clicked, save them both. # originally clicked, save them both.
url = self._orig_url.toString(QUrl.FullyEncoded | url = self._orig_url.toString(QUrl.FullyEncoded |
QUrl.RemovePassword) QUrl.RemovePassword)
history.add_url(url, self.title()) history.add_url(url, self.title(), hidden=True)
url = self.cur_url.toString(QUrl.FullyEncoded | QUrl.RemovePassword) url = self.cur_url.toString(QUrl.FullyEncoded | QUrl.RemovePassword)
history.add_url(url, self.title()) history.add_url(url, self.title())

View File

@ -21,7 +21,6 @@ Feature: Page history
When I open redirect-to?url=data/title.html without waiting When I open redirect-to?url=data/title.html without waiting
And I wait until data/title.html is loaded And I wait until data/title.html is loaded
Then the history file should contain: Then the history file should contain:
http://localhost:(port)/redirect-to?url=data/title.html Test title
http://localhost:(port)/data/title.html Test title http://localhost:(port)/data/title.html Test title
Scenario: History item with spaces in URL Scenario: History item with spaces in URL