mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
Created new base WebView and WebPage classes.
- they can be used standalone, they are no longer bound to being in TabWidget
This commit is contained in:
parent
61d41046b6
commit
bbadb4ec37
@ -16,61 +16,94 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#include "webpage.h"
|
#include "webpage.h"
|
||||||
#include "webview.h"
|
#include "tabbedwebview.h"
|
||||||
#include "tabwidget.h"
|
#include "tabwidget.h"
|
||||||
#include "qupzilla.h"
|
#include "qupzilla.h"
|
||||||
#include "downloadmanager.h"
|
#include "downloadmanager.h"
|
||||||
#include "webpluginfactory.h"
|
#include "webpluginfactory.h"
|
||||||
#include "mainapplication.h"
|
#include "mainapplication.h"
|
||||||
|
#ifdef NONBLOCK_JS_DIALOGS
|
||||||
#include "ui_jsconfirm.h"
|
#include "ui_jsconfirm.h"
|
||||||
#include "ui_jsalert.h"
|
#include "ui_jsalert.h"
|
||||||
#include "ui_jsprompt.h"
|
#include "ui_jsprompt.h"
|
||||||
|
#endif
|
||||||
|
#include "ui_closedialog.h"
|
||||||
#include "widget.h"
|
#include "widget.h"
|
||||||
#include "globalfunctions.h"
|
#include "globalfunctions.h"
|
||||||
#include "pluginproxy.h"
|
#include "pluginproxy.h"
|
||||||
#include "speeddial.h"
|
#include "speeddial.h"
|
||||||
|
#include "popupwebpage.h"
|
||||||
|
#include "popupwebview.h"
|
||||||
|
#include "networkmanagerproxy.h"
|
||||||
|
|
||||||
QString WebPage::UserAgent = "";
|
QString WebPage::UserAgent = "";
|
||||||
|
|
||||||
QString WebPage::m_lastUploadLocation = QDir::homePath();
|
QString WebPage::m_lastUploadLocation = QDir::homePath();
|
||||||
|
|
||||||
WebPage::WebPage(WebView* parent, QupZilla* mainClass)
|
WebPage::WebPage(QupZilla* mainClass)
|
||||||
: QWebPage(parent)
|
: QWebPage()
|
||||||
, p_QupZilla(mainClass)
|
, p_QupZilla(mainClass)
|
||||||
, m_view(parent)
|
, m_view(0)
|
||||||
, m_speedDial(mApp->plugins()->speedDial())
|
, m_speedDial(mApp->plugins()->speedDial())
|
||||||
, m_fileWatcher(0)
|
, m_fileWatcher(0)
|
||||||
, m_runningLoop(0)
|
, m_runningLoop(0)
|
||||||
, m_blockAlerts(false)
|
, m_blockAlerts(false)
|
||||||
, m_secureStatus(false)
|
, m_secureStatus(false)
|
||||||
// , m_isOpeningNextWindowAsNewTab(false)
|
, m_isClosing(false)
|
||||||
{
|
{
|
||||||
|
m_networkProxy = new NetworkManagerProxy(this);
|
||||||
|
m_networkProxy->setPrimaryNetworkAccessManager(mApp->networkManager());
|
||||||
|
m_networkProxy->setPage(this);
|
||||||
|
setNetworkAccessManager(m_networkProxy);
|
||||||
|
|
||||||
setForwardUnsupportedContent(true);
|
setForwardUnsupportedContent(true);
|
||||||
setPluginFactory(new WebPluginFactory(this));
|
setPluginFactory(new WebPluginFactory(this));
|
||||||
history()->setMaximumItemCount(20);
|
history()->setMaximumItemCount(20);
|
||||||
|
|
||||||
connect(this, SIGNAL(unsupportedContent(QNetworkReply*)), this, SLOT(handleUnsupportedContent(QNetworkReply*)));
|
connect(this, SIGNAL(unsupportedContent(QNetworkReply*)), this, SLOT(handleUnsupportedContent(QNetworkReply*)));
|
||||||
// connect(this, SIGNAL(loadStarted()), this, SLOT(loadingStarted()));
|
|
||||||
connect(this, SIGNAL(loadProgress(int)), this, SLOT(progress(int)));
|
connect(this, SIGNAL(loadProgress(int)), this, SLOT(progress(int)));
|
||||||
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(finished()));
|
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(finished()));
|
||||||
connect(m_view, SIGNAL(urlChanged(QUrl)), this, SLOT(urlChanged(QUrl)));
|
connect(this, SIGNAL(printRequested(QWebFrame*)), this, SLOT(printFrame(QWebFrame*)));
|
||||||
|
connect(this, SIGNAL(downloadRequested(QNetworkRequest)), this, SLOT(downloadRequested(QNetworkRequest)));
|
||||||
|
|
||||||
connect(mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(addJavaScriptObject()));
|
connect(mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(addJavaScriptObject()));
|
||||||
connect(this, SIGNAL(printRequested(QWebFrame*)), this, SLOT(printFrame(QWebFrame*)));
|
}
|
||||||
|
|
||||||
m_runningLoop = 0;
|
QUrl WebPage::url() const
|
||||||
|
{
|
||||||
|
return mainFrame()->url();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebPage::setWebView(TabbedWebView* view)
|
||||||
|
{
|
||||||
|
if (m_view == view) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_view) {
|
||||||
|
delete m_view;
|
||||||
|
m_view = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_view = view;
|
||||||
|
m_view->setWebPage(this);
|
||||||
|
|
||||||
|
connect(m_view, SIGNAL(urlChanged(QUrl)), this, SLOT(urlChanged(QUrl)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebPage::scheduleAdjustPage()
|
void WebPage::scheduleAdjustPage()
|
||||||
{
|
{
|
||||||
if (m_view->isLoading()) {
|
if (m_view && m_view->isLoading()) {
|
||||||
m_adjustingScheduled = true;
|
m_adjustingScheduled = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mainFrame()->setZoomFactor(mainFrame()->zoomFactor() + 1);
|
mainFrame()->setZoomFactor(mainFrame()->zoomFactor() + 1);
|
||||||
mainFrame()->setZoomFactor(mainFrame()->zoomFactor() - 1);
|
mainFrame()->setZoomFactor(mainFrame()->zoomFactor() - 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WebPage::isRunningLoop()
|
||||||
|
{
|
||||||
|
return m_runningLoop;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebPage::urlChanged(const QUrl &url)
|
void WebPage::urlChanged(const QUrl &url)
|
||||||
@ -101,19 +134,19 @@ void WebPage::finished()
|
|||||||
mainFrame()->setZoomFactor(mainFrame()->zoomFactor() - 1);
|
mainFrame()->setZoomFactor(mainFrame()->zoomFactor() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mainFrame()->url().scheme() == "file") {
|
if (url().scheme() == "file") {
|
||||||
if (!m_fileWatcher) {
|
if (!m_fileWatcher) {
|
||||||
m_fileWatcher = new QFileSystemWatcher(this);
|
m_fileWatcher = new QFileSystemWatcher(this);
|
||||||
connect(m_fileWatcher, SIGNAL(fileChanged(QString)), this, SLOT(watchedFileChanged(QString)));
|
connect(m_fileWatcher, SIGNAL(fileChanged(QString)), this, SLOT(watchedFileChanged(QString)));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString filePath = mainFrame()->url().toLocalFile();
|
QString filePath = url().toLocalFile();
|
||||||
|
|
||||||
if (!m_fileWatcher->files().contains(filePath)) {
|
if (QFile::exists(filePath) && !m_fileWatcher->files().contains(filePath)) {
|
||||||
m_fileWatcher->addPath(filePath);
|
m_fileWatcher->addPath(filePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (m_fileWatcher) {
|
else if (m_fileWatcher && !m_fileWatcher->files().isEmpty()) {
|
||||||
m_fileWatcher->removePaths(m_fileWatcher->files());
|
m_fileWatcher->removePaths(m_fileWatcher->files());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,26 +155,24 @@ void WebPage::finished()
|
|||||||
|
|
||||||
void WebPage::watchedFileChanged(const QString &file)
|
void WebPage::watchedFileChanged(const QString &file)
|
||||||
{
|
{
|
||||||
if (mainFrame()->url().toLocalFile() == file) {
|
if (url().toLocalFile() == file) {
|
||||||
triggerAction(QWebPage::Reload);
|
triggerAction(QWebPage::Reload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebPage::printFrame(QWebFrame* frame)
|
void WebPage::printFrame(QWebFrame* frame)
|
||||||
{
|
{
|
||||||
p_QupZilla->printPage(frame);
|
WebView* webView = qobject_cast<WebView*>(view());
|
||||||
}
|
if (!webView) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//void WebPage::loadingStarted()
|
webView->printPage(frame);
|
||||||
//{
|
}
|
||||||
// m_adBlockedEntries.clear();
|
|
||||||
// m_blockAlerts = false;
|
|
||||||
// m_SslCert.clear();
|
|
||||||
//}
|
|
||||||
|
|
||||||
void WebPage::addJavaScriptObject()
|
void WebPage::addJavaScriptObject()
|
||||||
{
|
{
|
||||||
if (mainFrame()->url().toString() != "qupzilla:speeddial") {
|
if (url().toString() != "qupzilla:speeddial") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,16 +206,23 @@ void WebPage::handleUnsupportedContent(QNetworkReply* reply)
|
|||||||
qDebug() << "WebPage::UnsupportedContent error" << reply->errorString();
|
qDebug() << "WebPage::UnsupportedContent error" << reply->errorString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebPage::downloadRequested(const QNetworkRequest &request)
|
||||||
|
{
|
||||||
|
DownloadManager* dManager = mApp->downManager();
|
||||||
|
dManager->download(request, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void WebPage::setSSLCertificate(const QSslCertificate &cert)
|
void WebPage::setSSLCertificate(const QSslCertificate &cert)
|
||||||
{
|
{
|
||||||
// if (cert != m_SslCert) -- crashing on linux :-|
|
// if (cert != m_SslCert)
|
||||||
m_SslCert = cert;
|
m_SslCert = cert;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSslCertificate WebPage::sslCertificate()
|
QSslCertificate WebPage::sslCertificate()
|
||||||
{
|
{
|
||||||
if (mainFrame()->url().scheme() == "https" &&
|
if (url().scheme() == "https" &&
|
||||||
m_SslCert.subjectInfo(QSslCertificate::CommonName).remove("*").contains(QRegExp(mainFrame()->url().host()))) {
|
m_SslCert.subjectInfo(QSslCertificate::CommonName).remove("*").contains(QRegExp(url().host()))) {
|
||||||
return m_SslCert;
|
return m_SslCert;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -203,8 +241,10 @@ bool WebPage::acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest &r
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type == QWebPage::NavigationTypeFormResubmitted) {
|
if (type == QWebPage::NavigationTypeFormResubmitted) {
|
||||||
bool result = javaScriptConfirm(frame, tr("To show this page, QupZilla must resend request which do it again \n"
|
QString message = tr("To show this page, QupZilla must resend request which do it again \n"
|
||||||
"(like searching on making an shoping, which has been already done.)"));
|
"(like searching on making an shoping, which has been already done.)");
|
||||||
|
bool result = (QMessageBox::question(view(), tr("Resend request confirmation"),
|
||||||
|
message, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -217,29 +257,21 @@ bool WebPage::acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest &r
|
|||||||
void WebPage::populateNetworkRequest(QNetworkRequest &request)
|
void WebPage::populateNetworkRequest(QNetworkRequest &request)
|
||||||
{
|
{
|
||||||
WebPage* pagePointer = this;
|
WebPage* pagePointer = this;
|
||||||
WebView* webViewPointer = m_view;
|
|
||||||
|
|
||||||
QVariant variant = qVariantFromValue((void*) pagePointer);
|
QVariant variant = qVariantFromValue((void*) pagePointer);
|
||||||
request.setAttribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100), variant);
|
request.setAttribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100), variant);
|
||||||
request.setAttribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 101), m_lastRequestType);
|
request.setAttribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 101), m_lastRequestType);
|
||||||
|
|
||||||
variant = qVariantFromValue((void*) webViewPointer);
|
|
||||||
request.setAttribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 102), variant);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QWebPage* WebPage::createWindow(QWebPage::WebWindowType type)
|
QWebPage* WebPage::createWindow(QWebPage::WebWindowType type)
|
||||||
{
|
{
|
||||||
// if (m_isOpeningNextWindowAsNewTab)
|
#if 0
|
||||||
// return 0;
|
|
||||||
// m_isOpeningNextWindowAsNewTab = false;
|
|
||||||
// qDebug() << type;
|
|
||||||
// QWebView* view = new QWebView();
|
|
||||||
// view->show();
|
|
||||||
// return view->page();
|
|
||||||
|
|
||||||
Q_UNUSED(type);
|
Q_UNUSED(type);
|
||||||
int index = p_QupZilla->tabWidget()->addView(QUrl(), TabWidget::CleanSelectedPage);
|
int index = p_QupZilla->tabWidget()->addView(QUrl(), TabWidget::CleanSelectedPage);
|
||||||
return p_QupZilla->weView(index)->page();
|
return p_QupZilla->weView(index)->page();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return new PopupWebPage(type, p_QupZilla);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebPage::addAdBlockRule(const QString &filter, const QUrl &url)
|
void WebPage::addAdBlockRule(const QString &filter, const QUrl &url)
|
||||||
@ -263,7 +295,7 @@ void WebPage::cleanBlockedObjects()
|
|||||||
}
|
}
|
||||||
|
|
||||||
findingStrings.append(entry.url.toString());
|
findingStrings.append(entry.url.toString());
|
||||||
QUrl mainFrameUrl = mainFrame()->url();
|
QUrl mainFrameUrl = url();
|
||||||
if (entry.url.scheme() == mainFrameUrl.scheme() && entry.url.host() == mainFrameUrl.host()) {
|
if (entry.url.scheme() == mainFrameUrl.scheme() && entry.url.host() == mainFrameUrl.host()) {
|
||||||
//May be relative url
|
//May be relative url
|
||||||
QString relativeUrl = qz_makeRelativeUrl(mainFrameUrl, entry.url).toString();
|
QString relativeUrl = qz_makeRelativeUrl(mainFrameUrl, entry.url).toString();
|
||||||
@ -296,16 +328,45 @@ QString WebPage::userAgentForUrl(const QUrl &url) const
|
|||||||
return UserAgent;
|
return UserAgent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WebPage::supportsExtension(Extension extension) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(extension)
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool WebPage::extension(Extension extension, const ExtensionOption* option, ExtensionReturn* output)
|
bool WebPage::extension(Extension extension, const ExtensionOption* option, ExtensionReturn* output)
|
||||||
{
|
{
|
||||||
if (extension == ChooseMultipleFilesExtension) {
|
if (extension == ChooseMultipleFilesExtension) {
|
||||||
return QWebPage::extension(extension, option, output);
|
const QWebPage::ChooseMultipleFilesExtensionOption* exOption = static_cast<const QWebPage::ChooseMultipleFilesExtensionOption*>(option);
|
||||||
|
QWebPage::ChooseMultipleFilesExtensionReturn* exReturn = static_cast<QWebPage::ChooseMultipleFilesExtensionReturn*>(output);
|
||||||
|
|
||||||
|
if (!exOption || !exReturn) {
|
||||||
|
return QWebPage::extension(extension, option, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString suggestedFileName;
|
||||||
|
if (!exOption->suggestedFileNames.isEmpty()) {
|
||||||
|
suggestedFileName = exOption->suggestedFileNames.first();
|
||||||
|
}
|
||||||
|
|
||||||
|
exReturn->fileNames = QFileDialog::getOpenFileNames(0, tr("Select files to upload..."), suggestedFileName);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ErrorPageExtensionOption* exOption = static_cast<const QWebPage::ErrorPageExtensionOption*>(option);
|
const ErrorPageExtensionOption* exOption = static_cast<const QWebPage::ErrorPageExtensionOption*>(option);
|
||||||
ErrorPageExtensionReturn* exReturn = static_cast<QWebPage::ErrorPageExtensionReturn*>(output);
|
ErrorPageExtensionReturn* exReturn = static_cast<QWebPage::ErrorPageExtensionReturn*>(output);
|
||||||
|
|
||||||
|
if (!exOption || !exReturn) {
|
||||||
|
return QWebPage::extension(extension, option, output);
|
||||||
|
}
|
||||||
|
|
||||||
WebPage* erPage = qobject_cast<WebPage*>(exOption->frame->page());
|
WebPage* erPage = qobject_cast<WebPage*>(exOption->frame->page());
|
||||||
|
|
||||||
|
if (!erPage) {
|
||||||
|
return QWebPage::extension(extension, option, output);
|
||||||
|
}
|
||||||
|
|
||||||
QString errorString;
|
QString errorString;
|
||||||
if (exOption->domain == QWebPage::QtNetwork) {
|
if (exOption->domain == QWebPage::QtNetwork) {
|
||||||
switch (exOption->error) {
|
switch (exOption->error) {
|
||||||
@ -414,9 +475,16 @@ bool WebPage::extension(Extension extension, const ExtensionOption* option, Exte
|
|||||||
|
|
||||||
bool WebPage::javaScriptPrompt(QWebFrame* originatingFrame, const QString &msg, const QString &defaultValue, QString* result)
|
bool WebPage::javaScriptPrompt(QWebFrame* originatingFrame, const QString &msg, const QString &defaultValue, QString* result)
|
||||||
{
|
{
|
||||||
WebView* _view = qobject_cast<WebView*>(originatingFrame->page()->view());
|
#ifndef NONBLOCK_JS_DIALOGS
|
||||||
|
return QWebPage::javaScriptPrompt(originatingFrame, msg, defaultValue, result);
|
||||||
|
#else
|
||||||
|
if (m_runningLoop) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
WebView* webView = qobject_cast<WebView*>(originatingFrame->page()->view());
|
||||||
|
ResizableFrame* widget = new ResizableFrame(webView->overlayForJsAlert());
|
||||||
|
|
||||||
ResizableFrame* widget = new ResizableFrame(_view->webTab());
|
|
||||||
widget->setObjectName("jsFrame");
|
widget->setObjectName("jsFrame");
|
||||||
Ui_jsPrompt* ui = new Ui_jsPrompt();
|
Ui_jsPrompt* ui = new Ui_jsPrompt();
|
||||||
ui->setupUi(widget);
|
ui->setupUi(widget);
|
||||||
@ -426,14 +494,14 @@ bool WebPage::javaScriptPrompt(QWebFrame* originatingFrame, const QString &msg,
|
|||||||
widget->resize(originatingFrame->page()->viewportSize());
|
widget->resize(originatingFrame->page()->viewportSize());
|
||||||
widget->show();
|
widget->show();
|
||||||
|
|
||||||
connect(_view, SIGNAL(viewportResized(QSize)), widget, SLOT(slotResize(QSize)));
|
connect(webView, SIGNAL(viewportResized(QSize)), widget, SLOT(slotResize(QSize)));
|
||||||
connect(ui->lineEdit, SIGNAL(returnPressed()), ui->buttonBox->button(QDialogButtonBox::Ok), SLOT(animateClick()));
|
connect(ui->lineEdit, SIGNAL(returnPressed()), ui->buttonBox->button(QDialogButtonBox::Ok), SLOT(animateClick()));
|
||||||
|
|
||||||
QEventLoop eLoop;
|
QEventLoop eLoop;
|
||||||
m_runningLoop = &eLoop;
|
m_runningLoop = &eLoop;
|
||||||
connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), &eLoop, SLOT(quit()));
|
connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), &eLoop, SLOT(quit()));
|
||||||
|
|
||||||
if (eLoop.exec() == 1) {
|
if (eLoop.exec() == 1 || m_isClosing) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
m_runningLoop = 0;
|
m_runningLoop = 0;
|
||||||
@ -443,16 +511,24 @@ bool WebPage::javaScriptPrompt(QWebFrame* originatingFrame, const QString &msg,
|
|||||||
*result = x;
|
*result = x;
|
||||||
|
|
||||||
delete widget;
|
delete widget;
|
||||||
_view->setFocus();
|
webView->setFocus();
|
||||||
|
|
||||||
return _result;
|
return _result;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebPage::javaScriptConfirm(QWebFrame* originatingFrame, const QString &msg)
|
bool WebPage::javaScriptConfirm(QWebFrame* originatingFrame, const QString &msg)
|
||||||
{
|
{
|
||||||
WebView* _view = qobject_cast<WebView*>(originatingFrame->page()->view());
|
#ifndef NONBLOCK_JS_DIALOGS
|
||||||
|
return QWebPage::javaScriptConfirm(originatingFrame, msg);
|
||||||
|
#else
|
||||||
|
if (m_runningLoop) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
WebView* webView = qobject_cast<WebView*>(originatingFrame->page()->view());
|
||||||
|
ResizableFrame* widget = new ResizableFrame(webView->overlayForJsAlert());
|
||||||
|
|
||||||
ResizableFrame* widget = new ResizableFrame(_view->webTab());
|
|
||||||
widget->setObjectName("jsFrame");
|
widget->setObjectName("jsFrame");
|
||||||
Ui_jsConfirm* ui = new Ui_jsConfirm();
|
Ui_jsConfirm* ui = new Ui_jsConfirm();
|
||||||
ui->setupUi(widget);
|
ui->setupUi(widget);
|
||||||
@ -461,13 +537,13 @@ bool WebPage::javaScriptConfirm(QWebFrame* originatingFrame, const QString &msg)
|
|||||||
widget->resize(originatingFrame->page()->viewportSize());
|
widget->resize(originatingFrame->page()->viewportSize());
|
||||||
widget->show();
|
widget->show();
|
||||||
|
|
||||||
connect(_view, SIGNAL(viewportResized(QSize)), widget, SLOT(slotResize(QSize)));
|
connect(webView, SIGNAL(viewportResized(QSize)), widget, SLOT(slotResize(QSize)));
|
||||||
|
|
||||||
QEventLoop eLoop;
|
QEventLoop eLoop;
|
||||||
m_runningLoop = &eLoop;
|
m_runningLoop = &eLoop;
|
||||||
connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), &eLoop, SLOT(quit()));
|
connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), &eLoop, SLOT(quit()));
|
||||||
|
|
||||||
if (eLoop.exec() == 1) {
|
if (eLoop.exec() == 1 || m_isClosing) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
m_runningLoop = 0;
|
m_runningLoop = 0;
|
||||||
@ -475,20 +551,36 @@ bool WebPage::javaScriptConfirm(QWebFrame* originatingFrame, const QString &msg)
|
|||||||
bool result = ui->buttonBox->clickedButtonRole() == QDialogButtonBox::AcceptRole;
|
bool result = ui->buttonBox->clickedButtonRole() == QDialogButtonBox::AcceptRole;
|
||||||
|
|
||||||
delete widget;
|
delete widget;
|
||||||
_view->setFocus();
|
webView->setFocus();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebPage::javaScriptAlert(QWebFrame* originatingFrame, const QString &msg)
|
void WebPage::javaScriptAlert(QWebFrame* originatingFrame, const QString &msg)
|
||||||
{
|
{
|
||||||
if (m_blockAlerts) {
|
if (m_blockAlerts || m_runningLoop) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
WebView* _view = qobject_cast<WebView*>(originatingFrame->page()->view());
|
#ifndef NONBLOCK_JS_DIALOGS
|
||||||
|
QDialog dialog(view());
|
||||||
|
Ui_CloseDialog* ui = new Ui_CloseDialog();
|
||||||
|
ui->setupUi(&dialog);
|
||||||
|
ui->buttonBox->setStandardButtons(QDialogButtonBox::Ok);
|
||||||
|
ui->dontAskAgain->setText(tr("Prevent this page from creating additional dialogs"));
|
||||||
|
ui->textLabel->setText(Qt::escape(msg));
|
||||||
|
ui->iconLabel->setPixmap(mApp->style()->standardPixmap(QStyle::SP_MessageBoxInformation));
|
||||||
|
dialog.setWindowTitle(tr("JavaScript alert - %1").arg(originatingFrame->url().host()));
|
||||||
|
dialog.exec();
|
||||||
|
|
||||||
|
if (ui->dontAskAgain->isChecked()) {
|
||||||
|
m_blockAlerts = true;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
WebView* webView = qobject_cast<WebView*>(originatingFrame->page()->view());
|
||||||
|
ResizableFrame* widget = new ResizableFrame(webView->overlayForJsAlert());
|
||||||
|
|
||||||
ResizableFrame* widget = new ResizableFrame(_view->webTab());
|
|
||||||
widget->setObjectName("jsFrame");
|
widget->setObjectName("jsFrame");
|
||||||
Ui_jsAlert* ui = new Ui_jsAlert();
|
Ui_jsAlert* ui = new Ui_jsAlert();
|
||||||
ui->setupUi(widget);
|
ui->setupUi(widget);
|
||||||
@ -497,13 +589,13 @@ void WebPage::javaScriptAlert(QWebFrame* originatingFrame, const QString &msg)
|
|||||||
widget->resize(originatingFrame->page()->viewportSize());
|
widget->resize(originatingFrame->page()->viewportSize());
|
||||||
widget->show();
|
widget->show();
|
||||||
|
|
||||||
connect(_view, SIGNAL(viewportResized(QSize)), widget, SLOT(slotResize(QSize)));
|
connect(webView, SIGNAL(viewportResized(QSize)), widget, SLOT(slotResize(QSize)));
|
||||||
|
|
||||||
QEventLoop eLoop;
|
QEventLoop eLoop;
|
||||||
m_runningLoop = &eLoop;
|
m_runningLoop = &eLoop;
|
||||||
connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), &eLoop, SLOT(quit()));
|
connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), &eLoop, SLOT(quit()));
|
||||||
|
|
||||||
if (eLoop.exec() == 1) {
|
if (eLoop.exec() == 1 || m_isClosing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_runningLoop = 0;
|
m_runningLoop = 0;
|
||||||
@ -512,7 +604,8 @@ void WebPage::javaScriptAlert(QWebFrame* originatingFrame, const QString &msg)
|
|||||||
|
|
||||||
delete widget;
|
delete widget;
|
||||||
|
|
||||||
_view->setFocus();
|
webView->setFocus();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QString WebPage::chooseFile(QWebFrame* originatingFrame, const QString &oldFile)
|
QString WebPage::chooseFile(QWebFrame* originatingFrame, const QString &oldFile)
|
||||||
@ -535,12 +628,19 @@ QString WebPage::chooseFile(QWebFrame* originatingFrame, const QString &oldFile)
|
|||||||
|
|
||||||
void WebPage::disconnectObjects()
|
void WebPage::disconnectObjects()
|
||||||
{
|
{
|
||||||
|
if (m_runningLoop) {
|
||||||
|
m_runningLoop->exit(1);
|
||||||
|
m_runningLoop = 0;
|
||||||
|
}
|
||||||
|
|
||||||
disconnect(this);
|
disconnect(this);
|
||||||
|
m_networkProxy->disconnectObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
WebPage::~WebPage()
|
WebPage::~WebPage()
|
||||||
{
|
{
|
||||||
if (m_runningLoop) {
|
if (m_runningLoop) {
|
||||||
m_runningLoop->exit(1);
|
m_runningLoop->exit(1);
|
||||||
|
m_runningLoop = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
#include <QWebFrame>
|
#include <QWebFrame>
|
||||||
#include <QWebHistory>
|
#include <QWebHistory>
|
||||||
#include <QtNetwork/QtNetwork>
|
#include <QtNetwork/QtNetwork>
|
||||||
#include <QDebug>
|
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
@ -34,8 +33,9 @@
|
|||||||
#include <QFileSystemWatcher>
|
#include <QFileSystemWatcher>
|
||||||
|
|
||||||
class QupZilla;
|
class QupZilla;
|
||||||
class WebView;
|
class TabbedWebView;
|
||||||
class SpeedDial;
|
class SpeedDial;
|
||||||
|
class NetworkManagerProxy;
|
||||||
class WebPage : public QWebPage
|
class WebPage : public QWebPage
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -49,11 +49,15 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
WebPage(WebView* parent, QupZilla* mainClass);
|
WebPage(QupZilla* mainClass);
|
||||||
void populateNetworkRequest(QNetworkRequest &request);
|
|
||||||
~WebPage();
|
~WebPage();
|
||||||
|
|
||||||
WebView* getView() { return m_view; }
|
QUrl url() const;
|
||||||
|
|
||||||
|
void setWebView(TabbedWebView* view);
|
||||||
|
void populateNetworkRequest(QNetworkRequest &request);
|
||||||
|
|
||||||
|
TabbedWebView* getView() { return m_view; }
|
||||||
void setSSLCertificate(const QSslCertificate &cert);
|
void setSSLCertificate(const QSslCertificate &cert);
|
||||||
QSslCertificate sslCertificate();
|
QSslCertificate sslCertificate();
|
||||||
|
|
||||||
@ -64,8 +68,8 @@ public:
|
|||||||
void addAdBlockRule(const QString &filter, const QUrl &url);
|
void addAdBlockRule(const QString &filter, const QUrl &url);
|
||||||
QList<AdBlockedEntry> adBlockedEntries() { return m_adBlockedEntries; }
|
QList<AdBlockedEntry> adBlockedEntries() { return m_adBlockedEntries; }
|
||||||
|
|
||||||
QupZilla* qupzilla() { return p_QupZilla; }
|
|
||||||
void scheduleAdjustPage();
|
void scheduleAdjustPage();
|
||||||
|
bool isRunningLoop();
|
||||||
|
|
||||||
static QString UserAgent;
|
static QString UserAgent;
|
||||||
QString userAgentForUrl(const QUrl &url) const;
|
QString userAgentForUrl(const QUrl &url) const;
|
||||||
@ -78,7 +82,7 @@ signals:
|
|||||||
protected slots:
|
protected slots:
|
||||||
QWebPage* createWindow(QWebPage::WebWindowType type);
|
QWebPage* createWindow(QWebPage::WebWindowType type);
|
||||||
void handleUnsupportedContent(QNetworkReply* url);
|
void handleUnsupportedContent(QNetworkReply* url);
|
||||||
// void loadingStarted();
|
|
||||||
void progress(int prog);
|
void progress(int prog);
|
||||||
void finished();
|
void finished();
|
||||||
|
|
||||||
@ -89,19 +93,21 @@ private slots:
|
|||||||
|
|
||||||
void watchedFileChanged(const QString &file);
|
void watchedFileChanged(const QString &file);
|
||||||
void printFrame(QWebFrame* frame);
|
void printFrame(QWebFrame* frame);
|
||||||
|
void downloadRequested(const QNetworkRequest &request);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool supportsExtension(Extension extension) const { return (extension == ErrorPageExtension); }
|
virtual bool supportsExtension(Extension extension) const;
|
||||||
virtual bool extension(Extension extension, const ExtensionOption* option, ExtensionReturn* output = 0);
|
virtual bool extension(Extension extension, const ExtensionOption* option, ExtensionReturn* output = 0);
|
||||||
bool acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest &request, NavigationType type);
|
bool acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest &request, NavigationType type);
|
||||||
|
|
||||||
QString chooseFile(QWebFrame* originatingFrame, const QString &oldFile);
|
QString chooseFile(QWebFrame* originatingFrame, const QString &oldFile);
|
||||||
|
|
||||||
static QString m_lastUploadLocation;
|
static QString m_lastUploadLocation;
|
||||||
|
|
||||||
QupZilla* p_QupZilla;
|
QupZilla* p_QupZilla;
|
||||||
|
NetworkManagerProxy* m_networkProxy;
|
||||||
QNetworkRequest m_lastRequest;
|
QNetworkRequest m_lastRequest;
|
||||||
QWebPage::NavigationType m_lastRequestType;
|
QWebPage::NavigationType m_lastRequestType;
|
||||||
WebView* m_view;
|
TabbedWebView* m_view;
|
||||||
SpeedDial* m_speedDial;
|
SpeedDial* m_speedDial;
|
||||||
QSslCertificate m_SslCert;
|
QSslCertificate m_SslCert;
|
||||||
QList<QSslCertificate> m_SslCerts;
|
QList<QSslCertificate> m_SslCerts;
|
||||||
@ -113,7 +119,8 @@ private:
|
|||||||
bool m_blockAlerts;
|
bool m_blockAlerts;
|
||||||
bool m_secureStatus;
|
bool m_secureStatus;
|
||||||
bool m_adjustingScheduled;
|
bool m_adjustingScheduled;
|
||||||
// bool m_isOpeningNextWindowAsNewTab;
|
|
||||||
|
bool m_isClosing;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WEBPAGE_H
|
#endif // WEBPAGE_H
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -19,167 +19,95 @@
|
|||||||
#define WEBVIEW_H
|
#define WEBVIEW_H
|
||||||
|
|
||||||
#include <QWebView>
|
#include <QWebView>
|
||||||
#include <QDebug>
|
#include <QWebFrame>
|
||||||
#include <QTabWidget>
|
#include <QWebElementCollection>
|
||||||
#include <QContextMenuEvent>
|
#include <QTouchEvent>
|
||||||
#include <QWebElement>
|
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QLabel>
|
#include <QPrintPreviewDialog>
|
||||||
#include <QProcess>
|
#include <QFile>
|
||||||
#include <QWebInspector>
|
|
||||||
#include <QDockWidget>
|
|
||||||
#include <QWebPage>
|
|
||||||
#include <QHostInfo>
|
|
||||||
|
|
||||||
class QupZilla;
|
|
||||||
class TabWidget;
|
|
||||||
class WebPage;
|
|
||||||
class NetworkManagerProxy;
|
|
||||||
class WebTab;
|
|
||||||
class LocationBar;
|
|
||||||
class WebView : public QWebView
|
class WebView : public QWebView
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit WebView(QupZilla* mainClass, WebTab* webTab);
|
explicit WebView(QWidget* parent = 0);
|
||||||
~WebView();
|
|
||||||
bool isLoading() { return m_isLoading;}
|
|
||||||
int getLoading() { return m_progress; }
|
|
||||||
|
|
||||||
void zoomReset();
|
QIcon icon() const;
|
||||||
QUrl url() const;
|
|
||||||
QString title() const;
|
QString title() const;
|
||||||
void reload();
|
QUrl url() const;
|
||||||
WebPage* webPage() const;
|
|
||||||
WebTab* webTab() const;
|
|
||||||
QString getIp() { return m_currentIp; }
|
|
||||||
QLabel* animationLoading(int index, bool addMovie);
|
|
||||||
QIcon siteIcon();
|
|
||||||
void addNotification(QWidget* notif);
|
|
||||||
bool hasRss() { return m_hasRss; }
|
|
||||||
void setMouseWheelEnabled(bool state) { m_mouseWheelEnabled = state; }
|
|
||||||
|
|
||||||
|
bool isLoading() const;
|
||||||
|
int loadProgress() const;
|
||||||
|
|
||||||
|
void addNotification(QWidget* notif);
|
||||||
bool eventFilter(QObject* obj, QEvent* event);
|
bool eventFilter(QObject* obj, QEvent* event);
|
||||||
|
|
||||||
void setLocationBar(LocationBar* bar) { m_locationBar = bar; }
|
virtual QWidget* overlayForJsAlert() = 0;
|
||||||
LocationBar* locationBar() { return m_locationBar; }
|
|
||||||
|
|
||||||
static QUrl guessUrlFromString(const QString &string);
|
|
||||||
static bool isUrlValid(const QUrl &url);
|
static bool isUrlValid(const QUrl &url);
|
||||||
int tabIndex() const;
|
static QUrl guessUrlFromString(const QString &string);
|
||||||
|
|
||||||
void disconnectObjects();
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void showUrl(QUrl url);
|
void viewportResized(QSize);
|
||||||
void wantsCloseTab(int index);
|
void showNotification(QWidget*);
|
||||||
void changed();
|
void iconChanged();
|
||||||
void ipChanged(QString ip);
|
|
||||||
void showNotification(QWidget* notif);
|
|
||||||
void viewportResized(QSize size);
|
|
||||||
void rssChanged(bool state);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void load(const QUrl &url);
|
|
||||||
void titleChanged();
|
|
||||||
|
|
||||||
void stop();
|
|
||||||
void back();
|
|
||||||
void forward();
|
|
||||||
void slotReload();
|
|
||||||
void iconChanged();
|
|
||||||
void selectAll();
|
|
||||||
void closeTab();
|
|
||||||
|
|
||||||
void zoomIn();
|
void zoomIn();
|
||||||
void zoomOut();
|
void zoomOut();
|
||||||
|
void zoomReset();
|
||||||
|
|
||||||
private slots:
|
void load(const QUrl &url);
|
||||||
void copyText();
|
void reload();
|
||||||
|
|
||||||
void trackMouse(bool state) { m_mouseTrack = state; }
|
void back();
|
||||||
void showImage();
|
void forward();
|
||||||
void copyImageToClipboard();
|
|
||||||
void downloadImageToDisk();
|
void selectAll();
|
||||||
void searchSelectedText();
|
void printPage(QWebFrame* frame = 0);
|
||||||
void copyLinkToClipboard();
|
|
||||||
void loadStarted();
|
virtual void closeView() = 0;
|
||||||
void downloadRequested(const QNetworkRequest &request);
|
|
||||||
void setProgress(int prog);
|
protected slots:
|
||||||
void loadFinished(bool state);
|
void slotLoadStarted();
|
||||||
void linkClicked(const QUrl &url);
|
void slotLoadProgress(int progress);
|
||||||
void urlChanged(const QUrl &url);
|
void slotLoadFinished();
|
||||||
void linkHovered(const QString &link, const QString &title, const QString &content);
|
|
||||||
void openUrlInNewWindow();
|
|
||||||
void openUrlInNewTab();
|
|
||||||
void downloadLinkToDisk();
|
|
||||||
void sendLinkByMail();
|
|
||||||
void bookmarkLink();
|
|
||||||
void showSource();
|
|
||||||
void showSourceOfSelection();
|
|
||||||
void showSiteInfo();
|
|
||||||
void getFocus(const QUrl &urla);
|
|
||||||
void showInspector();
|
|
||||||
void stopAnimation();
|
|
||||||
void setIp(const QHostInfo &info);
|
|
||||||
void checkRss();
|
|
||||||
void slotIconChanged();
|
void slotIconChanged();
|
||||||
|
|
||||||
// ClickedFrame
|
// Context menu slots
|
||||||
void loadClickedFrame();
|
void openUrlInNewWindow();
|
||||||
void loadClickedFrameInNewTab();
|
void sendLinkByMail();
|
||||||
void reloadClickedFrame();
|
void copyLinkToClipboard();
|
||||||
void printClickedFrame();
|
void downloadLinkToDisk();
|
||||||
void clickedFrameZoomIn();
|
void copyImageToClipboard();
|
||||||
void clickedFrameZoomOut();
|
void openActionUrl();
|
||||||
void clickedFrameZoomReset();
|
void showSource(QWebFrame* frame = 0, const QString &selectedHtml = QString());
|
||||||
void showClickedFrameSource();
|
void showSiteInfo();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void wheelEvent(QWheelEvent* event);
|
||||||
|
void mousePressEvent(QMouseEvent* event);
|
||||||
|
void keyPressEvent(QKeyEvent* event);
|
||||||
|
void resizeEvent(QResizeEvent* event);
|
||||||
|
|
||||||
|
void setZoom(int zoom);
|
||||||
|
void applyZoom();
|
||||||
|
void copyText();
|
||||||
|
QUrl lastUrl();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void mousePressEvent(QMouseEvent* event);
|
|
||||||
void mouseReleaseEvent(QMouseEvent* event);
|
|
||||||
void contextMenuEvent(QContextMenuEvent* event);
|
|
||||||
void wheelEvent(QWheelEvent* event);
|
|
||||||
void mouseMoveEvent(QMouseEvent* event);
|
|
||||||
void resizeEvent(QResizeEvent* event);
|
|
||||||
void keyPressEvent(QKeyEvent* event);
|
|
||||||
|
|
||||||
TabWidget* tabWidget() const;
|
|
||||||
bool isCurrent();
|
|
||||||
void applyZoom();
|
|
||||||
|
|
||||||
QupZilla* p_QupZilla;
|
|
||||||
|
|
||||||
QString m_hoveredLink;
|
|
||||||
QList<int> m_zoomLevels;
|
QList<int> m_zoomLevels;
|
||||||
QUrl m_aboutToLoadUrl;
|
|
||||||
QUrl m_lastUrl;
|
|
||||||
QString m_currentIp;
|
|
||||||
QIcon m_siteIcon;
|
|
||||||
int m_progress;
|
|
||||||
int m_currentZoom;
|
int m_currentZoom;
|
||||||
|
|
||||||
WebPage* m_page;
|
QIcon m_siteIcon;
|
||||||
WebTab* m_webTab;
|
QUrl m_siteIconUrl;
|
||||||
NetworkManagerProxy* m_networkProxy;
|
|
||||||
LocationBar* m_locationBar;
|
|
||||||
QMenu* m_menu;
|
|
||||||
QWebFrame* m_clickedFrame;
|
|
||||||
|
|
||||||
bool m_mouseTrack;
|
|
||||||
bool m_navigationVisible;
|
|
||||||
bool m_mouseWheelEnabled;
|
|
||||||
bool m_wantsClose;
|
|
||||||
bool m_isLoading;
|
bool m_isLoading;
|
||||||
|
int m_progress;
|
||||||
bool m_hasRss;
|
QUrl m_aboutToLoadUrl;
|
||||||
bool m_rssChecked;
|
QUrl m_lastUrl;
|
||||||
|
|
||||||
QList<QTouchEvent::TouchPoint> m_touchPoints;
|
QList<QTouchEvent::TouchPoint> m_touchPoints;
|
||||||
//QTimer* m_loadingTimer;
|
|
||||||
|
|
||||||
// static QList<WebView*> s_deletedPointers;
|
|
||||||
// static bool isPointerValid(WebView* pointer);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WEBVIEW_H
|
#endif // WEBVIEW_H
|
||||||
|
Loading…
Reference in New Issue
Block a user