From a10292205e73d26b7d5298bf2faa924cae66cbc5 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 16 Feb 2015 11:47:06 +0100 Subject: [PATCH] Move to Chromium. --- alethzero/CMakeLists.txt | 5 +++ alethzero/Main.ui | 15 ++++--- alethzero/MainWin.cpp | 87 +++++++++++++++++++--------------------- alethzero/MainWin.h | 2 - 4 files changed, 53 insertions(+), 56 deletions(-) diff --git a/alethzero/CMakeLists.txt b/alethzero/CMakeLists.txt index 9e41260fe..83fe797fe 100644 --- a/alethzero/CMakeLists.txt +++ b/alethzero/CMakeLists.txt @@ -14,6 +14,9 @@ include_directories(..) include_directories(BEFORE ${JSONCPP_INCLUDE_DIRS}) include_directories(${JSON_RPC_CPP_INCLUDE_DIRS}) +find_package (Qt5WebEngine QUIET) +find_package (Qt5WebEngineWidgets QUIET) + qt5_wrap_ui(ui_Main.h Main.ui) qt5_wrap_ui(ui_Debugger.h Debugger.ui) qt5_wrap_ui(ui_Transact.h Transact.ui) @@ -39,6 +42,8 @@ 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} Qt5::WebEngine) +target_link_libraries(${EXECUTABLE} Qt5::WebEngineWidgets) target_link_libraries(${EXECUTABLE} webthree) target_link_libraries(${EXECUTABLE} ethereum) target_link_libraries(${EXECUTABLE} evm) diff --git a/alethzero/Main.ui b/alethzero/Main.ui index b7c4f6c96..05f5b17bd 100644 --- a/alethzero/Main.ui +++ b/alethzero/Main.ui @@ -95,13 +95,7 @@ - - - - about:blank - - - + @@ -1672,6 +1666,12 @@ font-size: 14pt
DownloadView.h
1 + + QWebEngineView + QWidget +
QtWebEngineWidgets/QWebEngineView
+ 1 +
shhTo @@ -1686,7 +1686,6 @@ font-size: 14pt jsConsole tabWidget urlEdit - webView idealPeers forceAddress port diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 00fb29e2d..68078a95d 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -19,13 +19,15 @@ * @date 2014 */ +#define QWEBENGINEINSPECTOR 1 #include #include #include #include #include -#include -#include +#include +#include +#include #include #include #include @@ -154,31 +156,24 @@ Main::Main(QWidget *parent) : m_server->setIdentities(keysAsVector(owned())); m_server->StartListening(); - connect(ui->webView, &QWebView::loadStarted, [this]() + connect(ui->webView, &QWebEngineView::loadFinished, [this]() { - QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); - QWebFrame* f = ui->webView->page()->mainFrame(); - f->disconnect(SIGNAL(javaScriptWindowObjectCleared())); - - 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")); - }); +// f->disconnect(); +// f->addToJavaScriptWindowObject("env", this, QWebFrame::QtOwnership); + auto f = ui->webView->page(); + f->runJavaScript(contentsOfQResource(":/js/bignumber.min.js")); + f->runJavaScript(contentsOfQResource(":/js/webthree.js")); + f->runJavaScript(contentsOfQResource(":/js/setup.js")); }); - connect(ui->webView, &QWebView::loadFinished, [=]() - { - }); - - connect(ui->webView, &QWebView::titleChanged, [=]() + connect(ui->webView, &QWebEngineView::titleChanged, [=]() { ui->tabWidget->setTabText(0, ui->webView->title()); }); + ui->webView->page()->settings()->setAttribute(QWebEngineSettings::DeveloperExtrasEnabled, true); +// QWebEngineInspector* inspector = new QWebEngineInspector(); +// inspector->setPage(page); readSettings(); installWatches(); startTimer(100); @@ -361,7 +356,7 @@ QString Main::contents(QString _s) void Main::load(QString _s) { QString contents = QString::fromStdString(dev::asString(dev::contents(_s.toStdString()))); - ui->webView->page()->currentFrame()->evaluateJavaScript(contents); + ui->webView->page()->runJavaScript(contents); /* QFile fin(_s); if (!fin.open(QFile::ReadOnly)) @@ -420,35 +415,35 @@ void Main::on_jsInput_returnPressed() ui->jsInput->setText(""); } -QVariant Main::evalRaw(QString const& _js) -{ - return ui->webView->page()->currentFrame()->evaluateJavaScript(_js); -} - void Main::eval(QString const& _js) { if (_js.trimmed().isEmpty()) return; - QVariant ev = ui->webView->page()->currentFrame()->evaluateJavaScript((_js.startsWith("{") || _js.startsWith("if ") || _js.startsWith("if(")) ? _js : ("___RET=(" + _js + ")")); - QVariant jsonEv = ui->webView->page()->currentFrame()->evaluateJavaScript("JSON.stringify(___RET)"); - QString s; - if (ev.isNull()) - s = "null"; - else if (ev.type() == QVariant::String) - s = "\"" + ev.toString().toHtmlEscaped() + "\""; - else if (ev.type() == QVariant::Int || ev.type() == QVariant::Double) - s = "" + ev.toString().toHtmlEscaped() + ""; - else if (jsonEv.type() == QVariant::String) - s = "" + jsonEv.toString().toHtmlEscaped() + ""; - else - s = "unknown type"; - m_consoleHistory.push_back(qMakePair(_js, s)); - s = "" Div(Mono "position: absolute; bottom: 0; border: 0px; margin: 0px; width: 100%"); - for (auto const& i: m_consoleHistory) - s += "
>" + i.first.toHtmlEscaped() + "
" - "
 " + i.second + "
"; - s += ""; - ui->jsConsole->setHtml(s); + auto f = [=](QVariant ev) { + auto f2 = [=](QVariant jsonEv) { + QString s; + if (ev.isNull()) + s = "null"; + else if (ev.type() == QVariant::String) + s = "\"" + ev.toString().toHtmlEscaped() + "\""; + else if (ev.type() == QVariant::Int || ev.type() == QVariant::Double) + s = "" + ev.toString().toHtmlEscaped() + ""; + else if (jsonEv.type() == QVariant::String) + s = "" + jsonEv.toString().toHtmlEscaped() + ""; + else + s = "unknown type"; + m_consoleHistory.push_back(qMakePair(_js, s)); + s = "" Div(Mono "position: absolute; bottom: 0; border: 0px; margin: 0px; width: 100%"); + for (auto const& i: m_consoleHistory) + s += "
>" + i.first.toHtmlEscaped() + "
" + "
 " + i.second + "
"; + s += ""; + ui->jsConsole->setHtml(s); + }; + ui->webView->page()->runJavaScript("JSON.stringify(___RET)", f2); + }; + auto c = (_js.startsWith("{") || _js.startsWith("if ") || _js.startsWith("if(")) ? _js : ("___RET=(" + _js + ")"); + ui->webView->page()->runJavaScript(c, f); } static Public stringToPublic(QString const& _a) diff --git a/alethzero/MainWin.h b/alethzero/MainWin.h index 6c4a97301..5cb7aa964 100644 --- a/alethzero/MainWin.h +++ b/alethzero/MainWin.h @@ -74,8 +74,6 @@ public: NatSpecFace* natSpec() { return &m_natSpecDB; } - QVariant evalRaw(QString const& _js); - QString pretty(dev::Address _a) const override; QString prettyU256(dev::u256 _n) const override; QString render(dev::Address _a) const override;