Roll src/third_party/WebKit bf18a82:a9cee16 (svn 185297:185304)
[chromium-blink-merge.git] / chrome / test / chromedriver / chrome / devtools_http_client.h
blobba8098bdd261241b54471b424ce7bf6964e3fa42
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.
5 #ifndef CHROME_TEST_CHROMEDRIVER_CHROME_DEVTOOLS_HTTP_CLIENT_H_
6 #define CHROME_TEST_CHROMEDRIVER_CHROME_DEVTOOLS_HTTP_CLIENT_H_
8 #include <string>
9 #include <vector>
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "chrome/test/chromedriver/chrome/browser_info.h"
14 #include "chrome/test/chromedriver/net/sync_websocket_factory.h"
16 namespace base {
17 class TimeDelta;
20 struct DeviceMetrics;
21 class DevToolsClient;
22 class NetAddress;
23 class Status;
24 class URLRequestContextGetter;
26 struct WebViewInfo {
27 enum Type {
28 kApp,
29 kBackgroundPage,
30 kPage,
31 kWorker,
32 kWebView,
33 kIFrame,
34 kOther,
35 kServiceWorker
38 WebViewInfo(const std::string& id,
39 const std::string& debugger_url,
40 const std::string& url,
41 Type type);
42 ~WebViewInfo();
44 bool IsFrontend() const;
46 std::string id;
47 std::string debugger_url;
48 std::string url;
49 Type type;
52 class WebViewsInfo {
53 public:
54 WebViewsInfo();
55 explicit WebViewsInfo(const std::vector<WebViewInfo>& info);
56 ~WebViewsInfo();
58 const WebViewInfo& Get(int index) const;
59 size_t GetSize() const;
60 const WebViewInfo* GetForId(const std::string& id) const;
62 private:
63 std::vector<WebViewInfo> views_info;
66 class DevToolsHttpClient {
67 public:
68 DevToolsHttpClient(
69 const NetAddress& address,
70 scoped_refptr<URLRequestContextGetter> context_getter,
71 const SyncWebSocketFactory& socket_factory,
72 scoped_ptr<DeviceMetrics> device_metrics);
73 ~DevToolsHttpClient();
75 Status Init(const base::TimeDelta& timeout);
77 Status GetWebViewsInfo(WebViewsInfo* views_info);
79 scoped_ptr<DevToolsClient> CreateClient(const std::string& id);
81 Status CloseWebView(const std::string& id);
83 Status ActivateWebView(const std::string& id);
85 const BrowserInfo* browser_info();
86 const DeviceMetrics* device_metrics();
88 private:
89 Status CloseFrontends(const std::string& for_client_id);
90 bool FetchUrlAndLog(const std::string& url,
91 URLRequestContextGetter* getter,
92 std::string* response);
94 scoped_refptr<URLRequestContextGetter> context_getter_;
95 SyncWebSocketFactory socket_factory_;
96 std::string server_url_;
97 std::string web_socket_url_prefix_;
98 BrowserInfo browser_info_;
99 scoped_ptr<DeviceMetrics> device_metrics_;
101 DISALLOW_COPY_AND_ASSIGN(DevToolsHttpClient);
104 namespace internal {
105 Status ParseWebViewsInfo(const std::string& data, WebViewsInfo* views_info);
106 Status ParseType(const std::string& data, WebViewInfo::Type* type);
107 } // namespace internal
109 #endif // CHROME_TEST_CHROMEDRIVER_CHROME_DEVTOOLS_HTTP_CLIENT_H_