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

View File

@ -15,14 +15,13 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#ifndef WEBINSPECTORDOCKWIDGET_H
#define WEBINSPECTORDOCKWIDGET_H
#pragma once
#include <QWebEngineView>
#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