Heavily simplified (and I dare to say: speed up) the way the remote debugger harness is loaded and injected.

1.5
Ivan De Marino 2012-01-04 17:24:36 +00:00
parent e5cd882e6a
commit 1531595d2e
6 changed files with 26 additions and 46 deletions

View File

@ -1,8 +0,0 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script src="%1" type="text/javascript"></script>
</head>
<body>
</body>
</html>

View File

@ -1,12 +0,0 @@
// This is a wrapper for the script to be executed.
// When remote debugging, there's no way to reload the page
// to be able to run the script being debugged, because there's
// no user-facing way to interact with phantomjs.
// This provides a function wrapper around the script in order to
// make the whole script callable from the console on the remote debugger.
var __run = function() {
%1
};

View File

@ -1,7 +1,6 @@
<RCC>
<qresource prefix="/">
<file>debug_harness.html</file>
<file>debug_wrapper.js</file>
<file>remote_debugger_harness.html</file>
<file>phantomjs-icon.png</file>
<file>coffee-script.js</file>
<file>usage.txt</file>

View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<!--
This is a wrapper for the script to be executed.
When remote debugging, there's no way to reload the page
to be able to run the script being debugged, because there's
no user-facing way to interact with phantomjs.
This provides a function wrapper around the script in order to
make the whole script callable from the console on the remote debugger.
-->
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript">
var __run = function() {
%1
};
</script>
</head>
<body></body>
</html>

View File

@ -105,31 +105,12 @@ bool Utils::loadJSForDebug(const QString& jsFilePath, const QString& libraryPath
bool Utils::loadJSForDebug(const QString& jsFilePath, const Encoding& jsFileEnc, const QString& libraryPath, QWebFrame* targetFrame)
{
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()));
QString remoteDebuggerHarnessSrc = Utils::readResourceFileUtf8(":/remote_debugger_harness.html");
remoteDebuggerHarnessSrc = remoteDebuggerHarnessSrc.arg(scriptBody);
targetFrame->setHtml(remoteDebuggerHarnessSrc);
return true;
}

View File

@ -54,8 +54,8 @@ public:
static bool injectJsInFrame(const QString &jsFilePath, const Encoding &jsFileEnc, const QString &libraryPath, QWebFrame *targetFrame, const bool startingScript = false);
static QString readResourceFileUtf8(const QString &resourceFilePath);
static bool loadJSForDebug(const QString &jsFilePath, const Encoding &jsFileEnc, const QString &libraryPath, QWebFrame *targetFrame, const bool startingScript = false);
static bool loadJSForDebug(const QString &jsFilePath, const QString &libraryPath, QWebFrame *targetFrame, const bool startingScript = false);
static bool loadJSForDebug(const QString &jsFilePath, const Encoding &jsFileEnc, const QString &libraryPath, QWebFrame *targetFrame);
static bool loadJSForDebug(const QString &jsFilePath, const QString &libraryPath, QWebFrame *targetFrame);
static void cleanupFromDebug();
private:
static QString findScript(const QString &jsFilePath, const QString& libraryPath);