Skip to content

Commit

Permalink
Porting from QWebKit to QWebEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
kaygdev authored and trollixx committed Apr 26, 2020
1 parent 4a30207 commit 9b2450e
Show file tree
Hide file tree
Showing 24 changed files with 508 additions and 257 deletions.
16 changes: 5 additions & 11 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ branches:
- stable
- /release\/.*/
image:
- Visual Studio 2015
- Visual Studio 2017
configuration: Release
platform:
- x86
Expand All @@ -19,25 +19,19 @@ environment:
init:
- ps: |-
if ($Env:PLATFORM -eq "x64") {
$Env:QT_ROOT = "C:\Qt\5.11\msvc2015_64"
$Env:QT_ROOT = "C:\Qt\5.12\msvc2017_64"
} else {
$Env:QT_ROOT = "C:\Qt\5.11\msvc2015"
$Env:QT_ROOT = "C:\Qt\5.12\msvc2017"
}
$Env:Path += ";${Env:QT_ROOT}\bin;C:\Program Files\7-Zip"
install:
- ps: |-
# Install vcpkg toolchain.
$Env:VCPKG_ROOT = "c:\projects\vcpkg-export"
$vcpkgArchive = "vcpkg-export-20181014.4-${Env:PLATFORM}.7z"
$vcpkgArchive = "vcpkg-export-20200420.6-${Env:PLATFORM}.7z"
appveyor DownloadFile "https://dl.bintray.com/zealdocs/windows-ci/$vcpkgArchive"
7z x $vcpkgArchive -o"${Env:VCPKG_ROOT}"
# Install QtWebKit.
$qtWebKitArchiveBaseName = "qtwebkit-5.212.0_72cfbd7-qt5111-msvc2015-${Env:PLATFORM}"
appveyor Downloadfile "https://dl.bintray.com/zealdocs/windows-ci/$qtWebKitArchiveBaseName.zip"
7z x "$qtWebKitArchiveBaseName.zip"
Get-ChildItem ".\$qtWebKitArchiveBaseName" | Copy -Destination ${Env:QT_ROOT} -Recurse -Force
before_build:
- ps: |-
Write-Output "Source directory: ${Env:APPVEYOR_BUILD_FOLDER}"
Expand All @@ -46,7 +40,7 @@ before_build:
Set-Location -Path dist
# Prepare .sln with CMake:
$cmakeGenerator = "Visual Studio 14 2015"
$cmakeGenerator = "Visual Studio 15 2017"
if ($Env:PLATFORM -eq "x64") {
$cmakeGenerator += " Win64"
}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ jobs:
cmake \
extra-cmake-modules \
libarchive-dev \
libqt5webkit5-dev \
libqt5x11extras5-dev \
libsqlite3-dev \
libxcb-keysyms1-dev \
qt5-default
qt5-default \
qtwebengine5-dev
- name: Configure
run: |
Expand Down Expand Up @@ -59,12 +59,12 @@ jobs:
cmake extra-cmake-modules
libappindicator-dev
libarchive-dev
libqt5webkit5-dev
libqt5x11extras5-dev
libsqlite3-dev
libxcb-keysyms1-dev
ninja-build
qtbase5-dev
qtwebengine5-dev
- name: Upload AppImage
uses: actions/upload-artifact@v2-preview
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ After installing Zeal, go to *Tools->Docsets*, select the ones you want, and cli
### Required dependencies

