From 1df4cacc4065436bb111c1e17513222cd3fc0851 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Sat, 14 Feb 2015 19:48:19 +0100 Subject: [PATCH] removed libqwebthree --- CMakeLists.txt | 1 - alethzero/CMakeLists.txt | 4 +- alethzero/MainWin.cpp | 21 +++---- alethzero/MainWin.h | 8 ++- libjsqrc/setup.js | 4 +- libqwebthree/CMakeLists.txt | 41 -------------- libqwebthree/QWebThree.cpp | 107 ------------------------------------ libqwebthree/QWebThree.h | 89 ------------------------------ third/CMakeLists.txt | 5 +- third/MainWin.cpp | 20 ++++--- third/MainWin.h | 8 ++- 11 files changed, 41 insertions(+), 267 deletions(-) delete mode 100644 libqwebthree/CMakeLists.txt delete mode 100644 libqwebthree/QWebThree.cpp delete mode 100644 libqwebthree/QWebThree.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 682ba5a14..0cd7a80c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -181,7 +181,6 @@ if (NOT HEADLESS) add_subdirectory(libnatspec) add_subdirectory(libjsqrc) - add_subdirectory(libqwebthree) add_subdirectory(alethzero) add_subdirectory(third) add_subdirectory(mix) diff --git a/alethzero/CMakeLists.txt b/alethzero/CMakeLists.txt index c18a76c36..b4fc1a938 100644 --- a/alethzero/CMakeLists.txt +++ b/alethzero/CMakeLists.txt @@ -34,8 +34,10 @@ eth_add_executable(${EXECUTABLE} add_dependencies(${EXECUTABLE} BuildInfo.h) target_link_libraries(${EXECUTABLE} Qt5::Core) +target_link_libraries(${EXECUTABLE} Qt5::Widgets) +target_link_libraries(${EXECUTABLE} Qt5::WebKit) +target_link_libraries(${EXECUTABLE} Qt5::WebKitWidgets) target_link_libraries(${EXECUTABLE} webthree) -target_link_libraries(${EXECUTABLE} qwebthree) target_link_libraries(${EXECUTABLE} ethereum) target_link_libraries(${EXECUTABLE} evm) target_link_libraries(${EXECUTABLE} ethcore) diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 397b2330c..865cfec3e 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include "MainWin.h" #include "DownloadView.h" #include "MiningView.h" @@ -167,25 +168,26 @@ Main::Main(QWidget *parent) : bytesConstRef network((byte*)m_networkConfig.data(), m_networkConfig.size()); m_webThree.reset(new WebThreeDirect(string("AlethZero/v") + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM), getDataDir() + "/AlethZero", false, {"eth", "shh"}, p2p::NetworkPreferences(), network)); - m_qwebConnector.reset(new QWebThreeConnector()); - m_server.reset(new OurWebThreeStubServer(*m_qwebConnector, *web3(), keysAsVector(m_myKeys), this)); + m_httpConnector.reset(new jsonrpc::HttpServer(8080)); + m_server.reset(new OurWebThreeStubServer(*m_httpConnector, *web3(), keysAsVector(m_myKeys), this)); connect(&*m_server, SIGNAL(onNewId(QString)), SLOT(addNewId(QString))); m_server->setIdentities(keysAsVector(owned())); m_server->StartListening(); connect(ui->webView, &QWebView::loadStarted, [this]() { - // NOTE: no need to delete as QETH_INSTALL_JS_NAMESPACE adopts it. - m_qweb = new QWebThree(this); - auto qweb = m_qweb; - m_qwebConnector->setQWeb(qweb); - QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); QWebFrame* f = ui->webView->page()->mainFrame(); f->disconnect(SIGNAL(javaScriptWindowObjectCleared())); - connect(f, &QWebFrame::javaScriptWindowObjectCleared, QETH_INSTALL_JS_NAMESPACE(f, this, qweb)); - connect(m_qweb, SIGNAL(onNewId(QString)), this, SLOT(addNewId(QString))); + connect(f, &QWebFrame::javaScriptWindowObjectCleared, [f, this]() + { + f->disconnect(); + f->addToJavaScriptWindowObject("env", this, QWebFrame::QtOwnership); + f->evaluateJavaScript(contentsOfQResource(":/js/bignumber.min.js")); + f->evaluateJavaScript(contentsOfQResource(":/js/webthree.js")); + f->evaluateJavaScript(contentsOfQResource(":/js/setup.js")); + }); }); connect(ui->webView, &QWebView::loadFinished, [=]() @@ -216,7 +218,6 @@ Main::~Main() writeSettings(); // Must do this here since otherwise m_ethereum'll be deleted (and therefore clearWatches() called by the destructor) // *after* the client is dead. - m_qweb->clientDieing(); g_logPost = simpleDebugOut; } diff --git a/alethzero/MainWin.h b/alethzero/MainWin.h index 2625f566d..94dcaabe5 100644 --- a/alethzero/MainWin.h +++ b/alethzero/MainWin.h @@ -34,7 +34,6 @@ #include #include #include -#include #include #include @@ -49,6 +48,10 @@ class Client; class State; }} +namespace jsonrpc { +class HttpServer; +} + class QQuickView; class OurWebThreeStubServer; @@ -278,9 +281,8 @@ private: QString m_logHistory; bool m_logChanged = true; - std::unique_ptr m_qwebConnector; + std::unique_ptr m_httpConnector; std::unique_ptr m_server; - QWebThree* m_qweb = nullptr; static QString fromRaw(dev::h256 _n, unsigned* _inc = nullptr); NatspecHandler m_natspecDB; diff --git a/libjsqrc/setup.js b/libjsqrc/setup.js index 2aa54ed30..fa1921877 100644 --- a/libjsqrc/setup.js +++ b/libjsqrc/setup.js @@ -20,8 +20,6 @@ * @date 2014 */ -navigator.qt = _web3; - var web3 = require('web3'); -web3.setProvider(new web3.providers.QtSyncProvider()); +web3.setProvider(new web3.providers.HttpSyncProvider()); diff --git a/libqwebthree/CMakeLists.txt b/libqwebthree/CMakeLists.txt deleted file mode 100644 index 4de131ead..000000000 --- a/libqwebthree/CMakeLists.txt +++ /dev/null @@ -1,41 +0,0 @@ -cmake_policy(SET CMP0015 NEW) -# let cmake autolink dependencies on windows -cmake_policy(SET CMP0020 NEW) -# this policy was introduced in cmake 3.0 -# remove if, once 3.0 will be used on unix -if (${CMAKE_MAJOR_VERSION} GREATER 2) - # old policy do not use MACOSX_RPATH - cmake_policy(SET CMP0042 OLD) - cmake_policy(SET CMP0043 OLD) -endif() - -set(CMAKE_INCLUDE_CURRENT_DIR ON) -aux_source_directory(. SRC_LIST) - -include_directories(${JSON_RPC_CPP_INCLUDE_DIRS}) -include_directories(..) - -set(EXECUTABLE qwebthree) - -file(GLOB HEADERS "*.h") - -if(ETH_STATIC) - add_library(${EXECUTABLE} STATIC ${RESOURCE_ADDED} ${SRC_LIST} ${HEADERS}) -else() - add_library(${EXECUTABLE} SHARED ${RESOURCE_ADDED} ${SRC_LIST} ${HEADERS}) -endif() - -target_link_libraries(${EXECUTABLE} Qt5::Core) -target_link_libraries(${EXECUTABLE} Qt5::Gui) -target_link_libraries(${EXECUTABLE} Qt5::WebKit) -target_link_libraries(${EXECUTABLE} Qt5::WebKitWidgets) -target_link_libraries(${EXECUTABLE} Qt5::Widgets) -target_link_libraries(${EXECUTABLE} Qt5::Network) -target_link_libraries(${EXECUTABLE} Qt5::Quick) -target_link_libraries(${EXECUTABLE} Qt5::Qml) -target_link_libraries(${EXECUTABLE} ${JSON_RPC_CPP_SERVER_LIBRARIES}) -target_link_libraries(${EXECUTABLE} ethereum) -target_link_libraries(${EXECUTABLE} secp256k1) - -install( TARGETS ${EXECUTABLE} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) -install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} ) diff --git a/libqwebthree/QWebThree.cpp b/libqwebthree/QWebThree.cpp deleted file mode 100644 index 31f2f6b92..000000000 --- a/libqwebthree/QWebThree.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - This file is part of cpp-ethereum. - - cpp-ethereum is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - cpp-ethereum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . -*/ -/** @file QWebThree.cpp - * @authors: - * Gav Wood - * Marek Kotewicz - * @date 2014 - */ - -#include -#include "QWebThree.h" - -using namespace std; - -QWebThree::QWebThree(QObject* _p): QObject(_p) -{ - moveToThread(_p->thread()); -} - -QWebThree::~QWebThree() -{ - clientDieing(); -} - -void QWebThree::clientDieing() -{ - this->disconnect(); -} - -QString QWebThree::callMethod(QString _json) -{ - emit processData(_json, ""); // it's synchronous - return m_response; -} - -void QWebThree::onDataProcessed(QString _json, QString) -{ - QJsonObject f = QJsonDocument::fromJson(_json.toUtf8()).object(); - syncResponse(QString::fromUtf8(QJsonDocument(f).toJson())); -} - -void QWebThree::syncResponse(QString _json) -{ - m_response = _json; -} - -QWebThreeConnector::QWebThreeConnector() -{ -} - -QWebThreeConnector::~QWebThreeConnector() -{ - StopListening(); -} - -void QWebThreeConnector::setQWeb(QWebThree* _q) -{ - m_qweb = _q; - if (m_isListening) - { - StopListening(); - StartListening(); - } -} - -bool QWebThreeConnector::StartListening() -{ - m_isListening = true; - if (m_qweb) - { - connect(m_qweb, SIGNAL(processData(QString, QString)), this, SLOT(onProcessData(QString, QString))); - connect(this, SIGNAL(dataProcessed(QString, QString)), m_qweb, SLOT(onDataProcessed(QString, QString))); - } - return true; -} - -bool QWebThreeConnector::StopListening() -{ - this->disconnect(); - return true; -} - -bool QWebThreeConnector::SendResponse(std::string const& _response, void* _addInfo) -{ - emit dataProcessed(QString::fromStdString(_response), *(QString*)_addInfo); - return true; -} - -void QWebThreeConnector::onProcessData(QString const& _json, QString const& _addInfo) -{ - OnRequest(_json.toStdString(), (void*)&_addInfo); -} - diff --git a/libqwebthree/QWebThree.h b/libqwebthree/QWebThree.h deleted file mode 100644 index 72c434649..000000000 --- a/libqwebthree/QWebThree.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - This file is part of cpp-ethereum. - - cpp-ethereum is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - cpp-ethereum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . -*/ -/** @file QWebThree.h - * @authors: - * Gav Wood - * Marek Kotewicz - * @date 2014 - */ - -#pragma once - -#include -#include -#include - -class QWebThree: public QObject -{ - Q_OBJECT - -public: - QWebThree(QObject* _p); - virtual ~QWebThree(); - void clientDieing(); - - Q_INVOKABLE QString callMethod(QString _json); - void syncResponse(QString _json); - -public slots: - void onDataProcessed(QString _json, QString _addInfo); - -signals: - void processData(QString _json, QString _addInfo); - void response(QString _json); - void onNewId(QString _id); - -private: - QString m_response; -}; - -class QWebThreeConnector: public QObject, public jsonrpc::AbstractServerConnector -{ - Q_OBJECT - -public: - QWebThreeConnector(); - virtual ~QWebThreeConnector(); - - void setQWeb(QWebThree *_q); - - virtual bool StartListening(); - virtual bool StopListening(); - virtual bool SendResponse(std::string const& _response, void* _addInfo = NULL); - -public slots: - void onProcessData(QString const& _json, QString const& _addInfo); - -signals: - void dataProcessed(QString const& _json, QString const& _addInfo); - -private: - QWebThree* m_qweb = nullptr; - bool m_isListening; -}; - -#define QETH_INSTALL_JS_NAMESPACE(_frame, _env, qweb) [_frame, _env, qweb]() \ -{ \ - _frame->disconnect(); \ - _frame->addToJavaScriptWindowObject("_web3", qweb, QWebFrame::ScriptOwnership); \ - _frame->addToJavaScriptWindowObject("env", _env, QWebFrame::QtOwnership); \ - _frame->evaluateJavaScript(contentsOfQResource(":/js/bignumber.min.js")); \ - _frame->evaluateJavaScript(contentsOfQResource(":/js/webthree.js")); \ - _frame->evaluateJavaScript(contentsOfQResource(":/js/setup.js")); \ -} - - diff --git a/third/CMakeLists.txt b/third/CMakeLists.txt index 71f1e70f2..3f4981e29 100644 --- a/third/CMakeLists.txt +++ b/third/CMakeLists.txt @@ -32,8 +32,11 @@ eth_add_executable(${EXECUTABLE} add_dependencies(${EXECUTABLE} BuildInfo.h) target_link_libraries(${EXECUTABLE} Qt5::Core) +target_link_libraries(${EXECUTABLE} Qt5::Widgets) +target_link_libraries(${EXECUTABLE} Qt5::WebKit) +target_link_libraries(${EXECUTABLE} Qt5::WebKitWidgets) +target_link_libraries(${EXECUTABLE} webthree) target_link_libraries(${EXECUTABLE} webthree) -target_link_libraries(${EXECUTABLE} qwebthree) target_link_libraries(${EXECUTABLE} ethereum) target_link_libraries(${EXECUTABLE} evm) target_link_libraries(${EXECUTABLE} ethcore) diff --git a/third/MainWin.cpp b/third/MainWin.cpp index f1b7bc826..5fb5074bc 100644 --- a/third/MainWin.cpp +++ b/third/MainWin.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include "BuildInfo.h" #include "MainWin.h" #include "ui_Main.h" @@ -118,20 +119,24 @@ Main::Main(QWidget *parent) : m_web3.reset(new WebThreeDirect("Third", getDataDir() + "/Third", false, {"eth", "shh"}, NetworkPreferences(), networkConfig)); m_web3->connect(Host::pocHost()); - m_server = unique_ptr(new WebThreeStubServer(m_qwebConnector, *web3(), keysAsVector(m_myKeys))); + m_httpConnector.reset(new jsonrpc::HttpServer(8080)); + m_server.reset(new WebThreeStubServer(*m_httpConnector, *web3(), keysAsVector(m_myKeys))); +// m_server = unique_ptr(new WebThreeStubServer(m_httpConnector, *web3(), keysAsVector(m_myKeys))); m_server->setIdentities(keysAsVector(owned())); m_server->StartListening(); connect(ui->webView, &QWebView::loadStarted, [this]() { - // NOTE: no need to delete as QETH_INSTALL_JS_NAMESPACE adopts it. - m_qweb = new QWebThree(this); - auto qweb = m_qweb; - m_qwebConnector.setQWeb(qweb); - QWebFrame* f = ui->webView->page()->mainFrame(); f->disconnect(SIGNAL(javaScriptWindowObjectCleared())); - connect(f, &QWebFrame::javaScriptWindowObjectCleared, QETH_INSTALL_JS_NAMESPACE(f, this, qweb)); + connect(f, &QWebFrame::javaScriptWindowObjectCleared, [f, this]() + { + f->disconnect(); + f->addToJavaScriptWindowObject("env", this, QWebFrame::QtOwnership); + f->evaluateJavaScript(contentsOfQResource(":/js/bignumber.min.js")); + f->evaluateJavaScript(contentsOfQResource(":/js/webthree.js")); + f->evaluateJavaScript(contentsOfQResource(":/js/setup.js")); + }); }); connect(ui->webView, &QWebView::loadFinished, [=]() @@ -163,7 +168,6 @@ Main::~Main() { // Must do this here since otherwise m_ethereum'll be deleted (and therefore clearWatches() called by the destructor) // *after* the client is dead. - m_qweb->clientDieing(); writeSettings(); } diff --git a/third/MainWin.h b/third/MainWin.h index 924fc057e..513cfe96e 100644 --- a/third/MainWin.h +++ b/third/MainWin.h @@ -30,7 +30,6 @@ #include #include #include -#include namespace Ui { class Main; @@ -47,6 +46,10 @@ class WhisperHost; } } +namespace jsonrpc { +class HttpServer; +} + class QQuickView; class WebThreeStubServer; @@ -136,7 +139,6 @@ private: QNetworkAccessManager m_webCtrl; + std::unique_ptr m_httpConnector; std::unique_ptr m_server; - QWebThreeConnector m_qwebConnector; - QWebThree* m_qweb = nullptr; };