1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-22 02:02:10 +02:00

Plugins: New method in API (createRequest in network manager)

This commit is contained in:
nowrep 2012-07-08 00:15:03 +02:00
parent f9b38c4376
commit 7fee7053d4
10 changed files with 47 additions and 15 deletions

View File

@ -193,7 +193,7 @@ void AdBlockManager::load()
continue; continue;
} }
const QString absolutePath = adblockDir.absoluteFilePath(fileName); const QString &absolutePath = adblockDir.absoluteFilePath(fileName);
QFile file(absolutePath); QFile file(absolutePath);
if (!file.open(QFile::ReadOnly)) { if (!file.open(QFile::ReadOnly)) {
continue; continue;

View File

@ -69,7 +69,7 @@ public slots:
AdBlockDialog* showDialog(); AdBlockDialog* showDialog();
private: private:
bool canBeBlocked(const QUrl &url) const; inline bool canBeBlocked(const QUrl &url) const;
static AdBlockManager* s_adBlockManager; static AdBlockManager* s_adBlockManager;
bool m_loaded; bool m_loaded;

View File

@ -355,6 +355,12 @@ QNetworkReply* NetworkManager::createRequest(QNetworkAccessManager::Operation op
} }
} }
// Plugins
reply = mApp->plugins()->createRequest(op, request, outgoingData);
if (reply) {
return reply;
}
if (m_doNotTrack) { if (m_doNotTrack) {
req.setRawHeader("DNT", QByteArray("1")); req.setRawHeader("DNT", QByteArray("1"));
} }

View File

@ -81,6 +81,8 @@ public:
virtual bool keyPress(const Qz::ObjectName &type, QObject* obj, QKeyEvent* event) { Q_UNUSED(type) Q_UNUSED(obj) Q_UNUSED(event) return false; } virtual bool keyPress(const Qz::ObjectName &type, QObject* obj, QKeyEvent* event) { Q_UNUSED(type) Q_UNUSED(obj) Q_UNUSED(event) return false; }
virtual bool keyRelease(const Qz::ObjectName &type, QObject* obj, QKeyEvent* event) { Q_UNUSED(type) Q_UNUSED(obj) Q_UNUSED(event) return false; } virtual bool keyRelease(const Qz::ObjectName &type, QObject* obj, QKeyEvent* event) { Q_UNUSED(type) Q_UNUSED(obj) Q_UNUSED(event) return false; }
virtual QNetworkReply* createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice* outgoingData) { Q_UNUSED(op) Q_UNUSED(request) Q_UNUSED(outgoingData) return 0; }
}; };
Q_DECLARE_INTERFACE(PluginInterface, "QupZilla.Browser.PluginInterface/1.1") Q_DECLARE_INTERFACE(PluginInterface, "QupZilla.Browser.PluginInterface/1.1")

View File

