1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-21 17:52:10 +02:00

WebInspector: Don't require remote debugging with QtWebEngine 5.11

This commit is contained in:
David Rosca 2018-03-01 15:14:15 +01:00
parent ce3f4ed1e8
commit 48ca42d645
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
2 changed files with 14 additions and 8 deletions

View File

@ -19,6 +19,8 @@
#include "mainapplication.h" #include "mainapplication.h"
#include "networkmanager.h" #include "networkmanager.h"
#include "settings.h" #include "settings.h"
#include "webview.h"
#include "webpage.h"
#include <QJsonArray> #include <QJsonArray>
#include <QJsonObject> #include <QJsonObject>
@ -60,11 +62,15 @@ WebInspector::~WebInspector()
} }
} }
void WebInspector::setView(QWebEngineView *view) void WebInspector::setView(WebView *view)
{ {
m_view = view; m_view = view;
Q_ASSERT(isEnabled()); Q_ASSERT(isEnabled());
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
page()->setInspectedPage(m_view->page());
connect(m_view, &WebView::pageChanged, this, &WebInspector::deleteLater);
#else
int port = qEnvironmentVariableIntValue("QTWEBENGINE_REMOTE_DEBUGGING"); int port = qEnvironmentVariableIntValue("QTWEBENGINE_REMOTE_DEBUGGING");
QUrl inspectorUrl = QUrl(QSL("http://localhost:%1").arg(port)); QUrl inspectorUrl = QUrl(QSL("http://localhost:%1").arg(port));
int index = s_views.indexOf(m_view); int index = s_views.indexOf(m_view);
@ -81,6 +87,7 @@ void WebInspector::setView(QWebEngineView *view)
pushView(this); pushView(this);
show(); show();
}); });
#endif
} }
void WebInspector::inspectElement() void WebInspector::inspectElement()
@ -90,9 +97,11 @@ void WebInspector::inspectElement()
bool WebInspector::isEnabled() bool WebInspector::isEnabled()
{ {
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
if (!qEnvironmentVariableIsSet("QTWEBENGINE_REMOTE_DEBUGGING")) { if (!qEnvironmentVariableIsSet("QTWEBENGINE_REMOTE_DEBUGGING")) {
return false; return false;
} }
#endif
if (!mApp->webSettings()->testAttribute(QWebEngineSettings::JavascriptEnabled)) { if (!mApp->webSettings()->testAttribute(QWebEngineSettings::JavascriptEnabled)) {
return false; return false;
} }

View File

@ -15,14 +15,13 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */ * ============================================================ */
#ifndef WEBINSPECTORDOCKWIDGET_H #pragma once
#define WEBINSPECTORDOCKWIDGET_H
#include <QWebEngineView> #include <QWebEngineView>
#include "qzcommon.h" #include "qzcommon.h"
class ToolButton; class WebView;
class FALKON_EXPORT WebInspector : public QWebEngineView class FALKON_EXPORT WebInspector : public QWebEngineView
{ {
@ -32,7 +31,7 @@ public:
explicit WebInspector(QWidget *parent = Q_NULLPTR); explicit WebInspector(QWidget *parent = Q_NULLPTR);
~WebInspector(); ~WebInspector();
void setView(QWebEngineView *view); void setView(WebView *view);
void inspectElement(); void inspectElement();
static bool isEnabled(); static bool isEnabled();
@ -53,7 +52,5 @@ private:
int m_height; int m_height;
QSize m_windowSize; QSize m_windowSize;
bool m_inspectElement = false; bool m_inspectElement = false;
QWebEngineView *m_view; WebView *m_view;
}; };
#endif // WEBINSPECTORDOCKWIDGET_H