OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_DEBUGGER_DEVTOOLS_HTTP_PROTOCOL_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_DEBUGGER_DEVTOOLS_HTTP_HANDLER_IMPL_H_ |
6 #define CONTENT_BROWSER_DEBUGGER_DEVTOOLS_HTTP_PROTOCOL_HANDLER_H_ | 6 #define CONTENT_BROWSER_DEBUGGER_DEVTOOLS_HTTP_HANDLER_IMPL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 17 #include "content/public/browser/devtools_http_handler.h" |
17 #include "net/server/http_server.h" | 18 #include "net/server/http_server.h" |
18 #include "net/url_request/url_request.h" | 19 #include "net/url_request/url_request.h" |
19 | 20 |
20 class TabContents; | 21 class TabContents; |
21 | 22 |
22 namespace content { | |
23 class DevToolsClientHost; | |
24 } | |
25 | |
26 namespace net { | 23 namespace net { |
27 class URLRequestContext; | 24 class URLRequestContext; |
28 } | 25 } |
29 | 26 |
30 class DevToolsHttpProtocolHandler | 27 namespace content { |
31 : public net::HttpServer::Delegate, | |
32 public net::URLRequest::Delegate, | |
33 public base::RefCountedThreadSafe<DevToolsHttpProtocolHandler> { | |
34 public: | |
35 typedef std::vector<TabContents*> InspectableTabs; | |
36 class Delegate { | |
37 public: | |
38 Delegate() {} | |
39 virtual ~Delegate() {} | |
40 | 28 |
41 // Should return the list of inspectable tabs. Called on the UI thread. | 29 class DevToolsClientHost; |
42 virtual InspectableTabs GetInspectableTabs() = 0; | |
43 | 30 |
44 // Should return discovery page HTML that should list available tabs | 31 class DevToolsHttpHandlerImpl |
45 // and provide attach links. Called on the IO thread. | 32 : public DevToolsHttpHandler, |
46 virtual std::string GetDiscoveryPageHTML() = 0; | 33 public base::RefCountedThreadSafe<DevToolsHttpHandlerImpl>, |
| 34 public net::HttpServer::Delegate, |
| 35 public net::URLRequest::Delegate { |
| 36 private: |
| 37 friend class base::RefCountedThreadSafe<DevToolsHttpHandlerImpl>; |
| 38 friend class DevToolsHttpHandler; |
| 39 DevToolsHttpHandlerImpl(const std::string& ip, |
| 40 int port, |
| 41 const std::string& frontend_url, |
| 42 DevToolsHttpHandlerDelegate* delegate); |
| 43 virtual ~DevToolsHttpHandlerImpl(); |
| 44 void Start(); |
47 | 45 |
48 // Should return URL request context for issuing requests against devtools | 46 // DevToolsHttpHandler implementation. |
49 // webui or NULL if no context is available. Called on the IO thread. | 47 virtual void Stop() OVERRIDE; |
50 virtual net::URLRequestContext* GetURLRequestContext() = 0; | |
51 private: | |
52 DISALLOW_COPY_AND_ASSIGN(Delegate); | |
53 }; | |
54 | |
55 // Takes ownership over |delegate|. | |
56 CONTENT_EXPORT static scoped_refptr<DevToolsHttpProtocolHandler> Start( | |
57 const std::string& ip, | |
58 int port, | |
59 const std::string& frontend_url, | |
60 Delegate* delegate); | |
61 | |
62 // Called from the main thread in order to stop protocol handler. | |
63 // Will schedule tear down task on IO thread. | |
64 CONTENT_EXPORT void Stop(); | |
65 | |
66 private: | |
67 friend class base::RefCountedThreadSafe<DevToolsHttpProtocolHandler>; | |
68 | |
69 DevToolsHttpProtocolHandler(const std::string& ip, | |
70 int port, | |
71 const std::string& frontend_url, | |
72 Delegate* delegate); | |
73 virtual ~DevToolsHttpProtocolHandler(); | |
74 void Start(); | |
75 | 48 |
76 // net::HttpServer::Delegate implementation. | 49 // net::HttpServer::Delegate implementation. |
77 virtual void OnHttpRequest(int connection_id, | 50 virtual void OnHttpRequest(int connection_id, |
78 const net::HttpServerRequestInfo& info) OVERRIDE; | 51 const net::HttpServerRequestInfo& info) OVERRIDE; |
79 virtual void OnWebSocketRequest( | 52 virtual void OnWebSocketRequest( |
80 int connection_id, | 53 int connection_id, |
81 const net::HttpServerRequestInfo& info) OVERRIDE; | 54 const net::HttpServerRequestInfo& info) OVERRIDE; |
82 virtual void OnWebSocketMessage(int connection_id, | 55 virtual void OnWebSocketMessage(int connection_id, |
83 const std::string& data) OVERRIDE; | 56 const std::string& data) OVERRIDE; |
84 virtual void OnClose(int connection_id) OVERRIDE; | 57 virtual void OnClose(int connection_id) OVERRIDE; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 RequestToSocketMap request_to_connection_io_; | 92 RequestToSocketMap request_to_connection_io_; |
120 typedef std::map<int, std::set<net::URLRequest*> > | 93 typedef std::map<int, std::set<net::URLRequest*> > |
121 ConnectionToRequestsMap; | 94 ConnectionToRequestsMap; |
122 ConnectionToRequestsMap connection_to_requests_io_; | 95 ConnectionToRequestsMap connection_to_requests_io_; |
123 typedef std::map<net::URLRequest*, scoped_refptr<net::IOBuffer> > | 96 typedef std::map<net::URLRequest*, scoped_refptr<net::IOBuffer> > |
124 BuffersMap; | 97 BuffersMap; |
125 BuffersMap request_to_buffer_io_; | 98 BuffersMap request_to_buffer_io_; |
126 typedef std::map<int, content::DevToolsClientHost*> | 99 typedef std::map<int, content::DevToolsClientHost*> |
127 ConnectionToClientHostMap; | 100 ConnectionToClientHostMap; |
128 ConnectionToClientHostMap connection_to_client_host_ui_; | 101 ConnectionToClientHostMap connection_to_client_host_ui_; |
129 scoped_ptr<Delegate> delegate_; | 102 scoped_ptr<DevToolsHttpHandlerDelegate> delegate_; |
130 DISALLOW_COPY_AND_ASSIGN(DevToolsHttpProtocolHandler); | 103 scoped_refptr<DevToolsHttpHandlerImpl> protect_ptr_; |
| 104 DISALLOW_COPY_AND_ASSIGN(DevToolsHttpHandlerImpl); |
131 }; | 105 }; |
132 | 106 |
133 #endif // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_HTTP_PROTOCOL_HANDLER_H_ | 107 } // namespace content |
| 108 |
| 109 #endif // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_HTTP_HANDLER_IMPL_H_ |
OLD | NEW |