From 48ca42d645b155069a57eaede3e560874ed07bc7 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Thu, 1 Mar 2018 15:14:15 +0100 Subject: WebInspector: Don't require remote debugging with QtWebEngine 5.11 --- src/lib/webengine/webinspector.cpp | 11 ++++++++++- src/lib/webengine/webinspector.h | 11 ++++------- 2 files changed, 14 insertions(+), 8 deletions(-) * asturm@gentoo.org: Make #ifdef obsolete by requiring Qt 5.11.0. diff -u b/src/lib/webengine/webinspector.cpp b/src/lib/webengine/webinspector.cpp --- b/src/lib/webengine/webinspector.cpp +++ b/src/lib/webengine/webinspector.cpp @@ -19,6 +19,8 @@ #include "mainapplication.h" #include "networkmanager.h" #include "settings.h" +#include "webview.h" +#include "webpage.h" #include #include @@ -60,27 +62,13 @@ } } -void WebInspector::setView(QWebEngineView *view) +void WebInspector::setView(WebView *view) { m_view = view; Q_ASSERT(isEnabled()); - int port = qEnvironmentVariableIntValue("QTWEBENGINE_REMOTE_DEBUGGING"); - QUrl inspectorUrl = QUrl(QSL("http://localhost:%1").arg(port)); - int index = s_views.indexOf(m_view); - - QNetworkReply *reply = mApp->networkManager()->get(QNetworkRequest(inspectorUrl.resolved(QUrl("json/list")))); - connect(reply, &QNetworkReply::finished, this, [=]() { - QJsonArray clients = QJsonDocument::fromJson(reply->readAll()).array(); - QUrl pageUrl; - if (clients.size() > index) { - QJsonObject object = clients.at(index).toObject(); - pageUrl = inspectorUrl.resolved(QUrl(object.value(QSL("devtoolsFrontendUrl")).toString())); - } - load(pageUrl); - pushView(this); - show(); - }); + page()->setInspectedPage(m_view->page()); + connect(m_view, &WebView::pageChanged, this, &WebInspector::deleteLater); } void WebInspector::inspectElement() @@ -90,9 +78,6 @@ bool WebInspector::isEnabled() { - if (!qEnvironmentVariableIsSet("QTWEBENGINE_REMOTE_DEBUGGING")) { - return false; - } if (!mApp->webSettings()->testAttribute(QWebEngineSettings::JavascriptEnabled)) { return false; } --- a/src/lib/webengine/webinspector.h +++ b/src/lib/webengine/webinspector.h @@ -15,14 +15,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . * ============================================================ */ -#ifndef WEBINSPECTORDOCKWIDGET_H -#define WEBINSPECTORDOCKWIDGET_H +#pragma once #include #include "qzcommon.h" -class ToolButton; +class WebView; class FALKON_EXPORT WebInspector : public QWebEngineView { @@ -32,7 +31,7 @@ public: explicit WebInspector(QWidget *parent = Q_NULLPTR); ~WebInspector(); - void setView(QWebEngineView *view); + void setView(WebView *view); void inspectElement(); static bool isEnabled(); @@ -53,7 +52,5 @@ private: int m_height; QSize m_windowSize; bool m_inspectElement = false; - QWebEngineView *m_view; + WebView *m_view; }; - -#endif // WEBINSPECTORDOCKWIDGET_H