Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions platform/shared/qt/RhoSimulator_dev.pro
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ SUBDIRS = rubylib rholib sqlite3 syncengine \
#../../../lib/extensions/fcntl/ext/fcntl.pro \
#../../../lib/extensions/openssl/ext/openssl.pro \
#../../../lib/extensions/bigdecimal/ext/bigdecimal.pro \
../../../lib/extensions/zlib/ext/zlib.pro \#\
../../../../RMS-Testing/auto/feature_def/auto_common_spec/extensions/genPropBag/ext/platform/qt/genPropBag.pro \
../../../lib/extensions/zlib/ext/zlib.pro #\#\
#../../../../RMS-Testing/auto/feature_def/auto_common_spec/extensions/genPropBag/ext/platform/qt/genPropBag.pro \
#../../../lib/extensions/serialport/ext/serialport.pro \
../../../lib/commonAPI/signature/ext/platform/qt/Signature.pro \
../../../lib/commonAPI/mediacapture/ext/platform/qt/Mediacapture.pro \
../../../lib/commonAPI/barcode/ext/platform/qt/Barcode.pro
#../../../lib/commonAPI/signature/ext/platform/qt/Signature.pro \
#../../../lib/commonAPI/mediacapture/ext/platform/qt/Mediacapture.pro \
#../../../lib/commonAPI/barcode/ext/platform/qt/Barcode.pro

unix:!macx {
SUBDIRS += curl
Expand Down
12 changes: 9 additions & 3 deletions platform/shared/qt/rhodes/newVersion/QtMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ QtMainWindow::QtMainWindow(QWidget *parent) : QMainWindow(parent), mainWindowCal
profile->setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies);

webView->setContextMenuPolicy(Qt::NoContextMenu);
webView->setPage(new QtWebEnginePage(this));
webView->setPage(new QtWebEnginePage(webView));
webView->setAttribute(Qt::WA_AcceptTouchEvents, false);
this->main_webView = webView;

