Changeset 73712 in webkit


Ignore:
Timestamp:
Dec 10, 2010 2:51:18 AM (13 years ago)
Author:
jocelyn.turcotte@nokia.com
Message:

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):
Location:
trunk/WebKitTools
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r73695 r73712  
     12010-12-10  Jocelyn Turcotte  <jocelyn.turcotte@nokia.com>
     2
     3        Reviewed by Kenneth Rohde Christiansen.
     4
     5        [Qt] Make QtTestBrowser spawn QNAM in a secondary thread.
     6
     7        A menu allows to switch QNAM back to the same thread.
     8
     9        * QtTestBrowser/launcherwindow.cpp:
     10        (LauncherWindow::initializeView):
     11        (LauncherWindow::createChrome):
     12        (LauncherWindow::toggleThreadedQnam):
     13        * QtTestBrowser/launcherwindow.h:
     14        (WindowOptions::WindowOptions):
     15        * QtTestBrowser/webpage.cpp:
     16        (WebPage::WebPage):
     17        (WebPage::setQnamThreaded):
     18        * QtTestBrowser/webpage.h:
     19        (QnamThread::QnamThread):
     20        (QnamThread::~QnamThread):
     21        (QnamThread::networkAccessManager):
     22        (QnamThread::run):
     23
    1242010-12-10  Martin Robinson  <mrobinson@igalia.com>
    225
  • trunk/WebKitTools/QtTestBrowser/launcherwindow.cpp

    r70980 r73712  
    9696    QUrl url = page()->mainFrame()->url();
    9797    setPage(new WebPage(this));
     98    page()->setQnamThreaded(m_windowOptions.useThreadedQnam);
    9899
    99100    QSplitter* splitter = static_cast<QSplitter*>(centralWidget());
     
    234235    toggleWebGL->setCheckable(true);
    235236    toggleWebGL->setChecked(settings->testAttribute(QWebSettings::WebGLEnabled));
     237
     238    QAction* toggleThreadedQnam = toolsMenu->addAction("Toggle threaded network", this, SLOT(toggleThreadedQnam(bool)));
     239    toggleThreadedQnam->setCheckable(true);
     240    toggleThreadedQnam->setChecked(m_windowOptions.useThreadedQnam);
    236241
    237242    QAction* spatialNavigationAction = toolsMenu->addAction("Toggle Spatial Navigation", this, SLOT(toggleSpatialNavigation(bool)));
     
    703708}
    704709
     710void LauncherWindow::toggleThreadedQnam(bool toggle)
     711{
     712    m_windowOptions.useThreadedQnam = toggle;
     713    page()->setQnamThreaded(toggle);
     714}
     715
    705716void LauncherWindow::animatedFlip()
    706717{
  • trunk/WebKitTools/QtTestBrowser/launcherwindow.h

    r68514 r73712  
    8888        , useFrameFlattening(false)
    8989#endif
     90        , useThreadedQnam(true)
    9091        , cacheWebView(false)
    9192        , showFrameRate(false)
     
    103104    bool useWebGL;
    104105    bool useFrameFlattening;
     106    bool useThreadedQnam;
    105107    bool cacheWebView;
    106108    bool showFrameRate;
     
    154156    void toggleResizesToContents(bool toggle);
    155157    void toggleWebGL(bool toggle);
     158    void toggleThreadedQnam(bool toggle);
    156159    void toggleSpatialNavigation(bool b);
    157160    void toggleFullScreenMode(bool enable);
  • trunk/WebKitTools/QtTestBrowser/webpage.cpp

    r72603 r73712  
    4949    applyProxy();
    5050
    51     connect(networkAccessManager(), SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)),
    52             this, SLOT(authenticationRequired(QNetworkReply*, QAuthenticator*)));
    5351    connect(this, SIGNAL(featurePermissionRequested(QWebFrame*, QWebPage::Feature)), this, SLOT(requestPermission(QWebFrame*, QWebPage::Feature)));
    5452    connect(this, SIGNAL(featurePermissionRequestCanceled(QWebFrame*, QWebPage::Feature)), this, SLOT(featurePermissionRequestCanceled(QWebFrame*, QWebPage::Feature)));
     
    120118        return m_userAgent;
    121119    return QWebPage::userAgentForUrl(url);
     120}
     121
     122void WebPage::setQnamThreaded(bool threaded)
     123{
     124    bool alreadyThreaded = networkAccessManager()->thread() != thread();
     125    if (threaded == alreadyThreaded)
     126        return;
     127
     128    if (threaded) {
     129        m_qnamThread.reset(new QtNAMThread);
     130        m_qnamThread->start();
     131        setNetworkAccessManager(m_qnamThread->networkAccessManager());
     132    } else {
     133        setNetworkAccessManager(0);
     134        m_qnamThread.reset();
     135    }
     136
     137    Qt::ConnectionType connectionType = threaded ? Qt::BlockingQueuedConnection : Qt::DirectConnection;
     138    connect(networkAccessManager(), SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)),
     139            this, SLOT(authenticationRequired(QNetworkReply*, QAuthenticator*)),
     140            connectionType);
     141    applyProxy();
    122142}
    123143
  • trunk/WebKitTools/QtTestBrowser/webpage.h

    r72603 r73712  
    3434#define webpage_h
    3535
     36#include <QFuture>
     37#include <QScopedPointer>
     38#include <QThread>
    3639#include <qwebframe.h>
    3740#include <qwebpage.h>
     41
     42class QtNAMThread;
    3843
    3944class WebPage : public QWebPage {
     
    5257    QString userAgentForUrl(const QUrl& url) const;
    5358    void setInterruptingJavaScriptEnabled(bool enabled) { m_interruptingJavaScriptEnabled = enabled; }
     59    void setQnamThreaded(bool threaded);
    5460
    5561public slots:
     
    6571    QString m_userAgent;
    6672    bool m_interruptingJavaScriptEnabled;
     73    QScopedPointer<QtNAMThread> m_qnamThread;
     74};
     75
     76
     77class QtNAMThread : public QThread {
     78public:
     79    QtNAMThread()
     80    {
     81        m_qnamFuture.reportStarted();
     82    }
     83    ~QtNAMThread()
     84    {
     85        quit();
     86        wait();
     87    }
     88
     89    QFuture<QNetworkAccessManager*> networkAccessManager()
     90    {
     91        return m_qnamFuture.future();
     92    }
     93protected:
     94    void run()
     95    {
     96        QNetworkAccessManager qnam;
     97        m_qnamFuture.reportResult(&qnam);
     98        m_qnamFuture.reportFinished();
     99        exec();
     100    }
     101private:
     102    QFutureInterface<QNetworkAccessManager*> m_qnamFuture;
    67103};
    68104
Note: See TracChangeset for help on using the changeset viewer.