Replace Google with DuckDuckGo as the optional fallback favicon fetcher (#2309)

* Replace Google with DuckDuckGo for optional fallback favicon fetch URL
Modify the work initially done in #36, and most recently modified in #1786,
to use DuckDuckGo's https://icons.duckduckgo.com/ip3/www.example.com.ico
favicon endpoint.

Fixes #2258

* Close failed favicon fetch progress bars

Name the UrlFetchProgressDialog() with the corresponding URL in order to
be identified by name by its parent when the failed request is handeled
in EditWidgetIcons::fetchFinished(). fetchFinished() retrieves the
relevant UrlFetchProgressDialog() and calls close() on it.

Fixes: #2265
This commit is contained in:
Kyle Kneitinger 2018-09-20 18:52:51 -07:00 committed by Jonathan White
parent a64d2ec716
commit 341635f6bd
4 changed files with 19 additions and 14 deletions

View File

@ -148,7 +148,7 @@ void Config::init(const QString& fileName)
m_defaults.insert("security/passwordscleartext", false);
m_defaults.insert("security/hidepassworddetails", true);
m_defaults.insert("security/autotypeask", true);
m_defaults.insert("security/IconDownloadFallbackToGoogle", false);
m_defaults.insert("security/IconDownloadFallback", false);
m_defaults.insert("security/resettouchid", false);
m_defaults.insert("security/resettouchidtimeout", 30);
m_defaults.insert("security/resettouchidscreenlock", true);

View File

@ -45,7 +45,7 @@ UrlFetchProgressDialog::UrlFetchProgressDialog(const QUrl &url, QWidget *parent)
setWindowTitle(tr("Download Progress"));
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setLabelText(tr("Downloading %1.").arg(url.toDisplayString()));
setMinimumDuration(2000);
setMinimumDuration(0);
setMinimumSize(QSize(400, 75));
}
@ -219,12 +219,12 @@ void EditWidgetIcons::downloadFavicon()
}
m_urlsToTry.append(QUrl(m_url.scheme() + "://" + secondLevelDomain + "/favicon.ico"));
// Try to use Google fallback, if enabled
if (config()->get("security/IconDownloadFallbackToGoogle", false).toBool()) {
QUrl urlGoogle = QUrl("https://www.google.com/s2/favicons");
// 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");
urlGoogle.setQuery("domain=" + QUrl::toPercentEncoding(secondLevelDomain));
m_urlsToTry.append(urlGoogle);
m_urlsToTry.append(fallbackUrl);
}
startFetchFavicon(m_urlsToTry.takeFirst());
@ -242,8 +242,9 @@ void EditWidgetIcons::fetchFinished()
{
#ifdef WITH_XC_NETWORKING
QImage image;
bool googleFallbackEnabled = config()->get("security/IconDownloadFallbackToGoogle", false).toBool();
bool fallbackEnabled = config()->get("security/IconDownloadFallback", false).toBool();
bool error = (m_reply->error() != QNetworkReply::NoError);
QUrl url = m_reply->url();
QUrl redirectTarget = getRedirectTarget(m_reply);
m_reply->deleteLater();
@ -264,6 +265,9 @@ void EditWidgetIcons::fetchFinished()
// No redirect, and we theoretically have some icon data now.
image.loadFromData(m_bytesReceived);
}
} else {
UrlFetchProgressDialog *progress = findChild<UrlFetchProgressDialog *>(url.toString());
progress->close();
}
if (!image.isNull()) {
@ -275,9 +279,9 @@ void EditWidgetIcons::fetchFinished()
startFetchFavicon(m_urlsToTry.takeFirst());
return;
} else {
if (!googleFallbackEnabled) {
if (!fallbackEnabled) {
emit messageEditEntry(tr("Unable to fetch favicon.") + "\n" +
tr("Hint: You can enable Google as a fallback under Tools>Settings>Security"),
tr("Hint: You can enable DuckDuckGo as a fallback under Tools>Settings>Security"),
MessageWidget::Error);
} else {
emit messageEditEntry(tr("Unable to fetch favicon."), MessageWidget::Error);
@ -311,6 +315,7 @@ void EditWidgetIcons::startFetchFavicon(const QUrl& url)
connect(m_reply, &QIODevice::readyRead, this, &EditWidgetIcons::fetchReadyRead);
UrlFetchProgressDialog *progress = new UrlFetchProgressDialog(url, this);
progress->setObjectName(url.toString());
progress->setAttribute(Qt::WA_DeleteOnClose);
connect(m_reply, &QNetworkReply::finished, progress, &QProgressDialog::hide);
connect(m_reply, &QNetworkReply::downloadProgress, progress, &UrlFetchProgressDialog::networkReplyProgress);

View File

@ -186,7 +186,7 @@ void SettingsWidget::loadSettings()
m_secUi->lockDatabaseMinimizeCheckBox->setChecked(config()->get("security/lockdatabaseminimize").toBool());
m_secUi->lockDatabaseOnScreenLockCheckBox->setChecked(config()->get("security/lockdatabasescreenlock").toBool());
m_secUi->relockDatabaseAutoTypeCheckBox->setChecked(config()->get("security/relockautotype").toBool());
m_secUi->fallbackToGoogle->setChecked(config()->get("security/IconDownloadFallbackToGoogle").toBool());
m_secUi->fallbackToSearch->setChecked(config()->get("security/IconDownloadFallback").toBool());
m_secUi->passwordCleartextCheckBox->setChecked(config()->get("security/passwordscleartext").toBool());
m_secUi->passwordDetailsCleartextCheckBox->setChecked(config()->get("security/hidepassworddetails").toBool());
@ -256,7 +256,7 @@ void SettingsWidget::saveSettings()
config()->set("security/lockdatabaseminimize", m_secUi->lockDatabaseMinimizeCheckBox->isChecked());
config()->set("security/lockdatabasescreenlock", m_secUi->lockDatabaseOnScreenLockCheckBox->isChecked());
config()->set("security/relockautotype", m_secUi->relockDatabaseAutoTypeCheckBox->isChecked());
config()->set("security/IconDownloadFallbackToGoogle", m_secUi->fallbackToGoogle->isChecked());
config()->set("security/IconDownloadFallback", m_secUi->fallbackToSearch->isChecked());
config()->set("security/passwordscleartext", m_secUi->passwordCleartextCheckBox->isChecked());
config()->set("security/hidepassworddetails", m_secUi->passwordDetailsCleartextCheckBox->isChecked());

View File

@ -203,9 +203,9 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QCheckBox" name="fallbackToGoogle">
<widget class="QCheckBox" name="fallbackToSearch">
<property name="text">
<string>Use Google as fallback for downloading website icons</string>
<string>Use DuckDuckGo as fallback for downloading website icons</string>
</property>
</widget>
</item>