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/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; | 30 class DevToolsHttpHandlerDelegate; |
43 | 31 |
44 // Should return discovery page HTML that should list available tabs | 32 class DevToolsHttpHandlerImpl |
45 // and provide attach links. Called on the IO thread. | 33 : public DevToolsHttpHandler, |
46 virtual std::string GetDiscoveryPageHTML() = 0; | 34 public net::HttpServer::Delegate, |
47 | 35 public net::URLRequest::Delegate { |
48 // Should return URL request context for issuing requests against devtools | |
49 // webui or NULL if no context is available. Called on the IO thread. | |
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: | 36 private: |
67 friend class base::RefCountedThreadSafe<DevToolsHttpProtocolHandler>; | 37 friend class DevToolsHttpHandler; |
68 | 38 DevToolsHttpHandlerImpl(const std::string& ip, |
69 DevToolsHttpProtocolHandler(const std::string& ip, | |
70 int port, | 39 int port, |
71 const std::string& frontend_url, | 40 const std::string& frontend_url, |
72 Delegate* delegate); | 41 DevToolsHttpHandlerDelegate* delegate); |
73 virtual ~DevToolsHttpProtocolHandler(); | 42 virtual ~DevToolsHttpHandlerImpl(); |
74 void Start(); | 43 void Start(); |
75 | 44 |
| 45 // DevToolsHttpHandler implementation. |
| 46 virtual void Stop() OVERRIDE; |
| 47 |
76 // net::HttpServer::Delegate implementation. | 48 // net::HttpServer::Delegate implementation. |
77 virtual void OnHttpRequest(int connection_id, | 49 virtual void OnHttpRequest(int connection_id, |
78 const net::HttpServerRequestInfo& info) OVERRIDE; | 50 const net::HttpServerRequestInfo& info) OVERRIDE; |
79 virtual void OnWebSocketRequest( | 51 virtual void OnWebSocketRequest( |
80 int connection_id, | 52 int connection_id, |
81 const net::HttpServerRequestInfo& info) OVERRIDE; | 53 const net::HttpServerRequestInfo& info) OVERRIDE; |
82 virtual void OnWebSocketMessage(int connection_id, | 54 virtual void OnWebSocketMessage(int connection_id, |
83 const std::string& data) OVERRIDE; | 55 const std::string& data) OVERRIDE; |
84 virtual void OnClose(int connection_id) OVERRIDE; | 56 virtual void OnClose(int connection_id) OVERRIDE; |
85 | 57 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 RequestToSocketMap request_to_connection_io_; | 91 RequestToSocketMap request_to_connection_io_; |
120 typedef std::map<int, std::set<net::URLRequest*> > | 92 typedef std::map<int, std::set<net::URLRequest*> > |
121 ConnectionToRequestsMap; | 93 ConnectionToRequestsMap; |
122 ConnectionToRequestsMap connection_to_requests_io_; | 94 ConnectionToRequestsMap connection_to_requests_io_; |
123 typedef std::map<net::URLRequest*, scoped_refptr<net::IOBuffer> > | 95 typedef std::map<net::URLRequest*, scoped_refptr<net::IOBuffer> > |
124 BuffersMap; | 96 BuffersMap; |
125 BuffersMap request_to_buffer_io_; | 97 BuffersMap request_to_buffer_io_; |
126 typedef std::map<int, content::DevToolsClientHost*> | 98 typedef std::map<int, content::DevToolsClientHost*> |
127 ConnectionToClientHostMap; | 99 ConnectionToClientHostMap; |
128 ConnectionToClientHostMap connection_to_client_host_ui_; | 100 ConnectionToClientHostMap connection_to_client_host_ui_; |
129 scoped_ptr<Delegate> delegate_; | 101 scoped_ptr<DevToolsHttpHandlerDelegate> delegate_; |
130 DISALLOW_COPY_AND_ASSIGN(DevToolsHttpProtocolHandler); | 102 DISALLOW_COPY_AND_ASSIGN(DevToolsHttpHandlerImpl); |
131 }; | 103 }; |
132 | 104 |
133 #endif // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_HTTP_PROTOCOL_HANDLER_H_ | 105 } // namespace content |
| 106 |
| 107 #endif // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_HTTP_HANDLER_IMPL_H_ |
OLD | NEW |