1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

Bring back support for web inspector

QtWebEngine only supports remote web inspector, so this
starts it on port 33417.
This commit is contained in:
David Rosca 2015-08-30 14:44:00 +02:00
parent bdd5dee361
commit eec26c9af4
8 changed files with 100 additions and 67 deletions

View File

@ -23,6 +23,8 @@
#include "qzcommon.h"
class QWebEngineView;
class QUPZILLA_EXPORT Scripts
{
public:

View File

@ -16,59 +16,72 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "webinspector.h"
#include "toolbutton.h"
#include "iconprovider.h"
#include "mainapplication.h"
#if QTWEBENGINE_DISABLED
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonDocument>
#include <QNetworkReply>
#include <QTimer>
QList<QWebEngineView*> WebInspector::s_views;
WebInspector::WebInspector(QWidget* parent)
: QWebInspector(parent)
, m_closeButton(0)
, m_blockHideEvent(true)
WebInspector::WebInspector(QWidget *parent)
: QWebEngineView(parent)
{
setObjectName(QSL("web-inspector"));
setMinimumHeight(80);
registerView(this);
connect(page(), &QWebEnginePage::windowCloseRequested, this, &WebInspector::deleteLater);
connect(page(), &QWebEnginePage::loadFinished, this, &WebInspector::updateCloseButton);
}
WebInspector::~WebInspector()
{
unregisterView(this);
}
void WebInspector::setView(QWebEngineView *view)
{
QUrl inspectorUrl = QUrl(QSL("http://localhost:%1").arg(WEBINSPECTOR_PORT));
int index = s_views.indexOf(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();
});
}
void WebInspector::pushView(QWebEngineView *view)
{
s_views.removeOne(view);
s_views.prepend(view);
}
void WebInspector::registerView(QWebEngineView *view)
{
s_views.prepend(view);
}
void WebInspector::unregisterView(QWebEngineView *view)
{
s_views.removeOne(view);
}
void WebInspector::updateCloseButton()
{
if (!m_closeButton) {
m_closeButton = new ToolButton(this);
m_closeButton->setAutoRaise(true);
m_closeButton->setIcon(IconProvider::standardIcon(QStyle::SP_DialogCloseButton));
connect(m_closeButton, SIGNAL(clicked()), this, SLOT(hideInspector()));
}
m_closeButton->show();
m_closeButton->move(width() - m_closeButton->width(), 0);
page()->runJavaScript(QL1S("var button = document.getElementsByClassName('toolbar-close-button-item')[0];"
"button.style.display = 'inline-block';"
"button.addEventListener('click', function() {"
" window.close();"
"})"));
}
void WebInspector::hideInspector()
{
m_blockHideEvent = false;
hide();
m_blockHideEvent = true;
// This is needed to correctly show close button after QWebInspector re-initialization
m_closeButton->deleteLater();
m_closeButton = 0;
}
void WebInspector::hideEvent(QHideEvent* event)
{
// Prevent re-initializing QWebInspector after changing tab
if (!m_blockHideEvent) {
QWebInspector::hideEvent(event);
}
}
void WebInspector::resizeEvent(QResizeEvent* event)
{
QWebInspector::resizeEvent(event);
QTimer::singleShot(0, this, SLOT(updateCloseButton()));
}
#endif

View File

@ -18,31 +18,33 @@
#ifndef WEBINSPECTORDOCKWIDGET_H
#define WEBINSPECTORDOCKWIDGET_H
#if QTWEBENGINE_DISABLED
#include <QWebInspector>
#define WEBINSPECTOR_PORT "33417"
#include <QWebEngineView>
#include "qzcommon.h"
class ToolButton;
class QUPZILLA_EXPORT WebInspector : public QWebInspector
class QUPZILLA_EXPORT WebInspector : public QWebEngineView
{
Q_OBJECT
public:
explicit WebInspector(QWidget* parent = 0);
explicit WebInspector(QWidget *parent = Q_NULLPTR);
~WebInspector();
void setView(QWebEngineView *view);
static void pushView(QWebEngineView *view);
static void registerView(QWebEngineView *view);
static void unregisterView(QWebEngineView *view);
private slots:
void updateCloseButton();
void hideInspector();
private:
void hideEvent(QHideEvent* event);
void resizeEvent(QResizeEvent* event);
ToolButton* m_closeButton;
bool m_blockHideEvent;
static QList<QWebEngineView*> s_views;
};
#endif
#endif // WEBINSPECTORDOCKWIDGET_H

