Home | History | Annotate | Download | only in chrome
      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 Log;
     21 class Status;
     22 class URLRequestContextGetter;
     23 
     24 struct WebViewInfo {
     25   enum Type {
     26     kPage,
     27     kOther
     28   };
     29 
     30   WebViewInfo(const std::string& id,
     31               const std::string& debugger_url,
     32               const std::string& url,
     33               Type type);
     34   ~WebViewInfo();
     35 
     36   bool IsFrontend() const;
     37 
     38   std::string id;
     39   std::string debugger_url;
     40   std::string url;
     41   Type type;
     42 };
     43 
     44 class WebViewsInfo {
     45  public:
     46   WebViewsInfo();
     47   explicit WebViewsInfo(const std::vector<WebViewInfo>& info);
     48   ~WebViewsInfo();
     49 
     50   const WebViewInfo& Get(int index) const;
     51   size_t GetSize() const;
     52   const WebViewInfo* GetForId(const std::string& id) const;
     53 
     54  private:
     55   std::vector<WebViewInfo> views_info;
     56 };
     57 
     58 class DevToolsHttpClient {
     59  public:
     60   DevToolsHttpClient(
     61       int port,
     62       scoped_refptr<URLRequestContextGetter> context_getter,
     63       const SyncWebSocketFactory& socket_factory,
     64       Log* log);
     65   ~DevToolsHttpClient();
     66 
     67   Status Init(const base::TimeDelta& timeout);
     68 
     69   Status GetWebViewsInfo(WebViewsInfo* views_info);
     70 
     71   scoped_ptr<DevToolsClient> CreateClient(const std::string& id);
     72 
     73   Status CloseWebView(const std::string& id);
     74 
     75   const std::string& version() const;
     76   int build_no() const;
     77 
     78  private:
     79   Status GetVersion(std::string* version);
     80   Status CloseFrontends(const std::string& for_client_id);
     81   bool FetchUrlAndLog(const std::string& url,
     82                       URLRequestContextGetter* getter,
     83                       std::string* response);
     84 
     85   scoped_refptr<URLRequestContextGetter> context_getter_;
     86   SyncWebSocketFactory socket_factory_;
     87   Log* log_;
     88   std::string server_url_;
     89   std::string web_socket_url_prefix_;
     90   std::string version_;
     91   int build_no_;
     92 
     93   DISALLOW_COPY_AND_ASSIGN(DevToolsHttpClient);
     94 };
     95 
     96 namespace internal {
     97 Status ParseWebViewsInfo(const std::string& data,
     98                          WebViewsInfo* views_info);
     99 Status ParseVersionInfo(const std::string& data,
    100                         std::string* version);
    101 }  // namespace internal
    102 
    103 #endif  // CHROME_TEST_CHROMEDRIVER_CHROME_DEVTOOLS_HTTP_CLIENT_H_
    104