diff --git a/src/lib/app/browserwindow.cpp b/src/lib/app/browserwindow.cpp index 6ac820416..6a079693f 100644 --- a/src/lib/app/browserwindow.cpp +++ b/src/lib/app/browserwindow.cpp @@ -742,17 +742,11 @@ void BrowserWindow::showHistoryManager() mApp->browsingLibrary()->showHistory(this); } -void BrowserWindow::showSource(QWebEngineFrame* frame, const QString &selectedHtml) +void BrowserWindow::showSource(WebView *view) { -#if QTWEBENGINE_DISABLED - if (!frame) { - frame = weView()->page()->mainFrame(); - } - - SourceViewer* source = new SourceViewer(frame, selectedHtml); - QzTools::centerWidgetToParent(source, this); - source->show(); -#endif + if (!view) + view = weView(); + view->showSource(); } SideBar* BrowserWindow::addSideBar() diff --git a/src/lib/app/browserwindow.h b/src/lib/app/browserwindow.h index 54dbc551c..e396c5e15 100644 --- a/src/lib/app/browserwindow.h +++ b/src/lib/app/browserwindow.h @@ -43,6 +43,7 @@ class BookmarksToolbar; class AutoFill; class MainApplication; class WebTab; +class WebView; class AdBlockIcon; class SideBar; class SideBarManager; @@ -140,7 +141,7 @@ public slots: void bookmarkPage(); void bookmarkAllTabs(); void loadAddress(const QUrl &url); - void showSource(QWebEngineFrame* frame = 0, const QString &selectedHtml = QString()); + void showSource(WebView *view = Q_NULLPTR); void printPage(QWebEngineFrame* frame = 0); private slots: diff --git a/src/lib/popupwindow/popupwebview.h b/src/lib/popupwindow/popupwebview.h index b31aeacad..17fd76039 100644 --- a/src/lib/popupwindow/popupwebview.h +++ b/src/lib/popupwindow/popupwebview.h @@ -30,9 +30,9 @@ class QUPZILLA_EXPORT PopupWebView : public WebView public: explicit PopupWebView(QWidget* parent = 0); - QWidget* overlayWidget(); - void loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags position); - void openNewTab(Qz::NewTabPositionFlags position); + QWidget* overlayWidget() Q_DECL_OVERRIDE; + void loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags position) Q_DECL_OVERRIDE; + void openNewTab(Qz::NewTabPositionFlags position) Q_DECL_OVERRIDE; signals: diff --git a/src/lib/popupwindow/popupwindow.cpp b/src/lib/popupwindow/popupwindow.cpp index 216aa4734..0e72ea970 100644 --- a/src/lib/popupwindow/popupwindow.cpp +++ b/src/lib/popupwindow/popupwindow.cpp @@ -86,7 +86,7 @@ PopupWindow::PopupWindow(PopupWebView* view) m_menuView->addAction(QIcon::fromTheme("zoom-out"), tr("Zoom &Out"), m_view, SLOT(zoomOut()))->setShortcut(QKeySequence("Ctrl+-")); m_menuView->addAction(QIcon::fromTheme("zoom-original"), tr("Reset"), m_view, SLOT(zoomReset()))->setShortcut(QKeySequence("Ctrl+0")); m_menuView->addSeparator(); - //m_menuView->addAction(QIcon::fromTheme("text-html"), tr("&Page Source"), m_view, SLOT(showSource()))->setShortcut(QKeySequence("Ctrl+U")); + m_menuView->addAction(QIcon::fromTheme("text-html"), tr("&Page Source"), m_view, SLOT(showSource()))->setShortcut(QKeySequence("Ctrl+U")); m_menuBar->addMenu(m_menuView); // Make shortcuts available even with hidden menubar diff --git a/src/lib/webkit/webview.cpp b/src/lib/webkit/webview.cpp index f77116383..ec65099fc 100644 --- a/src/lib/webkit/webview.cpp +++ b/src/lib/webkit/webview.cpp @@ -41,6 +41,8 @@ #include "macwebviewscroller.h" #endif +#include + #include #include #include @@ -626,18 +628,21 @@ void WebView::openActionUrl() } } -#if QTWEBENGINE_DISABLED -void WebView::showSource(QWebEngineFrame* frame, const QString &selectedHtml) +void WebView::showSource() { - if (!frame) { - frame = page()->mainFrame(); + // view-source: doesn't work on itself and custom schemes + if (url().scheme() == QL1S("view-source") || url().scheme() == QL1S("qupzilla")) { + page()->toHtml([](const QString &html) { + std::cout << html.toLocal8Bit().constData() << std::endl; + }); + return; } - SourceViewer* source = new SourceViewer(frame, selectedHtml); - QzTools::centerWidgetToParent(source, this); - source->show(); + QUrl u; + u.setScheme(QSL("view-source")); + u.setPath(url().toString()); + openUrlInNewTab(u, Qz::NT_SelectedTab); } -#endif void WebView::showSiteInfo() { diff --git a/src/lib/webkit/webview.h b/src/lib/webkit/webview.h index 25819e2dd..3d0c4c1f1 100644 --- a/src/lib/webkit/webview.h +++ b/src/lib/webkit/webview.h @@ -103,6 +103,7 @@ public slots: #if QTWEBENGINE_DISABLED void printPage(QWebEngineFrame* frame = 0); #endif + void showSource(); void sendPageByMail(); void savePageAs(); @@ -126,9 +127,6 @@ protected slots: void downloadUrlToDisk(); void copyImageToClipboard(); void openActionUrl(); -#if QTWEBENGINE_DISABLED - void showSource(QWebEngineFrame* frame = 0, const QString &selectedHtml = QString()); -#endif void showSiteInfo(); void searchSelectedText(); void searchSelectedTextInBackgroundTab(); diff --git a/src/lib/webtab/tabbedwebview.h b/src/lib/webtab/tabbedwebview.h index b373991df..c5cbbf131 100644 --- a/src/lib/webtab/tabbedwebview.h +++ b/src/lib/webtab/tabbedwebview.h @@ -47,7 +47,10 @@ public: QString getIp() const; int tabIndex() const; - QWidget* overlayWidget(); + QWidget* overlayWidget() Q_DECL_OVERRIDE; + void closeView() Q_DECL_OVERRIDE; + void openNewTab(Qz::NewTabPositionFlags position) Q_DECL_OVERRIDE; + void loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags position) Q_DECL_OVERRIDE; signals: void wantsCloseTab(int); @@ -58,10 +61,6 @@ public slots: void setAsCurrentTab(); void userLoadAction(const LoadRequest &req); - void closeView(); - void openNewTab(Qz::NewTabPositionFlags position); - void loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags position); - private slots: void slotLoadStarted(); void slotLoadFinished();