Пример #1
0
bool Utils::loadJSForDebug(const QString& jsFilePath, const Encoding& jsFileEnc, const QString& libraryPath, QWebFrame* targetFrame, const bool startingScript)
{

    QString scriptPath = findScript(jsFilePath, libraryPath);
    QString scriptBody = jsFromScriptFile(scriptPath, jsFileEnc);

    QFile wrapper(":/debug_wrapper.js");
    if (!wrapper.open(QIODevice::ReadOnly))
        return false; // We got big issues
    QString jsWrapper = QString::fromUtf8(wrapper.readAll());
    jsWrapper = jsWrapper.arg(scriptBody);
    m_tempWrapper = new QTemporaryFile(QDir::tempPath() + "/debugwrapper_XXXXXX.js");
    m_tempWrapper->open();
    m_tempWrapper->write(jsWrapper.toUtf8());
    m_tempWrapper->close();

    QFile f(":/debug_harness.html");
    if (!f.open(QIODevice::ReadOnly))
        return false;
    QString html = QString::fromUtf8(f.readAll());

    html = html.arg(m_tempWrapper->fileName());
    m_tempHarness = new QTemporaryFile(QDir::tempPath() + "/debugharness_XXXXXX.html");
    m_tempHarness->open();
    m_tempHarness->write(html.toLocal8Bit());
    m_tempHarness->close();
    targetFrame->load(QUrl::fromLocalFile(m_tempHarness->fileName()));
    return true;
}
Пример #2
0
bool loadJSForDebug(const QString& jsFilePath, const QString& jsFileLanguage, const Encoding& jsFileEnc, const QString& libraryPath, QWebFrame* targetFrame, const bool autorun)
{
    QString scriptPath = findScript(jsFilePath, libraryPath);
    QString scriptBody = jsFromScriptFile(scriptPath, jsFileLanguage, jsFileEnc);

    scriptBody = QString("function __run() {\n%1\n}").arg(scriptBody);
    targetFrame->evaluateJavaScript(scriptBody);

    if (autorun) {
        targetFrame->evaluateJavaScript("__run()", QString());
    }

    return true;
}
Пример #3
0
bool Utils::loadJSForDebug(const QString& jsFilePath, const Encoding& jsFileEnc, const QString& libraryPath, QWebFrame* targetFrame, const bool autorun)
{
    QString scriptPath = findScript(jsFilePath, libraryPath);
    QString scriptBody = jsFromScriptFile(scriptPath, jsFileEnc);

    QString remoteDebuggerHarnessSrc =  Utils::readResourceFileUtf8(":/remote_debugger_harness.html");
    remoteDebuggerHarnessSrc = remoteDebuggerHarnessSrc.arg(scriptBody);
    targetFrame->setHtml(remoteDebuggerHarnessSrc);

    if (autorun) {
        targetFrame->evaluateJavaScript("__run()", QString());
    }

    return true;
}
Пример #4
0
bool injectJsInFrame(const QString& jsFilePath, const QString& jsFileLanguage, const Encoding& jsFileEnc, const QString& libraryPath, QWebFrame* targetFrame, const bool startingScript)
{
    // Don't do anything if an empty string is passed
    QString scriptPath = findScript(jsFilePath, libraryPath);
    QString scriptBody = jsFromScriptFile(scriptPath, jsFileLanguage, jsFileEnc);
    if (scriptBody.isEmpty()) {
        if (startingScript) {
            Terminal::instance()->cerr(QString("Can't open '%1'").arg(jsFilePath));
        } else {
            qWarning("Can't open '%s'", qPrintable(jsFilePath));
        }
        return false;
    }
    // Execute JS code in the context of the document
    targetFrame->evaluateJavaScript(scriptBody, jsFilePath);
    return true;
}