Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 50 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.7.0)
cmake_minimum_required(VERSION 3.16)

project(otter-browser)

Expand Down Expand Up @@ -69,15 +69,25 @@ include(FeatureSummary)
include(GNUInstallDirs)

option(ALLOW_WITHOUT_WEB_BACKENDS "Allow to build without any web backends (build testing only)" OFF)
option(ENABLE_QTWEBENGINE "Enable QtWebEngine backend (requires QtWebEngine 5.15)" ON)
option(ENABLE_QTWEBKIT "Enable QtWebKit backend (requires QtWebKit 5.212)" ON)
option(ENABLE_CRASH_REPORTS "Enable built-in crash reporting (official builds only)" OFF)
option(ENABLE_DBUS "Enable D-Bus based integration for notifications (only freedesktop.org compatible platforms)" ON)
option(ENABLE_SPELLCHECK "Enable Hunspell based spell checking" ON)

find_package(Qt5 5.15.0 REQUIRED COMPONENTS Core Gui Multimedia Network PrintSupport Qml Svg Widgets)
find_package(Hunspell 1.5.0 QUIET)
option(ENABLE_SPELLCHECK "Enable Hunspell based spell checking" OFF)
option(ENABLE_QT6 "Build using Qt 6" ON)
option(ENABLE_QTWEBENGINE "Enable QtWebEngine backend (requires Qt WebEngine version ${QT_MINIMUM_VERSION} or higher)" ON)
option(ENABLE_QTWEBKIT "Enable QtWebKit backend (requires QtWebKit ${QT_MINIMUM_VERSION_WEBKIT})" OFF)

if (NOT ENABLE_QT6)
set(QT_MAJOR_VERSION Qt5)
set(QT_MINIMUM_VERSION 5.15)
set(QT_MINIMUM_VERSION_WEBKIT 5.212)
else ()
set(QT_MAJOR_VERSION Qt6)
set(QT_MINIMUM_VERSION 6.2)
find_package(${QT_MAJOR_VERSION} REQUIRED COMPONENTS Core5Compat)
endif ()

find_package(${QT_MAJOR_VERSION} REQUIRED COMPONENTS Core Gui Multimedia Network PrintSupport Qml Svg Widgets)
find_package(Hunspell 1.5.0 REQUIRED)
set_package_properties(Hunspell PROPERTIES URL "https://hunspell.github.io/" DESCRIPTION "Generic spell checking support" TYPE OPTIONAL)

set(OTTER_SOURCES
Expand Down Expand Up @@ -290,11 +300,7 @@ set(OTTER_SOURCES
3rdparty/qrcodegen/qrcodegen.cpp
)

qt5_add_resources(OTTER_RESOURCES
resources/resources.qrc
)

qt5_wrap_ui(OTTER_UI
qt_wrap_ui(OTTER_UI
src/ui/AcceptCookieDialog.ui
src/ui/ActionParametersDialog.ui
src/ui/AuthenticationDialog.ui
Expand Down Expand Up @@ -368,11 +374,14 @@ qt5_wrap_ui(OTTER_UI
src/modules/windows/windows/WindowsContentsWidget.ui
)

foreach (_dir ${Qt5Widgets_PRIVATE_INCLUDE_DIRS})
qt_add_resources(OTTER_RESOURCES
resources/resources.qrc
)

foreach (_dir ${QT_MAJOR_VERSION}Widgets_PRIVATE_INCLUDE_DIRS})
if (EXISTS "${_dir}/private/qpixmapfilter_p.h")
add_definitions(-DOTTER_ENABLE_STARTPAGEBLUR)
include_directories(${Qt5Widgets_PRIVATE_INCLUDE_DIRS})

include_directories(${QT_MAJOR_VERSION}Widgets_PRIVATE_INCLUDE_DIRS})
break ()
endif ()
endforeach ()
Expand Down Expand Up @@ -448,8 +457,6 @@ endif ()
if (WIN32)
add_definitions(-DUNICODE -D_UNICODE)

find_package(Qt5 5.15.0 QUIET COMPONENTS WinExtras)

if (MSVC)
set(CMAKE_PREFIX_PATH $ENV{QTDIR})
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MP")
Expand All @@ -470,8 +477,6 @@ if (WIN32)
src/modules/platforms/windows/WindowsPlatformStyle.cpp
)
elseif (APPLE)
find_package(Qt5 5.15.0 QUIET COMPONENTS MacExtras)

