Skip to content

Commit e72a9f6

Browse files
Andrii BoichukAndrii Boichuk
authored andcommitted
Merge commit
2 parents ee0147c + 78892cc commit e72a9f6

File tree

8 files changed

+71
-18
lines changed

8 files changed

+71
-18
lines changed

inc/webdriver_switches.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,13 @@ class Switches {
6969

7070
/// \page page_webdriver_switches WD Server switches
7171
/// - <b>vnc</b><br>
72-
/// Enabling VNC support (by default - false)
73-
static const char kVNCEnabled[];
72+
/// VNC server listening port (by default - 5900)
73+
static const char kVNCPort[];
74+
75+
/// \page page_webdriver_switches WD Server switches
76+
/// - <b>vnc</b><br>
77+
/// VNC server IP address (by default - 127.0.0.1)
78+
static const char kVNCServer[];
7479

7580
};
7681

src/Test/main.cc

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,6 @@ int main(int argc, char *argv[])
148148
routeTableWithShutdownCommand->Add<webdriver::ShutdownCommand>(shutdownCommandRoute);
149149
wd_server->SetRouteTable(routeTableWithShutdownCommand);
150150

151-
VNCClient *client = new VNCClient();
152-
client->Init("http://127.0.0.1", 5900);
153-
154-
155-
CommandLine cmdLine = webdriver::Server::GetInstance()->GetCommandLine();
156-
157-
if (cmdLine.HasSwitch(webdriver::Switches::kVNCEnabled))
158-
{
159-
WDEventDispatcher::getInstance()->add(new VNCEventDispatcher(client));
160-
}
161151

162152
setQtSettings();
163153
wd_server->Start();
@@ -214,7 +204,9 @@ void PrintHelp() {
214204
<< " described above (port, root, etc.)" << std::endl
215205
<< "wi-server false If true, web inspector will be enabled" << std::endl
216206
<< "wi-port 9222 Web inspector listening port" << std::endl
217-
<< "version Print version information to stdout and exit" << std::endl;
207+
<< "version Print version information to stdout and exit" << std::endl
208+
<< "vnc-port 5900 VNC server listening port" << std::endl
209+
<< "vnc-server 127.0.0.1 VNC server IP address" << std::endl;
218210
}
219211

220212

src/vnc/vncclient.cc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
#include <iostream>
44
#include <QtNetwork/QHostAddress>
55
#include <QtCore/QMap>
6+
#include <QtCore/QRegExp>
67

78
#define MAJOR_INDEX 6
89
#define MINOR_INDEX 10
910

11+
VNCClient* VNCClient::_instance = NULL;
12+
1013
static QMap<quint32, quint16> initializeMap()
1114
{
1215
QMap<quint32, quint16> resultMap;
@@ -70,10 +73,28 @@ VNCClient::~VNCClient()
7073
delete _serverParameters;
7174
}
7275

76+
VNCClient* VNCClient::getInstance()
77+
{
78+
if (NULL == _instance)
79+
{
80+
_instance = new VNCClient();
81+
}
82+
83+
return _instance;
84+
}
85+
7386
bool VNCClient::Init(QString remoteHost, quint16 port)
7487
{
7588
_socket = new QTcpSocket();
76-
_socket->connectToHost(QHostAddress::LocalHost, port);
89+
QHostAddress addr;
90+
91+
if (!addr.setAddress(remoteHost))
92+
{
93+
remoteHost.replace(QRegExp("http*://"), "");
94+
addr.setAddress(remoteHost);
95+
}
96+
97+
_socket->connectToHost(addr, port);
7798

7899
// QObject::connect(_socket, SIGNAL(bytesWritten(qint64)), this, SLOT(readSocket(qint64)));
79100
QObject::connect(_socket, SIGNAL(readyRead()), this, SLOT(readSocket()));

src/vnc/vncclient.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ class VNCClient : public QObject
1212
Q_OBJECT
1313

1414
public:
15-
VNCClient();
1615
~VNCClient();
1716

17+
static VNCClient* getInstance();
18+
1819
bool Init(QString remoteHost, quint16 port);
1920
void sendKeyEvent(QKeyEvent *key);
2021
void sendMouseEvent(QMouseEvent *mouse);
@@ -30,6 +31,8 @@ private slots:
3031
void onError(QAbstractSocket::SocketError error);
3132

3233
private:
34+
VNCClient();
35+
3336
bool establishProtocolVersion(QByteArray& data);
3437
bool establishSecurity(QByteArray& data);
3538
bool finishHandshaking(QByteArray& data);
@@ -68,6 +71,7 @@ private slots:
6871
static QMap<quint32, quint16> _keymap;
6972

7073
private:
74+
static VNCClient *_instance;
7175
QTcpSocket *_socket;
7276
bool _versionEstablished;
7377
bool _securityEstablished;

src/webdriver/extension_qt/q_session_lifecycle_actions.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#include "extension_qt/q_session_lifecycle_actions.h"
2+
#include "extension_qt/wd_event_dispatcher.h"
3+
#include "extension_qt/vnc_event_dispatcher.h"
4+
#include "webdriver_switches.h"
5+
#include "webdriver_server.h"
26

37
#include "q_proxy_parser.h"
48

@@ -29,6 +33,25 @@ Error* QSessionLifeCycleActions::PostInit(const base::DictionaryValue* desired_c
2933
session_->logger().Log(kInfoLogLevel, "no proxy settings requsted.");
3034
}
3135

36+
// start VNC module
37+
CommandLine cmdLine = webdriver::Server::GetInstance()->GetCommandLine();
38+
if (cmdLine.HasSwitch(webdriver::Switches::kVNCServer) || cmdLine.HasSwitch(webdriver::Switches::kVNCPort))
39+
{
40+
QString address = "127.0.0.1";
41+
int port = 5900;
42+
43+
if (cmdLine.HasSwitch(webdriver::Switches::kVNCServer))
44+
address = cmdLine.GetSwitchValueASCII(webdriver::Switches::kVNCServer).c_str();
45+
if (cmdLine.HasSwitch(webdriver::Switches::kVNCPort))
46+
port = QString(cmdLine.GetSwitchValueASCII(webdriver::Switches::kVNCPort).c_str()).toInt();
47+
48+
VNCClient *client = VNCClient::getInstance();
49+
if (!client->isReady())
50+
client->Init(address, port);
51+
52+
WDEventDispatcher::getInstance()->add(new VNCEventDispatcher(client));
53+
}
54+
3255
return error;
3356
}
3457

src/webdriver/webdriver_server.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#include "webdriver_server.h"
32
#include "webdriver_route_table.h"
43
#include "commands/command.h"

src/webdriver/webdriver_switches.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const char Switches::kWIServer[] = "wi-server";
2222

2323
const char Switches::kWIPort[] = "wi-port";
2424

25-
const char Switches::kVNCEnabled[] = "vnc";
25+
const char Switches::kVNCPort[] = "vnc-port";
26+
27+
const char Switches::kVNCServer[] = "vnc-server";
2628

2729
} // namespace webdriver

wd_build_options.gypi

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,17 @@
6666
'NOMINMAX',
6767
'_UNICODE',
6868
'_WINSOCKAPI_',
69-
],
69+
],
7070
} ],
7171

7272
[ 'OS == "mac"', {
73+
'actions': [ {
74+
'action_name': 'create_input_dir',
75+
'inputs': [],
76+
'outputs': [],
77+
'action': ['mkdir', '-p', '<(INTERMEDIATE_DIR)'],
78+
} ],
79+
7380
'defines': [
7481
'OS_POSIX',
7582
],

0 commit comments

Comments
 (0)