1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +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" #include "qzcommon.h"
class QWebEngineView;
class QUPZILLA_EXPORT Scripts class QUPZILLA_EXPORT Scripts
{ {
public: public:

View File

@ -16,59 +16,72 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */ * ============================================================ */
#include "webinspector.h" #include "webinspector.h"
#include "toolbutton.h" #include "mainapplication.h"
#include "iconprovider.h"
#if QTWEBENGINE_DISABLED #include <QJsonArray>
#include <QJsonObject>
#include <QJsonDocument>
#include <QNetworkReply>
#include <QTimer> QList<QWebEngineView*> WebInspector::s_views;
WebInspector::WebInspector(QWidget* parent) WebInspector::WebInspector(QWidget *parent)
: QWebInspector(parent) : QWebEngineView(parent)
, m_closeButton(0)
, m_blockHideEvent(true)
{ {
setObjectName(QSL("web-inspector")); setObjectName(QSL("web-inspector"));
setMinimumHeight(80); 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() void WebInspector::updateCloseButton()
{ {
if (!m_closeButton) { page()->runJavaScript(QL1S("var button = document.getElementsByClassName('toolbar-close-button-item')[0];"
m_closeButton = new ToolButton(this); "button.style.display = 'inline-block';"
m_closeButton->setAutoRaise(true); "button.addEventListener('click', function() {"
m_closeButton->setIcon(IconProvider::standardIcon(QStyle::SP_DialogCloseButton)); " window.close();"
connect(m_closeButton, SIGNAL(clicked()), this, SLOT(hideInspector())); "})"));
}
m_closeButton->show();
m_closeButton->move(width() - m_closeButton->width(), 0);
} }
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 #ifndef WEBINSPECTORDOCKWIDGET_H
#define WEBINSPECTORDOCKWIDGET_H #define WEBINSPECTORDOCKWIDGET_H
#if QTWEBENGINE_DISABLED #define WEBINSPECTOR_PORT "33417"
#include <QWebInspector>
#include <QWebEngineView>
#include "qzcommon.h" #include "qzcommon.h"
class ToolButton; class ToolButton;
class QUPZILLA_EXPORT WebInspector : public QWebInspector class QUPZILLA_EXPORT WebInspector : public QWebEngineView
{ {
Q_OBJECT Q_OBJECT
public: 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: private slots:
void updateCloseButton(); void updateCloseButton();
void hideInspector();
private: private:
void hideEvent(QHideEvent* event); static QList<QWebEngineView*> s_views;
void resizeEvent(QResizeEvent* event);
ToolButton* m_closeButton;
bool m_blockHideEvent;
}; };
#endif
#endif // WEBINSPECTORDOCKWIDGET_H #endif // WEBINSPECTORDOCKWIDGET_H

View File

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

View File

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

View File

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

View File

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

View File

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