From 23aac1aeb4f764e2d57d3375422b2d911c2ff101 Mon Sep 17 00:00:00 2001 From: Oleg Shparber Date: Thu, 24 Mar 2016 05:34:45 -0400 Subject: [PATCH] ui: Allow accessing online resources in web view (fixes #474) This removes a custom network manager that was blocking all requests to non-local resources. --- src/ui/mainwindow.cpp | 11 ++---- src/ui/mainwindow.h | 2 - src/ui/networkaccessmanager.cpp | 70 --------------------------------- src/ui/networkaccessmanager.h | 43 -------------------- 4 files changed, 4 insertions(+), 122 deletions(-) delete mode 100644 src/ui/networkaccessmanager.cpp delete mode 100644 src/ui/networkaccessmanager.h diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index dff20f12f..7454fb35b 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -25,7 +25,6 @@ #include "ui_mainwindow.h" #include "aboutdialog.h" -#include "networkaccessmanager.h" #include "searchitemdelegate.h" #include "settingsdialog.h" #include "core/application.h" @@ -108,11 +107,9 @@ MainWindow::MainWindow(Core::Application *app, QWidget *parent) : restoreGeometry(m_settings->windowGeometry); ui->splitter->restoreState(m_settings->verticalSplitterGeometry); - m_zealNetworkManager = new NetworkAccessManager(this); -#ifdef USE_WEBENGINE - /// FIXME AngularJS workaround (zealnetworkaccessmanager.cpp) -#else - ui->webView->page()->setNetworkAccessManager(m_zealNetworkManager); + /// TODO: Custom headers and URL scheme for Qt WebEngine. +#ifndef USE_WEBENGINE + ui->webView->page()->setNetworkAccessManager(m_application->networkManager()); #endif // menu @@ -462,7 +459,7 @@ void MainWindow::createTab() newTab->page->load(QUrl(startPageUrl)); #else newTab->page->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks); - newTab->page->setNetworkAccessManager(m_zealNetworkManager); + newTab->page->setNetworkAccessManager(m_application->networkManager()); newTab->page->mainFrame()->load(QUrl(startPageUrl)); #endif diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index b7a0b2f60..5fc43f1e3 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -61,7 +61,6 @@ class Settings; } class ListModel; -class NetworkAccessManager; class SearchModel; class SettingsDialog; @@ -143,7 +142,6 @@ private slots: QList m_tabs; SearchState *m_searchState = nullptr; - Zeal::NetworkAccessManager *m_zealNetworkManager = nullptr; Ui::MainWindow *ui = nullptr; Zeal::Core::Application *m_application = nullptr; diff --git a/src/ui/networkaccessmanager.cpp b/src/ui/networkaccessmanager.cpp deleted file mode 100644 index dad5ef961..000000000 --- a/src/ui/networkaccessmanager.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015-2016 Oleg Shparber -** Copyright (C) 2013-2014 Jerzy Kozera -** Contact: http://zealdocs.org/contact.html -** -** This file is part of Zeal. -** -** Zeal is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Zeal is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Zeal. If not, see . -** -****************************************************************************/ - -#include "networkaccessmanager.h" - -#include - -using namespace Zeal; - -NetworkAccessManager::NetworkAccessManager(QObject *parent) : - QNetworkAccessManager(parent) -{ -} - -QNetworkReply *NetworkAccessManager::createRequest(QNetworkAccessManager::Operation op, - const QNetworkRequest &req, - QIODevice *outgoingData) -{ - const QString scheme = req.url().scheme(); - - if (scheme == QLatin1String("qrc")) - return QNetworkAccessManager::createRequest(op, req, outgoingData); - - const bool nonFileScheme = scheme != QLatin1String("file"); - const bool nonLocalFile = !nonFileScheme && !req.url().host().isEmpty(); - - // Ignore requests which cause Zeal to hang - if (nonLocalFile || nonFileScheme) { - return QNetworkAccessManager::createRequest(QNetworkAccessManager::GetOperation, - QNetworkRequest()); - } -#ifdef Q_OS_WIN32 - // Fix for AngularJS docset - Windows doesn't allow ':'s in filenames, - // and bsdtar.exe replaces them with '_'s, so replace all ':'s in requests - // with '_'s. - QNetworkRequest winReq(req); - QUrl winUrl(req.url()); - QString winPath = winUrl.path(); - // absolute paths are of form /C:/..., so don't replace colons occuring - // within first 3 characters - while (winPath.lastIndexOf(':') > 2) - winPath = winPath.replace(winPath.lastIndexOf(':'), 1, "_"); - - winUrl.setPath(winPath); - winReq.setUrl(winUrl); - return QNetworkAccessManager::createRequest(op, winReq, outgoingData); -#else - return QNetworkAccessManager::createRequest(op, req, outgoingData); -#endif -} diff --git a/src/ui/networkaccessmanager.h b/src/ui/networkaccessmanager.h deleted file mode 100644 index e66f6ee9f..000000000 --- a/src/ui/networkaccessmanager.h +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015-2016 Oleg Shparber -** Copyright (C) 2013-2014 Jerzy Kozera -** Contact: http://zealdocs.org/contact.html -** -** This file is part of Zeal. -** -** Zeal is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Zeal is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Zeal. If not, see . -** -****************************************************************************/ - -#ifndef NETWORKACCESSMANAGER_H -#define NETWORKACCESSMANAGER_H - -#include - -namespace Zeal { - -class NetworkAccessManager : public QNetworkAccessManager -{ - Q_OBJECT -public: - explicit NetworkAccessManager(QObject *parent = nullptr); - - QNetworkReply *createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &req, - QIODevice *outgoingData = nullptr) override; -}; - -} // namespace Zeal - -#endif // NETWORKACCESSMANAGER_H