View File

@ -32,6 +32,7 @@
#include "qzsettings.h"
#include "enhancedmenu.h"
#include "locationbar.h"
#include "webinspector.h"
#ifdef USE_HUNSPELL
#include "qtwebkit/spellcheck/speller.h"
@ -64,6 +65,7 @@ WebView::WebView(QWidget* parent)
, m_page(0)
, m_disableTouchMocking(false)
, m_isReloading(false)
, m_firstLoad(false)
{
connect(this, SIGNAL(loadStarted()), this, SLOT(slotLoadStarted()));
connect(this, SIGNAL(loadProgress(int)), this, SLOT(slotLoadProgress(int)));
@ -76,6 +78,8 @@ WebView::WebView(QWidget* parent)
installEventFilter(this);
WebInspector::registerView(this);
#ifdef Q_OS_MAC
new MacWebViewScroller(this);
#endif
@ -83,7 +87,7 @@ WebView::WebView(QWidget* parent)
WebView::~WebView()
{
//delete m_page;
WebInspector::unregisterView(this);
}
QIcon WebView::icon() const
@ -180,6 +184,16 @@ void WebView::setPage(QWebEnginePage* page)
#endif
}
void WebView::load(const QUrl &url)
{
QWebEngineView::load(url);
if (!m_firstLoad) {
m_firstLoad = true;
WebInspector::pushView(this);
}
}
void WebView::load(const LoadRequest &request)
{
const QUrl reqUrl = request.url();
@ -1594,7 +1608,7 @@ void WebView::loadRequest(const LoadRequest &req)
else
QWebEngineView::load(req.networkRequest(), QNetworkAccessManager::PostOperation, req.data());
#else
QWebEngineView::load(req.url());
load(req.url());
#endif
}

View File

@ -44,6 +44,7 @@ public:
WebPage* page() const;
void setPage(QWebEnginePage* page);
void load(const QUrl &url);
void load(const LoadRequest &request);
bool isLoading() const;
@ -214,6 +215,7 @@ private:
bool m_disableTouchMocking;
bool m_isReloading;
bool m_firstLoad;
static bool s_forceContextMenuOnMouseRelease;
};

View File

@ -87,7 +87,6 @@ QDataStream &operator >>(QDataStream &stream, WebTab::SavedTab &tab)
WebTab::WebTab(BrowserWindow* window)
: QWidget()
, m_window(window)
, m_inspector(0)
, m_tabBar(0)
, m_isPinned(false)
{
@ -130,15 +129,12 @@ TabbedWebView* WebTab::webView() const
void WebTab::showWebInspector()
{
#if QTWEBENGINE_DISABLED
if (!m_inspector) {
m_inspector = new WebInspector(this);
m_inspector->setPage(m_webView->page());
m_splitter->addWidget(m_inspector);
}
if (m_splitter->count() != 1)
return;
m_inspector->show();
#endif
WebInspector *inspector = new WebInspector(this);
inspector->setView(m_webView);
m_splitter->addWidget(inspector);
}
QUrl WebTab::url() const

View File

@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "mainapplication.h"
#include "webinspector.h"
#include "proxystyle.h"
#include "datapaths.h"
@ -154,6 +155,8 @@ int main(int argc, char* argv[])
argv = args;
}
qputenv("QTWEBENGINE_REMOTE_DEBUGGING", WEBINSPECTOR_PORT);
MainApplication app(argc, argv);
if (app.isClosing())

View File

@ -20,6 +20,7 @@ unix:!contains(DEFINES, "DISABLE_DBUS") QT += dbus
INCLUDEPATH += ../lib/3rdparty \
../lib/app \
../lib/session \
../lib/webengine \
../lib/webtab \
DEPENDPATH += $$INCLUDEPATH