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