@ -191,6 +191,18 @@ bool PluginProxy::processKeyRelease(const Qz::ObjectName &type, QObject* obj, QK
return accepted; return accepted;
} }
QNetworkReply* PluginProxy::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice* outgoingData)
{
foreach(PluginInterface * iPlugin, m_loadedPlugins) {
QNetworkReply* reply = iPlugin->createRequest(op, request, outgoingData);
if (reply) {
return reply;
}
}
return 0;
}
void PluginProxy::emitWebPageCreated(WebPage* page) void PluginProxy::emitWebPageCreated(WebPage* page)
{ {
emit webPageCreated(page); emit webPageCreated(page);

View File

@ -49,6 +49,8 @@ public:
bool processKeyPress(const Qz::ObjectName &type, QObject* obj, QKeyEvent* event); bool processKeyPress(const Qz::ObjectName &type, QObject* obj, QKeyEvent* event);
bool processKeyRelease(const Qz::ObjectName &type, QObject* obj, QKeyEvent* event); bool processKeyRelease(const Qz::ObjectName &type, QObject* obj, QKeyEvent* event);
QNetworkReply* createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice* outgoingData);
void emitWebPageCreated(WebPage* page); void emitWebPageCreated(WebPage* page);
void emitWebPageDeleted(WebPage* page); void emitWebPageDeleted(WebPage* page);

View File

@ -33,6 +33,11 @@ QNetworkReply* FollowRedirectReply::reply() const
return m_reply; return m_reply;
} }
QUrl FollowRedirectReply::originalUrl() const
{
return m_reply->request().url();
}
QUrl FollowRedirectReply::url() const QUrl FollowRedirectReply::url() const
{ {
return m_reply->url(); return m_reply->url();

View File

@ -36,6 +36,7 @@ public:
~FollowRedirectReply(); ~FollowRedirectReply();
QNetworkReply* reply() const; QNetworkReply* reply() const;
QUrl originalUrl() const;
QUrl url() const; QUrl url() const;
QNetworkReply::NetworkError error() const; QNetworkReply::NetworkError error() const;

View File

@ -53,13 +53,15 @@ QPixmap qz_pixmapFromByteArray(const QByteArray &data)
QByteArray qz_readAllFileContents(const QString &filename) QByteArray qz_readAllFileContents(const QString &filename)
{ {
QFile file(filename); QFile file(filename);
file.open(QFile::ReadOnly); if (file.open(QFile::ReadOnly)) {
QByteArray a = file.readAll(); QByteArray a = file.readAll();
file.close(); file.close();
return a; return a;
} }
return QByteArray();
}
void qz_centerWidgetOnScreen(QWidget* w) void qz_centerWidgetOnScreen(QWidget* w)
{ {
const QRect screen = QApplication::desktop()->screenGeometry(); const QRect screen = QApplication::desktop()->screenGeometry();
@ -176,23 +178,24 @@ QString qz_urlEncodeQueryString(const QUrl &url)
return returnString; return returnString;
} }
QString qz_ensureUniqueFilename(const QString &pathToFile) QString qz_ensureUniqueFilename(const QString &name, const QString &appendFormat)
{ {
if (!QFile::exists(pathToFile)) { if (!QFile::exists(name)) {
return pathToFile; return name;
} }
QString tmpFileName = pathToFile; QString tmpFileName = name;
int i = 1; int i = 1;
while (QFile::exists(tmpFileName)) { while (QFile::exists(tmpFileName)) {
tmpFileName = pathToFile; tmpFileName = name;
int index = tmpFileName.lastIndexOf("."); int index = tmpFileName.lastIndexOf(".");
QString appendString = appendFormat.arg(i);
if (index == -1) { if (index == -1) {
tmpFileName.append("(" + QString::number(i) + ")"); tmpFileName.append(appendString);
} }
else { else {
tmpFileName = tmpFileName.left(index) + "(" + QString::number(i) + ")" + tmpFileName.mid(index); tmpFileName = tmpFileName.left(index) + appendString + tmpFileName.mid(index);
} }
i++; i++;
} }

View File

@ -19,6 +19,7 @@
#define GLOBALFUNCTIONS_H #define GLOBALFUNCTIONS_H
#include <QList> #include <QList>
#include <QString>
#include "qz_namespace.h" #include "qz_namespace.h"
@ -43,7 +44,7 @@ QString QT_QUPZILLA_EXPORT qz_samePartOfStrings(const QString &one, const QStrin
QUrl QT_QUPZILLA_EXPORT qz_makeRelativeUrl(const QUrl &baseUrl, const QUrl &rUrl); QUrl QT_QUPZILLA_EXPORT qz_makeRelativeUrl(const QUrl &baseUrl, const QUrl &rUrl);
QString QT_QUPZILLA_EXPORT qz_urlEncodeQueryString(const QUrl &url); QString QT_QUPZILLA_EXPORT qz_urlEncodeQueryString(const QUrl &url);
QString QT_QUPZILLA_EXPORT qz_ensureUniqueFilename(const QString &name); QString QT_QUPZILLA_EXPORT qz_ensureUniqueFilename(const QString &name, const QString &appendFormat = QString("(%1)"));
QString QT_QUPZILLA_EXPORT qz_getFileNameFromUrl(const QUrl &url); QString QT_QUPZILLA_EXPORT qz_getFileNameFromUrl(const QUrl &url);
QString QT_QUPZILLA_EXPORT qz_filterCharsFromFilename(const QString &name); QString QT_QUPZILLA_EXPORT qz_filterCharsFromFilename(const QString &name);