summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@qt.io>2018-05-14 10:20:34 +0200
committerMichal Klocek <michal.klocek@qt.io>2018-05-17 12:44:30 +0000
commit216f19d52ce9e920349da9247afc2c8e85df2c56 (patch)
tree2e546b04f1acfa1572f2e8c8e80b37fcb1105a17
parent0d330addcf37820e516737167bf174d2c35c4010 (diff)
Reduce boilerplate code for FaviconManager
Remove private implementation for FaviconManager Make FaviconManager non QObject since there no reason to do so. Change-Id: I8e341f9bd2dbc6f3fa977693383bbbf7349ab0b0 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r--src/core/core_chromium.pri1
-rw-r--r--src/core/favicon_manager.cpp68
-rw-r--r--src/core/favicon_manager.h45
-rw-r--r--src/core/favicon_manager_p.h106
-rw-r--r--src/core/web_contents_delegate_qt.cpp3
5 files changed, 58 insertions, 165 deletions
diff --git a/src/core/core_chromium.pri b/src/core/core_chromium.pri
index ba843e9f6..d036f82fd 100644
--- a/src/core/core_chromium.pri
+++ b/src/core/core_chromium.pri
@@ -146,7 +146,6 @@ HEADERS = \
devtools_manager_delegate_qt.h \
download_manager_delegate_qt.h \
chromium_gpu_helper.h \
- favicon_manager_p.h \
favicon_manager.h \
file_picker_controller.h \
gl_context_qt.h \
diff --git a/src/core/favicon_manager.cpp b/src/core/favicon_manager.cpp
index 03da67335..2a7d78320 100644
--- a/src/core/favicon_manager.cpp
+++ b/src/core/favicon_manager.cpp
@@ -38,8 +38,6 @@
****************************************************************************/
#include "favicon_manager.h"
-#include "favicon_manager_p.h"
-
#include "type_conversion.h"
#include "web_contents_adapter_client.h"
#include "web_engine_settings.h"
@@ -72,18 +70,19 @@ static inline unsigned area(const QSize &size)
}
-FaviconManagerPrivate::FaviconManagerPrivate(content::WebContents *webContents, WebContentsAdapterClient *viewClient)
+FaviconManager::FaviconManager(content::WebContents *webContents, WebContentsAdapterClient *viewClient)
: m_webContents(webContents)
, m_viewClient(viewClient)
- , m_weakFactory(this)
+ , m_candidateCount(0)
+ , m_weakFactory(new base::WeakPtrFactory<FaviconManager>(this))
{
}
-FaviconManagerPrivate::~FaviconManagerPrivate()
+FaviconManager::~FaviconManager()
{
}
-int FaviconManagerPrivate::downloadIcon(const QUrl &url)
+int FaviconManager::downloadIcon(const QUrl &url)
{
static int fakeId = 0;
int id;
@@ -98,7 +97,7 @@ int FaviconManagerPrivate::downloadIcon(const QUrl &url)
true, // is_favicon
0, // no max size
false, // normal cache policy
- base::Bind(&FaviconManagerPrivate::iconDownloadFinished, m_weakFactory.GetWeakPtr()));
+ base::Bind(&FaviconManager::iconDownloadFinished, m_weakFactory->GetWeakPtr()));
}
Q_ASSERT(!m_inProgressRequests.contains(id));
@@ -107,7 +106,7 @@ int FaviconManagerPrivate::downloadIcon(const QUrl &url)
return id;
}
-void FaviconManagerPrivate::iconDownloadFinished(int id,
+void FaviconManager::iconDownloadFinished(int id,
int status,
const GURL &url,
const std::vector<SkBitmap> &bitmaps,
@@ -125,7 +124,7 @@ void FaviconManagerPrivate::iconDownloadFinished(int id,
* icons are stored in m_icons explicitly by this function. It is necessary to avoid
* m_inProgressRequests being emptied right before the next icon is added by a downloadIcon() call.
*/
-void FaviconManagerPrivate::downloadPendingRequests()
+void FaviconManager::downloadPendingRequests()
{
for (auto it = m_pendingRequests.cbegin(), end = m_pendingRequests.cend(); it != end; ++it) {
QIcon icon;
@@ -150,16 +149,15 @@ void FaviconManagerPrivate::downloadPendingRequests()
m_pendingRequests.clear();
}
-void FaviconManagerPrivate::storeIcon(int id, const QIcon &icon)
+void FaviconManager::storeIcon(int id, const QIcon &icon)
{
- Q_Q(FaviconManager);
// Icon download has been interrupted
if (!m_inProgressRequests.contains(id))
return;
QUrl requestUrl = m_inProgressRequests[id];
- FaviconInfo &faviconInfo = q->m_faviconInfoMap[requestUrl];
+ FaviconInfo &faviconInfo = m_faviconInfoMap[requestUrl];
unsigned iconCount = 0;
if (!icon.isNull())
@@ -190,13 +188,13 @@ void FaviconManagerPrivate::storeIcon(int id, const QIcon &icon)
WebEngineSettings *settings = m_viewClient->webEngineSettings();
bool touchIconsEnabled = settings->testAttribute(WebEngineSettings::TouchIconsEnabled);
- q->generateCandidateIcon(touchIconsEnabled);
- const QUrl &iconUrl = q->candidateIconUrl(touchIconsEnabled);
+ generateCandidateIcon(touchIconsEnabled);
+ const QUrl &iconUrl = candidateIconUrl(touchIconsEnabled);
propagateIcon(iconUrl);
}
}
-void FaviconManagerPrivate::propagateIcon(const QUrl &iconUrl) const
+void FaviconManager::propagateIcon(const QUrl &iconUrl) const
{
content::NavigationEntry *entry = m_webContents->GetController().GetVisibleEntry();
if (entry) {
@@ -208,30 +206,15 @@ void FaviconManagerPrivate::propagateIcon(const QUrl &iconUrl) const
m_viewClient->iconChanged(iconUrl);
}
-FaviconManager::FaviconManager(FaviconManagerPrivate *d)
- : m_candidateCount(0)
-{
- Q_ASSERT(d);
- d_ptr.reset(d);
-
- d->q_ptr = this;
-}
-
-FaviconManager::~FaviconManager()
-{
-}
-
QIcon FaviconManager::getIcon(const QUrl &url) const
{
- Q_D(const FaviconManager);
-
if (url.isEmpty())
return m_candidateIcon;
- if (!d->m_icons.contains(url))
+ if (!m_icons.contains(url))
return QIcon();
- return d->m_icons[url];
+ return m_icons[url];
}
FaviconInfo FaviconManager::getFaviconInfo(const QUrl &url) const
@@ -257,12 +240,11 @@ QList<FaviconInfo> FaviconManager::getFaviconInfoList(bool candidatesOnly) const
void FaviconManager::update(const QList<FaviconInfo> &candidates)
{
- Q_D(FaviconManager);
updateCandidates(candidates);
- WebEngineSettings *settings = d->m_viewClient->webEngineSettings();
+ WebEngineSettings *settings = m_viewClient->webEngineSettings();
if (!settings->testAttribute(WebEngineSettings::AutoLoadIconsForPage)) {
- d->m_viewClient->iconChanged(QUrl());
+ m_viewClient->iconChanged(QUrl());
return;
}
@@ -274,16 +256,16 @@ void FaviconManager::update(const QList<FaviconInfo> &candidates)
continue;
if (it->isValid())
- d->downloadIcon(it->url);
+ downloadIcon(it->url);
}
- d->downloadPendingRequests();
+ downloadPendingRequests();
// Reset icon if nothing was downloaded
- if (d->m_inProgressRequests.isEmpty()) {
- content::NavigationEntry *entry = d->m_webContents->GetController().GetVisibleEntry();
+ if (m_inProgressRequests.isEmpty()) {
+ content::NavigationEntry *entry = m_webContents->GetController().GetVisibleEntry();
if (entry && !entry->GetFavicon().valid)
- d->m_viewClient->iconChanged(QUrl());
+ m_viewClient->iconChanged(QUrl());
}
}
@@ -306,11 +288,9 @@ void FaviconManager::updateCandidates(const QList<FaviconInfo> &candidates)
void FaviconManager::resetCandidates()
{
- Q_D(FaviconManager);
-
// Interrupt in progress icon downloads
- d->m_pendingRequests.clear();
- d->m_inProgressRequests.clear();
+ m_pendingRequests.clear();
+ m_inProgressRequests.clear();
m_candidateCount = 0;
m_candidateIcon = QIcon();
diff --git a/src/core/favicon_manager.h b/src/core/favicon_manager.h
index e351831c2..28244f90b 100644
--- a/src/core/favicon_manager.h
+++ b/src/core/favicon_manager.h
@@ -41,7 +41,7 @@
#define FAVICON_MANAGER_H
#include "qtwebenginecoreglobal.h"
-
+#include <memory>
#include <QtCore/QMap>
#include <QtCore/QObject>
#include <QtCore/QSize>
@@ -50,9 +50,25 @@
#include "web_engine_settings.h"
+class GURL;
+class SkBitmap;
+
+namespace gfx {
+class Size;
+}
+
+namespace content {
+class WebContents;
+}
+
+namespace base {
+template<class T>
+class WeakPtrFactory;
+}
+
namespace QtWebEngineCore {
-class FaviconManagerPrivate;
+class WebContentsAdapterClient;
// Based on src/3rdparty/chromium/content/public/common/favicon_url.h
class QWEBENGINE_EXPORT FaviconInfo {
@@ -81,9 +97,10 @@ public:
};
-class QWEBENGINE_EXPORT FaviconManager : public QObject {
- Q_OBJECT
+class QWEBENGINE_EXPORT FaviconManager {
+
public:
+ FaviconManager(content::WebContents *, WebContentsAdapterClient *);
~FaviconManager();
QIcon getIcon(const QUrl &url = QUrl()) const;
@@ -91,24 +108,28 @@ public:
QList<FaviconInfo> getFaviconInfoList(bool) const;
private:
- FaviconManager(FaviconManagerPrivate *);
-
void update(const QList<FaviconInfo> &);
void updateCandidates(const QList<FaviconInfo> &);
void resetCandidates();
bool hasCandidate() const;
-
QUrl candidateIconUrl(bool touchIconsEnabled) const;
void generateCandidateIcon(bool touchIconsEnabled);
+ int downloadIcon(const QUrl &);
+ void iconDownloadFinished(int, int, const GURL &, const std::vector<SkBitmap> &, const std::vector<gfx::Size> &);
+ void storeIcon(int, const QIcon &);
+ void downloadPendingRequests();
+ void propagateIcon(const QUrl &) const;
+private:
+ content::WebContents *m_webContents;
+ WebContentsAdapterClient *m_viewClient;
QMap<QUrl, FaviconInfo> m_faviconInfoMap;
int m_candidateCount;
QIcon m_candidateIcon;
-
- Q_DISABLE_COPY(FaviconManager)
- Q_DECLARE_PRIVATE(FaviconManager)
- QScopedPointer<FaviconManagerPrivate> d_ptr;
-
+ QMap<QUrl, QIcon> m_icons;
+ QMap<int, QUrl> m_inProgressRequests;
+ QMap<int, QUrl> m_pendingRequests;
+ std::unique_ptr<base::WeakPtrFactory<FaviconManager>> m_weakFactory;
friend class WebContentsDelegateQt;
};
diff --git a/src/core/favicon_manager_p.h b/src/core/favicon_manager_p.h
deleted file mode 100644
index e2a49dbc7..000000000
--- a/src/core/favicon_manager_p.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebEngine module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef FAVICON_MANAGER_P_H
-#define FAVICON_MANAGER_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qtwebenginecoreglobal_p.h"
-
-#include <QtCore/QMap>
-#include <QtCore/QObject>
-#include <vector>
-
-#include "base/memory/weak_ptr.h"
-
-QT_FORWARD_DECLARE_CLASS(QUrl)
-
-class GURL;
-class SkBitmap;
-
-namespace gfx {
- class Size;
-}
-
-namespace content {
- class WebContents;
-}
-
-namespace QtWebEngineCore {
-
-class FaviconManager;
-class WebContentsAdapterClient;
-
-class FaviconManagerPrivate {
-public:
- FaviconManagerPrivate(content::WebContents *, WebContentsAdapterClient *);
- ~FaviconManagerPrivate();
-
- int downloadIcon(const QUrl &);
-
- void iconDownloadFinished(int, int, const GURL &, const std::vector<SkBitmap> &, const std::vector<gfx::Size> &);
- void storeIcon(int, const QIcon &);
- void downloadPendingRequests();
- void propagateIcon(const QUrl &) const;
-
- content::WebContents *m_webContents;
- WebContentsAdapterClient *m_viewClient;
- base::WeakPtrFactory<FaviconManagerPrivate> m_weakFactory;
-
- QMap<QUrl, QIcon> m_icons;
- QMap<int, QUrl> m_inProgressRequests;
- QMap<int, QUrl> m_pendingRequests;
-
- Q_DECLARE_PUBLIC(FaviconManager)
- FaviconManager *q_ptr;
-};
-
-} // namespace QtWebEngineCore
-
-#endif // FAVICON_MANAGER_P_H
diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp
index dc70f80bd..2de8fd64a 100644
--- a/src/core/web_contents_delegate_qt.cpp
+++ b/src/core/web_contents_delegate_qt.cpp
@@ -47,7 +47,6 @@
#include "color_chooser_qt.h"
#include "color_chooser_controller.h"
#include "favicon_manager.h"
-#include "favicon_manager_p.h"
#include "file_picker_controller.h"
#include "media_capture_devices_dispatcher.h"
#include "net/network_delegate_qt.h"
@@ -99,7 +98,7 @@ static WebContentsAdapterClient::JavaScriptConsoleMessageLevel mapToJavascriptCo
WebContentsDelegateQt::WebContentsDelegateQt(content::WebContents *webContents, WebContentsAdapterClient *adapterClient)
: m_viewClient(adapterClient)
, m_lastReceivedFindReply(0)
- , m_faviconManager(new FaviconManager(new FaviconManagerPrivate(webContents, adapterClient)))
+ , m_faviconManager(new FaviconManager(webContents, adapterClient))
, m_lastLoadProgress(-1)
{
webContents->SetDelegate(this);