1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_TEST_CHROMEDRIVER_DEVTOOLS_CLIENT_IMPL_H_
#define CHROME_TEST_CHROMEDRIVER_DEVTOOLS_CLIENT_IMPL_H_
#include <list>
#include <map>
#include <string>
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/test/chromedriver/devtools_client.h"
#include "chrome/test/chromedriver/net/sync_websocket_factory.h"
#include "googleurl/src/gurl.h"
namespace base {
class DictionaryValue;
}
namespace internal {
enum InspectorMessageType {
kEventMessageType = 0,
kCommandResponseMessageType
};
struct InspectorEvent {
InspectorEvent();
~InspectorEvent();
std::string method;
scoped_ptr<base::DictionaryValue> params;
};
struct InspectorCommandResponse {
InspectorCommandResponse();
~InspectorCommandResponse();
int id;
std::string error;
scoped_ptr<base::DictionaryValue> result;
};
} // namespace internal
class DevToolsEventListener;
class Status;
class SyncWebSocket;
class DevToolsClientImpl : public DevToolsClient {
public:
typedef base::Callback<Status()> FrontendCloserFunc;
DevToolsClientImpl(const SyncWebSocketFactory& factory,
const std::string& url,
const FrontendCloserFunc& frontend_closer_func);
typedef base::Callback<bool(
const std::string&,
int,
internal::InspectorMessageType*,
internal::InspectorEvent*,
internal::InspectorCommandResponse*)> ParserFunc;
DevToolsClientImpl(const SyncWebSocketFactory& factory,
const std::string& url,
const FrontendCloserFunc& frontend_closer_func,
const ParserFunc& parser_func);
virtual ~DevToolsClientImpl();
void SetParserFuncForTesting(const ParserFunc& parser_func);
// Overridden from DevToolsClient:
virtual Status ConnectIfNecessary() OVERRIDE;
virtual Status SendCommand(const std::string& method,
const base::DictionaryValue& params) OVERRIDE;
virtual Status SendCommandAndGetResult(
const std::string& method,
const base::DictionaryValue& params,
scoped_ptr<base::DictionaryValue>* result) OVERRIDE;
virtual void AddListener(DevToolsEventListener* listener) OVERRIDE;
virtual Status HandleEventsUntil(
const ConditionalFunc& conditional_func) OVERRIDE;
private:
Status SendCommandInternal(
const std::string& method,
const base::DictionaryValue& params,
scoped_ptr<base::DictionaryValue>* result);
Status ReceiveCommandResponse(
int command_id,
scoped_ptr<base::DictionaryValue>* result);
Status ReceiveNextMessage(
int expected_id,
internal::InspectorMessageType* type,
internal::InspectorEvent* event,
internal::InspectorCommandResponse* response);
bool HasReceivedCommandResponse(int cmd_id);
Status NotifyEventListeners(const std::string& method,
const base::DictionaryValue& params);
Status EnsureAllListenersNotifiedOfConnection();
scoped_ptr<SyncWebSocket> socket_;
GURL url_;
FrontendCloserFunc frontend_closer_func_;
ParserFunc parser_func_;
std::list<DevToolsEventListener*> listeners_;
std::list<DevToolsEventListener*> listeners_for_on_connected_;
typedef std::map<int, base::DictionaryValue*> ResponseMap;
ResponseMap cmd_response_map_;
int next_id_;
DISALLOW_COPY_AND_ASSIGN(DevToolsClientImpl);
};
namespace internal {
bool ParseInspectorMessage(
const std::string& message,
int expected_id,
InspectorMessageType* type,
InspectorEvent* event,
InspectorCommandResponse* command_response);
} // namespace internal
#endif // CHROME_TEST_CHROMEDRIVER_DEVTOOLS_CLIENT_IMPL_H_
|