File indexing completed on 2024-05-19 05:01:22
0001 /* 0002 This file is part of the KDE project. 0003 0004 SPDX-FileCopyrightText: 2008 Laurent Montel <montel@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.1-or-later 0007 */ 0008 0009 #include "webenginepartfactory.h" 0010 #include "webenginepart_ext.h" 0011 #include "webenginepart.h" 0012 0013 #include <kparts_version.h> 0014 #include <KPluginMetaData> 0015 0016 #include <QWidget> 0017 0018 WebEngineFactory::~WebEngineFactory() 0019 { 0020 // qCDebug(WEBENGINEPART_LOG) << this; 0021 } 0022 0023 #if QT_VERSION_MAJOR < 6 0024 QObject *WebEngineFactory::create(const char* iface, QWidget *parentWidget, QObject *parent, const QVariantList &args, const QString&) 0025 #else 0026 QObject *WebEngineFactory::create(const char* iface, QWidget *parentWidget, QObject *parent, const QVariantList &args) 0027 #endif 0028 { 0029 Q_UNUSED(iface); 0030 Q_UNUSED(args); 0031 0032 connect(parentWidget, &QObject::destroyed, this, &WebEngineFactory::slotDestroyed); 0033 0034 // NOTE: The code below is what makes it possible to properly integrate QtWebEngine's PORTING_TODO 0035 // history management with any KParts based application. 0036 QByteArray histData (m_historyBufContainer.value(parentWidget)); 0037 if (!histData.isEmpty()) histData = qUncompress(histData); 0038 WebEnginePart* part = new WebEnginePart(parentWidget, parent, metaData(), histData); 0039 WebEngineNavigationExtension* ext = qobject_cast<WebEngineNavigationExtension*>(part->navigationExtension()); 0040 if (ext) { 0041 connect(ext, QOverload<QObject *, const QByteArray &>::of(&WebEngineNavigationExtension::saveHistory), 0042 this, &WebEngineFactory::slotSaveHistory); 0043 } 0044 return part; 0045 } 0046 0047 void WebEngineFactory::slotSaveHistory(QObject* widget, const QByteArray& buffer) 0048 { 0049 // qCDebug(WEBENGINEPART_LOG) << "Caching history data from" << widget; 0050 m_historyBufContainer.insert(widget, buffer); 0051 } 0052 0053 void WebEngineFactory::slotDestroyed(QObject* object) 0054 { 0055 // qCDebug(WEBENGINEPART_LOG) << "Removing cached history data of" << object; 0056 m_historyBufContainer.remove(object); 0057 }