Skip to content

Commit

Permalink
Drop legacy QtWebKit support
Browse files Browse the repository at this point in the history
See #2742
  • Loading branch information
The-Compiler committed Sep 18, 2017
1 parent 3e70bf5 commit 3772dc5
Show file tree
Hide file tree
Showing 20 changed files with 44 additions and 375 deletions.
10 changes: 6 additions & 4 deletions doc/install.asciidoc
Expand Up @@ -170,11 +170,11 @@ Make sure you have `python3_4` in your `PYTHON_TARGETS`
(`/etc/portage/make.conf`) and rebuild your system (`emerge -uDNav @world`) if
necessary.

It's also recommended to install QtWebKit-NG via
https://gist.github.com/annulen/309569fb61e5d64a703c055c1e726f71[this ebuild],
or install Qt >= 5.7.1 with QtWebEngine in order to use an up-to-date backend.
You'll also need to install `dev-qt/qtwebengine` or a newer QtWebKit using
https://gist.github.com/annulen/309569fb61e5d64a703c055c1e726f71[this ebuild].

If video or sound don't seem to work, try installing the gstreamer plugins:
If video or sound don't work with QtWebKit, try installing the gstreamer
plugins:

----
# emerge -av gst-plugins-{base,good,bad,ugly,libav}
Expand Down Expand Up @@ -219,6 +219,8 @@ On openSUSE
There are prebuilt RPMs available at https://software.opensuse.org/download.html?project=network&package=qutebrowser[OBS].
To use the QtWebEngine backend, install `libqt5-qtwebengine`.
On OpenBSD
----------

Expand Down
2 changes: 0 additions & 2 deletions pytest.ini
Expand Up @@ -19,8 +19,6 @@ markers =
qtwebengine_todo: Features still missing with QtWebEngine
qtwebengine_skip: Tests not applicable with QtWebEngine
qtwebkit_skip: Tests not applicable with QtWebKit
qtwebkit_ng_xfail: Tests failing with QtWebKit-NG
qtwebkit_ng_skip: Tests skipped with QtWebKit-NG
qtwebengine_flaky: Tests which are flaky (and currently skipped) with QtWebEngine
qtwebengine_mac_xfail: Tests which fail on macOS with QtWebEngine
js_prompt: Tests needing to display a javascript prompt
Expand Down
11 changes: 0 additions & 11 deletions qutebrowser/app.py
Expand Up @@ -332,17 +332,6 @@ def _open_special_pages(args):
tabbed_browser = objreg.get('tabbed-browser', scope='window',
window='last-focused')

# Legacy QtWebKit warning

needs_warning = (objects.backend == usertypes.Backend.QtWebKit and
not qtutils.is_qtwebkit_ng())
warning_shown = general_sect.get('backend-warning-shown') == '1'

if not warning_shown and needs_warning:
tabbed_browser.tabopen(QUrl('qute://backend-warning'),
background=False)
general_sect['backend-warning-shown'] = '1'

# Quickstart page

quickstart_done = general_sect.get('quickstart-done') == '1'
Expand Down
51 changes: 7 additions & 44 deletions qutebrowser/browser/qutescheme.py
Expand Up @@ -224,50 +224,13 @@ def qute_history(url):

return 'text/html', json.dumps(history_data(start_time, offset))
else:
if (
config.val.content.javascript.enabled and
(objects.backend == usertypes.Backend.QtWebEngine or
qtutils.is_qtwebkit_ng())
):
return 'text/html', jinja.render(
'history.html',
title='History',
gap_interval=config.val.history_gap_interval
)
else:
# Get current date from query parameter, if not given choose today.
curr_date = datetime.date.today()
try:
query_date = QUrlQuery(url).queryItemValue("date")
if query_date:
curr_date = datetime.datetime.strptime(query_date,
"%Y-%m-%d").date()
except ValueError:
log.misc.debug("Invalid date passed to qute:history: " +
query_date)

one_day = datetime.timedelta(days=1)
next_date = curr_date + one_day
prev_date = curr_date - one_day

# start_time is the last second of curr_date
start_time = time.mktime(next_date.timetuple()) - 1
history = [
(i["url"], i["title"],
datetime.datetime.fromtimestamp(i["time"]),
QUrl(i["url"]).host())
for i in history_data(start_time)
]

return 'text/html', jinja.render(
'history_nojs.html',
title='History',
history=history,
curr_date=curr_date,
next_date=next_date,
prev_date=prev_date,
today=datetime.date.today(),
)
if not config.val.content.javascript.enabled:
return 'text/plain', b'JavaScript is required for qute://history'
return 'text/html', jinja.render(
'history.html',
title='History',
gap_interval=config.val.history_gap_interval
)


@add_handler('javascript')
Expand Down
93 changes: 4 additions & 89 deletions qutebrowser/browser/webkit/tabhistory.py
Expand Up @@ -25,13 +25,7 @@
from qutebrowser.utils import qtutils


def _encode_url(url):
"""Encode a QUrl suitable to pass to QWebHistory."""
data = bytes(QUrl.toPercentEncoding(url.toString(), b':/#?&+=@%*'))
return data.decode('ascii')


