Esempio n. 1
0
QWebEngineScript GM_Script::webScript() const
{
    QWebEngineScript::InjectionPoint injectionPoint;
    switch (startAt()) {
    case DocumentStart:
        injectionPoint = QWebEngineScript::DocumentCreation;
        break;
    case DocumentEnd:
        injectionPoint = QWebEngineScript::DocumentReady;
        break;
    case DocumentIdle:
        injectionPoint = QWebEngineScript::Deferred;
        break;
    default:
        Q_UNREACHABLE();
    }

    QWebEngineScript script;
    script.setName(fullName());
    script.setWorldId(QWebEngineScript::MainWorld);
    script.setInjectionPoint(injectionPoint);
    script.setRunsOnSubFrames(!m_noframes);
    script.setSourceCode(QSL("%1\n%2").arg(m_manager->bootstrapScript(), m_script));
    return script;
}
Esempio n. 2
0
void AutoScrollPlugin::updateScript()
{
    const QString name = QSL("_qupzilla_autoscroll");

    QWebEngineScript oldScript = mApp->webProfile()->scripts()->findScript(name);
    if (!oldScript.isNull()) {
        mApp->webProfile()->scripts()->remove(oldScript);
    }

    QWebEngineScript script;
    script.setName(name);
    script.setInjectionPoint(QWebEngineScript::DocumentCreation);
    script.setWorldId(QWebEngineScript::ApplicationWorld);
    script.setRunsOnSubFrames(false);

    QSettings settings(m_settingsPath + QL1S("/extensions.ini"), QSettings::IniFormat);
    settings.beginGroup(QSL("AutoScroll"));

    QString source = QzTools::readAllFileContents(QSL(":/autoscroll/data/autoscroll.js"));
    source.replace(QSL("%MOVE_SPEED%"), settings.value(QSL("Speed"), 5).toString());
    source.replace(QSL("%CTRL_CLICK%"), settings.value(QSL("CtrlClick"), true).toString());
    source.replace(QSL("%MIDDLE_CLICK%"), settings.value(QSL("MiddleClick"), true).toString());
    source.replace(QSL("%IMG_ALL%"), QzTools::pixmapToByteArray(QPixmap(QSL(":/autoscroll/data/scroll_all.png"))));
    source.replace(QSL("%IMG_HORIZONTAL%"), QzTools::pixmapToByteArray(QPixmap(QSL(":/autoscroll/data/scroll_horizontal.png"))));
    source.replace(QSL("%IMG_VERTICAL%"), QzTools::pixmapToByteArray(QPixmap(QSL(":/autoscroll/data/scroll_vertical.png"))));

    script.setSourceCode(source);

    mApp->webProfile()->scripts()->insert(script);
}
Esempio n. 3
0
NetworkAccessManager::NetworkAccessManager(QString id)
    : QNetworkAccessManager(0)
    , m_Id(id)
    , m_UserAgent(QString())
    , m_SslProtocol(QSsl::UnknownProtocol)
#ifdef WEBENGINEVIEW
    , m_Profile(new QWebEngineProfile(id))
#endif
{
#ifdef WEBENGINEVIEW
    if(Application::SaveSessionCookie())
        m_Profile->setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies);
    else
        m_Profile->setPersistentCookiesPolicy(QWebEngineProfile::AllowPersistentCookies);

    m_Profile->setHttpAcceptLanguage(Application::GetAcceptLanguage());
#endif

#if defined(USE_WEBCHANNEL) || defined(PASSWORD_MANAGER) || QT_VERSION >= 0x050900
    static QString source;
    if(source.isEmpty()){
        QString inner;

#  ifdef USE_WEBCHANNEL
        inner += View::InstallWebChannelJsCode();
#  endif
#  ifdef PASSWORD_MANAGER
        inner += View::InstallSubmitEventJsCode();
#  endif
#  if defined WEBENGINEVIEW && QT_VERSION >= 0x050900
        static const QList<QEvent::Type> types =
            QList<QEvent::Type>() << QEvent::KeyPress << QEvent::KeyRelease;
        inner += View::InstallEventFilterJsCode(types);
#  endif
        source = QStringLiteral
            ("(function(){\n"
             "%1\n"
             "})();").arg(inner);
    }
#  ifdef WEBENGINEVIEW
    QWebEngineScript script;
    script.setInjectionPoint(QWebEngineScript::DocumentReady);
    script.setWorldId(QWebEngineScript::MainWorld);
    script.setRunsOnSubFrames(true);
    script.setSourceCode(source);
    m_Profile->scripts()->insert(script);
#  endif
#endif

#ifdef WEBENGINEVIEW
    connect(m_Profile, &QWebEngineProfile::downloadRequested,
            this, &NetworkAccessManager::HandleDownload);
#endif
    connect(this, &NetworkAccessManager::authenticationRequired,
            this, &NetworkAccessManager::HandleAuthentication);
#ifndef QT_NO_NETWORKPROXY
    connect(this, &NetworkAccessManager::proxyAuthenticationRequired,
            this, &NetworkAccessManager::HandleProxyAuthentication);
#endif
}
Esempio n. 4
0
QWebEngineProfile* createWebEngineProfile(const WizWebEngineViewInjectObjects& objects, QObject* parent)
{
    if (objects.empty())
        return nullptr;
    //
    QWebEngineProfile *profile = new QWebEngineProfile("WizNoteWebEngineProfile", parent);
    //
    QString jsWebChannelFileName = Utils::WizPathResolve::resourcesPath() + "files/webengine/wizwebchannel.js";
    QString jsWebChannel;
    WizLoadUnicodeTextFromFile(jsWebChannelFileName, jsWebChannel);
    //
    QString initFileName = Utils::WizPathResolve::resourcesPath() + "files/webengine/wizwebengineviewinit.js";
    QString jsInit;
    WizLoadUnicodeTextFromFile(initFileName, jsInit);
    //
    CWizStdStringArray names;
    for (auto inject : objects) {
        names.push_back("\"" + inject.name + "\"");
    }
    //
    CString objectNames;
    WizStringArrayToText(names, objectNames, ", ");
    //
    jsInit.replace("__objectNames__", objectNames);
    //
    QString jsAll = jsWebChannel + "\n" + jsInit;
    //
    {
        QWebEngineScript script;
        script.setSourceCode(jsAll);
        script.setName("qwebchannel.js");
        script.setWorldId(QWebEngineScript::MainWorld);
        script.setInjectionPoint(QWebEngineScript::DocumentCreation);
        script.setRunsOnSubFrames(true);
        profile->scripts()->insert(script);
    }
    //
    return profile;
}
Esempio n. 5
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;
}