Skip to content

Commit

Permalink
Fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
fnkkio committed Dec 21, 2019
2 parents e090104 + f71ad91 commit d0af800
Show file tree
Hide file tree
Showing 44 changed files with 1,654 additions and 1,599 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ if (Qt5WebKitWidgets_FOUND AND ENABLE_QTWEBKIT)
src/modules/backends/web/qtwebkit/QtWebKitCookieJar.cpp
src/modules/backends/web/qtwebkit/QtWebKitFtpListingNetworkReply.cpp
src/modules/backends/web/qtwebkit/QtWebKitHistoryInterface.cpp
src/modules/backends/web/qtwebkit/QtWebKitInspector.cpp
src/modules/backends/web/qtwebkit/QtWebKitNetworkManager.cpp
src/modules/backends/web/qtwebkit/QtWebKitNotificationPresenter.cpp
src/modules/backends/web/qtwebkit/QtWebKitPage.cpp
Expand Down
34 changes: 8 additions & 26 deletions src/core/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,9 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv),
QCryptographicHash hash(QCryptographicHash::Md5);
hash.addData(profilePath.toUtf8());

const QString identifier(QString::fromLatin1(hash.result().toHex()));
const QString server(applicationName() + (identifier.isEmpty() ? QString() : (QLatin1Char('-') + identifier)));
const QString serverName(applicationName() + QLatin1Char('-') + QString::fromLatin1(hash.result().toHex()));
QLocalSocket socket;
socket.connectToServer(server);
socket.connectToServer(serverName);

if (socket.waitForConnected(500))
{
Expand Down Expand Up @@ -311,9 +310,9 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv),

m_localServer->setSocketOptions(QLocalServer::UserAccessOption);

if (!m_localServer->listen(server) && m_localServer->serverError() == QAbstractSocket::AddressInUseError && QLocalServer::removeServer(server))
if (!m_localServer->listen(serverName) && m_localServer->serverError() == QAbstractSocket::AddressInUseError && QLocalServer::removeServer(serverName))
{
m_localServer->listen(server);
m_localServer->listen(serverName);
}

m_isFirstRun = !QFile::exists(profilePath);
Expand Down Expand Up @@ -445,7 +444,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv),

const WebBackend *webBackend(AddonsManager::getWebBackend());

if (!QSslSocket::supportsSsl() || (webBackend && webBackend->getSslVersion().isEmpty()))
if (!QSslSocket::supportsSsl() || (webBackend && !webBackend->hasSslSupport()))
{
QMessageBox::warning(nullptr, tr("Warning"), tr("SSL support is not available or incomplete.\nSome websites may work incorrectly or do not work at all."), QMessageBox::Close);
}
Expand Down Expand Up @@ -1017,14 +1016,7 @@ void Application::handleNewConnection()

if (!mainWindow || !SettingsManager::getOption(SettingsManager::Browser_OpenLinksInNewTabOption).toBool() || (isPrivate && !mainWindow->isPrivate()))
{
QVariantMap parameters;

if (isPrivate)
{
parameters[QLatin1String("hints")] = SessionsManager::PrivateOpen;
}

createWindow(parameters);
createWindow({{QLatin1String("hints"), (isPrivate ? SessionsManager::PrivateOpen : SessionsManager::DefaultOpen)}});
}
}
else
Expand All @@ -1033,12 +1025,7 @@ void Application::handleNewConnection()

