Skip to content

Commit 86bea98

Browse files
committed
Fix for MHA-643; prevent to register other widget than QWebView and subclasses
1 parent 24ad5cf commit 86bea98

File tree

3 files changed

+19
-33
lines changed

3 files changed

+19
-33
lines changed

inc/viewfactory.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55

66
#include <QtCore/QGlobalStatic>
77
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
8-
#include <QtWidgets/QWidget>
8+
#include <QtWebKitWidgets/QWebView>
99
#else
10-
#include <QtGui/QWidget>
10+
#include <QtWebKit/QWebView>
1111
#endif
1212

1313
class AbstractViewCreator
1414
{
1515
public:
16-
virtual QWidget * create() const = 0;
16+
virtual QWebView * create() const = 0;
1717
};
1818

1919
template <class C>
2020
class ViewCreator: public AbstractViewCreator
2121
{
2222
public:
23-
virtual QWidget* create() const { return new C(); }
23+
virtual QWebView * create() const { return new C(); }
2424
};
2525

2626
class ViewFactory
@@ -37,7 +37,7 @@ class ViewFactory
3737
factory[id] = new ViewCreator<C>();
3838
}
3939

40-
QWidget* create(const std::string &id);
40+
QWebView * create(const std::string &id);
4141

4242

4343
protected:

src/chrome/test/webdriver/webdriver_automation.cc

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,24 @@ void Automation::Init(const BrowserOptions& options, int* build_no, Error** erro
109109
qsrand(QTime::currentTime().msec()+10);
110110
sessionId = qrand();
111111

112-
QWidget *pStartView = NULL;
112+
QWebView *pStartView = NULL;
113113

114114
//Searching for a allready opened window
115115
if (!options.browser_start_window.empty())
116116
{
117117
qDebug()<<"[WD]:"<<"Browser Start Window: "<<options.browser_start_window.c_str();
118-
foreach(QWidget* pWidget, qApp->allWidgets())
118+
foreach(QWidget* pWidget, qApp->topLevelWidgets())
119119
{
120120

121121
//check found widget if it is QWebView or top level widget
122-
if ((pWidget != NULL) || pWidget->isTopLevel())
122+
QWebView* pWebView = qobject_cast<QWebView*>(pWidget);
123+
if ((pWebView != NULL))
123124
{
124125
qDebug()<<"[WD]:"<<"looking for start window: "<<pWidget<<pWidget->windowTitle();
125126

126127
if ((options.browser_start_window == pWidget->windowTitle().toStdString()) || (options.browser_start_window == "*"))
127128
{
128-
pStartView = pWidget;
129+
pStartView = pWebView;
129130

130131
qDebug()<<"[WD]: found view to attach: "<<pWidget<<pWidget->windowTitle();
131132

@@ -140,21 +141,15 @@ void Automation::Init(const BrowserOptions& options, int* build_no, Error** erro
140141
pStartView = ViewFactory::GetInstance()->create(options.browser_class);
141142

142143
qDebug()<<"[WD]:"<<"Using window:"<<pStartView;
143-
if (pStartView == NULL)
144-
{
145-
*error = new Error(kBadRequest, "Can't create WebView");
146-
return;
147-
}
148144

149145
// TODO: save proxy settings for further usage
150-
QWebView* pWebView = qobject_cast<QWebView*>(pStartView);
151-
if (pWebView != NULL)
146+
if (pStartView != NULL)
152147
{
153148
//proxy setup
154149
if (options.command.HasSwitch(switches::kNoProxyServer))
155150
{
156151
qDebug()<<"[WD]:" << "No proxy";
157-
pWebView->page()->networkAccessManager()->setProxy(QNetworkProxy(QNetworkProxy::NoProxy));
152+
pStartView->page()->networkAccessManager()->setProxy(QNetworkProxy(QNetworkProxy::NoProxy));
158153
}
159154
else if (options.command.HasSwitch(switches::kProxyServer))
160155
{
@@ -175,7 +170,7 @@ void Automation::Init(const BrowserOptions& options, int* build_no, Error** erro
175170
if (proxyUrl.isValid() && !proxyUrl.host().isEmpty())
176171
{
177172
int proxyPort = (proxyUrl.port() > 0) ? proxyUrl.port() : 8080;
178-
pWebView->page()->networkAccessManager()->setProxy(QNetworkProxy(QNetworkProxy::HttpProxy, proxyUrl.host(), proxyPort));
173+
pStartView->page()->networkAccessManager()->setProxy(QNetworkProxy(QNetworkProxy::HttpProxy, proxyUrl.host(), proxyPort));
179174
}
180175
}
181176
}
@@ -199,12 +194,12 @@ void Automation::Init(const BrowserOptions& options, int* build_no, Error** erro
199194
if (proxyUrl.isValid() && !proxyUrl.host().isEmpty())
200195
{
201196
int proxyPort = (proxyUrl.port() > 0) ? proxyUrl.port() : 8080;
202-
pWebView->page()->networkAccessManager()->setProxy(QNetworkProxy(QNetworkProxy::HttpProxy, proxyUrl.host(), proxyPort));
197+
pStartView->page()->networkAccessManager()->setProxy(QNetworkProxy(QNetworkProxy::HttpProxy, proxyUrl.host(), proxyPort));
203198
}
204199
}
205200

206-
qDebug()<<"[WD]:" << "hostname = " << pWebView->page()->networkAccessManager()->proxy().hostName()
207-
<< ", port = " << pWebView->page()->networkAccessManager()->proxy().port();
201+
qDebug()<<"[WD]:" << "hostname = " << pStartView->page()->networkAccessManager()->proxy().hostName()
202+
<< ", port = " << pStartView->page()->networkAccessManager()->proxy().port();
208203
}
209204

210205
//handle initial window size and position

src/viewfactory.cc

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ViewFactory* ViewFactory::GetInstance()
1515
return instance;
1616
}
1717

18-
QWidget* ViewFactory::create(const std::string &id)
18+
QWebView* ViewFactory::create(const std::string &id)
1919
{
2020
FactoryMap::iterator it = factory.find(id);
2121
if (it != factory.end())
@@ -29,17 +29,8 @@ QWidget* ViewFactory::create(const std::string &id)
2929
FactoryMap::iterator it = factory.begin();
3030
for (it; it != factory.end(); ++it)
3131
{
32-
QWidget* retWidget;
33-
34-
retWidget = it->second->create();
35-
QWebView* retView = qobject_cast<QWebView*> (retWidget);
36-
if (retView)
37-
{
38-
qDebug()<<"[WD]:"<<"ViewFactory create first found registered QWebView subclass:"<<QString(it->first.c_str());
39-
return retView;
40-
}
41-
else
42-
delete retWidget;
32+
qDebug()<<"[WD]:"<<"ViewFactory create first found registered QWebView subclass:"<<QString(it->first.c_str());
33+
return it->second->create();
4334
}
4435
qDebug()<<"[WD]:"<<"ViewFactory create default QWebViewExt";
4536
return new QWebViewExt;

0 commit comments

Comments
 (0)