1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

Implement changing custom user agent

Per-domain user agent is however not working
This commit is contained in:
David Rosca 2015-05-22 22:00:06 +02:00
parent c08a584333
commit bbc7628de0
2 changed files with 10 additions and 18 deletions

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* QupZilla - WebKit based browser * QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com> * Copyright (C) 2010-2015 David Rosca <nowrep@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -20,13 +20,12 @@
#include "qztools.h" #include "qztools.h"
#include "settings.h" #include "settings.h"
#include <QWebEnginePage> // QTWEBKIT_VERSION_CHECK macro #include <QWebEngineProfile>
UserAgentManager::UserAgentManager(QObject* parent) UserAgentManager::UserAgentManager(QObject* parent)
: QObject(parent) : QObject(parent)
, m_usePerDomainUserAgent(false) , m_usePerDomainUserAgent(false)
{ {
m_fakeUserAgent = QString("Mozilla/5.0 (%1) AppleWebKit/%2 (KHTML, like Gecko) Chrome/37.0 Safari/537.36").arg(QzTools::operatingSystem());
} }
void UserAgentManager::loadSettings() void UserAgentManager::loadSettings()
@ -49,6 +48,13 @@ void UserAgentManager::loadSettings()
m_userAgentsList[domainList.at(i)] = userAgentsList.at(i); m_userAgentsList[domainList.at(i)] = userAgentsList.at(i);
} }
} }
QString userAgent = m_globalUserAgent;
if (userAgent.isEmpty()) {
userAgent = QWebEngineProfile::defaultProfile()->httpUserAgent();
userAgent.replace(QSL("QtWebEngine/%1").arg(qVersion()), QSL("QupZilla/%1").arg(Qz::VERSION));
}
QWebEngineProfile::defaultProfile()->setHttpUserAgent(userAgent);
} }
QString UserAgentManager::userAgentForUrl(const QUrl &url) const QString UserAgentManager::userAgentForUrl(const QUrl &url) const
@ -65,19 +71,6 @@ QString UserAgentManager::userAgentForUrl(const QUrl &url) const
} }
} }
#if QTWEBKIT_TO_2_3
if (host.contains(QLatin1String("google"))) {
return m_fakeUserAgent;
}
#endif
#ifdef Q_OS_WIN
// Facebook chat is not working with default user-agent
if (host.endsWith(QLatin1String("facebook.com"))) {
return "Mozilla/5.0 (Windows XP) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.77 Safari/535.7";
}
#endif
return m_globalUserAgent; return m_globalUserAgent;
} }

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* QupZilla - WebKit based browser * QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com> * Copyright (C) 2010-2015 David Rosca <nowrep@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -42,7 +42,6 @@ public:
private: private:
QString m_globalUserAgent; QString m_globalUserAgent;
QString m_fakeUserAgent;
bool m_usePerDomainUserAgent; bool m_usePerDomainUserAgent;
QHash<QString, QString> m_userAgentsList; QHash<QString, QString> m_userAgentsList;