• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2013 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_CHROME_DEVTOOLS_HTTP_CLIENT_H_
6 #define CHROME_TEST_CHROMEDRIVER_CHROME_DEVTOOLS_HTTP_CLIENT_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "chrome/test/chromedriver/net/sync_websocket_factory.h"
14 
15 namespace base {
16 class TimeDelta;
17 }
18 
19 class DevToolsClient;
20 class NetAddress;
21 class Status;
22 class URLRequestContextGetter;
23 
24 struct WebViewInfo {
25   enum Type {
26     kApp,
27     kBackgroundPage,
28     kPage,
29     kWorker,
30     kOther
31   };
32 
33   WebViewInfo(const std::string& id,
34               const std::string& debugger_url,
35               const std::string& url,
36               Type type);
37   ~WebViewInfo();
38 
39   bool IsFrontend() const;
40 
41   std::string id;
42   std::string debugger_url;
43   std::string url;
44   Type type;
45 };
46 
47 class WebViewsInfo {
48  public:
49   WebViewsInfo();
50   explicit WebViewsInfo(const std::vector<WebViewInfo>& info);
51   ~WebViewsInfo();
52 
53   const WebViewInfo& Get(int index) const;
54   size_t GetSize() const;
55   const WebViewInfo* GetForId(const std::string& id) const;
56 
57  private:
58   std::vector<WebViewInfo> views_info;
59 };
60 
61 class DevToolsHttpClient {
62  public:
63   DevToolsHttpClient(
64       const NetAddress& address,
65       scoped_refptr<URLRequestContextGetter> context_getter,
66       const SyncWebSocketFactory& socket_factory);
67   ~DevToolsHttpClient();
68 
69   Status Init(const base::TimeDelta& timeout);
70 
71   Status GetWebViewsInfo(WebViewsInfo* views_info);
72 
73   scoped_ptr<DevToolsClient> CreateClient(const std::string& id);
74 
75   Status CloseWebView(const std::string& id);
76 
77   Status ActivateWebView(const std::string& id);
78 
79   const std::string& version() const;
80   int build_no() const;
81 
82  private:
83   Status GetVersion(std::string* version);
84   Status CloseFrontends(const std::string& for_client_id);
85   bool FetchUrlAndLog(const std::string& url,
86                       URLRequestContextGetter* getter,
87                       std::string* response);
88 
89   scoped_refptr<URLRequestContextGetter> context_getter_;
90   SyncWebSocketFactory socket_factory_;
91   std::string server_url_;
92   std::string web_socket_url_prefix_;
93   std::string version_;
94   int build_no_;
95 
96   DISALLOW_COPY_AND_ASSIGN(DevToolsHttpClient);
97 };
98 
99 namespace internal {
100 Status ParseWebViewsInfo(const std::string& data,
101                          WebViewsInfo* views_info);
102 Status ParseVersionInfo(const std::string& data,
103                         std::string* version);
104 }  // namespace internal
105 
106 #endif  // CHROME_TEST_CHROMEDRIVER_CHROME_DEVTOOLS_HTTP_CLIENT_H_
107