* [CMake](https://cmake.org/).
* [Qt](https://www.qt.io/) version 5.9.5 or above. Required module: Qt WebKit Widgets.
* [Qt](https://www.qt.io/) version 5.9.5 or above. Required module: Qt WebEngine Widgets.
* [libarchive](http://libarchive.org/).
* [SQLite](https://sqlite.org/).
* X11 platforms only: Qt X11 Extras and `xcb-util-keysyms`.
Expand Down
2 changes: 1 addition & 1 deletion pkg/appimage/appimage-amd64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ AppDir:
- libqt5x11extras5
- libqt5concurrent5
- libqt5webchannel5
- libqt5webkit5
- libqt5webengine5
- libqt5widgets5
- qtwayland5
# Other dependencies.
Expand Down
9 changes: 9 additions & 0 deletions src/app/resources/browser/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@
</div>
</div>
</section>

<script type="text/javascript" src="qrc:///qtwebchannel/qwebchannel.js"></script>
<script>
new QWebChannel(qt.webChannelTransport, function (channel) {
var JSobject = channel.objects.zAppBridge;
document.getElementById("version").textContent = JSobject.AppVersion;
window.zAppBridge = channel.objects.zAppBridge;
});
</script>
</body>

</html>
25 changes: 21 additions & 4 deletions src/app/resources/browser/assets/css/darkmode.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
/* Dark mode (see #466). */
/* TODO: Check if we need -webkit-filter for old Qt WebKit. */

body {
background-color: white !important;
transition-duration: 0s !important;
}

html {
-webkit-filter: invert() hue-rotate(180deg) contrast(70%);
filter: invert() hue-rotate(180deg) contrast(70%);
background-color: #262626 !important;
filter: invert(1) hue-rotate(180deg) contrast(70%) !important;
}

html img {
-webkit-filter: invert() hue-rotate(180deg) contrast(120%);
filter: invert() hue-rotate(180deg) contrast(120%);
filter: invert(1) hue-rotate(180deg) contrast(120%) !important;
}

::-webkit-scrollbar {
width: 15px;
height: 15px;
}
::-webkit-scrollbar-track-piece {
background-color: black;
}
::-webkit-scrollbar-thumb:vertical {
height: 30px;
background-color: #0A4C95;
}
7 changes: 6 additions & 1 deletion src/app/resources/browser/welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,13 @@
</div>
</section>

<script type="text/javascript" src="qrc:///qtwebchannel/qwebchannel.js"></script>
<script>
document.getElementById("version").textContent = zAppBridge.AppVersion;
new QWebChannel(qt.webChannelTransport, function (channel) {
var JSobject = channel.objects.zAppBridge;
document.getElementById("version").textContent = JSobject.AppVersion;
window.zAppBridge = channel.objects.zAppBridge;
});
</script>
</body>

Expand Down
6 changes: 4 additions & 2 deletions src/libs/browser/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
add_library(Browser STATIC
searchtoolbar.cpp
urlrequestinterceptor.cpp
webbridge.cpp
webcontrol.cpp
webpage.cpp
webview.cpp
)

target_link_libraries(Browser)

find_package(Qt5 COMPONENTS WebKitWidgets REQUIRED)
target_link_libraries(Browser Qt5::WebKitWidgets)
find_package(Qt5 COMPONENTS WebEngineWidgets WebChannel REQUIRED)
target_link_libraries(Browser Qt5::WebEngineWidgets Qt5::WebChannel)
22 changes: 11 additions & 11 deletions src/libs/browser/searchtoolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
#include <QLineEdit>
#include <QStyle>
#include <QToolButton>
#include <QWebPage>
#include <QWebView>
#include <QWebEnginePage>
#include <QWebEngineView>

using namespace Zeal::Browser;

SearchToolBar::SearchToolBar(QWebView *webView, QWidget *parent)
SearchToolBar::SearchToolBar(QWebEngineView *webView, QWidget *parent)
: QWidget(parent)
, m_webView(webView)
{
Expand Down Expand Up @@ -172,8 +172,8 @@ void SearchToolBar::findNext()
return;
}

QWebPage::FindFlags ff = QWebPage::FindWrapsAroundDocument;
ff.setFlag(QWebPage::FindCaseSensitively, m_matchCaseButton->isChecked());
QWebEnginePage::FindFlags ff;
ff.setFlag(QWebEnginePage::FindCaseSensitively, m_matchCaseButton->isChecked());
m_webView->findText(m_lineEdit->text(), ff);
}

Expand All @@ -183,24 +183,24 @@ void SearchToolBar::findPrevious()
return;
}

QWebPage::FindFlags ff = QWebPage::FindWrapsAroundDocument;
ff.setFlag(QWebPage::FindCaseSensitively, m_matchCaseButton->isChecked());
ff.setFlag(QWebPage::FindBackward);
QWebEnginePage::FindFlags ff;
ff.setFlag(QWebEnginePage::FindCaseSensitively, m_matchCaseButton->isChecked());
ff.setFlag(QWebEnginePage::FindBackward);
m_webView->findText(m_lineEdit->text(), ff);
}

void SearchToolBar::hideHighlight()
{
m_webView->findText(QString(), QWebPage::HighlightAllOccurrences);
m_webView->findText(QString());
}

void SearchToolBar::updateHighlight()
{
hideHighlight();

if (m_highlightAllButton->isChecked()) {
QWebPage::FindFlags ff = QWebPage::HighlightAllOccurrences;
ff.setFlag(QWebPage::FindCaseSensitively, m_matchCaseButton->isChecked());
QWebEnginePage::FindFlags ff;
ff.setFlag(QWebEnginePage::FindCaseSensitively, m_matchCaseButton->isChecked());
m_webView->findText(m_lineEdit->text(), ff);
}
}
6 changes: 3 additions & 3 deletions src/libs/browser/searchtoolbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

class QLineEdit;
class QToolButton;
class QWebView;
class QWebEngineView;

namespace Zeal {
namespace Browser {
Expand All @@ -37,7 +37,7 @@ class SearchToolBar final : public QWidget
Q_OBJECT
Q_DISABLE_COPY(SearchToolBar)
public:
explicit SearchToolBar(QWebView *webView, QWidget *parent = nullptr);
explicit SearchToolBar(QWebEngineView *webView, QWidget *parent = nullptr);

void setText(const QString &text);
void activate();
Expand All @@ -63,7 +63,7 @@ class SearchToolBar final : public QWidget
QToolButton *m_highlightAllButton = nullptr;
QToolButton *m_matchCaseButton = nullptr;

QWebView *m_webView = nullptr;
QWebEngineView *m_webView = nullptr;
};

} // namespace Browser
Expand Down
79 changes: 79 additions & 0 deletions src/libs/browser/urlrequestinterceptor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/****************************************************************************
**
** Copyright (C) 2020 Oleg Shparber
** Copyright (C) 2019 Kay Gawlik
** Contact: https://go.zealdocs.org/l/contact
**
** This file is part of Zeal.
**
** Zeal is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Zeal is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Zeal. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/

#include "urlrequestinterceptor.h"

#include <core/application.h>
#include <core/networkaccessmanager.h>
#include <core/settings.h>

using namespace Zeal::Browser;

UrlRequestInterceptor::UrlRequestInterceptor(QObject *parent)
: QWebEngineUrlRequestInterceptor(parent)
{
}

void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
{
QUrl requestUrl = info.requestUrl();
QUrl firstPartyUrl = info.firstPartyUrl();

if (!firstPartyUrl.isValid()) {
return;
}

bool firstPartyUrlLocal = Core::NetworkAccessManager::isLocalUrl(firstPartyUrl);
bool requestUrlLocal = Core::NetworkAccessManager::isLocalUrl(requestUrl);

if (firstPartyUrlLocal && requestUrlLocal) {
return;
}

if (firstPartyUrlLocal != requestUrlLocal) {
blockRequest(info);
return;
}

Core::Settings::ExternalLinkPolicy linkPolicy = Core::Application::instance()->settings()->externalLinkPolicy;
switch (info.resourceType()) {
case QWebEngineUrlRequestInfo::ResourceTypeMainFrame:
if (linkPolicy != Core::Settings::ExternalLinkPolicy::Open
&& linkPolicy != Core::Settings::ExternalLinkPolicy::Ask) {
blockRequest(info);
}
break;
case QWebEngineUrlRequestInfo::ResourceTypeSubFrame:
if (linkPolicy != Core::Settings::ExternalLinkPolicy::Open) {
blockRequest(info);
}
break;
default:
break;
}
}

void UrlRequestInterceptor::blockRequest(QWebEngineUrlRequestInfo &info)
{
info.block(true);
}
47 changes: 47 additions & 0 deletions src/libs/browser/urlrequestinterceptor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/****************************************************************************
**
** Copyright (C) 2020 Oleg Shparber
** Copyright (C) 2019 Kay Gawlik
** Contact: https://go.zealdocs.org/l/contact
**
** This file is part of Zeal.
**
** Zeal is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Zeal is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Zeal. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/

#ifndef ZEAL_BROWSER_URLREQUESTINTERCEPTOR_H
#define ZEAL_BROWSER_URLREQUESTINTERCEPTOR_H

#include <QWebEngineUrlRequestInterceptor>

namespace Zeal {
namespace Browser {

class UrlRequestInterceptor final : public QWebEngineUrlRequestInterceptor
{
Q_OBJECT
Q_DISABLE_COPY(UrlRequestInterceptor)
public:
UrlRequestInterceptor(QObject *parent = nullptr);
void interceptRequest(QWebEngineUrlRequestInfo &info) override;

private:
void blockRequest(QWebEngineUrlRequestInfo &info);
};

} // namespace Browser
} // namespace Zeal

#endif // ZEAL_BROWSER_URLREQUESTINTERCEPTOR_H
Loading

0 comments on commit 9b2450e

Please sign in to comment.