11#include "alkwebview.h"
13#if defined(BUILD_WITH_WEBENGINE)
14#include "../3rdparty/qtwebengine/tests/auto/util/util.h"
18#include <QContextMenuEvent>
19#include <QDesktopServices>
25#include <QWebEnginePage>
26#include <QWebEngineProfile>
27#include <QWebEngineView>
29class AlkWebPage::Private :
public QObject
36 explicit Private(AlkWebPage *_q)
40 Private(
const Private& right) =
delete;
41 Private& operator=(
const Private& right) =
delete;
44AlkWebPage::AlkWebPage(
QWidget *parent)
45 : QWebEnginePage(parent)
46 , d(new Private(this))
50AlkWebPage::~AlkWebPage()
55void AlkWebPage::load(
const QUrl &url,
const QString &acceptLanguage)
57 profile()->setHttpAcceptLanguage(acceptLanguage);
63 CallbackSpy<QString> spy;
64 QWebEnginePage::toHtml(spy.ref());
65 QString
html = d->timeout != -1 ? spy.waitForResult(d->timeout) : spy.waitForResult();
83void AlkWebPage::setTimeout(
int timeout)
88int AlkWebPage::timeout()
93bool AlkWebPage::acceptNavigationRequest(
const QUrl &url, QWebEnginePage::NavigationType type,
bool isMainFrame)
95 if (type == QWebEnginePage::NavigationTypeRedirect && isMainFrame)
96 Q_EMIT loadRedirectedTo(url);
97 return QWebEnginePage::acceptNavigationRequest(url, type, isMainFrame);
100#include "alkwebpage.moc"
102#elif defined(BUILD_WITH_WEBKIT)
104#include <QWebElement>
105#include <QWebInspector>
107#include <QNetworkRequest>
109class AlkWebPage::Private
113 QNetworkAccessManager *networkAccessManager;
114 explicit Private(AlkWebPage *
parent)
116 , networkAccessManager(new QNetworkAccessManager)
118#if QT_VERSION >= QT_VERSION_CHECK(5,9,0)
122 p->setNetworkAccessManager(networkAccessManager);
127 delete networkAccessManager;
131AlkWebPage::AlkWebPage(
QObject *parent)
133 , d(new Private(this))
135 settings()->setAttribute(QWebSettings::JavaEnabled,
false);
136 settings()->setAttribute(QWebSettings::AutoLoadImages,
false);
137 settings()->setAttribute(QWebSettings::PluginsEnabled,
false);
140AlkWebPage::~AlkWebPage()
145void AlkWebPage::load(
const QUrl &url,
const QString &acceptLanguage)
147 QNetworkRequest request;
151#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
156 if (url.hasQueryItem(QLatin1String(
"method")) && url.queryItemValue(QLatin1String(
"method")).toLower()== QLatin1String(
"post")) {
161 mainFrame()->load(request);
167 mainFrame()->setHtml(data);
172 QWebFrame *frame = mainFrame();
173 return frame->toHtml();
176QStringList AlkWebPage::getAllElements(
const QString &symbol)
179 QWebFrame *frame = mainFrame();
180 QWebElementCollection elements = frame->findAllElements(symbol);
181 for (
const auto &e: elements) {
182 result.
append(e.toPlainText());
187QString AlkWebPage::getFirstElement(
const QString &symbol)
189 QWebFrame *frame = mainFrame();
190 QWebElement element = frame->findFirstElement(symbol);
191 return element.toPlainText();
197#include <QNetworkAccessManager>
198#include <QNetworkReply>
201class AlkWebPage::Private
210 setOpenExternalLinks(
false);
212 connect(
this, SIGNAL(sourceChanged(
QUrl)), SIGNAL(loadRedirectedTo(
QUrl)));
215AlkWebPage::~AlkWebPage()
220void AlkWebPage::load(
const QUrl &url,
const QString &acceptLanguage)
222 Q_UNUSED(acceptLanguage)
223#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
231void AlkWebPage::setUrl(
const QUrl &url)
233 load(url, QString());
240 return QStringList();
250QVariant AlkWebPage::loadResource(
int type,
const QUrl &name)
255 QNetworkAccessManager networkManager;
256 QNetworkRequest request;
258 QNetworkReply* reply = networkManager.
get(request);
260 connect(reply, SIGNAL(finished()), &loop, SLOT(
quit()));
263 QString data = reply->
readAll();
264 Q_EMIT loadFinished(
true);
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
QAction * quit(const QObject *recvr, const char *slot, QObject *parent)
int exec(ProcessEventsFlags flags)
void append(QList< T > &&value)
QNetworkReply * get(const QNetworkRequest &request)
void setRedirectPolicy(QNetworkRequest::RedirectPolicy policy)
void setUrl(const QUrl &url)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QByteArray toLocal8Bit() const const
QString toLower() const const
QByteArray toUtf8() const const
QTextBrowser(QWidget *parent)
void setSource(const QUrl &url, QTextDocument::ResourceType type)
QString toHtml() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QString query(ComponentFormattingOptions options) const const