mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
WebView: Fix loading favicons that are on different hosts than site
This commit is contained in:
parent
7f101700ca
commit
6ac34f74c1
@ -226,16 +226,17 @@ SOURCES += \
|
||||
tools/toolbutton.cpp \
|
||||
tools/treewidget.cpp \
|
||||
tools/widget.cpp \
|
||||
webengine/iconloader.cpp \
|
||||
webengine/javascript/autofilljsobject.cpp \
|
||||
webengine/javascript/externaljsobject.cpp \
|
||||
webengine/loadrequest.cpp \
|
||||
webengine/webhittestresult.cpp \
|
||||
webengine/webinspector.cpp \
|
||||
webengine/webpage.cpp \
|
||||
webengine/webview.cpp \
|
||||
webtab/searchtoolbar.cpp \
|
||||
webtab/tabbedwebview.cpp \
|
||||
webtab/webtab.cpp \
|
||||
webengine/webhittestresult.cpp
|
||||
|
||||
HEADERS += \
|
||||
3rdparty/ecwin7.h \
|
||||
@ -424,16 +425,17 @@ HEADERS += \
|
||||
tools/toolbutton.h \
|
||||
tools/treewidget.h \
|
||||
tools/widget.h \
|
||||
webengine/iconloader.h \
|
||||
webengine/javascript/autofilljsobject.h \
|
||||
webengine/javascript/externaljsobject.h \
|
||||
webengine/loadrequest.h \
|
||||
webengine/webhittestresult.cpp \
|
||||
webengine/webinspector.h \
|
||||
webengine/webpage.h \
|
||||
webengine/webview.h \
|
||||
webtab/searchtoolbar.h \
|
||||
webtab/tabbedwebview.h \
|
||||
webtab/webtab.h \
|
||||
webengine/webhittestresult.h
|
||||
|
||||
FORMS += \
|
||||
adblock/adblockaddsubscriptiondialog.ui \
|
||||
|
@ -19,8 +19,8 @@
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
|
||||
FollowRedirectReply::FollowRedirectReply(const QUrl &url, QNetworkAccessManager* manager)
|
||||
: QObject()
|
||||
FollowRedirectReply::FollowRedirectReply(const QUrl &url, QNetworkAccessManager* manager, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_manager(manager)
|
||||
, m_redirectCount(0)
|
||||
{
|
||||
|
@ -32,7 +32,7 @@ class QUPZILLA_EXPORT FollowRedirectReply : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FollowRedirectReply(const QUrl &url, QNetworkAccessManager* manager);
|
||||
explicit FollowRedirectReply(const QUrl &url, QNetworkAccessManager* manager, QObject *parent = Q_NULLPTR);
|
||||
~FollowRedirectReply();
|
||||
|
||||
QNetworkReply* reply() const;
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include "iconprovider.h"
|
||||
#include "mainapplication.h"
|
||||
#include "networkmanager.h"
|
||||
#include "followredirectreply.h"
|
||||
#include "sqldatabase.h"
|
||||
#include "autosaver.h"
|
||||
#include "webview.h"
|
||||
@ -257,30 +256,3 @@ QIcon IconProvider::iconFromImage(const QImage &image)
|
||||
{
|
||||
return QIcon(QPixmap::fromImage(image));
|
||||
}
|
||||
|
||||
// IconLoader
|
||||
IconLoader::IconLoader(const QUrl &url, QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
m_reply = new FollowRedirectReply(url, mApp->networkManager());
|
||||
connect(m_reply, &FollowRedirectReply::finished, this, &IconLoader::finished);
|
||||
}
|
||||
|
||||
IconLoader::~IconLoader()
|
||||
{
|
||||
delete m_reply;
|
||||
}
|
||||
|
||||
void IconLoader::finished()
|
||||
{
|
||||
if (m_reply->error() != QNetworkReply::NoError) {
|
||||
emit error();
|
||||
}
|
||||
else {
|
||||
const QByteArray data = m_reply->readAll();
|
||||
emit iconLoaded(QIcon(QPixmap::fromImage(QImage::fromData(data))));
|
||||
}
|
||||
|
||||
delete m_reply;
|
||||
m_reply = 0;
|
||||
}
|
||||
|
@ -25,12 +25,10 @@
|
||||
|
||||
#include "qzcommon.h"
|
||||
|
||||
class QTimer;
|
||||
class QIcon;
|
||||
|
||||
class WebView;
|
||||
class AutoSaver;
|
||||
class FollowRedirectReply;
|
||||
|
||||
// Needs to be QWidget subclass, otherwise qproperty- setting won't work
|
||||
class QUPZILLA_EXPORT IconProvider : public QWidget
|
||||
@ -84,23 +82,4 @@ private:
|
||||
AutoSaver* m_autoSaver;
|
||||
};
|
||||
|
||||
class QUPZILLA_EXPORT IconLoader : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit IconLoader(const QUrl &url, QObject* parent = 0);
|
||||
~IconLoader();
|
||||
|
||||
signals:
|
||||
void iconLoaded(const QIcon &icon);
|
||||
void error();
|
||||
|
||||
private slots:
|
||||
void finished();
|
||||
|
||||
private:
|
||||
FollowRedirectReply* m_reply;
|
||||
};
|
||||
|
||||
#endif // ICONPROVIDER_H
|
||||
|
46
src/lib/webengine/iconloader.cpp
Normal file
46
src/lib/webengine/iconloader.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/* ============================================================
|
||||
* QupZilla - QtWebEngine based browser
|
||||
* Copyright (C) 2015 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#include "iconloader.h"
|
||||
#include "mainapplication.h"
|
||||
#include "networkmanager.h"
|
||||
#include "followredirectreply.h"
|
||||
#include "qztools.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
IconLoader::IconLoader(const QUrl &url, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_reply(Q_NULLPTR)
|
||||
{
|
||||
m_reply = new FollowRedirectReply(url, mApp->networkManager());
|
||||
connect(m_reply, &FollowRedirectReply::finished, this, &IconLoader::finished);
|
||||
}
|
||||
|
||||
void IconLoader::finished()
|
||||
{
|
||||
if (m_reply->error() != QNetworkReply::NoError) {
|
||||
emit error();
|
||||
}
|
||||
else {
|
||||
const QByteArray data = m_reply->readAll();
|
||||
emit iconLoaded(QIcon(QPixmap::fromImage(QImage::fromData(data))));
|
||||
}
|
||||
|
||||
delete m_reply;
|
||||
m_reply = Q_NULLPTR;
|
||||
}
|
47
src/lib/webengine/iconloader.h
Normal file
47
src/lib/webengine/iconloader.h
Normal file
@ -0,0 +1,47 @@
|
||||
/* ============================================================
|
||||
* QupZilla - QtWebEngine based browser
|
||||
* Copyright (C) 2015 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#ifndef ICONLOADER_H
|
||||
#define ICONLOADER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "qzcommon.h"
|
||||
|
||||
class QIcon;
|
||||
|
||||
class FollowRedirectReply;
|
||||
|
||||
class QUPZILLA_EXPORT IconLoader : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit IconLoader(const QUrl &url, QObject* parent = 0);
|
||||
|
||||
signals:
|
||||
void iconLoaded(const QIcon &icon);
|
||||
void error();
|
||||
|
||||
private slots:
|
||||
void finished();
|
||||
|
||||
private:
|
||||
FollowRedirectReply* m_reply;
|
||||
};
|
||||
|
||||
#endif // ICONLOADER_H
|
@ -35,6 +35,7 @@
|
||||
#include "webinspector.h"
|
||||
#include "scripts.h"
|
||||
#include "webhittestresult.h"
|
||||
#include "iconloader.h"
|
||||
|
||||
#ifdef USE_HUNSPELL
|
||||
#include "qtwebkit/spellcheck/speller.h"
|
||||
@ -79,20 +80,16 @@ WebView::~WebView()
|
||||
|
||||
QIcon WebView::icon() const
|
||||
{
|
||||
if (url().scheme() == QLatin1String("qupzilla")) {
|
||||
return QIcon(":icons/qupzilla.png");
|
||||
}
|
||||
|
||||
if (url().scheme() == QLatin1String("file")) {
|
||||
return IconProvider::standardIcon(QStyle::SP_DriveHDIcon);
|
||||
if (!m_siteIcon.isNull()) {
|
||||
return m_siteIcon;
|
||||
}
|
||||
|
||||
if (url().scheme() == QLatin1String("ftp")) {
|
||||
return IconProvider::standardIcon(QStyle::SP_ComputerIcon);
|
||||
}
|
||||
|
||||
if (!m_siteIcon.isNull() && m_siteIconUrl.host() == url().host()) {
|
||||
return m_siteIcon;
|
||||
if (url().scheme() == QLatin1String("file")) {
|
||||
return IconProvider::standardIcon(QStyle::SP_DriveHDIcon);
|
||||
}
|
||||
|
||||
return IconProvider::iconForUrl(url());
|
||||
@ -394,11 +391,6 @@ void WebView::slotLoadFinished(bool ok)
|
||||
|
||||
void WebView::slotIconUrlChanged(const QUrl &url)
|
||||
{
|
||||
if (m_siteIconUrl == url) {
|
||||
emit iconChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
delete m_siteIconLoader;
|
||||
m_siteIconLoader = new IconLoader(url, this);
|
||||
|
||||
@ -407,7 +399,6 @@ void WebView::slotIconUrlChanged(const QUrl &url)
|
||||
return;
|
||||
|
||||
m_siteIcon = icon;
|
||||
m_siteIconUrl = url;
|
||||
emit iconChanged();
|
||||
|
||||
IconProvider::instance()->saveIcon(this);
|
||||
|
@ -170,7 +170,6 @@ private:
|
||||
int m_currentZoomLevel;
|
||||
|
||||
QIcon m_siteIcon;
|
||||
QUrl m_siteIconUrl;
|
||||
IconLoader* m_siteIconLoader;
|
||||
|
||||
int m_progress;
|
||||
|
Loading…
Reference in New Issue
Block a user