diff --git a/src/config.cpp b/src/config.cpp index 5ca0af7d1d..443923a101 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -388,20 +388,6 @@ void Config::setScriptEncoding(const QString& value) m_scriptEncoding = value; } -QString Config::scriptLanguage() const -{ - return m_scriptLanguage; -} - -void Config::setScriptLanguage(const QString& value) -{ - if (value.isEmpty()) { - return; - } - - m_scriptLanguage = value; -} - QString Config::scriptFile() const { return m_scriptFile; @@ -516,7 +502,6 @@ void Config::resetToDefaults() m_proxyAuthPass.clear(); m_scriptArgs.clear(); m_scriptEncoding = "UTF-8"; - m_scriptLanguage.clear(); m_scriptFile.clear(); m_unknownOption.clear(); m_versionFlag = false; @@ -706,10 +691,6 @@ void Config::handleOption(const QString& option, const QVariant& value) setScriptEncoding(value.toString()); } - if (option == "script-language") { - setScriptLanguage(value.toString()); - } - if (option == "web-security") { setWebSecurityEnabled(boolValue); } diff --git a/src/config.h b/src/config.h index 9fe063c5c2..eb15beea50 100644 --- a/src/config.h +++ b/src/config.h @@ -137,9 +137,6 @@ class Config: public QObject QString scriptEncoding() const; void setScriptEncoding(const QString& value); - QString scriptLanguage() const; - void setScriptLanguage(const QString& value); - QString scriptFile() const; void setScriptFile(const QString& value); diff --git a/src/phantom.cpp b/src/phantom.cpp index 170f66cbf4..2a614f40c1 100644 --- a/src/phantom.cpp +++ b/src/phantom.cpp @@ -208,15 +208,6 @@ bool Phantom::execute() if (m_config.scriptFile().isEmpty()) { // REPL mode requested qDebug() << "Phantom - execute: Starting REPL mode"; - // REPL is only valid for javascript - const QString& scriptLanguage = m_config.scriptLanguage(); - if (scriptLanguage != "javascript" && !scriptLanguage.isNull()) { - QString errMessage = QString("Unsupported language: %1").arg(scriptLanguage); - Terminal::instance()->cerr(errMessage); - qWarning("%s", qPrintable(errMessage)); - return false; - } - // Create the REPL: it will launch itself, no need to store this variable. REPL::getInstance(m_page->mainFrame(), this); } else { // Load the User Script @@ -229,12 +220,12 @@ bool Phantom::execute() if (m_config.remoteDebugPort() == 0) { qWarning() << "Can't bind remote debugging server to the port" << originalPort; } - if (!Utils::loadJSForDebug(m_config.scriptFile(), m_config.scriptLanguage(), m_scriptFileEnc, QDir::currentPath(), m_page->mainFrame(), m_config.remoteDebugAutorun())) { + if (!Utils::loadJSForDebug(m_config.scriptFile(), m_scriptFileEnc, QDir::currentPath(), m_page->mainFrame(), m_config.remoteDebugAutorun())) { m_returnValue = -1; return false; } } else { - if (!Utils::injectJsInFrame(m_config.scriptFile(), m_config.scriptLanguage(), m_scriptFileEnc, QDir::currentPath(), m_page->mainFrame(), true)) { + if (!Utils::injectJsInFrame(m_config.scriptFile(), m_scriptFileEnc, QDir::currentPath(), m_page->mainFrame(), true)) { m_returnValue = -1; return false; } @@ -391,7 +382,7 @@ bool Phantom::injectJs(const QString& jsFilePath) return false; } - return Utils::injectJsInFrame(pre + jsFilePath, libraryPath(), m_page->mainFrame()); + return Utils::injectJsInFrame(pre + jsFilePath, Encoding::UTF8, libraryPath(), m_page->mainFrame()); } void Phantom::setProxy(const QString& ip, const qint64& port, const QString& proxyType, const QString& user, const QString& password) diff --git a/src/utils.cpp b/src/utils.cpp index 9970e1cc07..543bfb4cff 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -55,7 +55,7 @@ static QString findScript(const QString& jsFilePath, const QString& libraryPath) return QString(); } -static QString jsFromScriptFile(const QString& scriptPath, const QString& scriptLanguage, const Encoding& enc) +static QString jsFromScriptFile(const QString& scriptPath, const Encoding& enc) { QFile jsFile(scriptPath); if (jsFile.exists() && jsFile.open(QFile::ReadOnly)) { @@ -69,14 +69,6 @@ static QString jsFromScriptFile(const QString& scriptPath, const QString& script scriptBody.remove(0, len); } - // If a language is specified and is not "javascript", reject it. - if (scriptLanguage != "javascript" && !scriptLanguage.isNull()) { - QString errMessage = QString("Unsupported language: %1").arg(scriptLanguage); - Terminal::instance()->cerr(errMessage); - qWarning("%s", qPrintable(errMessage)); - return QString(); - } - return scriptBody; } else { return QString(); @@ -113,16 +105,11 @@ void messageHandler(QtMsgType type, const QMessageLogContext& context, const QSt } } -bool injectJsInFrame(const QString& jsFilePath, const QString& libraryPath, QWebFrame* targetFrame, const bool startingScript) -{ - return injectJsInFrame(jsFilePath, QString(), Encoding::UTF8, libraryPath, targetFrame, startingScript); -} - -bool injectJsInFrame(const QString& jsFilePath, const QString& jsFileLanguage, const Encoding& jsFileEnc, const QString& libraryPath, QWebFrame* targetFrame, const bool startingScript) +bool injectJsInFrame(const QString& jsFilePath, 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); + QString scriptBody = jsFromScriptFile(scriptPath, jsFileEnc); if (scriptBody.isEmpty()) { if (startingScript) { Terminal::instance()->cerr(QString("Can't open '%1'").arg(jsFilePath)); @@ -136,15 +123,10 @@ bool injectJsInFrame(const QString& jsFilePath, const QString& jsFileLanguage, c return true; } -bool loadJSForDebug(const QString& jsFilePath, const QString& libraryPath, QWebFrame* targetFrame, const bool autorun) -{ - return loadJSForDebug(jsFilePath, QString(), Encoding::UTF8, libraryPath, targetFrame, autorun); -} - -bool loadJSForDebug(const QString& jsFilePath, const QString& jsFileLanguage, const Encoding& jsFileEnc, const QString& libraryPath, QWebFrame* targetFrame, const bool autorun) +bool loadJSForDebug(const QString& jsFilePath, const Encoding& jsFileEnc, const QString& libraryPath, QWebFrame* targetFrame, const bool autorun) { QString scriptPath = findScript(jsFilePath, libraryPath); - QString scriptBody = jsFromScriptFile(scriptPath, jsFileLanguage, jsFileEnc); + QString scriptBody = jsFromScriptFile(scriptPath, jsFileEnc); scriptBody = QString("function __run() {\n%1\n}").arg(scriptBody); targetFrame->evaluateJavaScript(scriptBody); diff --git a/src/utils.h b/src/utils.h index a4c3d14feb..251c6c17b7 100644 --- a/src/utils.h +++ b/src/utils.h @@ -49,24 +49,12 @@ void messageHandler(QtMsgType type, extern bool printDebugMessages; bool injectJsInFrame(const QString& jsFilePath, - const QString& libraryPath, - QWebFrame* targetFrame, - const bool startingScript = false); - -bool injectJsInFrame(const QString& jsFilePath, - const QString& jsFileLanguage, const Encoding& jsFileEnc, const QString& libraryPath, QWebFrame* targetFrame, const bool startingScript = false); bool loadJSForDebug(const QString& jsFilePath, - const QString& libraryPath, - QWebFrame* targetFrame, - const bool autorun = false); - -bool loadJSForDebug(const QString& jsFilePath, - const QString& jsFileLanguage, const Encoding& jsFileEnc, const QString& libraryPath, QWebFrame* targetFrame, diff --git a/src/webpage.cpp b/src/webpage.cpp index 897f6dd025..0d2b13fd1c 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -1383,7 +1383,7 @@ void WebPage::_uploadFile(const QString& selector, const QStringList& fileNames) bool WebPage::injectJs(const QString& jsFilePath) { - return Utils::injectJsInFrame(jsFilePath, m_libraryPath, m_currentFrame); + return Utils::injectJsInFrame(jsFilePath, Encoding::UTF8, m_libraryPath, m_currentFrame); } void WebPage::_appendScriptElement(const QString& scriptUrl)