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