set(CMAKE_OSX_DEPLOYMENT_TARGET 10.13)
set(MACOSX_BUNDLE_BUNDLE_NAME "Otter Browser")
set(MACOSX_BUNDLE_BUNDLE_VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION})
Expand All @@ -489,9 +494,7 @@ elseif (APPLE)

set_source_files_properties(resources/icons/otter-browser.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
elseif (UNIX)
find_package(Qt5 5.15.0 QUIET COMPONENTS DBus)

if (TARGET Qt5::DBus AND ENABLE_DBUS)
if (TARGET ${QT_MAJOR_VERSION}::DBus AND ENABLE_DBUS)
add_definitions(-DOTTER_ENABLE_DBUS)
endif ()

Expand Down Expand Up @@ -570,25 +573,45 @@ if (TARGET Hunspell::Hunspell AND ENABLE_SPELLCHECK)
endif ()

if (WIN32)
target_link_libraries(otter-browser Qt5::WinExtras ole32 shell32 advapi32 user32)
if (NOT ENABLE_QT6)
target_link_libraries(${QT_MAJOR_VERSION}::WinExtras)
endif ()
target_link_libraries(otter-browser ole32 shell32 advapi32 user32)
elseif (APPLE)
find_library(FRAMEWORK_Cocoa Cocoa)
find_library(FRAMEWORK_Foundation Foundation)

set_target_properties(otter-browser PROPERTIES OUTPUT_NAME "Otter Browser")

target_link_libraries(otter-browser Qt5::MacExtras ${FRAMEWORK_Cocoa} ${FRAMEWORK_Foundation})
if (NOT ENABLE_QT6)
target_link_libraries(otter-browser ${QT_MAJOR_VERSION}::MacExtras ${FRAMEWORK_Cocoa} ${FRAMEWORK_Foundation})
endif ()
target_link_libraries(otter-browser ${FRAMEWORK_Cocoa} ${FRAMEWORK_Foundation})
elseif (UNIX)
if (TARGET Qt5::DBus AND ENABLE_DBUS)
target_link_libraries(otter-browser Qt5::DBus)
if (TARGET ${QT_MAJOR_VERSION}::DBus AND ENABLE_DBUS)
target_link_libraries(otter-browser ${QT_MAJOR_VERSION}::DBus)
endif ()

if (ENABLE_CRASH_REPORTS)
target_link_libraries(otter-browser -lpthread)
endif ()
endif ()

target_link_libraries(otter-browser Qt5::Core Qt5::Gui Qt5::Multimedia Qt5::Network Qt5::PrintSupport Qt5::Qml Qt5::Svg Qt5::Widgets)
target_link_libraries(
otter-browser
${QT_MAJOR_VERSION}::Core
${QT_MAJOR_VERSION}::Gui
${QT_MAJOR_VERSION}::Multimedia
${QT_MAJOR_VERSION}::Network
${QT_MAJOR_VERSION}::PrintSupport
${QT_MAJOR_VERSION}::Qml
${QT_MAJOR_VERSION}::Svg
${QT_MAJOR_VERSION}::Widgets
)

if (ENABLE_QT6)
target_link_libraries(otter-browser ${QT_MAJOR_VERSION}::Core5Compat)
endif ()

set(XDG_APPS_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/applications CACHE FILEPATH "Install path for .desktop files")

Expand Down
3 changes: 3 additions & 0 deletions src/core/TransfersManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,9 @@ Transfer* TransfersManager::startTransfer(const QUrl &source, const QString &tar
{
QNetworkRequest request;
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork);
#if QT_VERSION < 0x060000
request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
#endif
request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
request.setHeader(QNetworkRequest::UserAgentHeader, NetworkManagerFactory::getUserAgent());
request.setUrl(QUrl(source));
Expand Down
2 changes: 2 additions & 0 deletions src/core/UserScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,12 @@ bool UserScript::checkUrl(const QUrl &url, const QStringList &rules) const
return QRegularExpression(rule.mid(1, rule.length() - 2)).match(url.url()).hasMatch();
}

#if QT_VERSION < 0x060000 // qt6: ‘const class QUrl’ has no member named ‘topLevelDomain’
if (rule.contains(QLatin1String(".tld"), Qt::CaseInsensitive))
{
rule.replace(QLatin1String(".tld"), Utils::getTopLevelDomain(url), Qt::CaseInsensitive);
}
#endif

bool useExactMatch(true);

Expand Down
5 changes: 5 additions & 0 deletions src/core/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,12 @@ QString normalizePath(const QString &path)
return path;
}

