2010-12-10 Jocelyn Turcotte <jocelyn.turcotte@nokia.com>

        Reviewed by Kenneth Rohde Christiansen.

        [Qt] Make QtTestBrowser spawn QNAM in a secondary thread.

        A menu allows to switch QNAM back to the same thread.

        * QtTestBrowser/launcherwindow.cpp:
        (LauncherWindow::initializeView):
        (LauncherWindow::createChrome):
        (LauncherWindow::toggleThreadedQnam):
        * QtTestBrowser/launcherwindow.h:
        (WindowOptions::WindowOptions):
        * QtTestBrowser/webpage.cpp:
        (WebPage::WebPage):
        (WebPage::setQnamThreaded):
        * QtTestBrowser/webpage.h:
        (QnamThread::QnamThread):
        (QnamThread::~QnamThread):
        (QnamThread::networkAccessManager):
        (QnamThread::run):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@73712 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 004662b8
2010-12-10 Jocelyn Turcotte <jocelyn.turcotte@nokia.com>
Reviewed by Kenneth Rohde Christiansen.
[Qt] Make QtTestBrowser spawn QNAM in a secondary thread.
A menu allows to switch QNAM back to the same thread.
* QtTestBrowser/launcherwindow.cpp:
(LauncherWindow::initializeView):
(LauncherWindow::createChrome):
(LauncherWindow::toggleThreadedQnam):
* QtTestBrowser/launcherwindow.h:
(WindowOptions::WindowOptions):
* QtTestBrowser/webpage.cpp:
(WebPage::WebPage):
(WebPage::setQnamThreaded):
* QtTestBrowser/webpage.h:
(QnamThread::QnamThread):
(QnamThread::~QnamThread):
(QnamThread::networkAccessManager):
(QnamThread::run):
2010-12-10 Martin Robinson <mrobinson@igalia.com>
Reviewed by Xan Lopez.
......
......@@ -95,6 +95,7 @@ void LauncherWindow::initializeView()
QUrl url = page()->mainFrame()->url();
setPage(new WebPage(this));
page()->setQnamThreaded(m_windowOptions.useThreadedQnam);
QSplitter* splitter = static_cast<QSplitter*>(centralWidget());
......@@ -234,6 +235,10 @@ void LauncherWindow::createChrome()
toggleWebGL->setCheckable(true);
toggleWebGL->setChecked(settings->testAttribute(QWebSettings::WebGLEnabled));
QAction* toggleThreadedQnam = toolsMenu->addAction("Toggle threaded network", this, SLOT(toggleThreadedQnam(bool)));
toggleThreadedQnam->setCheckable(true);
toggleThreadedQnam->setChecked(m_windowOptions.useThreadedQnam);
QAction* spatialNavigationAction = toolsMenu->addAction("Toggle Spatial Navigation", this, SLOT(toggleSpatialNavigation(bool)));
spatialNavigationAction->setCheckable(true);
spatialNavigationAction->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_S));
......@@ -702,6 +707,12 @@ void LauncherWindow::toggleWebGL(bool toggle)
page()->settings()->setAttribute(QWebSettings::WebGLEnabled, toggle);
}
void LauncherWindow::toggleThreadedQnam(bool toggle)
{
m_windowOptions.useThreadedQnam = toggle;
page()->setQnamThreaded(toggle);
}
void LauncherWindow::animatedFlip()
{
qobject_cast<WebViewGraphicsBased*>(m_view)->animatedFlip();
......
......@@ -87,6 +87,7 @@ public:
#else
, useFrameFlattening(false)
#endif
, useThreadedQnam(true)
, cacheWebView(false)
, showFrameRate(false)
, resizesToContents(false)
......@@ -102,6 +103,7 @@ public:
bool useTiledBackingStore;
bool useWebGL;
bool useFrameFlattening;
bool useThreadedQnam;
bool cacheWebView;
bool showFrameRate;
bool resizesToContents;
......@@ -153,6 +155,7 @@ protected slots:
void toggleTiledBackingStore(bool toggle);
void toggleResizesToContents(bool toggle);
void toggleWebGL(bool toggle);
void toggleThreadedQnam(bool toggle);
void toggleSpatialNavigation(bool b);
void toggleFullScreenMode(bool enable);
void toggleFrameFlattening(bool toggle);
......
......@@ -48,8 +48,6 @@ WebPage::WebPage(QObject* parent)
{
applyProxy();
connect(networkAccessManager(), SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)),
this, SLOT(authenticationRequired(QNetworkReply*, QAuthenticator*)));
connect(this, SIGNAL(featurePermissionRequested(QWebFrame*, QWebPage::Feature)), this, SLOT(requestPermission(QWebFrame*, QWebPage::Feature)));
connect(this, SIGNAL(featurePermissionRequestCanceled(QWebFrame*, QWebPage::Feature)), this, SLOT(featurePermissionRequestCanceled(QWebFrame*, QWebPage::Feature)));
}
......@@ -121,6 +119,28 @@ QString WebPage::userAgentForUrl(const QUrl& url) const
return QWebPage::userAgentForUrl(url);
}
void WebPage::setQnamThreaded(bool threaded)
{
bool alreadyThreaded = networkAccessManager()->thread() != thread();
if (threaded == alreadyThreaded)
return;
if (threaded) {
m_qnamThread.reset(new QtNAMThread);
m_qnamThread->start();
setNetworkAccessManager(m_qnamThread->networkAccessManager());
} else {
setNetworkAccessManager(0);
m_qnamThread.reset();
}
Qt::ConnectionType connectionType = threaded ? Qt::BlockingQueuedConnection : Qt::DirectConnection;
connect(networkAccessManager(), SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)),
this, SLOT(authenticationRequired(QNetworkReply*, QAuthenticator*)),
connectionType);
applyProxy();
}
bool WebPage::shouldInterruptJavaScript()
{
if (!m_interruptingJavaScriptEnabled)
......
......@@ -33,9 +33,14 @@
#ifndef webpage_h
#define webpage_h
#include <QFuture>
#include <QScopedPointer>
#include <QThread>
#include <qwebframe.h>
#include <qwebpage.h>
class QtNAMThread;
class WebPage : public QWebPage {
Q_OBJECT
......@@ -51,6 +56,7 @@ public:
QString userAgentForUrl(const QUrl& url) const;
void setInterruptingJavaScriptEnabled(bool enabled) { m_interruptingJavaScriptEnabled = enabled; }
void setQnamThreaded(bool threaded);
public slots:
void openUrlInDefaultBrowser(const QUrl& url = QUrl());
......@@ -64,6 +70,36 @@ private:
void applyProxy();
QString m_userAgent;
bool m_interruptingJavaScriptEnabled;
QScopedPointer<QtNAMThread> m_qnamThread;
};
class QtNAMThread : public QThread {
public:
QtNAMThread()
{
m_qnamFuture.reportStarted();
}
~QtNAMThread()
{
quit();
wait();
}
QFuture<QNetworkAccessManager*> networkAccessManager()
{
return m_qnamFuture.future();
}
protected:
void run()
{
QNetworkAccessManager qnam;
m_qnamFuture.reportResult(&qnam);
m_qnamFuture.reportFinished();
exec();
}
private:
QFutureInterface<QNetworkAccessManager*> m_qnamFuture;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment