2011-03-03 18:29:20 +01:00
/* ============================================================
* QupZilla - WebKit based browser
2012-01-01 15:29:55 +01:00
* Copyright ( C ) 2010 - 2012 David Rosca < nowrep @ gmail . com >
2011-03-03 18:29:20 +01:00
*
* 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
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program 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 this program . If not , see < http : //www.gnu.org/licenses/>.
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
2011-03-02 16:57:41 +01:00
# include "webpage.h"
2012-01-21 20:20:48 +01:00
# include "tabbedwebview.h"
2011-03-02 16:57:41 +01:00
# include "tabwidget.h"
# include "qupzilla.h"
# include "downloadmanager.h"
# include "webpluginfactory.h"
# include "mainapplication.h"
2012-03-15 19:35:37 +01:00
# include "checkboxdialog.h"
2011-05-22 10:47:03 +02:00
# include "widget.h"
2011-09-18 15:35:44 +02:00
# include "globalfunctions.h"
2011-12-02 23:25:27 +01:00
# include "pluginproxy.h"
2011-12-09 21:56:01 +01:00
# include "speeddial.h"
2012-01-21 20:20:48 +01:00
# include "popupwebpage.h"
# include "popupwebview.h"
# include "networkmanagerproxy.h"
2012-02-04 18:45:59 +01:00
# include "adblockicon.h"
2012-06-25 16:07:25 +02:00
# include "adblockmanager.h"
2012-03-28 16:42:50 +02:00
# include "iconprovider.h"
2012-04-13 13:26:32 +02:00
# include "websettings.h"
2011-03-02 16:57:41 +01:00
2012-03-16 23:28:23 +01:00
# ifdef NONBLOCK_JS_DIALOGS
# include "ui_jsconfirm.h"
# include "ui_jsalert.h"
# include "ui_jsprompt.h"
# include <QPushButton>
# endif
2012-02-29 18:33:50 +01:00
# include <QDir>
# include <QWebHistory>
# include <QFileSystemWatcher>
# include <QTimer>
# include <QNetworkReply>
# include <QDebug>
# include <QDesktopServices>
# include <QMessageBox>
# include <QFileDialog>
# include <QWebFrame>
2012-04-17 18:26:01 +02:00
QString WebPage : : s_lastUploadLocation = QDir : : homePath ( ) ;
QString WebPage : : s_userAgent ;
QString WebPage : : s_fakeUserAgent ;
QUrl WebPage : : s_lastUnsupportedUrl ;
QList < WebPage * > WebPage : : s_livingPages ;
2011-10-26 19:23:50 +02:00
2012-01-21 20:20:48 +01:00
WebPage : : WebPage ( QupZilla * mainClass )
: QWebPage ( )
2011-10-26 19:23:50 +02:00
, p_QupZilla ( mainClass )
2012-01-21 20:20:48 +01:00
, m_view ( 0 )
2011-12-02 23:25:27 +01:00
, m_speedDial ( mApp - > plugins ( ) - > speedDial ( ) )
2011-12-15 19:08:33 +01:00
, m_fileWatcher ( 0 )
2011-12-13 15:38:09 +01:00
, m_runningLoop ( 0 )
2012-07-03 15:22:42 +02:00
, m_loadProgress ( - 1 )
2011-10-26 19:23:50 +02:00
, m_blockAlerts ( false )
, m_secureStatus ( false )
2012-04-04 17:41:33 +02:00
, m_adjustingScheduled ( false )
2011-03-02 16:57:41 +01:00
{
2012-01-21 20:20:48 +01:00
m_networkProxy = new NetworkManagerProxy ( this ) ;
m_networkProxy - > setPrimaryNetworkAccessManager ( mApp - > networkManager ( ) ) ;
m_networkProxy - > setPage ( this ) ;
setNetworkAccessManager ( m_networkProxy ) ;
2011-03-02 16:57:41 +01:00
setForwardUnsupportedContent ( true ) ;
setPluginFactory ( new WebPluginFactory ( this ) ) ;
2011-07-31 00:50:40 +02:00
history ( ) - > setMaximumItemCount ( 20 ) ;
2011-12-02 23:25:27 +01:00
2012-01-14 11:46:06 +01:00
connect ( this , SIGNAL ( unsupportedContent ( QNetworkReply * ) ) , this , SLOT ( handleUnsupportedContent ( QNetworkReply * ) ) ) ;
2011-07-11 20:30:49 +02:00
connect ( this , SIGNAL ( loadProgress ( int ) ) , this , SLOT ( progress ( int ) ) ) ;
2011-07-11 22:53:32 +02:00
connect ( this , SIGNAL ( loadFinished ( bool ) ) , this , SLOT ( finished ( ) ) ) ;
2012-01-21 20:20:48 +01:00
connect ( this , SIGNAL ( printRequested ( QWebFrame * ) ) , this , SLOT ( printFrame ( QWebFrame * ) ) ) ;
connect ( this , SIGNAL ( downloadRequested ( QNetworkRequest ) ) , this , SLOT ( downloadRequested ( QNetworkRequest ) ) ) ;
2012-03-04 14:25:52 +01:00
connect ( this , SIGNAL ( windowCloseRequested ( ) ) , this , SLOT ( windowCloseRequested ( ) ) ) ;
2011-12-02 23:25:27 +01:00
connect ( mainFrame ( ) , SIGNAL ( javaScriptWindowObjectCleared ( ) ) , this , SLOT ( addJavaScriptObject ( ) ) ) ;
2012-03-15 19:35:37 +01:00
2012-03-16 13:53:49 +01:00
# ifdef USE_QTWEBKIT_2_2
2012-03-15 19:35:37 +01:00
connect ( this , SIGNAL ( featurePermissionRequested ( QWebFrame * , QWebPage : : Feature ) ) , this , SLOT ( featurePermissionRequested ( QWebFrame * , QWebPage : : Feature ) ) ) ;
# endif
2012-04-03 19:28:12 +02:00
2012-04-17 18:26:01 +02:00
s_livingPages . append ( this ) ;
2012-01-21 20:20:48 +01:00
}
2011-12-13 15:38:09 +01:00
2012-01-21 20:20:48 +01:00
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 ) ) ) ;
2011-10-09 14:51:25 +02:00
}
2011-11-12 09:45:32 +01:00
void WebPage : : scheduleAdjustPage ( )
{
2012-03-04 14:25:52 +01:00
WebView * webView = qobject_cast < WebView * > ( view ( ) ) ;
if ( ! webView ) {
return ;
}
if ( webView - > isLoading ( ) ) {
2011-11-12 09:45:32 +01:00
m_adjustingScheduled = true ;
}
else {
2012-03-04 14:25:52 +01:00
const QSize & originalSize = webView - > size ( ) ;
QSize newSize ( originalSize . width ( ) - 1 , originalSize . height ( ) - 1 ) ;
webView - > resize ( newSize ) ;
webView - > resize ( originalSize ) ;
2011-11-12 09:45:32 +01:00
}
2012-01-21 20:20:48 +01:00
}
2011-11-12 09:45:32 +01:00
2012-04-04 14:45:45 +02:00
bool WebPage : : loadingError ( ) const
{
return ! mainFrame ( ) - > findFirstElement ( " span[id= \" qupzilla-error-page \" ] " ) . isNull ( ) ;
}
2012-07-03 15:22:42 +02:00
void WebPage : : addRejectedCerts ( const QList < QSslCertificate > & certs )
{
foreach ( const QSslCertificate & cert , certs ) {
if ( ! m_rejectedSslCerts . contains ( cert ) ) {
m_rejectedSslCerts . append ( cert ) ;
}
}
}
2012-07-03 21:54:04 +02:00
bool WebPage : : containsRejectedCerts ( const QList < QSslCertificate > & certs )
2012-07-03 15:22:42 +02:00
{
int matches = 0 ;
foreach ( const QSslCertificate & cert , certs ) {
if ( m_rejectedSslCerts . contains ( cert ) ) {
+ + matches ;
}
2012-07-03 21:54:04 +02:00
if ( m_sslCert = = cert ) {
m_sslCert . clear ( ) ;
}
2012-07-03 15:22:42 +02:00
}
return matches = = certs . count ( ) ;
}
2012-01-21 20:20:48 +01:00
bool WebPage : : isRunningLoop ( )
{
return m_runningLoop ;
2011-11-12 09:45:32 +01:00
}
2012-07-03 15:22:42 +02:00
bool WebPage : : isLoading ( ) const
{
return m_loadProgress < 100 ;
}
2012-02-07 18:37:44 +01:00
void WebPage : : setUserAgent ( const QString & agent )
{
2012-07-15 23:23:16 +02:00
s_userAgent = agent ;
2012-02-07 18:37:44 +01:00
}
2011-10-09 14:51:25 +02:00
void WebPage : : urlChanged ( const QUrl & url )
{
Q_UNUSED ( url )
2012-02-04 19:43:43 +01:00
2012-07-03 15:22:42 +02:00
if ( isLoading ( ) ) {
m_adBlockedEntries . clear ( ) ;
m_blockAlerts = false ;
}
2011-07-11 20:30:49 +02:00
}
void WebPage : : progress ( int prog )
{
2012-07-03 15:22:42 +02:00
m_loadProgress = prog ;
2012-02-04 19:43:43 +01:00
2011-07-11 20:30:49 +02:00
bool secStatus = sslCertificate ( ) . isValid ( ) ;
if ( secStatus ! = m_secureStatus ) {
m_secureStatus = secStatus ;
emit privacyChanged ( sslCertificate ( ) . isValid ( ) ) ;
}
2011-03-02 16:57:41 +01:00
}
2011-07-11 22:53:32 +02:00
void WebPage : : finished ( )
{
progress ( 100 ) ;
2011-10-30 16:32:36 +01:00
if ( m_adjustingScheduled ) {
m_adjustingScheduled = false ;
mainFrame ( ) - > setZoomFactor ( mainFrame ( ) - > zoomFactor ( ) + 1 ) ;
mainFrame ( ) - > setZoomFactor ( mainFrame ( ) - > zoomFactor ( ) - 1 ) ;
}
2012-01-21 20:20:48 +01:00
if ( url ( ) . scheme ( ) = = " file " ) {
2011-12-15 19:08:33 +01:00
if ( ! m_fileWatcher ) {
m_fileWatcher = new QFileSystemWatcher ( this ) ;
connect ( m_fileWatcher , SIGNAL ( fileChanged ( QString ) ) , this , SLOT ( watchedFileChanged ( QString ) ) ) ;
}
2012-02-04 19:43:43 +01:00
const QString & filePath = url ( ) . toLocalFile ( ) ;
2011-12-15 19:08:33 +01:00
2012-01-21 20:20:48 +01:00
if ( QFile : : exists ( filePath ) & & ! m_fileWatcher - > files ( ) . contains ( filePath ) ) {
2011-12-16 12:03:47 +01:00
m_fileWatcher - > addPath ( filePath ) ;
2011-12-15 19:08:33 +01:00
}
}
2012-01-21 20:20:48 +01:00
else if ( m_fileWatcher & & ! m_fileWatcher - > files ( ) . isEmpty ( ) ) {
2011-12-15 19:08:33 +01:00
m_fileWatcher - > removePaths ( m_fileWatcher - > files ( ) ) ;
}
2012-07-15 23:18:08 +02:00
cleanBlockedObjects ( ) ;
2011-07-11 22:53:32 +02:00
}
2011-12-15 19:08:33 +01:00
void WebPage : : watchedFileChanged ( const QString & file )
{
2012-01-21 20:20:48 +01:00
if ( url ( ) . toLocalFile ( ) = = file ) {
2011-12-15 19:08:33 +01:00
triggerAction ( QWebPage : : Reload ) ;
}
}
2012-01-07 10:29:38 +01:00
void WebPage : : printFrame ( QWebFrame * frame )
2012-01-04 19:02:33 +01:00
{
2012-01-21 20:20:48 +01:00
WebView * webView = qobject_cast < WebView * > ( view ( ) ) ;
if ( ! webView ) {
return ;
}
2012-01-04 19:02:33 +01:00
2012-01-21 20:20:48 +01:00
webView - > printPage ( frame ) ;
}
2011-05-22 10:47:03 +02:00
2011-12-02 23:25:27 +01:00
void WebPage : : addJavaScriptObject ( )
{
2012-01-21 20:20:48 +01:00
if ( url ( ) . toString ( ) ! = " qupzilla:speeddial " ) {
2011-12-02 23:25:27 +01:00
return ;
}
mainFrame ( ) - > addToJavaScriptWindowObject ( " speeddial " , m_speedDial ) ;
m_speedDial - > addWebFrame ( mainFrame ( ) ) ;
}
2011-03-02 16:57:41 +01:00
void WebPage : : handleUnsupportedContent ( QNetworkReply * reply )
{
2011-11-06 17:01:23 +01:00
if ( ! reply ) {
2011-03-02 16:57:41 +01:00
return ;
2011-11-06 17:01:23 +01:00
}
2012-02-04 19:43:43 +01:00
const QUrl & url = reply - > url ( ) ;
2011-03-02 16:57:41 +01:00
2011-11-06 17:01:23 +01:00
switch ( reply - > error ( ) ) {
2011-03-02 16:57:41 +01:00
case QNetworkReply : : NoError :
2012-02-11 14:19:41 +01:00
if ( reply - > header ( QNetworkRequest : : ContentTypeHeader ) . isValid ( ) ) {
QString requestUrl = reply - > request ( ) . url ( ) . toString ( QUrl : : RemoveFragment | QUrl : : RemoveQuery ) ;
if ( requestUrl . endsWith ( " .swf " ) ) {
2012-03-13 15:10:18 +01:00
const QWebElement & docElement = mainFrame ( ) - > documentElement ( ) ;
const QWebElement & object = docElement . findFirst ( QString ( " object[src= \" %1 \" ] " ) . arg ( requestUrl ) ) ;
const QWebElement & embed = docElement . findFirst ( QString ( " embed[src= \" %1 \" ] " ) . arg ( requestUrl ) ) ;
2012-02-11 14:19:41 +01:00
if ( ! object . isNull ( ) | | ! embed . isNull ( ) ) {
qDebug ( ) < < " WebPage::UnsupportedContent " < < url < < " Attempt to download flash object on site! " ;
reply - > deleteLater ( ) ;
return ;
}
}
2011-03-04 13:59:07 +01:00
DownloadManager * dManager = mApp - > downManager ( ) ;
2011-11-08 15:20:53 +01:00
dManager - > handleUnsupportedContent ( reply , this ) ;
2011-03-02 16:57:41 +01:00
return ;
}
2012-02-11 12:52:23 +01:00
2012-02-17 18:55:34 +01:00
case QNetworkReply : : ProtocolUnknownError : {
2012-02-11 12:52:23 +01:00
qDebug ( ) < < " WebPage::UnsupportedContent " < < url < < " ProtocolUnknowError " ;
2012-02-12 18:02:05 +01:00
2012-03-13 16:43:23 +01:00
// We will open last unsupported url only once
// (to prevent endless loop in case QDesktopServices::openUrl decide
// to open the url again in QupZilla )
2012-04-17 18:26:01 +02:00
if ( s_lastUnsupportedUrl ! = url ) {
s_lastUnsupportedUrl = url ;
2012-02-12 18:02:05 +01:00
QDesktopServices : : openUrl ( url ) ;
}
2012-02-11 12:52:23 +01:00
reply - > deleteLater ( ) ;
2011-03-02 16:57:41 +01:00
return ;
2012-02-17 18:55:34 +01:00
}
2011-03-02 16:57:41 +01:00
default :
break ;
}
2012-02-04 19:43:43 +01:00
2012-02-11 12:52:23 +01:00
qDebug ( ) < < " WebPage::UnsupportedContent error " < < url < < reply - > errorString ( ) ;
reply - > deleteLater ( ) ;
2011-03-02 16:57:41 +01:00
}
2012-04-13 13:26:32 +02:00
void WebPage : : handleUnknownProtocol ( const QUrl & url )
{
const QString & protocol = url . scheme ( ) ;
if ( WebSettings : : blockedProtocols . contains ( protocol ) ) {
qDebug ( ) < < " WebPage::handleUnknownProtocol Protocol " < < protocol < < " is blocked! " ;
return ;
}
if ( WebSettings : : autoOpenProtocols . contains ( protocol ) ) {
QDesktopServices : : openUrl ( url ) ;
return ;
}
2012-05-13 17:01:35 +02:00
CheckBoxDialog dialog ( QDialogButtonBox : : Yes | QDialogButtonBox : : No , view ( ) ) ;
const QString & wrappedUrl = qz_alignTextToWidth ( url . toString ( ) , " <br/> " , dialog . fontMetrics ( ) , 450 ) ;
2012-04-13 13:26:32 +02:00
const QString & text = tr ( " QupZilla cannot handle <b>%1:</b> links. The requested link "
" is <ul><li>%2</li></ul>Do you want QupZilla to try "
2012-05-13 17:01:35 +02:00
" open this link in system application? " ) . arg ( protocol , wrappedUrl ) ;
2012-04-13 13:26:32 +02:00
dialog . setText ( text ) ;
dialog . setCheckBoxText ( tr ( " Remember my choice for this protocol " ) ) ;
dialog . setWindowTitle ( tr ( " External Protocol Request " ) ) ;
2012-04-22 20:51:28 +02:00
dialog . setIcon ( qIconProvider - > standardIcon ( QStyle : : SP_MessageBoxQuestion ) ) ;
2012-04-13 13:26:32 +02:00
switch ( dialog . exec ( ) ) {
case QDialog : : Accepted :
if ( dialog . isChecked ( ) ) {
WebSettings : : autoOpenProtocols . append ( protocol ) ;
WebSettings : : saveSettings ( ) ;
}
QDesktopServices : : openUrl ( url ) ;
break ;
case QDialog : : Rejected :
if ( dialog . isChecked ( ) ) {
WebSettings : : blockedProtocols . append ( protocol ) ;
WebSettings : : saveSettings ( ) ;
}
break ;
default :
break ;
}
}
2012-01-21 20:20:48 +01:00
void WebPage : : downloadRequested ( const QNetworkRequest & request )
{
DownloadManager * dManager = mApp - > downManager ( ) ;
dManager - > download ( request , this ) ;
}
2012-03-04 14:25:52 +01:00
void WebPage : : windowCloseRequested ( )
{
WebView * webView = qobject_cast < WebView * > ( view ( ) ) ;
if ( ! webView ) {
return ;
}
webView - > closeView ( ) ;
}
2012-03-16 13:53:49 +01:00
# ifdef USE_QTWEBKIT_2_2
2012-03-15 19:35:37 +01:00
void WebPage : : featurePermissionRequested ( QWebFrame * frame , const QWebPage : : Feature & feature )
{
// We should probably ask user here ... -,-
setFeaturePermission ( frame , feature , PermissionGrantedByUser ) ;
}
# endif
2012-01-21 20:20:48 +01:00
2012-03-16 16:57:24 +01:00
bool WebPage : : event ( QEvent * event )
2012-03-16 15:55:34 +01:00
{
if ( event - > type ( ) = = QEvent : : Leave ) {
// QWebPagePrivate::leaveEvent():
// Fake a mouse move event just outside of the widget, since all
// the interesting mouse-out behavior like invalidating scrollbars
// is handled by the WebKit event handler's mouseMoved function.
// However, its implementation fake mouse move event on QCursor::pos()
// position that is in global screen coordinates. So instead of
// really faking it, it just creates mouse move event somewhere in
// page. It can for example focus a link, and then link url gets
// stuck in status bar message.
// So we are faking mouse move event with proper coordinates for
// so called "just outside of the widget" position
2012-05-27 11:38:21 +02:00
const QPoint cursorPos = view ( ) - > mapFromGlobal ( QCursor : : pos ( ) ) ;
QPoint mousePos ;
2012-05-08 14:28:54 +02:00
2012-05-27 11:38:21 +02:00
if ( cursorPos . y ( ) < 0 ) {
// Left on top
mousePos = QPoint ( cursorPos . x ( ) , - 1 ) ;
}
else if ( cursorPos . x ( ) < 0 ) {
// Left on left
mousePos = QPoint ( - 1 , cursorPos . y ( ) ) ;
}
2012-05-27 12:44:56 +02:00
else if ( cursorPos . y ( ) > view ( ) - > height ( ) ) {
2012-05-27 11:38:21 +02:00
// Left on bottom
mousePos = QPoint ( cursorPos . x ( ) , view ( ) - > height ( ) + 1 ) ;
}
else {
// Left on right
mousePos = QPoint ( view ( ) - > width ( ) + 1 , cursorPos . y ( ) ) ;
}
QMouseEvent fakeEvent ( QEvent : : MouseMove , mousePos , Qt : : NoButton , Qt : : NoButton , Qt : : NoModifier ) ;
2012-03-16 15:55:34 +01:00
return QWebPage : : event ( & fakeEvent ) ;
}
return QWebPage : : event ( event ) ;
}
2011-04-24 09:08:53 +02:00
void WebPage : : setSSLCertificate ( const QSslCertificate & cert )
2011-03-22 21:36:15 +01:00
{
2012-02-17 18:55:34 +01:00
// if (cert != m_SslCert)
2012-07-03 21:54:04 +02:00
m_sslCert = cert ;
2011-03-22 21:36:15 +01:00
}
2011-04-04 16:00:27 +02:00
QSslCertificate WebPage : : sslCertificate ( )
{
2012-07-03 21:54:04 +02:00
if ( url ( ) . scheme ( ) = = " https " & & m_sslCert . isValid ( ) ) {
return m_sslCert ;
2011-11-06 17:01:23 +01:00
}
2012-07-03 21:54:04 +02:00
return QSslCertificate ( ) ;
2011-04-04 16:00:27 +02:00
}
2011-03-17 17:03:04 +01:00
bool WebPage : : acceptNavigationRequest ( QWebFrame * frame , const QNetworkRequest & request , NavigationType type )
2011-03-02 16:57:41 +01:00
{
m_lastRequestType = type ;
2012-07-13 11:04:14 +02:00
m_lastRequestUrl = request . url ( ) ;
2012-02-04 19:43:43 +01:00
const QString & scheme = request . url ( ) . scheme ( ) ;
2011-03-02 16:57:41 +01:00
if ( scheme = = " mailto " | | scheme = = " ftp " ) {
QDesktopServices : : openUrl ( request . url ( ) ) ;
return false ;
}
if ( type = = QWebPage : : NavigationTypeFormResubmitted ) {
2012-01-21 20:20:48 +01:00
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.) " ) ;
2012-01-22 11:49:58 +01:00
bool result = ( QMessageBox : : question ( view ( ) , tr ( " Confirm form resubmission " ) ,
2012-01-21 20:20:48 +01:00
message , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : No ) = = QMessageBox : : Yes ) ;
2011-11-06 17:01:23 +01:00
if ( ! result ) {
2011-03-02 16:57:41 +01:00
return false ;
2011-11-06 17:01:23 +01:00
}
2011-03-02 16:57:41 +01:00
}
bool accept = QWebPage : : acceptNavigationRequest ( frame , request , type ) ;
return accept ;
}
void WebPage : : populateNetworkRequest ( QNetworkRequest & request )
{
2011-12-09 21:56:01 +01:00
WebPage * pagePointer = this ;
2011-11-08 15:20:53 +01:00
QVariant variant = qVariantFromValue ( ( void * ) pagePointer ) ;
2011-03-02 16:57:41 +01:00
request . setAttribute ( ( QNetworkRequest : : Attribute ) ( QNetworkRequest : : User + 100 ) , variant ) ;
2012-07-13 11:04:14 +02:00
if ( m_lastRequestUrl = = request . url ( ) ) {
request . setAttribute ( ( QNetworkRequest : : Attribute ) ( QNetworkRequest : : User + 101 ) , m_lastRequestType ) ;
if ( m_lastRequestType = = NavigationTypeLinkClicked ) {
request . setRawHeader ( " X-QupZilla-UserLoadAction " , QByteArray ( " 1 " ) ) ;
}
}
2011-03-02 16:57:41 +01:00
}
QWebPage * WebPage : : createWindow ( QWebPage : : WebWindowType type )
{
2012-01-21 20:20:48 +01:00
return new PopupWebPage ( type , p_QupZilla ) ;
2011-03-02 16:57:41 +01:00
}
2012-04-15 15:44:08 +02:00
QObject * WebPage : : createPlugin ( const QString & classid , const QUrl & url , const QStringList & paramNames , const QStringList & paramValues )
{
qDebug ( ) < < Q_FUNC_INFO ;
return pluginFactory ( ) - > create ( classid , url , paramNames , paramValues ) ;
}
2012-07-01 18:13:49 +02:00
void WebPage : : addAdBlockRule ( const AdBlockRule * rule , const QUrl & url )
2011-03-29 20:30:05 +02:00
{
AdBlockedEntry entry ;
2012-07-01 18:13:49 +02:00
entry . rule = rule ;
2011-03-29 20:30:05 +02:00
entry . url = url ;
2011-11-06 17:01:23 +01:00
if ( ! m_adBlockedEntries . contains ( entry ) ) {
2011-10-09 14:51:25 +02:00
m_adBlockedEntries . append ( entry ) ;
2011-11-06 17:01:23 +01:00
}
2011-10-09 14:51:25 +02:00
}
void WebPage : : cleanBlockedObjects ( )
{
2012-07-04 10:08:55 +02:00
AdBlockManager * manager = AdBlockManager : : instance ( ) ;
2012-07-13 14:12:48 +02:00
if ( ! manager - > isEnabled ( ) ) {
2012-06-25 16:07:25 +02:00
return ;
}
2012-07-04 10:08:55 +02:00
const QWebElement & docElement = mainFrame ( ) - > documentElement ( ) ;
2011-10-09 14:51:25 +02:00
2012-01-24 19:12:31 +01:00
foreach ( const AdBlockedEntry & entry , m_adBlockedEntries ) {
2012-07-04 10:08:55 +02:00
const QString & urlString = entry . url . toString ( ) ;
if ( urlString . endsWith ( " .js " ) | | urlString . endsWith ( " .css " ) ) {
2011-10-09 14:51:25 +02:00
continue ;
2011-11-06 17:01:23 +01:00
}
2011-10-09 14:51:25 +02:00
2012-07-13 14:12:48 +02:00
QString urlEnd ;
2012-07-04 10:08:55 +02:00
int pos = urlString . lastIndexOf ( ' / ' ) ;
2012-07-13 14:12:48 +02:00
if ( pos > 8 ) {
urlEnd = urlString . mid ( pos + 1 ) ;
}
if ( urlString . endsWith ( ' / ' ) ) {
urlEnd = urlString . left ( urlString . size ( ) - 1 ) ;
2011-10-09 14:51:25 +02:00
}
2011-08-04 21:37:04 +02:00
2012-07-04 10:08:55 +02:00
QString selector ( " img[src$= \" " + urlEnd + " \" ], iframe[src$= \" " + urlEnd + " \" ], "
" embed[src$= \" " + urlEnd + " \" ] " ) ;
QWebElementCollection elements = docElement . findAll ( selector ) ;
2012-01-23 17:30:34 +01:00
2012-07-04 10:08:55 +02:00
foreach ( QWebElement element , elements ) {
QString src = element . attribute ( " src " ) ;
src . remove ( " ../ " ) ;
2012-01-23 17:30:34 +01:00
2012-07-13 14:12:48 +02:00
if ( urlString . contains ( src ) ) {
element . setStyleProperty ( " display " , " none " ) ;
2012-07-04 10:08:55 +02:00
}
}
2012-01-23 17:30:34 +01:00
}
2012-06-25 16:07:25 +02:00
// Apply domain-specific element hiding rules
2012-07-04 16:00:53 +02:00
QString elementHiding = AdBlockManager : : instance ( ) - > elementHidingRulesForDomain ( url ( ) ) ;
if ( elementHiding . isEmpty ( ) ) {
return ;
}
2012-06-25 16:07:25 +02:00
elementHiding . append ( " {display: none !important;} \n </style> " ) ;
2012-07-04 10:08:55 +02:00
QWebElement bodyElement = docElement . findFirst ( " body " ) ;
bodyElement . appendInside ( " <style type= \" text/css \" > \n /* AdBlock for QupZilla */ \n " + elementHiding ) ;
2011-03-29 20:30:05 +02:00
}
2011-12-11 19:37:16 +01:00
QString WebPage : : userAgentForUrl ( const QUrl & url ) const
{
2012-04-23 15:50:21 +02:00
const QString & host = url . host ( ) ;
2012-06-15 19:08:43 +02:00
// Let Google services play nice with us
if ( host . contains ( " google " ) ) {
2012-04-17 18:26:01 +02:00
if ( s_fakeUserAgent . isEmpty ( ) ) {
2012-04-24 15:58:36 +02:00
s_fakeUserAgent = QString ( " Mozilla/5.0 (%1) AppleWebKit/%2 (KHTML, like Gecko) Chrome/10.0 Safari/%2 " ) . arg ( qz_buildSystem ( ) , QupZilla : : WEBKITVERSION ) ;
2012-04-05 12:43:48 +02:00
}
2012-04-17 18:26:01 +02:00
return s_fakeUserAgent ;
2012-03-31 21:36:27 +02:00
}
2012-04-17 18:26:01 +02:00
if ( s_userAgent . isEmpty ( ) ) {
s_userAgent = QWebPage : : userAgentForUrl ( url ) ;
2012-01-16 16:28:41 +01:00
# ifdef Q_WS_MAC
# ifdef __i386__ || __x86_64__
2012-02-07 18:37:44 +01:00
m_userAgent . replace ( " PPC Mac OS X " , " Intel Mac OS X " ) ;
2012-01-16 16:28:41 +01:00
# endif
# endif
2011-12-11 19:37:16 +01:00
}
2012-04-17 18:26:01 +02:00
return s_userAgent ;
2011-12-11 19:37:16 +01:00
}
2012-01-21 20:20:48 +01:00
bool WebPage : : supportsExtension ( Extension extension ) const
{
Q_UNUSED ( extension )
return true ;
}
2011-04-25 20:56:45 +02:00
bool WebPage : : extension ( Extension extension , const ExtensionOption * option , ExtensionReturn * output )
2011-03-02 16:57:41 +01:00
{
2011-11-06 17:01:23 +01:00
if ( extension = = ChooseMultipleFilesExtension ) {
2012-01-21 20:20:48 +01:00
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 ( ) ) {
2012-03-28 16:42:50 +02:00
suggestedFileName = exOption - > suggestedFileNames . at ( 0 ) ;
2012-01-21 20:20:48 +01:00
}
exReturn - > fileNames = QFileDialog : : getOpenFileNames ( 0 , tr ( " Select files to upload... " ) , suggestedFileName ) ;
return true ;
2011-11-06 17:01:23 +01:00
}
2011-03-02 16:57:41 +01:00
const ErrorPageExtensionOption * exOption = static_cast < const QWebPage : : ErrorPageExtensionOption * > ( option ) ;
ErrorPageExtensionReturn * exReturn = static_cast < QWebPage : : ErrorPageExtensionReturn * > ( output ) ;
2012-01-21 20:20:48 +01:00
if ( ! exOption | | ! exReturn ) {
return QWebPage : : extension ( extension , option , output ) ;
}
2012-01-13 21:04:40 +01:00
WebPage * erPage = qobject_cast < WebPage * > ( exOption - > frame - > page ( ) ) ;
2012-01-21 20:20:48 +01:00
if ( ! erPage ) {
return QWebPage : : extension ( extension , option , output ) ;
}
2011-03-02 16:57:41 +01:00
QString errorString ;
if ( exOption - > domain = = QWebPage : : QtNetwork ) {
switch ( exOption - > error ) {
case QNetworkReply : : ConnectionRefusedError :
errorString = tr ( " Server refused the connection " ) ;
break ;
case QNetworkReply : : RemoteHostClosedError :
errorString = tr ( " Server closed the connection " ) ;
break ;
case QNetworkReply : : HostNotFoundError :
errorString = tr ( " Server not found " ) ;
break ;
case QNetworkReply : : TimeoutError :
errorString = tr ( " Connection timed out " ) ;
break ;
case QNetworkReply : : SslHandshakeFailedError :
errorString = tr ( " Untrusted connection " ) ;
break ;
2012-01-14 12:44:14 +01:00
case QNetworkReply : : TemporaryNetworkFailureError :
errorString = tr ( " Temporary network failure " ) ;
break ;
case QNetworkReply : : ProxyConnectionRefusedError :
errorString = tr ( " Proxy connection refused " ) ;
break ;
case QNetworkReply : : ProxyNotFoundError :
2012-02-02 16:09:35 +01:00
errorString = tr ( " Proxy server not found " ) ;
2012-01-14 12:44:14 +01:00
break ;
case QNetworkReply : : ProxyTimeoutError :
errorString = tr ( " Proxy connection timed out " ) ;
break ;
case QNetworkReply : : ProxyAuthenticationRequiredError :
errorString = tr ( " Proxy authentication required " ) ;
break ;
case QNetworkReply : : ContentNotFoundError :
errorString = tr ( " Content not found " ) ;
break ;
2012-03-21 15:05:04 +01:00
case QNetworkReply : : UnknownNetworkError :
errorString = exOption - > errorString . isEmpty ( ) ? tr ( " Unknown network error " ) : exOption - > errorString ;
break ;
2012-06-27 20:32:13 +02:00
case QNetworkReply : : ProtocolUnknownError : {
// Sometimes exOption->url returns just "?" instead of actual url
const QUrl unknownProtocolUrl = ( exOption - > url = = QUrl ( " ? " ) ) ? erPage - > mainFrame ( ) - > requestedUrl ( ) : exOption - > url ;
handleUnknownProtocol ( unknownProtocolUrl ) ;
2012-04-13 13:26:32 +02:00
return false ;
2012-06-27 20:32:13 +02:00
}
2011-04-05 18:45:17 +02:00
case QNetworkReply : : ContentAccessDenied :
2012-06-21 21:49:41 +02:00
if ( exOption - > errorString . startsWith ( " AdBlock " ) ) {
2012-01-13 21:04:40 +01:00
if ( exOption - > frame ! = erPage - > mainFrame ( ) ) { //Content in <iframe>
QWebElement docElement = erPage - > mainFrame ( ) - > documentElement ( ) ;
2011-04-21 13:28:07 +02:00
QWebElementCollection elements ;
elements . append ( docElement . findAll ( " iframe " ) ) ;
2012-01-23 17:30:34 +01:00
2011-11-06 17:01:23 +01:00
foreach ( QWebElement element , elements ) {
2011-04-21 13:28:07 +02:00
QString src = element . attribute ( " src " ) ;
2011-11-06 17:01:23 +01:00
if ( exOption - > url . toString ( ) . contains ( src ) ) {
2012-01-23 17:30:34 +01:00
element . setStyleProperty ( " visibility " , " hidden " ) ;
2011-11-06 17:01:23 +01:00
}
2011-04-21 13:28:07 +02:00
}
2012-01-23 17:30:34 +01:00
2011-07-31 00:50:40 +02:00
return false ;
2011-11-06 17:01:23 +01:00
}
else { //The whole page is blocked
2011-07-31 00:50:40 +02:00
QString rule = exOption - > errorString ;
2012-07-01 18:13:49 +02:00
rule . remove ( " AdBlock: " ) ;
2011-07-31 00:50:40 +02:00
QFile file ( " :/html/adblockPage.html " ) ;
file . open ( QFile : : ReadOnly ) ;
QString errString = file . readAll ( ) ;
errString . replace ( " %TITLE% " , tr ( " AdBlocked Content " ) ) ;
2011-12-03 14:43:13 +01:00
errString . replace ( " %IMAGE% " , " qrc:html/adblock_big.png " ) ;
errString . replace ( " %FAVICON% " , " qrc:html/adblock_big.png " ) ;
2011-07-31 00:50:40 +02:00
2012-06-21 21:49:41 +02:00
errString . replace ( " %RULE% " , tr ( " Blocked by <i>%1</i> " ) . arg ( rule ) ) ;
2011-04-21 13:28:07 +02:00
2012-01-31 21:10:22 +01:00
exReturn - > baseUrl = exOption - > url ;
2012-04-04 14:45:45 +02:00
exReturn - > content = QString ( errString + " <span id= \" qupzilla-error-page \" ></span> " ) . toUtf8 ( ) ;
2012-02-04 18:45:59 +01:00
if ( PopupWebPage * popupPage = qobject_cast < PopupWebPage * > ( exOption - > frame - > page ( ) ) ) {
WebView * view = qobject_cast < WebView * > ( popupPage - > view ( ) ) ;
if ( view ) {
// Closing blocked popup
p_QupZilla - > adBlockIcon ( ) - > popupBlocked ( rule , exOption - > url ) ;
view - > closeView ( ) ;
}
}
2011-07-31 00:50:40 +02:00
return true ;
}
2011-04-05 18:45:17 +02:00
}
errorString = tr ( " Content Access Denied " ) ;
break ;
2011-03-02 16:57:41 +01:00
default :
2012-06-24 23:46:32 +02:00
if ( exOption - > errorString ! = " QupZilla:No Error " ) {
qDebug ( ) < < " Content error: " < < exOption - > errorString < < exOption - > error ;
}
2011-07-31 00:50:40 +02:00
return false ;
2011-03-02 16:57:41 +01:00
}
}
else if ( exOption - > domain = = QWebPage : : Http ) {
2012-04-22 21:23:51 +02:00
// 200 status code = OK
// It shouldn't be reported as an error, but sometimes it is ...
if ( exOption - > error = = 200 ) {
return false ;
}
2011-03-02 16:57:41 +01:00
errorString = tr ( " Error code %1 " ) . arg ( exOption - > error ) ;
}
2011-11-06 17:01:23 +01:00
else if ( exOption - > domain = = QWebPage : : WebKit ) {
return false ; // Downloads
}
2011-03-02 16:57:41 +01:00
2012-02-04 19:43:43 +01:00
const QUrl & loadedUrl = exOption - > url ;
2011-03-02 16:57:41 +01:00
exReturn - > baseUrl = loadedUrl ;
QFile file ( " :/html/errorPage.html " ) ;
file . open ( QFile : : ReadOnly ) ;
QString errString = file . readAll ( ) ;
errString . replace ( " %TITLE% " , tr ( " Failed loading page " ) ) ;
2012-04-22 20:51:28 +02:00
errString . replace ( " %IMAGE% " , qz_pixmapToByteArray ( qIconProvider - > standardIcon ( QStyle : : SP_MessageBoxWarning ) . pixmap ( 45 , 45 ) ) ) ;
errString . replace ( " %FAVICON% " , qz_pixmapToByteArray ( qIconProvider - > standardIcon ( QStyle : : SP_MessageBoxWarning ) . pixmap ( 16 , 16 ) ) ) ;
2011-12-02 23:25:27 +01:00
errString . replace ( " %BOX-BORDER% " , " qrc:html/box-border.png " ) ;
2011-03-02 16:57:41 +01:00
errString . replace ( " %HEADING% " , errorString ) ;
2012-01-31 21:10:22 +01:00
errString . replace ( " %HEADING2% " , tr ( " QupZilla can't load page from %1. " ) . arg ( loadedUrl . host ( ) ) ) ;
2011-03-02 16:57:41 +01:00
errString . replace ( " %LI-1% " , tr ( " Check the address for typing errors such as <b>ww.</b>example.com instead of <b>www.</b>example.com " ) ) ;
errString . replace ( " %LI-2% " , tr ( " If you are unable to load any pages, check your computer's network connection. " ) ) ;
errString . replace ( " %LI-3% " , tr ( " If your computer or network is protected by a firewall or proxy, make sure that QupZilla is permitted to access the Web. " ) ) ;
errString . replace ( " %TRY-AGAIN% " , tr ( " Try Again " ) ) ;
2012-04-04 14:45:45 +02:00
exReturn - > content = QString ( errString + " <span id= \" qupzilla-error-page \" ></span> " ) . toUtf8 ( ) ;
2011-03-02 16:57:41 +01:00
return true ;
}
2011-05-22 10:47:03 +02:00
bool WebPage : : javaScriptPrompt ( QWebFrame * originatingFrame , const QString & msg , const QString & defaultValue , QString * result )
{
2012-01-21 20:20:48 +01:00
# 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 ( ) ) ;
2011-05-22 10:47:03 +02:00
2011-11-24 22:18:45 +01:00
widget - > setObjectName ( " jsFrame " ) ;
2011-05-22 10:47:03 +02:00
Ui_jsPrompt * ui = new Ui_jsPrompt ( ) ;
ui - > setupUi ( widget ) ;
ui - > message - > setText ( msg ) ;
ui - > lineEdit - > setText ( defaultValue ) ;
ui - > lineEdit - > setFocus ( ) ;
widget - > resize ( originatingFrame - > page ( ) - > viewportSize ( ) ) ;
widget - > show ( ) ;
2012-01-21 20:20:48 +01:00
connect ( webView , SIGNAL ( viewportResized ( QSize ) ) , widget , SLOT ( slotResize ( QSize ) ) ) ;
2011-05-22 10:47:03 +02:00
connect ( ui - > lineEdit , SIGNAL ( returnPressed ( ) ) , ui - > buttonBox - > button ( QDialogButtonBox : : Ok ) , SLOT ( animateClick ( ) ) ) ;
QEventLoop eLoop ;
2011-12-13 15:38:09 +01:00
m_runningLoop = & eLoop ;
2011-11-06 17:01:23 +01:00
connect ( ui - > buttonBox , SIGNAL ( clicked ( QAbstractButton * ) ) , & eLoop , SLOT ( quit ( ) ) ) ;
2011-12-13 15:38:09 +01:00
2012-04-04 14:45:45 +02:00
if ( eLoop . exec ( ) = = 1 ) {
2011-12-13 15:38:09 +01:00
return result ;
}
m_runningLoop = 0 ;
2011-05-22 10:47:03 +02:00
QString x = ui - > lineEdit - > text ( ) ;
bool _result = ui - > buttonBox - > clickedButtonRole ( ) = = QDialogButtonBox : : AcceptRole ;
* result = x ;
2011-12-13 15:38:09 +01:00
delete widget ;
2012-01-21 20:20:48 +01:00
webView - > setFocus ( ) ;
2011-05-22 10:47:03 +02:00
return _result ;
2012-01-21 20:20:48 +01:00
# endif
2011-05-22 10:47:03 +02:00
}
bool WebPage : : javaScriptConfirm ( QWebFrame * originatingFrame , const QString & msg )
{
2012-01-21 20:20:48 +01:00
# 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 ( ) ) ;
2011-05-22 10:47:03 +02:00
2011-11-24 22:18:45 +01:00
widget - > setObjectName ( " jsFrame " ) ;
2011-05-22 10:47:03 +02:00
Ui_jsConfirm * ui = new Ui_jsConfirm ( ) ;
ui - > setupUi ( widget ) ;
ui - > message - > setText ( msg ) ;
ui - > buttonBox - > button ( QDialogButtonBox : : Ok ) - > setFocus ( ) ;
widget - > resize ( originatingFrame - > page ( ) - > viewportSize ( ) ) ;
widget - > show ( ) ;
2012-01-21 20:20:48 +01:00
connect ( webView , SIGNAL ( viewportResized ( QSize ) ) , widget , SLOT ( slotResize ( QSize ) ) ) ;
2011-05-22 10:47:03 +02:00
QEventLoop eLoop ;
2011-12-13 15:38:09 +01:00
m_runningLoop = & eLoop ;
2011-11-06 17:01:23 +01:00
connect ( ui - > buttonBox , SIGNAL ( clicked ( QAbstractButton * ) ) , & eLoop , SLOT ( quit ( ) ) ) ;
2011-12-13 15:38:09 +01:00
2012-04-04 14:45:45 +02:00
if ( eLoop . exec ( ) = = 1 ) {
2011-12-13 15:38:09 +01:00
return false ;
}
m_runningLoop = 0 ;
2011-05-22 10:47:03 +02:00
bool result = ui - > buttonBox - > clickedButtonRole ( ) = = QDialogButtonBox : : AcceptRole ;
2011-12-13 15:38:09 +01:00
delete widget ;
2012-01-21 20:20:48 +01:00
webView - > setFocus ( ) ;
2011-05-22 10:47:03 +02:00
return result ;
2012-01-21 20:20:48 +01:00
# endif
2011-05-22 10:47:03 +02:00
}
void WebPage : : javaScriptAlert ( QWebFrame * originatingFrame , const QString & msg )
{
2012-02-05 17:13:08 +01:00
Q_UNUSED ( originatingFrame )
2012-01-21 20:20:48 +01:00
if ( m_blockAlerts | | m_runningLoop ) {
2011-05-22 10:47:03 +02:00
return ;
2011-11-06 17:01:23 +01:00
}
2011-05-22 10:47:03 +02:00
2012-01-21 20:20:48 +01:00
# ifndef NONBLOCK_JS_DIALOGS
2012-03-15 19:35:37 +01:00
QString title = tr ( " JavaScript alert " ) ;
if ( ! url ( ) . host ( ) . isEmpty ( ) ) {
title . append ( QString ( " - %1 " ) . arg ( url ( ) . host ( ) ) ) ;
}
CheckBoxDialog dialog ( QDialogButtonBox : : Ok , view ( ) ) ;
dialog . setWindowTitle ( title ) ;
dialog . setText ( msg ) ;
dialog . setCheckBoxText ( tr ( " Prevent this page from creating additional dialogs " ) ) ;
2012-04-22 20:51:28 +02:00
dialog . setIcon ( qIconProvider - > standardIcon ( QStyle : : SP_MessageBoxInformation ) ) ;
2012-03-15 19:35:37 +01:00
dialog . exec ( ) ;
m_blockAlerts = dialog . isChecked ( ) ;
2012-01-21 20:20:48 +01:00
# else
WebView * webView = qobject_cast < WebView * > ( originatingFrame - > page ( ) - > view ( ) ) ;
ResizableFrame * widget = new ResizableFrame ( webView - > overlayForJsAlert ( ) ) ;
2011-05-22 10:47:03 +02:00
2011-11-24 22:18:45 +01:00
widget - > setObjectName ( " jsFrame " ) ;
2011-05-22 10:47:03 +02:00
Ui_jsAlert * ui = new Ui_jsAlert ( ) ;
ui - > setupUi ( widget ) ;
ui - > message - > setText ( msg ) ;
ui - > buttonBox - > button ( QDialogButtonBox : : Ok ) - > setFocus ( ) ;
widget - > resize ( originatingFrame - > page ( ) - > viewportSize ( ) ) ;
widget - > show ( ) ;
2012-01-21 20:20:48 +01:00
connect ( webView , SIGNAL ( viewportResized ( QSize ) ) , widget , SLOT ( slotResize ( QSize ) ) ) ;
2011-05-22 10:47:03 +02:00
QEventLoop eLoop ;
2011-12-13 15:38:09 +01:00
m_runningLoop = & eLoop ;
2011-11-06 17:01:23 +01:00
connect ( ui - > buttonBox , SIGNAL ( clicked ( QAbstractButton * ) ) , & eLoop , SLOT ( quit ( ) ) ) ;
2011-12-13 15:38:09 +01:00
2012-04-04 14:45:45 +02:00
if ( eLoop . exec ( ) = = 1 ) {
2011-12-13 15:38:09 +01:00
return ;
}
m_runningLoop = 0 ;
2011-05-22 10:47:03 +02:00
m_blockAlerts = ui - > preventAlerts - > isChecked ( ) ;
delete widget ;
2012-01-21 20:20:48 +01:00
webView - > setFocus ( ) ;
# endif
2011-05-22 10:47:03 +02:00
}
2011-11-06 17:01:23 +01:00
QString WebPage : : chooseFile ( QWebFrame * originatingFrame , const QString & oldFile )
2011-05-22 11:05:36 +02:00
{
QString suggFileName ;
2012-02-04 19:43:43 +01:00
2011-11-06 17:01:23 +01:00
if ( oldFile . isEmpty ( ) ) {
2012-04-17 18:26:01 +02:00
suggFileName = s_lastUploadLocation ;
2011-11-06 17:01:23 +01:00
}
else {
2011-05-22 11:05:36 +02:00
suggFileName = oldFile ;
2011-11-06 17:01:23 +01:00
}
2012-02-04 19:43:43 +01:00
const QString & fileName = QFileDialog : : getOpenFileName ( originatingFrame - > page ( ) - > view ( ) , tr ( " Choose file... " ) , suggFileName ) ;
2011-05-22 11:05:36 +02:00
2011-11-06 17:01:23 +01:00
if ( ! fileName . isEmpty ( ) ) {
2012-04-17 18:26:01 +02:00
s_lastUploadLocation = fileName ;
2011-11-06 17:01:23 +01:00
}
2011-05-22 11:05:36 +02:00
return fileName ;
}
2012-04-03 19:28:12 +02:00
bool WebPage : : isPointerSafeToUse ( WebPage * page )
2012-04-02 19:33:05 +02:00
{
2012-04-03 19:28:12 +02:00
// Pointer to WebPage is passed with every QNetworkRequest casted to void*
// So there is no way to test whether pointer is still valid or not, except
// this hack.
2012-04-17 18:26:01 +02:00
return page = = 0 ? false : s_livingPages . contains ( page ) ;
2012-04-02 19:33:05 +02:00
}
2012-01-14 11:46:06 +01:00
void WebPage : : disconnectObjects ( )
{
2012-01-21 20:20:48 +01:00
if ( m_runningLoop ) {
m_runningLoop - > exit ( 1 ) ;
m_runningLoop = 0 ;
}
2012-04-17 18:26:01 +02:00
s_livingPages . removeOne ( this ) ;
2012-04-02 19:33:05 +02:00
2012-01-14 11:46:06 +01:00
disconnect ( this ) ;
2012-01-21 20:20:48 +01:00
m_networkProxy - > disconnectObjects ( ) ;
2012-04-01 10:48:50 +02:00
mApp - > plugins ( ) - > emitWebPageDeleted ( this ) ;
2012-01-14 11:46:06 +01:00
}
2011-03-02 16:57:41 +01:00
WebPage : : ~ WebPage ( )
{
2011-12-13 15:38:09 +01:00
if ( m_runningLoop ) {
m_runningLoop - > exit ( 1 ) ;
2012-01-21 20:20:48 +01:00
m_runningLoop = 0 ;
2011-12-13 15:38:09 +01:00
}
2012-04-02 19:33:05 +02:00
2012-04-17 18:26:01 +02:00
s_livingPages . removeOne ( this ) ;
2011-03-02 16:57:41 +01:00
}