Commit f601f9ff authored by Laurent Montel's avatar Laurent Montel 😁

Now we can use messageviewer without javascript enabled.

parent 265b8b8e
......@@ -61,7 +61,9 @@ void WebEnginePartHtmlWriter::end()
insertExtraHead();
mExtraHead.clear();
}
#if QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
mHtml = removeJscripts(mHtml);
#endif
mHtmlView->setHtml(mHtml, QUrl(QStringLiteral("file:///")));
mHtmlView->show();
mHtml.clear();
......
......@@ -23,6 +23,7 @@
#include "settings/messageviewersettings.h"
#include "MessageViewer/ScamCheckShortUrl"
#include "webengineviewer/webenginescript.h"
#include <WebEngineViewer/WebEngineManageScript>
#include <KLocalizedString>
......@@ -84,7 +85,13 @@ ScamDetectionWebEngine::~ScamDetectionWebEngine()
void ScamDetectionWebEngine::scanPage(QWebEnginePage *page)
{
if (MessageViewer::MessageViewerSettings::self()->scamDetectionEnabled()) {
#if QT_VERSION >= 0x050700
page->runJavaScript(WebEngineViewer::WebEngineScript::findAllAnchorsAndForms(),
WebEngineViewer::WebEngineManageScript::scriptWordId(),
invoke(this, &ScamDetectionWebEngine::handleScanPage));
#else
page->runJavaScript(WebEngineViewer::WebEngineScript::findAllAnchorsAndForms(), invoke(this, &ScamDetectionWebEngine::handleScanPage));
#endif
}
}
......
......@@ -31,6 +31,7 @@
#include "settings/messageviewersettings.h"
#include "viewer/webengine/mailwebengineview.h"
#include <WebEngineViewer/WebHitTestResult>
#include <WebEngineViewer/WebEngineManageScript>
#include "viewer/mimeparttree/mimetreemodel.h"
#include "viewer/mimeparttree/mimeparttreeview.h"
#include "widgets/zoomactionmenu.h"
......@@ -636,8 +637,12 @@ QList<QAction *> Viewer::interceptorUrlActions(const WebEngineViewer::WebHitTest
void Viewer::runJavaScript(const QString &code)
{
Q_D(Viewer);
d->mViewer->page()->runJavaScript(code);
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
d->mViewer->page()->runJavaScript(code, WebEngineViewer::WebEngineManageScript::scriptWordId());
#else
d->mViewer->page()->runJavaScript(code);
#endif
}
}
......@@ -43,7 +43,11 @@ MailWebEnginePage::~MailWebEnginePage()
void MailWebEnginePage::initialize()
{
profile()->setHttpCacheType(QWebEngineProfile::MemoryHttpCache);
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, false);
#else
settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, true);
#endif
settings()->setAttribute(QWebEngineSettings::PluginsEnabled, false);
settings()->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, false);
settings()->setAttribute(QWebEngineSettings::JavascriptCanAccessClipboard, false);
......
......@@ -25,6 +25,7 @@
#include "loadexternalreferencesurlinterceptor/loadexternalreferencesurlinterceptor.h"
#include "cidreferencesurlinterceptor/cidreferencesurlinterceptor.h"
#include <WebEngineViewer/NetworkAccessManagerWebEngine>
#include <WebEngineViewer/WebEngineManageScript>
#include "scamdetection/scamdetectionwebengine.h"
#include "scamdetection/scamcheckshorturl.h"
......@@ -110,7 +111,11 @@ MailWebEngineView::~MailWebEngineView()
void MailWebEngineView::runJavaScriptInWordId(const QString &script)
{
#if QT_VERSION >= 0x050700
page()->runJavaScript(script, WebEngineViewer::WebEngineManageScript::scriptWordId());
#else
page()->runJavaScript(script);
#endif
}
void MailWebEngineView::initializeScripts()
......@@ -269,8 +274,13 @@ void MailWebEngineView::markAttachment(const QString &id, const QString &style)
void MailWebEngineView::scrollToAnchor(const QString &anchor)
{
//TODO add wordid here too
#if QT_VERSION >= 0x050700
page()->runJavaScript(WebEngineViewer::WebEngineScript::searchElementPosition(anchor),
WebEngineViewer::WebEngineManageScript::scriptWordId(),
invoke(this, &MailWebEngineView::handleScrollToAnchor));
#else
page()->runJavaScript(WebEngineViewer::WebEngineScript::searchElementPosition(anchor), invoke(this, &MailWebEngineView::handleScrollToAnchor));
#endif
}
void MailWebEngineView::handleScrollToAnchor(const QVariant &result)
......
......@@ -27,6 +27,7 @@
#include <QWebEngineSettings>
#include <MessageViewer/MailWebEngineView>
#include <WebEngineViewer/WebEngineManageScript>
TestMailWebEngine::TestMailWebEngine(QWidget *parent)
: QWidget(parent)
......@@ -75,12 +76,20 @@ void TestMailWebEngine::slotOpenUrl(const QUrl &url)
void TestMailWebEngine::slotScrollDown()
{
#if QT_VERSION >= 0x050700
mTestWebEngine->page()->runJavaScript(WebEngineViewer::WebEngineScript::scrollDown(10), WebEngineViewer::WebEngineManageScript::scriptWordId());
#else
mTestWebEngine->page()->runJavaScript(WebEngineViewer::WebEngineScript::scrollDown(10));
#endif
}
void TestMailWebEngine::slotScrollUp()
{
#if QT_VERSION >= 0x050700
mTestWebEngine->page()->runJavaScript(WebEngineViewer::WebEngineScript::scrollUp(10), WebEngineViewer::WebEngineManageScript::scriptWordId());
#else
mTestWebEngine->page()->runJavaScript(WebEngineViewer::WebEngineScript::scrollUp(10));
#endif
}
void TestMailWebEngine::slotZoomDown()
......
......@@ -179,6 +179,7 @@ ecm_generate_headers(WebEngineViewer_Camelcasewebengine_misc_HEADERS
WebEngineView
WebHitTest
WebEngineScript
WebEngineManageScript
WebEnginePrintMessageBox
WebEngineExportHtmlPageJob
REQUIRED_HEADERS WebEngineViewer_webengine_misc_HEADERS
......
......@@ -27,6 +27,7 @@
#include <QPushButton>
#include <QMessageBox>
#include <QTextEdit>
#include <WebEngineViewer/WebEngineManageScript>
TestJQuerySupportWebEngine::TestJQuerySupportWebEngine(QWidget *parent)
: QWidget(parent)
......@@ -57,7 +58,11 @@ void TestJQuerySupportWebEngine::slotExecuteQuery()
{
const QString code = mEditor->toPlainText();
if (!code.isEmpty()) {
#if QT_VERSION >= 0x050700
pageView->page()->runJavaScript(code, WebEngineViewer::WebEngineManageScript::scriptWordId());
#else
pageView->page()->runJavaScript(code);
#endif
}
}
......
......@@ -20,6 +20,7 @@
#include "webengineaccesskey.h"
#include "webengineaccesskeyanchor.h"
#include "webengineaccesskeyutils.h"
#include "webenginemanagescript.h"
#include <KActionCollection>
#include <QKeyEvent>
......@@ -385,6 +386,12 @@ void WebEngineAccessKey::handleSearchAccessKey(const QVariant &res)
void WebEngineAccessKey::showAccessKeys()
{
d->mAccessKeyActivated = WebEngineAccessKeyPrivate::Activated;
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
d->mWebEngine->page()->runJavaScript(WebEngineViewer::WebEngineAccessKeyUtils::script(),
WebEngineManageScript::scriptWordId(),
invoke(this, &WebEngineAccessKey::handleSearchAccessKey));
#else
d->mWebEngine->page()->runJavaScript(WebEngineViewer::WebEngineAccessKeyUtils::script(), invoke(this, &WebEngineAccessKey::handleSearchAccessKey));
#endif
}
......@@ -54,7 +54,7 @@ void WebEngineManageScript::addScript(QWebEngineProfile *profile, const QString
script.setName(scriptName);
script.setInjectionPoint(injectionPoint);
script.setRunsOnSubFrames(true);
script.setWorldId(QWebEngineScript::MainWorld);
script.setWorldId(scriptWordId());
}
script.setSourceCode(source);
profile->scripts()->insert(script);
......
......@@ -22,17 +22,20 @@
#include <QObject>
#include <QWebEngineScript>
#include "webengineviewer_export.h"
class QWebEngineProfile;
namespace WebEngineViewer
{
class WebEngineManageScript : public QObject
class WEBENGINEVIEWER_EXPORT WebEngineManageScript : public QObject
{
Q_OBJECT
public:
explicit WebEngineManageScript(QObject *parent = Q_NULLPTR);
~WebEngineManageScript();
void addScript(QWebEngineProfile *profile, const QString &source, const QString &scriptName, QWebEngineScript::InjectionPoint injectionPoint);
static qint32 scriptWordId() { return (QWebEngineScript::UserWorld + 1); }
};
}
#endif // WEBENGINEMANAGESCRIPT_H
......@@ -59,6 +59,11 @@ WebEngineView::~WebEngineView()
delete d;
}
WebEngineManageScript *WebEngineView::webEngineManagerScript() const
{
return d->mManagerScript;
}
void WebEngineView::initializeJQueryScript()
{
QFile file;
......
......@@ -26,6 +26,7 @@
namespace WebEngineViewer
{
class WebEngineViewPrivate;
class WebEngineManageScript;
class WEBENGINEVIEWER_EXPORT WebEngineView : public QWebEngineView
{
Q_OBJECT
......@@ -41,6 +42,9 @@ public:
void addScript(const QString &source, const QString &scriptName, QWebEngineScript::InjectionPoint injectionPoint);
void initializeJQueryScript();
WebEngineManageScript *webEngineManagerScript() const;
protected:
bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
QWebEngineView *createWindow(QWebEnginePage::WebWindowType type) Q_DECL_OVERRIDE;
......
......@@ -20,6 +20,7 @@
#include "webhittest.h"
#include "webhittestresult.h"
#include <QWebEnginePage>
#include "webenginemanagescript.h"
using namespace WebEngineViewer;
template<typename Arg, typename R, typename C>
......@@ -113,7 +114,13 @@ WebHitTest::WebHitTest(QWebEnginePage *page, const QPoint &pos, QObject *parent)
const QString &js = source.arg(pos.x()).arg(pos.y());
d->m_pageUrl = page->url();
#if QT_VERSION >= 0x050700
page->runJavaScript(js,
WebEngineViewer::WebEngineManageScript::scriptWordId(),
invoke(this, &WebHitTest::handleHitTest));
#else
page->runJavaScript(js, invoke(this, &WebHitTest::handleHitTest));
#endif
}
WebHitTest::~WebHitTest()
......
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