Commit 478fc472 authored by Laurent Montel's avatar Laurent Montel 😁

Use WebEngineEmbedPart

parent c1f58e1b
......@@ -37,6 +37,7 @@ if(BUILD_TESTING)
add_subdirectory(adblock/tests/)
add_subdirectory(adblock/common/autotests)
add_subdirectory(viewerplugins/tests/)
add_subdirectory(htmlwriter/autotests/)
if (QTWEBENGINE_SUPPORT_OPTION)
add_subdirectory(webengine/tests)
add_subdirectory(viewer/webengine/autotests)
......@@ -113,6 +114,7 @@ if (QTWEBENGINE_SUPPORT_OPTION)
webengine/webenginescript.cpp
webengine/webengineview.cpp
webengine/loadexternalreferencesurlinterceptor/loadexternalreferencesurlinterceptor.cpp
webengine/cidreferencesurlinterceptor/cidreferencesurlinterceptor.cpp
)
set(libmessageviewer_web_LIB Qt5::WebEngine Qt5::WebEngineWidgets ${libmessageviewer_web_LIB})
endif()
......@@ -203,6 +205,7 @@ set(libmessageviewer_utils_SRCS
if (QTWEBENGINE_SUPPORT_OPTION)
set(libmessageviewer_htmlwriter_webengine_SRCS
htmlwriter/webengineparthtmlwriter.cpp
htmlwriter/webengineembedpart.cpp
)
endif()
......
......@@ -15,6 +15,7 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "webengineparthtmlwriter.h"
#include "webengineembedpart.h"
#include "messageviewer_debug.h"
#include "viewer/webengine/mailwebengineview.h"
......@@ -46,7 +47,7 @@ void WebEnginePartHtmlWriter::begin(const QString &css)
reset();
}
mEmbeddedPartMap.clear();
MessageViewer::WebEngineEmbedPart::self()->clear();
// clear the widget:
mHtmlView->setUpdatesEnabled(false);
mHtmlView->scrollUp(10);
......@@ -68,7 +69,6 @@ void WebEnginePartHtmlWriter::end()
mHtmlView->show();
mHtml.clear();
resolveCidUrls();
mHtmlView->setUpdatesEnabled(true);
mHtmlView->update();
mState = Ended;
......@@ -107,31 +107,7 @@ void WebEnginePartHtmlWriter::flush()
void WebEnginePartHtmlWriter::embedPart(const QByteArray &contentId,
const QString &contentURL)
{
mEmbeddedPartMap[QLatin1String(contentId)] = contentURL;
}
void WebEnginePartHtmlWriter::resolveCidUrls()
{
#if 0
// FIXME: instead of patching around in the HTML source, this should
// be replaced by a custom QNetworkAccessManager (for QWebView), or
// virtual loadResource() (for QTextBrowser)
QWebElement root = mHtmlView->page()->mainFrame()->documentElement();
QWebElementCollection images = root.findAll(QStringLiteral("img"));
QWebElementCollection::iterator end(images.end());
for (QWebElementCollection::iterator it = images.begin(); it != end; ++it) {
QUrl url((*it).attribute(QStringLiteral("src")));
if (url.scheme() == QLatin1String("cid")) {
EmbeddedPartMap::const_iterator cit = mEmbeddedPartMap.constFind(url.path());
if (cit != mEmbeddedPartMap.constEnd()) {
qCDebug(MESSAGEVIEWER_LOG) << "Replacing" << url.toDisplayString() << "by" << cit.value();
(*it).setAttribute(QStringLiteral("src"), cit.value());
}
}
}
#else
qDebug() << "WebEnginePartHtmlWriter::resolveCidUrls() not implemented";
#endif
MessageViewer::WebEngineEmbedPart::self()->addEmbedPart(contentId, contentURL);
}
void WebEnginePartHtmlWriter::insertExtraHead()
......
......@@ -51,7 +51,6 @@ Q_SIGNALS:
void finished();
private:
void resolveCidUrls();
void insertExtraHead();
private:
......@@ -63,9 +62,6 @@ private:
Queued,
Ended
} mState;
// Key is Content-Id, value is URL
typedef QMap<QString, QString> EmbeddedPartMap;
EmbeddedPartMap mEmbeddedPartMap;
};
}
......
......@@ -21,6 +21,7 @@
#include "webengine/webenginescript.h"
#include "messageviewer/messageviewersettings.h"
#include "webengine/loadexternalreferencesurlinterceptor/loadexternalreferencesurlinterceptor.h"
#include "webengine/cidreferencesurlinterceptor/cidreferencesurlinterceptor.h"
#include <MessageViewer/NetworkAccessManagerWebEngine>
#include "scamdetection/scamdetectionwebengine.h"
......@@ -85,6 +86,8 @@ MailWebEngineView::MailWebEngineView(KActionCollection *ac, QWidget *parent)
d->mNetworkAccessManager = new MessageViewer::NetworkAccessManagerWebEngine(this, ac, this);
d->mExternalReference = new MessageViewer::LoadExternalReferencesUrlInterceptor(this);
d->mNetworkAccessManager->addInterceptor(d->mExternalReference);
MessageViewer::CidReferencesUrlInterceptor *cidReference = new MessageViewer::CidReferencesUrlInterceptor(this);
d->mNetworkAccessManager->addInterceptor(cidReference);
d->mPageEngine = new MailWebEnginePage(this);
setPage(d->mPageEngine);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment