Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remediate errors in various favicon fetch scenarios (#2779) #2795

Merged
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
36 changes: 30 additions & 6 deletions src/gui/EditWidgetIcons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "gui/MessageBox.h"

#ifdef WITH_XC_NETWORKING
#include <QHostInfo>
#include <QNetworkAccessManager>
#include <QtNetwork>
#endif
Expand Down Expand Up @@ -195,20 +196,43 @@ void EditWidgetIcons::downloadFavicon()
m_urlsToTry.clear();

QString fullyQualifiedDomain = m_url.host();
QString secondLevelDomain = getSecondLevelDomain(m_url);

// Attempt to simply load the favicon.ico file
if (fullyQualifiedDomain != secondLevelDomain) {
m_urlsToTry.append(QUrl(m_url.scheme() + "://" + fullyQualifiedDomain + "/favicon.ico"));
m_urlsToTry.append(QUrl(m_url.scheme() + "://" + fullyQualifiedDomain + "/favicon.ico"));

// Determine if host portion of URL is an IP address by resolving it and
// searching for a match with the returned address(es).
bool hostIsIp = false;
QList<QHostAddress> hostAddressess = QHostInfo::fromName(fullyQualifiedDomain).addresses();
for (auto addr : hostAddressess) {
if (addr.toString() == fullyQualifiedDomain) {
hostIsIp = true;
}
}

if (!hostIsIp) {
QString secondLevelDomain = getSecondLevelDomain(m_url);

// Attempt to simply load the favicon.ico file
if (fullyQualifiedDomain != secondLevelDomain) {
m_urlsToTry.append(QUrl(m_url.scheme() + "://" + secondLevelDomain + "/favicon.ico"));
}
}
m_urlsToTry.append(QUrl(m_url.scheme() + "://" + secondLevelDomain + "/favicon.ico"));

// Try to use alternative fallback URL, if enabled
if (config()->get("security/IconDownloadFallback", false).toBool()) {
QUrl fallbackUrl = QUrl("https://icons.duckduckgo.com");
fallbackUrl.setPath("/ip3/" + QUrl::toPercentEncoding(fullyQualifiedDomain) + ".ico");

m_urlsToTry.append(fallbackUrl);

if (!hostIsIp) {
QString secondLevelDomain = getSecondLevelDomain(m_url);

if (fullyQualifiedDomain != secondLevelDomain) {
fallbackUrl.setPath("/ip3/" + QUrl::toPercentEncoding(secondLevelDomain) + ".ico");
m_urlsToTry.append(fallbackUrl);
}
}
}

startFetchFavicon(m_urlsToTry.takeFirst());
Expand Down Expand Up @@ -276,7 +300,7 @@ void EditWidgetIcons::fetchFinished()
#endif
}

void EditWidgetIcons::fetchCanceled()
void EditWidgetIcons::abortRequests()
{
#ifdef WITH_XC_NETWORKING
if (m_reply) {
Expand Down
3 changes: 1 addition & 2 deletions src/gui/EditWidgetIcons.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#ifndef KEEPASSX_EDITWIDGETICONS_H
#define KEEPASSX_EDITWIDGETICONS_H

#include <QSet>
#include <QUrl>
#include <QUuid>
#include <QWidget>
Expand Down Expand Up @@ -66,6 +65,7 @@ class EditWidgetIcons : public QWidget

public slots:
void setUrl(const QString& url);
void abortRequests();

signals:
void messageEditEntry(QString, MessageWidget::MessageType);
Expand All @@ -77,7 +77,6 @@ private slots:
void startFetchFavicon(const QUrl& url);
void fetchFinished();
void fetchReadyRead();
void fetchCanceled();
droidmonkey marked this conversation as resolved.
Show resolved Hide resolved
void addCustomIconFromFile();
bool addCustomIcon(const QImage& icon);
void removeCustomIcon();
Expand Down
2 changes: 2 additions & 0 deletions src/gui/entry/EditEntryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ void EditEntryWidget::setupAdvanced()
void EditEntryWidget::setupIcon()
{
addPage(tr("Icon"), FilePath::instance()->icon("apps", "preferences-desktop-icons"), m_iconsWidget);
connect(this, SIGNAL(accepted()), m_iconsWidget, SLOT(abortRequests()));
connect(this, SIGNAL(rejected()), m_iconsWidget, SLOT(abortRequests()));
}

void EditEntryWidget::setupAutoType()
Expand Down