Ejemplo n.º 1
0
void ResultsJsInterface::resultsPageLoaded(bool success)
{
	// clear history, to prevent backspace from going 'back'
	_webViewResults->history()->clear();

	if (success)
	{
		QString version = tq(AppInfo::version.asString());

#ifdef JASP_DEBUG
		version+="-Debug";
#endif

		runJavaScript("window.setAppVersion('" + version + "')");

		setGlobalJsValues();

		runJavaScript("window.getPPI()", std::bind(&ResultsJsInterface::cbSetPPI, this, std::placeholders::_1));
	}
	else
	{
		std::cout << "Could not load result page!" << std::endl;
		std::cout.flush();
	}
}
Ejemplo n.º 2
0
void QtWebEnginePage::handlePageLoaded(const QString &result)
{
	QString string(url().toString());
	string.truncate(1000);

	const QRegularExpressionMatch match = QRegularExpression(QStringLiteral(">(<img style=\"-webkit-user-select: none;(?: cursor: zoom-in;)?\"|<video controls=\"\" autoplay=\"\" name=\"media\"><source) src=\"%1").arg(QRegularExpression::escape(string))).match(result);
	const bool isViewingMedia = match.hasMatch();

	if (isViewingMedia && match.captured().startsWith(QLatin1String("><img")))
	{
		settings()->setAttribute(QWebEngineSettings::AutoLoadImages, true);
		settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, true);

		QFile file(QLatin1String(":/modules/backends/web/qtwebengine/resources/imageViewer.js"));
		file.open(QIODevice::ReadOnly);

		runJavaScript(file.readAll());

		file.close();
	}

	if (isViewingMedia != m_isViewingMedia)
	{
		m_isViewingMedia = isViewingMedia;

		emit viewingMediaChanged(m_isViewingMedia);
	}
}
Ejemplo n.º 3
0
void ResultsJsInterface::setFixDecimalsHandler(QString numDecimals)
{
	if (numDecimals == "")
		numDecimals = "\"\"";
	QString js = "window.globSet.decimals = " + numDecimals + "; window.reRenderAnalyses();";
	runJavaScript(js);
}
Ejemplo n.º 4
0
void ResultsJsInterface::setExactPValuesHandler(bool exact)
{
	QString exactPValueString = (exact ? "true" : "false");
	QString js = "window.globSet.pExact = " + exactPValueString;
	js += "; window.reRenderAnalyses();";
	runJavaScript(js);
}
Ejemplo n.º 5
0
void ResultsJsInterface::noteSelected()
{
	QAction *action = (QAction *)this->sender();
	QString call = action->data().toString();

	runJavaScript(call);

	_mainWindow->setPackageModified();
}
Ejemplo n.º 6
0
void ResultsJsInterface::analysisChanged(Analysis *analysis)
{
	Json::Value analysisJson = analysis->asJSON();
	analysisJson["userdata"] = analysis->userData();
	QString results = tq(analysisJson.toStyledString());

	results = escapeJavascriptString(results);
	results = "window.analysisChanged(JSON.parse('" + results + "'));";
	runJavaScript(results);
}
Ejemplo n.º 7
0
void ResultsJsInterface::analysisImageEditedHandler(Analysis *analysis)
{
	Json::Value imgJson = analysis->getImgResults();
	QString	results = tq(imgJson.toStyledString());
	results = escapeJavascriptString(results);
	results = "window.modifySelectedImage(" + QString::number(analysis->id()) + ", JSON.parse('" + results + "'));";
	runJavaScript(results);

    return;
}
Ejemplo n.º 8
0
Json::Value &ResultsJsInterface::getResultsMeta()
{
	QEventLoop loop;

	runJavaScript("window.getResultsMeta()", std::bind(&ResultsJsInterface::cbSetResultstMeta, this, std::placeholders::_1));
	connect(this, SIGNAL(getResultsMetaCompleted()), &loop, SLOT(quit()));
	loop.exec();

	return _resultsMeta;
}
Ejemplo n.º 9
0
QVariant &ResultsJsInterface::getAllUserData()
{
	QEventLoop loop;

	runJavaScript("window.getAllUserData()", std::bind(&ResultsJsInterface::cbSetAllUserData, this, std::placeholders::_1));
	connect(this, SIGNAL(getAllUserDataCompleted()), &loop, SLOT(quit()));
	loop.exec();

	return _allUserData;
}
Ejemplo n.º 10
0
void ResultsJsInterface::getImageInBase64(int id, const QString &path)
{
	QString fullPath = tq(tempfiles_sessionDirName()) + "/" + path;
	QFile *file = new QFile(fullPath);
	file->open(QIODevice::ReadOnly);
	QByteArray image = file->readAll();
	QString result = QString(image.toBase64());

	QString eval = QString("window.convertToBase64Done({ id: %1, result: '%2'});").arg(id).arg(result);
	runJavaScript(eval);

}
Ejemplo n.º 11
0
void ResultsJsInterface::setGlobalJsValues()
{
	bool exactPValues = Settings::value(Settings::EXACT_PVALUES).toBool();
	QString exactPValueString = (exactPValues ? "true" : "false");
	QString numDecimals = Settings::value(Settings::NUM_DECIMALS).toString();
	QString tempFolder = "file:///" + tq(tempfiles_sessionDirName());

	QString js = "window.globSet.pExact = " + exactPValueString;
	js += "; window.globSet.decimals = " + (numDecimals.isEmpty() ? "\"\"" : numDecimals);
	js += "; window.globSet.tempFolder = \"" + tempFolder + "/\"";
	runJavaScript(js);
}
Ejemplo n.º 12
0
void ResultsJsInterface::saveTempImage(int id, QString path, QByteArray data)
{
	QByteArray byteArray = QByteArray::fromBase64(data);

	QString fullpath = tq(tempfiles_createSpecific_clipboard(fq(path)));

	QFile file(fullpath);
	file.open(QIODevice::WriteOnly);
	file.write(byteArray);
	file.close();

	QString eval = QString("window.imageSaved({ id: %1, fullPath: '%2'});").arg(id).arg(fullpath);
	runJavaScript(eval);
}
Ejemplo n.º 13
0
void JsExprNode::processMessage(const char *inlet, const Message &message)
{
    if (! utils::stringsMatch(inlet, INPUT_INLET))
        return;
    std::string script = this->getAttributeValue(SCRIPT_ATTR).getString(0);

    Message result;
    if (runJavaScript(script.c_str(), message, result))
    {
        if (Logger::isEnabledFor(INFO))
        {
            std::ostringstream os;
            os << "[expr]: " << script << " " << " == " <<  result;
            Logger::log(INFO, os);
        }
        output(OUTPUT_OUTLET, result);
    }
}
Ejemplo n.º 14
0
QVariant WebPage::execJavaScript(const QString &scriptSource, int timeout)
{
    QPointer<QEventLoop> loop = new QEventLoop;
    QVariant result;
    QTimer::singleShot(timeout, loop.data(), &QEventLoop::quit);

    runJavaScript(scriptSource, [loop, &result](const QVariant &res) {
        if (loop && loop->isRunning()) {
            result = res;
            loop->quit();
        }
    });

    loop->exec();
    delete loop;

    return result;
}
Ejemplo n.º 15
0
QVariant WebPage::execJavaScript(const QString &scriptSource, quint32 worldId, int timeout)
{
    QPointer<QEventLoop> loop = new QEventLoop;
    QVariant result;
    QTimer::singleShot(timeout, loop.data(), &QEventLoop::quit);

#if QT_VERSION >= QT_VERSION_CHECK(5,7,0)
    runJavaScript(scriptSource, worldId, [loop, &result](const QVariant &res) {
#else
    Q_UNUSED(worldId);
    runJavaScript(scriptSource, [loop, &result](const QVariant &res) {
#endif
        if (loop && loop->isRunning()) {
            result = res;
            loop->quit();
        }
    });

    loop->exec();
    delete loop;

    return result;
}

void WebPage::runJavaScript(const QString &scriptSource)
{
    return QWebEnginePage::runJavaScript(scriptSource);
}

void WebPage::runJavaScript(const QString &scriptSource, const QWebEngineCallback<const QVariant &> &resultCallback)
{
    return QWebEnginePage::runJavaScript(scriptSource, resultCallback);
}

void WebPage::runJavaScript(const QString &scriptSource, quint32 worldId)
{
#if QT_VERSION >= QT_VERSION_CHECK(5,7,0)
    QWebEnginePage::runJavaScript(scriptSource, worldId);
#else
    Q_UNUSED(worldId);
    QWebEnginePage::runJavaScript(scriptSource);
#endif
}
    void WebPage::clean_forms()
    {
        file_selector.clear();

        int policy_i = mainwindow->select_correct_policy();
        int display_i = mainwindow->select_correct_display();
        int verbosity_i = mainwindow->select_correct_verbosity();

        runJavaScript(QString("document.getElementById('checkerUpload_policy').value = %1;").arg(policy_i));
        runJavaScript(QString("document.getElementById('checkerUpload_display_selector').value = %1;").arg(display_i));
        runJavaScript(QString("document.getElementById('checkerUpload_verbosity_selector').value = %1;").arg(verbosity_i));
        runJavaScript("document.getElementById('checkerUpload_file').value = \"\";");

#if defined(MEDIAINFO_LIBCURL_YES)

        runJavaScript(QString("document.getElementById('checkerOnline_policy').value = %1;").arg(policy_i));
        runJavaScript(QString("document.getElementById('checkerOnline_display_selector').value = %1;").arg(display_i));
        runJavaScript(QString("document.getElementById('checkerOnline_verbosity_selector').value = %1;").arg(verbosity_i));
        runJavaScript("document.getElementById('checkerOnline_file').value = \"\";");

#endif

        runJavaScript(QString("document.getElementById('checkerRepository_policy').value = %1;").arg(policy_i));
        runJavaScript(QString("document.getElementById('checkerRepository_display_selector').value = %1;").arg(display_i));
        runJavaScript(QString("document.getElementById('checkerRepository_verbosity_selector').value = %1;").arg(verbosity_i));
        runJavaScript("document.getElementById('checkerRepository_directory').value = \"\";");
    }
Ejemplo n.º 17
0
void QtWebEnginePage::handlePageLoaded(const QString &result)
{
	if (m_widget)
	{
		const QVector<int> profiles(ContentBlockingManager::getProfileList(m_widget->getOption(QLatin1String("Content/BlockingProfiles"), url()).toStringList()));

		if (!profiles.isEmpty())
		{
			const QStringList domainList(ContentBlockingManager::createSubdomainList(url().host()));
			QStringList styleSheetBlackList(ContentBlockingManager::getStyleSheet(profiles));
			QStringList styleSheetWhiteList;

			for (int i = 0; i < domainList.count(); ++i)
			{
				styleSheetBlackList += ContentBlockingManager::getStyleSheetBlackList(domainList.at(i), profiles);
				styleSheetWhiteList += ContentBlockingManager::getStyleSheetWhiteList(domainList.at(i), profiles);
			}

			QFile file(QLatin1String(":/modules/backends/web/qtwebengine/resources/hideElements.js"));

			if (file.open(QIODevice::ReadOnly))
			{
				runJavaScript(QString(file.readAll()).arg(createJavaScriptList(styleSheetWhiteList)).arg(createJavaScriptList(styleSheetBlackList)));

				file.close();
			}
		}

		const QStringList blockedRequests(qobject_cast<QtWebEngineWebBackend*>(m_widget->getBackend())->getBlockedElements(url().host()));

		if (!blockedRequests.isEmpty())
		{
			QFile file(QLatin1String(":/modules/backends/web/qtwebengine/resources/hideBlockedRequests.js"));

			if (file.open(QIODevice::ReadOnly))
			{
				runJavaScript(QString(file.readAll()).arg(createJavaScriptList(blockedRequests)));

				file.close();
			}
		}
	}

	QString string(url().toString());
	string.truncate(1000);

	const QRegularExpressionMatch match(QRegularExpression(QStringLiteral(">(<img style=\"-webkit-user-select: none;(?: cursor: zoom-in;)?\"|<video controls=\"\" autoplay=\"\" name=\"media\"><source) src=\"%1").arg(QRegularExpression::escape(string))).match(result));
	const bool isViewingMedia(match.hasMatch());

	if (isViewingMedia && match.captured().startsWith(QLatin1String("><img")))
	{
		settings()->setAttribute(QWebEngineSettings::AutoLoadImages, true);
		settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, true);

		QFile file(QLatin1String(":/modules/backends/web/qtwebengine/resources/imageViewer.js"));
		file.open(QIODevice::ReadOnly);

		runJavaScript(file.readAll());

		file.close();
	}

	if (isViewingMedia != m_isViewingMedia)
	{
		m_isViewingMedia = isViewingMedia;

		emit viewingMediaChanged(m_isViewingMedia);
	}
}
Ejemplo n.º 18
0
bool QtWebEnginePage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame)
{
	if (m_isPopup)
	{
		emit aboutToNavigate(url, type);

		return false;
	}

	if (isMainFrame && url.scheme() == QLatin1String("javascript"))
	{
		runJavaScript(url.path());

		return false;
	}

	if (url.scheme() == QLatin1String("mailto"))
	{
		QDesktopServices::openUrl(url);

		return false;
	}

	if (isMainFrame && type == QWebEnginePage::NavigationTypeReload && m_previousNavigationType == QWebEnginePage::NavigationTypeFormSubmitted && SettingsManager::getValue(QLatin1String("Choices/WarnFormResend")).toBool())
	{
		bool cancel(false);
		bool warn(true);

		if (m_widget)
		{
			ContentsDialog dialog(ThemesManager::getIcon(QLatin1String("dialog-warning")), tr("Question"), tr("Are you sure that you want to send form data again?"), tr("Do you want to resend data?"), (QDialogButtonBox::Yes | QDialogButtonBox::Cancel), NULL, m_widget);
			dialog.setCheckBox(tr("Do not show this message again"), false);

			connect(m_widget, SIGNAL(aboutToReload()), &dialog, SLOT(close()));

			m_widget->showDialog(&dialog);

			cancel = !dialog.isAccepted();
			warn = !dialog.getCheckBoxState();
		}
		else
		{
			QMessageBox dialog;
			dialog.setWindowTitle(tr("Question"));
			dialog.setText(tr("Are you sure that you want to send form data again?"));
			dialog.setInformativeText(tr("Do you want to resend data?"));
			dialog.setIcon(QMessageBox::Question);
			dialog.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
			dialog.setDefaultButton(QMessageBox::Cancel);
			dialog.setCheckBox(new QCheckBox(tr("Do not show this message again")));

			cancel = (dialog.exec() == QMessageBox::Cancel);
			warn = !dialog.checkBox()->isChecked();
		}

		SettingsManager::setValue(QLatin1String("Choices/WarnFormResend"), warn);

		if (cancel)
		{
			return false;
		}
	}

	if (isMainFrame && type != QWebEnginePage::NavigationTypeReload)
	{
		m_previousNavigationType = type;
	}

	if (isMainFrame)
	{
		scripts().clear();

		const QList<UserScript*> scripts(AddonsManager::getUserScriptsForUrl(url));

		for (int i = 0; i < scripts.count(); ++i)
		{
			QWebEngineScript::InjectionPoint injectionPoint(QWebEngineScript::DocumentReady);

			if (scripts.at(i)->getInjectionTime() == UserScript::DocumentCreationTime)
			{
				injectionPoint = QWebEngineScript::DocumentCreation;
			}
			else if (scripts.at(i)->getInjectionTime() == UserScript::DeferredTime)
			{
				injectionPoint = QWebEngineScript::Deferred;
			}

			QWebEngineScript script;
			script.setSourceCode(scripts.at(i)->getSource());
			script.setRunsOnSubFrames(scripts.at(i)->shouldRunOnSubFrames());
			script.setInjectionPoint(injectionPoint);

			this->scripts().insert(script);
		}

		emit aboutToNavigate(url, type);
	}

	return true;
}
Ejemplo n.º 19
0
void ResultsJsInterface::exportSelected(const QString &filename)
{
	runJavaScript("window.exportHTML('" + filename + "');");
}
Ejemplo n.º 20
0
bool QtWebEnginePage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame)
{
	if (isMainFrame && url.scheme() == QLatin1String("javascript"))
	{
		runJavaScript(url.path());

		return false;
	}

	if (url.scheme() == QLatin1String("mailto"))
	{
		QDesktopServices::openUrl(url);

		return false;
	}

	if (isMainFrame && type == QWebEnginePage::NavigationTypeReload && m_previousNavigationType == QWebEnginePage::NavigationTypeFormSubmitted && SettingsManager::getValue(QLatin1String("Choices/WarnFormResend")).toBool())
	{
		bool cancel = false;
		bool warn = true;

		if (m_widget)
		{
			ContentsDialog dialog(Utils::getIcon(QLatin1String("dialog-warning")), tr("Question"), tr("Are you sure that you want to send form data again?"), tr("Do you want to resend data?"), (QDialogButtonBox::Yes | QDialogButtonBox::Cancel), NULL, m_widget);
			dialog.setCheckBox(tr("Do not show this message again"), false);

			connect(m_widget, SIGNAL(aboutToReload()), &dialog, SLOT(close()));

			m_widget->showDialog(&dialog);

			cancel = !dialog.isAccepted();
			warn = !dialog.getCheckBoxState();
		}
		else
		{
			QMessageBox dialog;
			dialog.setWindowTitle(tr("Question"));
			dialog.setText(tr("Are you sure that you want to send form data again?"));
			dialog.setInformativeText(tr("Do you want to resend data?"));
			dialog.setIcon(QMessageBox::Question);
			dialog.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
			dialog.setDefaultButton(QMessageBox::Cancel);
			dialog.setCheckBox(new QCheckBox(tr("Do not show this message again")));

			cancel = (dialog.exec() == QMessageBox::Cancel);
			warn = !dialog.checkBox()->isChecked();
		}

		SettingsManager::setValue(QLatin1String("Choices/WarnFormResend"), warn);

		if (cancel)
		{
			return false;
		}
	}

	if (isMainFrame && type != QWebEnginePage::NavigationTypeReload)
	{
		m_previousNavigationType = type;
	}

	return true;
}
Ejemplo n.º 21
0
void Application::handleResume()
{
    runJavaScript("cordova.fireDocumentEvent('resume');");
}
Ejemplo n.º 22
0
void ResultsJsInterface::unselect()
{
	runJavaScript("window.unselect()");
}
Ejemplo n.º 23
0
void ResultsJsInterface::setResultsMeta(QString str)
{
	QString results = escapeJavascriptString(str);
	results = "window.setResultsMeta(JSON.parse('" + results + "'));";
	runJavaScript(results);
}
Ejemplo n.º 24
0
void ResultsJsInterface::exportHTML()
{
	runJavaScript("window.exportHTML('%EXPORT%');");
}
Ejemplo n.º 25
0
void ResultsJsInterface::exportPreviewHTML()
{
	runJavaScript("window.exportHTML('%PREVIEW%');");
}
Ejemplo n.º 26
0
void ResultsJsInterface::showInstruction()
{
	runJavaScript("window.showInstructions()");
}
Ejemplo n.º 27
0
void ResultsJsInterface::setZoom(double zoom)
{
	_webViewZoom = zoom;
	QString js = "window.setZoom(" + QString::number(zoom) + ")";
	runJavaScript(js);
}
 void WebPage::use_javascript(const QString& js)
 {
     runJavaScript(js);
 }
Ejemplo n.º 29
0
void Application::handlePause()
{
    runJavaScript("cordova.fireDocumentEvent('pause');");
}
Ejemplo n.º 30
0
void ResultsJsInterface::removeAnalysis(Analysis *analysis)
{
	runJavaScript("window.remove(" % QString::number(analysis->id()) % ")");
}