Expand Down Expand Up @@ -524,6 +524,7 @@ void QtMainWindow::slotNavigate(QString url, int index)
wv->page()->runJavaScript(url);

} else if (!internalUrlProcessing(url)) {
wv->stop();
if (mainWindowCallback) {
const QByteArray asc_url = url.toLatin1();
mainWindowCallback->onWebViewUrlChanged(std::string(asc_url.constData(),
Expand All @@ -542,19 +543,24 @@ void QtMainWindow::slotNavigate(QString url, int index)
void QtMainWindow::GoBack(int index)
{
QtWebEngineView* wv = (index < tabViews.size()) && (index >= 0) ? tabViews[index] : webView;
wv->stop();
if (wv)
wv->back();
}

void QtMainWindow::GoForward(void)
{
if (webView) webView->forward();
if (webView) {
webView->stop();
webView->forward();
}
}

void QtMainWindow::Refresh(int index)
{
QtWebEngineView* wv = (index < tabViews.size()) && (index >= 0) ? tabViews[index] : webView;
if (wv) {
wv->stop();
if (mainWindowCallback) {
const QByteArray asc_url = wv->url().toString().toLatin1();
mainWindowCallback->onWebViewUrlChanged(::std::string(asc_url.constData(), asc_url.length()));
Expand Down Expand Up @@ -634,7 +640,7 @@ int QtMainWindow::tabbarAddTab(const QString& label, const char* icon, bool disa
wv->setParent(centralWidget());
wv->setAttribute(Qt::WA_AcceptTouchEvents, false);
verticalLayout->addWidget(wv);
wv->setPage(new QtWebEnginePage(this));
wv->setPage(new QtWebEnginePage(wv));
setUpWebPage(wv->page());
if (web_bkg_color && (web_bkg_color->name().length()>0))
wv->setHtml( QString("<!DOCTYPE html><html><body style=\"background:") + web_bkg_color->name() +
Expand Down
78 changes: 71 additions & 7 deletions platform/shared/qt/rhodes/newVersion/QtWebEnginePage.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
#include "QtWebEnginePage.h"
#include <QWebEngineSettings>
#include <QtDebug>
#include <QTimer>

QtWebEnginePage::QtWebEnginePage(QObject *parent) : QWebEnginePage(parent){

QtWebEnginePage::QtWebEnginePage(QtWebEngineView *webView) : QWebEnginePage(webView), webView(webView){
#ifdef DISABLE_WEB_SECURITY
settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, true);
settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true);
settings()->setAttribute(QWebEngineSettings::LocalStorageEnabled, true);
#endif
if (RHOCONF().isExist("force_webview_stop_before_navigation_request") && (RHOCONF().getInt("force_webview_stop_before_navigation_request") != 0)){
stopBeforeNavigationRequest = true;
}
}

IMPLEMENT_LOGCLASS(QtWebEnginePage,"JavaScript");

void QtWebEnginePage::javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID)
void QtWebEnginePage::javaScriptConsoleMessage(QWebEnginePage::JavaScriptConsoleMessageLevel level, const QString& message, int lineNumber, const QString& sourceID)
{
QString origin = "Console message at " + sourceID + ":" + QString::number(lineNumber);
const QByteArray asc_origin = origin.toLatin1();
Expand All @@ -18,12 +28,66 @@ void QtWebEnginePage::javaScriptConsoleMessage(const QString& message, int lineN
LOG(INFO) + str_message.c_str();
}

#ifdef _DEBUG
void QtWebEnginePage::triggerAction(QWebEnginePage::WebAction action, bool checked)
{
switch (action) {
case Back:
qDebug() << "triggerAction Back";
break;
case Forward:
qDebug() << "triggerAction Forward";
break;
case Reload:
qDebug() << "triggerAction Reload";
break;
case OpenLinkInThisWindow:
qDebug() << "triggerAction OpenLinkInThisWindow";
break;
default:
break;
}
QWebEnginePage::triggerAction(action, checked);
}
#endif

bool QtWebEnginePage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame)
{
bool flag = QWebEnginePage::acceptNavigationRequest(url, type, isMainFrame);
if (type == QWebEnginePage::NavigationTypeLinkClicked){
emit onLinkClicked(url);
#ifdef _DEBUG
switch (type) {
case QWebEnginePage::NavigationTypeLinkClicked:
qDebug() << "acceptNavigationRequest" << "NavigationTypeLinkClicked" << url.toString();
break;
case QWebEnginePage::NavigationTypeTyped:
qDebug() << "acceptNavigationRequest" << "NavigationTypeTyped" << url.toString();
break;
case QWebEnginePage::NavigationTypeFormSubmitted:
qDebug() << "acceptNavigationRequest" << "NavigationTypeFormSubmitted" << url.toString();
break;
case QWebEnginePage::NavigationTypeBackForward:
qDebug() << "acceptNavigationRequest" << "NavigationTypeBackForward" << url.toString();
break;
case QWebEnginePage::NavigationTypeReload:
qDebug() << "acceptNavigationRequest" << "NavigationTypeReload" << url.toString();
break;
case QWebEnginePage::NavigationTypeOther:
qDebug() << "acceptNavigationRequest" << "NavigationTypeOther" << url.toString();
break;
default:
qDebug() << "acceptNavigationRequest" << url.toString();
break;
}
#endif

if (stopBeforeNavigationRequest && (type == QWebEnginePage::NavigationTypeLinkClicked || type == QWebEnginePage::NavigationTypeBackForward)){
QTimer::singleShot(1, this, [url, this](){
LOG(INFO) + "Request to url has been manualy reconfigured to loading link in webview";
webView->stop();
webView->load(url);
});
return false;
}
emit linkClicked();

bool flag = QWebEnginePage::acceptNavigationRequest(url, type, isMainFrame);
return flag;
}
17 changes: 9 additions & 8 deletions platform/shared/qt/rhodes/newVersion/QtWebEnginePage.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef QTWEBENGINEPAGE_H
#define QTWEBENGINEPAGE_H

#include "QtWebEngineView.h"
#include <QWebEnginePage>
#include <QString>
#include "logging/RhoLog.h"
Expand All @@ -10,15 +11,15 @@ class QtWebEnginePage : public QWebEnginePage
Q_OBJECT
DEFINE_LOGCLASS
public:
explicit QtWebEnginePage(QObject *parent = 0);

virtual void javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID);
explicit QtWebEnginePage(QtWebEngineView *webView);
#ifdef _DEBUG
void triggerAction(QWebEnginePage::WebAction action, bool checked = false) override;
#endif
protected:
bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame);
signals:
void linkClicked();
void onLinkClicked(QUrl);
public slots:
bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame) override;
void javaScriptConsoleMessage(QWebEnginePage::JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID) override;
QtWebEngineView *webView;
bool stopBeforeNavigationRequest = false;
};

#endif // QTWEBENGINEPAGE_H
7 changes: 6 additions & 1 deletion platform/shared/qt/rhodes/newVersion/QtWebEngineView.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#include "QtWebEngineView.h"

#include <QWebEngineSettings>

QtWebEngineView::QtWebEngineView(QWidget *parent) : QWebEngineView(parent)
{
#ifdef DISABLE_WEB_SECURITY
settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, true);
settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true);
settings()->setAttribute(QWebEngineSettings::LocalStorageEnabled, true);
#endif
connect(page(), SIGNAL(linkHovered(QString)), this, SLOT(linkHovered(QString)));
}

Expand Down
17 changes: 15 additions & 2 deletions platform/shared/qt/rhodes/newVersion/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ char* parseToken(const char* start)
const char* szValue = start + i+1;
int nValueLen = 0;

while (*szValue==' ' || *szValue=='\'' || *szValue=='"' && nValueLen >= 0) { szValue++; }
while ((*szValue==' ' || *szValue=='\'' || *szValue=='"') && nValueLen >= 0) { szValue++; }
while (szValue[nValueLen] && szValue[nValueLen] !='\'' && szValue[nValueLen] != '"') { nValueLen++; }

//while (nValueLen > 0 && (szValue[nValueLen-1]==' ' || szValue[nValueLen-1]=='\'' || szValue[nValueLen-1]=='"')) nValueLen--;
Expand All @@ -111,9 +111,22 @@ char* parseToken(const char* start)
return value;
}


int main(int argc, char *argv[])
{
{
#ifdef DISABLE_WEB_SECURITY
char ARG_DISABLE_WEB_SECURITY[] = "--disable-web-security";
int newArgc = argc + 1;
char** newArgv = new char*[newArgc];
for(int i = 0; i < argc; i++) {
newArgv[i] = argv[i];
}
newArgv[argc] = ARG_DISABLE_WEB_SECURITY;
QApplication app(newArgc, newArgv);
#else
QApplication app(argc, argv);
#endif

#ifdef RHODES_MAC_BUILD
qputenv("QTWEBENGINE_REMOTE_DEBUGGING", QString::number(QtMainWindow::getDebPort()).toLocal8Bit());
#endif
Expand Down