#if QT_VERSION < 0x060000 // qt6: ‘const class QUrl’ has no member named ‘topLevelDomain’
QString getTopLevelDomain(const QUrl &url)
{
return url.topLevelDomain();
}
#endif

QString getStandardLocation(QStandardPaths::StandardLocation type)
{
Expand Down Expand Up @@ -802,6 +804,7 @@ bool ensureDirectoryExists(const QString &path)

bool isDomainTheSame(const QUrl &firstUrl, const QUrl &secondUrl)
{
#if QT_VERSION < 0x060000 // qt6: 'topLevelDomain()' is no more; port to 'qIsEffectiveTLD()'?
const QString firstTld(getTopLevelDomain(firstUrl));
const QString secondTld(getTopLevelDomain(secondUrl));

Expand All @@ -817,6 +820,8 @@ bool isDomainTheSame(const QUrl &firstUrl, const QUrl &secondUrl)
secondDomain.remove((secondDomain.length() - secondTld.length()), secondTld.length());

return firstDomain.section(QLatin1Char('.'), -1) == secondDomain.section(QLatin1Char('.'), -1);
#endif
return false;
}

bool isUrl(const QString &text)
Expand Down
28 changes: 22 additions & 6 deletions src/modules/backends/web/qtwebengine/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
find_package(Qt5 5.15.0 QUIET COMPONENTS WebEngineWidgets)
if (NOT ENABLE_QTWEBENGINE)
return ()
endif ()

find_package(${QT_MAJOR_VERSION} ${QT_MINIMUM_VERSION} REQUIRED COMPONENTS WebEngineCore WebEngineWidgets)

set_package_properties(Qt5WebEngineCore PROPERTIES URL "https://www.qt.io/" DESCRIPTION "QtWebEngine based backend (core)" TYPE OPTIONAL)
set_package_properties(Qt5WebEngineWidgets PROPERTIES URL "https://www.qt.io/" DESCRIPTION "QtWebEngine based backend (widgets)" TYPE OPTIONAL)
set_package_properties(${QT_MAJOR_VERSION}WebEngineCore PROPERTIES URL "https://www.qt.io/" DESCRIPTION "QtWebEngine based backend (core)" TYPE OPTIONAL)
set_package_properties(${QT_MAJOR_VERSION}WebEngineWidgets PROPERTIES URL "https://www.qt.io/" DESCRIPTION "QtWebEngine based backend (widgets)" TYPE OPTIONAL)

if (NOT TARGET Qt5::WebEngineWidgets)
if (NOT TARGET ${QT_MAJOR_VERSION}::WebEngineWidgets)
return ()
endif ()

add_definitions(-DOTTER_ENABLE_QTWEBENGINE)

list(APPEND OTTER_BACKENDS_WEB "QtWebEngine")
list(APPEND OTTER_LINK_LIBRARIES Qt5::WebEngineCore Qt5::WebEngineWidgets)
list(APPEND OTTER_LINK_LIBRARIES ${QT_MAJOR_VERSION}::WebEngineCore ${QT_MAJOR_VERSION}::WebEngineWidgets)

set(OTTER_SOURCES
${OTTER_SOURCES}
Expand All @@ -21,6 +25,18 @@ set(OTTER_SOURCES
src/modules/backends/web/qtwebengine/QtWebEngineWebWidget.cpp
)

qt5_add_resources(OTTER_RESOURCES
qt_add_resources(OTTER_RESOURCES
src/modules/backends/web/qtwebengine/QtWebEngineResources.qrc
)

if (WIN32)
if (NOT ENABLE_QT6)
find_package(Qt5 QUIET COMPONENTS WinExtras)
endif ()
elseif (APPLE)
if (NOT ENABLE_QT6)
find_package(Qt5 QUIET COMPONENTS MacExtras)
endif ()
elseif (UNIX AND ENABLE_DBUS)
find_package(${QT_MAJOR_VERSION} ${QT_MINIMUM_VERSION} REQUIRED COMPONENTS DBus)
endif ()
12 changes: 6 additions & 6 deletions src/modules/backends/web/qtwebengine/QtWebEnginePage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@

#include <QtCore/QFile>
#include <QtCore/QRegularExpression>
#include <QtWebEngineWidgets/QWebEngineHistory>
#include <QtWebEngineWidgets/QWebEngineProfile>
#include <QtWebEngineWidgets/QWebEngineScript>
#include <QtWebEngineWidgets/QWebEngineScriptCollection>
#include <QtWebEngineWidgets/QWebEngineSettings>
#include <QtWebEngineCore/QWebEngineHistory>
#include <QtWebEngineCore/QWebEngineProfile>
#include <QtWebEngineCore/QWebEngineScript>
#include <QtWebEngineCore/QWebEngineScriptCollection>
#include <QtWebEngineCore/QWebEngineSettings>
#include <QtWidgets/QMessageBox>

namespace Otter
Expand Down Expand Up @@ -603,7 +603,7 @@ bool QtWebEnginePage::acceptNavigationRequest(const QUrl &url, NavigationType ty
return true;
}

bool QtWebEnginePage::certificateError(const QWebEngineCertificateError &error)
bool QtWebEnginePage::handleCertificateError(QWebEngineCertificateError error)
{
if (!m_widget || error.certificateChain().isEmpty())
{
Expand Down
8 changes: 5 additions & 3 deletions src/modules/backends/web/qtwebengine/QtWebEnginePage.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include "../../../../core/SessionsManager.h"
#include "../../../../ui/WebWidget.h"

#include <QtWebEngineWidgets/QWebEngineCertificateError>
#include <QtWebEngineWidgets/QWebEnginePage>
#include <QtWebEngineCore/QWebEngineCertificateError>
#include <QtWebEngineCore/QWebEnginePage>

namespace Otter
{
Expand Down Expand Up @@ -69,7 +69,6 @@ class QtWebEnginePage final : public QWebEnginePage
QString createJavaScriptList(const QStringList &rules) const;
QStringList chooseFiles(FileSelectionMode mode, const QStringList &oldFiles, const QStringList &acceptedMimeTypes) override;
bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame) override;
bool certificateError(const QWebEngineCertificateError &error) override;
bool javaScriptConfirm(const QUrl &url, const QString &message) override;
bool javaScriptPrompt(const QUrl &url, const QString &message, const QString &defaultValue, QString *result) override;

Expand All @@ -87,6 +86,9 @@ protected slots:
bool m_isViewingMedia;
bool m_isPopup;

private slots:
bool handleCertificateError(QWebEngineCertificateError error);

signals:
void requestedNewWindow(WebWidget *widget, SessionsManager::OpenHints hints, const QVariantMap &parameters);
void requestedPopupWindow(const QUrl &parentUrl, const QUrl &popupUrl);
Expand Down
26 changes: 14 additions & 12 deletions src/modules/backends/web/qtwebengine/QtWebEngineTransfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,25 @@
namespace Otter
{

QtWebEngineTransfer::QtWebEngineTransfer(QWebEngineDownloadItem *item, TransferOptions options, QObject *parent) : Transfer(options, parent),
QtWebEngineTransfer::QtWebEngineTransfer(QWebEngineDownloadRequest *item, TransferOptions options, QObject *parent) : Transfer(options, parent),
m_item(item)
{
m_item->accept();
m_item->setParent(this);

markAsStarted();

connect(m_item, &QWebEngineDownloadItem::finished, this, &QtWebEngineTransfer::markAsFinished);
connect(m_item, &QWebEngineDownloadItem::downloadProgress, this, &QtWebEngineTransfer::handleDownloadProgress);
connect(m_item, &QWebEngineDownloadItem::stateChanged, this, [&](QWebEngineDownloadItem::DownloadState state)
connect(m_item, &QWebEngineDownloadRequest::isFinished, this, &QtWebEngineTransfer::markAsFinished);
/* qt6: cannot take the address of an rvalue of type 'QWebEngineDownloadRequest::DownloadState'
connect(m_item, &QWebEngineDownloadRequest::DownloadInProgress, this, &QtWebEngineTransfer::handleDownloadProgress);
*/
connect(m_item, &QWebEngineDownloadRequest::stateChanged, this, [&](QWebEngineDownloadRequest::DownloadState state)
{
switch (state)
{
case QWebEngineDownloadItem::DownloadCancelled:
case QWebEngineDownloadItem::DownloadCompleted:
case QWebEngineDownloadItem::DownloadInterrupted:
case QWebEngineDownloadRequest::DownloadCancelled:
case QWebEngineDownloadRequest::DownloadCompleted:
case QWebEngineDownloadRequest::DownloadInterrupted:
emit stopped();

break;
Expand Down Expand Up @@ -136,14 +138,14 @@ Transfer::TransferState QtWebEngineTransfer::getState() const

switch (m_item->state())
{
case QWebEngineDownloadItem::DownloadRequested:
case QWebEngineDownloadItem::DownloadInProgress:
case QWebEngineDownloadRequest::DownloadRequested:
case QWebEngineDownloadRequest::DownloadInProgress:
return RunningState;
case QWebEngineDownloadItem::DownloadCompleted:
case QWebEngineDownloadRequest::DownloadCompleted:
return FinishedState;
case QWebEngineDownloadItem::DownloadCancelled:
case QWebEngineDownloadRequest::DownloadCancelled:
return CancelledState;
case QWebEngineDownloadItem::DownloadInterrupted:
case QWebEngineDownloadRequest::DownloadInterrupted:
return ErrorState;
}

Expand Down
6 changes: 3 additions & 3 deletions src/modules/backends/web/qtwebengine/QtWebEngineTransfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "../../../../core/TransfersManager.h"

#include <QtWebEngineWidgets/QWebEngineDownloadItem>
#include <QtWebEngineCore/QWebEngineDownloadRequest>

namespace Otter
{
Expand All @@ -32,7 +32,7 @@ class QtWebEngineTransfer final : public Transfer
Q_OBJECT

public:
explicit QtWebEngineTransfer(QWebEngineDownloadItem *item, TransferOptions options = CanAskForPathOption, QObject *parent = nullptr);
explicit QtWebEngineTransfer(QWebEngineDownloadRequest *item, TransferOptions options = CanAskForPathOption, QObject *parent = nullptr);

QUrl getSource() const override;
QString getSuggestedFileName() override;
Expand All @@ -47,7 +47,7 @@ public slots:
bool setTarget(const QString &target, bool canOverwriteExisting = false) override;

private:
QPointer<QWebEngineDownloadItem> m_item;
QPointer<QWebEngineDownloadRequest> m_item;
};

}
Expand Down
Loading