def _serialize_ng(items, current_idx, stream):
def _serialize_items(items, current_idx, stream):
# {'currentItemIndex': 0,
# 'history': [{'children': [],
# 'documentSequenceNumber': 1485030525573123,
Expand All @@ -47,13 +41,13 @@ def _serialize_ng(items, current_idx, stream):
# 'urlString': 'about:blank'}]}
data = {'currentItemIndex': current_idx, 'history': []}
for item in items:
data['history'].append(_serialize_item_ng(item))
data['history'].append(_serialize_item(item))

stream.writeInt(3) # history stream version
stream.writeQVariantMap(data)


def _serialize_item_ng(item):
def _serialize_item(item):
data = {
'originalURLString': item.original_url.toString(QUrl.FullyEncoded),
'scrollPosition': {'x': 0, 'y': 0},
Expand All @@ -68,82 +62,6 @@ def _serialize_item_ng(item):
return data


def _serialize_old(items, current_idx, stream):
### Source/WebKit/qt/Api/qwebhistory.cpp operator<<
stream.writeInt(2) # history stream version
stream.writeInt(len(items))
stream.writeInt(current_idx)

for i, item in enumerate(items):
_serialize_item_old(i, item, stream)


def _serialize_item_old(i, item, stream):
"""Serialize a single WebHistoryItem into a QDataStream.
Args:
i: The index of the current item.
item: The WebHistoryItem to write.
stream: The QDataStream to write to.
"""
### Source/WebCore/history/qt/HistoryItemQt.cpp restoreState
## urlString
stream.writeQString(_encode_url(item.url))
## title
stream.writeQString(item.title)
## originalURLString
stream.writeQString(_encode_url(item.original_url))

### Source/WebCore/history/HistoryItem.cpp decodeBackForwardTree
## backForwardTreeEncodingVersion
stream.writeUInt32(2)
## size (recursion stack)
stream.writeUInt64(0)
## node->m_documentSequenceNumber
# If two HistoryItems have the same document sequence number, then they
# refer to the same instance of a document. Traversing history from one
# such HistoryItem to another preserves the document.
stream.writeInt64(i + 1)
## size (node->m_documentState)
stream.writeUInt64(0)
## node->m_formContentType
# info used to repost form data
stream.writeQString(None)
## hasFormData
stream.writeBool(False)
## node->m_itemSequenceNumber
# If two HistoryItems have the same item sequence number, then they are
# clones of one another. Traversing history from one such HistoryItem to
# another is a no-op. HistoryItem clones are created for parent and
# sibling frames when only a subframe navigates.
stream.writeInt64(i + 1)
## node->m_referrer
stream.writeQString(None)
## node->m_scrollPoint (x)
try:
stream.writeInt32(item.user_data['scroll-pos'].x())
except (KeyError, TypeError):
stream.writeInt32(0)
## node->m_scrollPoint (y)
try:
stream.writeInt32(item.user_data['scroll-pos'].y())
except (KeyError, TypeError):
stream.writeInt32(0)
## node->m_pageScaleFactor
stream.writeFloat(1)
## hasStateObject
# Support for HTML5 History
stream.writeBool(False)
## node->m_target
stream.writeQString(None)

### Source/WebCore/history/qt/HistoryItemQt.cpp restoreState
## validUserData
# We could restore the user data here, but we prefer to use the
# QWebHistoryItem API for that.
stream.writeBool(False)


def serialize(items):
"""Serialize a list of QWebHistoryItems to a data stream.
Expand Down Expand Up @@ -180,10 +98,7 @@ def serialize(items):
else:
current_idx = 0

if qtutils.is_qtwebkit_ng():
_serialize_ng(items, current_idx, stream)
else:
_serialize_old(items, current_idx, stream)
_serialize_items(items, current_idx, stream)

user_data += [item.user_data for item in items]

Expand Down
6 changes: 3 additions & 3 deletions qutebrowser/config/config.py
Expand Up @@ -28,7 +28,7 @@
from PyQt5.QtWidgets import QMessageBox

from qutebrowser.config import configdata, configexc, configtypes, configfiles
from qutebrowser.utils import utils, objreg, message, log, usertypes, jinja
from qutebrowser.utils import utils, objreg, message, log, usertypes, jinja, qtutils
from qutebrowser.misc import objects, msgbox, earlyinit
from qutebrowser.commands import cmdexc, cmdutils, runners
from qutebrowser.completion.models import configmodel
Expand Down Expand Up @@ -692,12 +692,12 @@ def early_init(args):

def get_backend(args):
"""Find out what backend to use based on available libraries."""
from qutebrowser.utils import usertypes
try:
import PyQt5.QtWebKit # pylint: disable=unused-variable
webkit_available = True
except ImportError:
webkit_available = False
else:
webkit_available = qtutils.is_new_webkit()

if args.backend is not None:
backends = {
Expand Down
6 changes: 4 additions & 2 deletions qutebrowser/config/configfiles.py
Expand Up @@ -51,8 +51,10 @@ def __init__(self):
self.add_section(sect)
except configparser.DuplicateSectionError:
pass
# See commit a98060e020a4ba83b663813a4b9404edb47f28ad.
self['general'].pop('fooled', None)

deleted_keys = ['fooled', 'backend-warning-shown']
for key in deleted_keys:
self['general'].pop(key, None)

def init_save_manager(self, save_manager):
"""Make sure the config gets saved properly.
Expand Down
100 changes: 0 additions & 100 deletions qutebrowser/html/backend-warning.html

This file was deleted.

0 comments on commit 3772dc5

Please sign in to comment.