if (sessionData.isClean || QMessageBox::warning(nullptr, tr("Warning"), tr("This session was not saved correctly.\nAre you sure that you want to restore this session anyway?"), (QMessageBox::Yes | QMessageBox::No), QMessageBox::No) == QMessageBox::Yes)
{
QVariantMap parameters;

if (isPrivate)
{
parameters[QLatin1String("hints")] = SessionsManager::PrivateOpen;
}
const QVariantMap parameters({{QLatin1String("hints"), (isPrivate ? SessionsManager::PrivateOpen : SessionsManager::DefaultOpen)}});

for (int i = 0; i < sessionData.windows.count(); ++i)
{
Expand Down Expand Up @@ -1084,12 +1071,7 @@ void Application::handlePositionalArguments(QCommandLineParser *parser, bool for

if (openHints.testFlag(SessionsManager::NewWindowOpen))
{
QVariantMap parameters;

if (openHints.testFlag(SessionsManager::PrivateOpen))
{
parameters[QLatin1String("hints")] = SessionsManager::PrivateOpen;
}
const QVariantMap parameters({{QLatin1String("hints"), (openHints.testFlag(SessionsManager::PrivateOpen) ? SessionsManager::PrivateOpen : SessionsManager::DefaultOpen)}});

if (urls.isEmpty())
{
Expand Down
1 change: 1 addition & 0 deletions src/core/BookmarksModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,7 @@ QMimeData* BookmarksModel::mimeData(const QModelIndexList &indexes) const
if (indexes.count() == 1)
{
mimeData->setProperty("x-item-index", indexes.at(0));
mimeData->setProperty("x-url-title", indexes.at(0).data(TitleRole).toString());
}

for (int i = 0; i < indexes.count(); ++i)
Expand Down
13 changes: 13 additions & 0 deletions src/core/Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ BookmarksModel::Bookmark* BookmarksImportJob::getImportFolder() const
return m_importFolder;
}

QDateTime BookmarksImportJob::getDateTime(const QString &timestamp) const
{
#if QT_VERSION < 0x050800
const uint seconds(timestamp.toUInt());

return ((seconds > 0) ? QDateTime::fromTime_t(seconds) : QDateTime());
#else
const qint64 seconds(timestamp.toLongLong());

return ((seconds != 0) ? QDateTime::fromSecsSinceEpoch(seconds) : QDateTime());
#endif
}

bool BookmarksImportJob::areDuplicatesAllowed() const
{
return m_areDuplicatesAllowed;
Expand Down
1 change: 1 addition & 0 deletions src/core/Importer.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class BookmarksImportJob : public ImportJob
void setCurrentFolder(BookmarksModel::Bookmark *folder);
BookmarksModel::Bookmark* getCurrentFolder() const;
BookmarksModel::Bookmark* getImportFolder() const;
QDateTime getDateTime(const QString &timestamp) const;
bool areDuplicatesAllowed() const;

private:
Expand Down
7 changes: 1 addition & 6 deletions src/core/SessionsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,12 +558,7 @@ bool SessionsManager::restoreSession(const SessionInformation &session, MainWind
m_sessionTitle = session.title;
}

QVariantMap parameters;

if (isPrivate)
{
parameters[QLatin1String("hints")] = PrivateOpen;
}
const QVariantMap parameters({{QLatin1String("hints"), (isPrivate ? SessionsManager::PrivateOpen : SessionsManager::DefaultOpen)}});

for (int i = 0; i < session.windows.count(); ++i)
{
Expand Down
7 changes: 6 additions & 1 deletion src/core/TransfersManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,12 @@ void TransfersManager::addTransfer(Transfer *transfer)
}
else
{
HistoryManager::addEntry(transfer->getSource());
const QString scheme(transfer->getSource().scheme());

if (scheme == QLatin1String("http") || scheme == QLatin1String("https"))
{
HistoryManager::addEntry(transfer->getSource());
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/core/WebBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class WebBackend : public QObject, public Addon
virtual QVector<SpellCheckManager::DictionaryInformation> getDictionaries() const;
AddonType getType() const override;
virtual BackendCapabilities getCapabilities() const;
virtual bool hasSslSupport() const = 0;
};

}
Expand Down
9 changes: 1 addition & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,7 @@ int main(int argc, char *argv[])

if (Application::getWindows().isEmpty())
{
QVariantMap parameters;

if (isPrivate)
{
parameters[QLatin1String("hints")] = SessionsManager::PrivateOpen;
}

Application::createWindow(parameters);
Application::createWindow({{QLatin1String("hints"), (isPrivate ? SessionsManager::PrivateOpen : SessionsManager::DefaultOpen)}});
}

return Application::exec();
Expand Down
52 changes: 49 additions & 3 deletions src/modules/backends/web/qtwebengine/QtWebEnginePage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,19 +337,21 @@ QtWebEngineWebWidget* QtWebEnginePage::createWidget(SessionsManager::OpenHints h
return widget;
}

QString QtWebEnginePage::createJavaScriptList(QStringList rules) const
QString QtWebEnginePage::createJavaScriptList(const QStringList &rules) const
{
if (rules.isEmpty())
{
return {};
}

QStringList parsedRules(rules);

for (int i = 0; i < rules.count(); ++i)
{
rules[i].replace(QLatin1Char('\''), QLatin1String("\\'"));
parsedRules[i].replace(QLatin1Char('\''), QLatin1String("\\'"));
}

return QLatin1Char('\'') + rules.join(QLatin1String("','")) + QLatin1Char('\'');
return QLatin1Char('\'') + parsedRules.join(QLatin1String("','")) + QLatin1Char('\'');
}

QString QtWebEnginePage::createScriptSource(const QString &path, const QStringList &parameters) const
Expand Down Expand Up @@ -402,6 +404,13 @@ QVariant QtWebEnginePage::runScriptFile(const QString &path, const QStringList &
return runScriptSource(createScriptSource(path, parameters));
}

#if QTWEBENGINECORE_VERSION >= 0x050E00
WebWidget::SslInformation QtWebEnginePage::getSslInformation() const
{
return m_sslInformation;
}
#endif

Session::Window::History QtWebEnginePage::getHistory() const
{
QWebEngineHistory *pageHistory(history());
Expand Down Expand Up @@ -526,6 +535,10 @@ bool QtWebEnginePage::acceptNavigationRequest(const QUrl &url, NavigationType ty
}
}

#if QTWEBENGINECORE_VERSION >= 0x050E00
m_sslInformation = {};
#endif

if (type != NavigationTypeReload)
{
m_previousNavigationType = type;
Expand Down Expand Up @@ -584,6 +597,39 @@ bool QtWebEnginePage::acceptNavigationRequest(const QUrl &url, NavigationType ty
return true;
}

#if QTWEBENGINECORE_VERSION >= 0x050E00
bool QtWebEnginePage::certificateError(const QWebEngineCertificateError &error)
{
if (!m_widget || error.certificateChain().isEmpty())
{
return false;
}

const QList<QSslError> errors(QSslCertificate::verify(error.certificateChain(), error.url().host()));

m_sslInformation.errors.reserve(m_sslInformation.errors.count() + errors.count());

for (int i = 0; i < errors.count(); ++i)
{
m_sslInformation.errors.append({errors.at(i), error.url()});
}

const QString firstPartyUrl(m_widget->getUrl().toString());
const QString thirdPartyUrl(error.url().toString());

if (m_widget->getOption(SettingsManager::Security_IgnoreSslErrorsOption, m_widget->getUrl()).toStringList().contains(QString::fromLatin1(error.certificateChain().first().digest().toBase64())))
{
Console::addMessage(QStringLiteral("[accepted] The page at %1 was allowed to display insecure content from %2").arg(firstPartyUrl, thirdPartyUrl), Console::SecurityCategory, Console::WarningLevel, thirdPartyUrl, -1, m_widget->getWindowIdentifier());

return true;
}

Console::addMessage(QStringLiteral("[blocked] The page at %1 was not allowed to display insecure content from %2").arg(firstPartyUrl, thirdPartyUrl), Console::SecurityCategory, Console::WarningLevel, thirdPartyUrl, -1, m_widget->getWindowIdentifier());

return false;
}
#endif

bool QtWebEnginePage::javaScriptConfirm(const QUrl &url, const QString &message)
{
if (m_isIgnoringJavaScriptPopups)
Expand Down
22 changes: 18 additions & 4 deletions src/modules/backends/web/qtwebengine/QtWebEnginePage.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
#define OTTER_QTWEBENGINEPAGE_H

#include "../../../../core/SessionsManager.h"
#include "../../../../ui/WebWidget.h"

#include <QtWebEngineCore/QtWebEngineCoreVersion>
#if QTWEBENGINECORE_VERSION >= 0x050E00
#include <QtWebEngineWidgets/QWebEngineCertificateError>
#endif
#include <QtWebEngineWidgets/QWebEnginePage>

namespace Otter
Expand Down Expand Up @@ -53,6 +58,9 @@ class QtWebEnginePage final : public QWebEnginePage
QString createScriptSource(const QString &path, const QStringList &parameters = {}) const;
QVariant runScriptSource(const QString &script);
QVariant runScriptFile(const QString &path, const QStringList &parameters = {});
#if QTWEBENGINECORE_VERSION >= 0x050E00
WebWidget::SslInformation getSslInformation() const;
#endif
Session::Window::History getHistory() const;
bool isPopup() const;
bool isViewingMedia() const;
Expand All @@ -63,9 +71,12 @@ class QtWebEnginePage final : public QWebEnginePage
void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString &note, int line, const QString &source) override;
QWebEnginePage* createWindow(WebWindowType type) override;
QtWebEngineWebWidget* createWidget(SessionsManager::OpenHints hints);
QString createJavaScriptList(QStringList rules) const;
QString createJavaScriptList(const QStringList &rules) const;
QStringList chooseFiles(FileSelectionMode mode, const QStringList &oldFiles, const QStringList &acceptedMimeTypes) override;
bool acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame) override;
bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame) override;
#if QTWEBENGINECORE_VERSION >= 0x050E00
bool certificateError(const QWebEngineCertificateError &error) override;
#endif
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 @@ -75,17 +86,20 @@ protected slots:

private:
QtWebEngineWebWidget *m_widget;
#if QTWEBENGINECORE_VERSION >= 0x050E00
WebWidget::SslInformation m_sslInformation;
#endif
QVector<QtWebEnginePage*> m_popups;
QVector<HistoryEntryInformation> m_history;
QWebEnginePage::NavigationType m_previousNavigationType;
NavigationType m_previousNavigationType;
bool m_isIgnoringJavaScriptPopups;
bool m_isViewingMedia;
bool m_isPopup;

signals:
void requestedNewWindow(WebWidget *widget, SessionsManager::OpenHints hints, const QVariantMap &parameters);
void requestedPopupWindow(const QUrl &parentUrl, const QUrl &popupUrl);
void aboutToNavigate(const QUrl &url, QWebEnginePage::NavigationType navigationType);
void aboutToNavigate(const QUrl &url, NavigationType navigationType);
void viewingMediaChanged(bool isViewingMedia);
};

Expand Down
29 changes: 27 additions & 2 deletions src/modules/backends/web/qtwebengine/QtWebEngineTransfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@

#include "QtWebEngineTransfer.h"

#if QTWEBENGINECORE_VERSION >= 0x050E00
#include <QtCore/QDir>
#endif
#include <QtCore/QFileInfo>
#include <QtCore/QMimeDatabase>

namespace Otter
{

QtWebEngineTransfer::QtWebEngineTransfer(QWebEngineDownloadItem *item, TransferOptions options, QObject *parent) : Transfer(options, parent),
m_item(item),
m_suggestedFileName(QFileInfo(item->path()).fileName())
m_item(item)
#if QTWEBENGINECORE_VERSION < 0x050E00
, m_suggestedFileName(QFileInfo(item->path()).fileName())
#endif
{
m_item->accept();
m_item->setParent(this);
Expand Down Expand Up @@ -79,7 +84,16 @@ QUrl QtWebEngineTransfer::getSource() const

QString QtWebEngineTransfer::getSuggestedFileName()
{
#if QTWEBENGINECORE_VERSION >= 0x050E00
if (!m_item)
{
return {};
}

return m_item->suggestedFileName();
#else
return m_suggestedFileName;
#endif
}

QString QtWebEngineTransfer::getTarget() const
Expand All @@ -89,7 +103,11 @@ QString QtWebEngineTransfer::getTarget() const
return Transfer::getTarget();
}

#if QTWEBENGINECORE_VERSION >= 0x050E00
return QDir(m_item->downloadDirectory()).absoluteFilePath(m_item->downloadFileName());
#else
return m_item->path();
#endif
}

QMimeType QtWebEngineTransfer::getMimeType() const
Expand Down Expand Up @@ -154,7 +172,14 @@ bool QtWebEngineTransfer::setTarget(const QString &target, bool canOverwriteExis
return Transfer::setTarget(target, canOverwriteExisting);
}

#if QTWEBENGINECORE_VERSION >= 0x050E00
QFileInfo fileInformation(target);

m_item->setDownloadDirectory(fileInformation.path());
m_item->setDownloadFileName(fileInformation.fileName());
#else
m_item->setPath(target);
#endif

return true;
}
Expand Down
Loading

0 comments on commit d0af800

Please sign in to comment.