OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 COMPONENTS_DEVTOOLS_HTTP_HANDLER_DEVTOOLS_HTTP_HANDLER_H_ | 5 #ifndef COMPONENTS_DEVTOOLS_HTTP_HANDLER_DEVTOOLS_HTTP_HANDLER_H_ |
6 #define COMPONENTS_DEVTOOLS_HTTP_HANDLER_DEVTOOLS_HTTP_HANDLER_H_ | 6 #define COMPONENTS_DEVTOOLS_HTTP_HANDLER_DEVTOOLS_HTTP_HANDLER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "content/public/browser/devtools_manager_delegate.h" | 14 #include "components/devtools_discovery/devtools_target_descriptor.h" |
15 #include "net/http/http_status_code.h" | 15 #include "net/http/http_status_code.h" |
16 | 16 |
17 class GURL; | 17 class GURL; |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 class Thread; | 20 class Thread; |
21 class Value; | 21 class Value; |
22 } | 22 } |
23 | 23 |
24 namespace net { | 24 namespace net { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 }; | 57 }; |
58 | 58 |
59 // Takes ownership over |socket_factory| and |delegate|. | 59 // Takes ownership over |socket_factory| and |delegate|. |
60 // If |frontend_url| is empty, assumes it's bundled, and uses | 60 // If |frontend_url| is empty, assumes it's bundled, and uses |
61 // |delegate->GetFrontendResource()|. | 61 // |delegate->GetFrontendResource()|. |
62 // |delegate| is only accessed on UI thread. | 62 // |delegate| is only accessed on UI thread. |
63 // If |active_port_output_directory| is non-empty, it is assumed the | 63 // If |active_port_output_directory| is non-empty, it is assumed the |
64 // socket_factory was initialized with an ephemeral port (0). The | 64 // socket_factory was initialized with an ephemeral port (0). The |
65 // port selected by the OS will be written to a well-known file in | 65 // port selected by the OS will be written to a well-known file in |
66 // the output directory. | 66 // the output directory. |
67 // TODO(dgozman): remove |manager_delegate| by moving targets to another | |
68 // component (http://crbug.com/476496). | |
69 DevToolsHttpHandler( | 67 DevToolsHttpHandler( |
70 scoped_ptr<ServerSocketFactory> server_socket_factory, | 68 scoped_ptr<ServerSocketFactory> server_socket_factory, |
71 const std::string& frontend_url, | 69 const std::string& frontend_url, |
72 DevToolsHttpHandlerDelegate* delegate, | 70 DevToolsHttpHandlerDelegate* delegate, |
73 content::DevToolsManagerDelegate* manager_delegate, | |
74 const base::FilePath& active_port_output_directory, | 71 const base::FilePath& active_port_output_directory, |
75 const base::FilePath& debug_frontend_dir, | 72 const base::FilePath& debug_frontend_dir, |
76 const std::string& product_name, | 73 const std::string& product_name, |
77 const std::string& user_agent); | 74 const std::string& user_agent); |
78 ~DevToolsHttpHandler(); | 75 ~DevToolsHttpHandler(); |
79 | 76 |
80 // Returns the URL for the file at |path| in frontend. | 77 // Returns the URL for the file at |path| in frontend. |
81 GURL GetFrontendURL(const std::string& path); | 78 GURL GetFrontendURL(const std::string& path); |
82 | 79 |
83 private: | 80 private: |
(...skipping 13 matching lines...) Expand all Loading... |
97 void OnWebSocketRequest(int connection_id, | 94 void OnWebSocketRequest(int connection_id, |
98 const net::HttpServerRequestInfo& info); | 95 const net::HttpServerRequestInfo& info); |
99 void OnWebSocketMessage(int connection_id, const std::string& data); | 96 void OnWebSocketMessage(int connection_id, const std::string& data); |
100 void OnClose(int connection_id); | 97 void OnClose(int connection_id); |
101 | 98 |
102 void ServerStarted(base::Thread* thread, | 99 void ServerStarted(base::Thread* thread, |
103 ServerWrapper* server_wrapper, | 100 ServerWrapper* server_wrapper, |
104 ServerSocketFactory* socket_factory, | 101 ServerSocketFactory* socket_factory, |
105 scoped_ptr<net::IPEndPoint> ip_address); | 102 scoped_ptr<net::IPEndPoint> ip_address); |
106 | 103 |
107 static void OnTargetListReceivedWeak( | 104 devtools_discovery::DevToolsTargetDescriptor* GetDescriptor( |
108 base::WeakPtr<DevToolsHttpHandler> handler, | 105 const std::string& target_id); |
109 int connection_id, | |
110 const std::string& host, | |
111 const content::DevToolsManagerDelegate::TargetList& targets); | |
112 void OnTargetListReceived( | |
113 int connection_id, | |
114 const std::string& host, | |
115 const content::DevToolsManagerDelegate::TargetList& targets); | |
116 | |
117 content::DevToolsTarget* GetTarget(const std::string& id); | |
118 | 106 |
119 void SendJson(int connection_id, | 107 void SendJson(int connection_id, |
120 net::HttpStatusCode status_code, | 108 net::HttpStatusCode status_code, |
121 base::Value* value, | 109 base::Value* value, |
122 const std::string& message); | 110 const std::string& message); |
123 void Send200(int connection_id, | 111 void Send200(int connection_id, |
124 const std::string& data, | 112 const std::string& data, |
125 const std::string& mime_type); | 113 const std::string& mime_type); |
126 void Send404(int connection_id); | 114 void Send404(int connection_id); |
127 void Send500(int connection_id, | 115 void Send500(int connection_id, |
128 const std::string& message); | 116 const std::string& message); |
129 void AcceptWebSocket(int connection_id, | 117 void AcceptWebSocket(int connection_id, |
130 const net::HttpServerRequestInfo& request); | 118 const net::HttpServerRequestInfo& request); |
131 | 119 |
132 // Returns the front end url without the host at the beginning. | 120 // Returns the front end url without the host at the beginning. |
133 std::string GetFrontendURLInternal(const std::string target_id, | 121 std::string GetFrontendURLInternal(const std::string target_id, |
134 const std::string& host); | 122 const std::string& host); |
135 | 123 |
136 base::DictionaryValue* SerializeTarget(const content::DevToolsTarget& target, | 124 base::DictionaryValue* SerializeDescriptor( |
137 const std::string& host); | 125 const devtools_discovery::DevToolsTargetDescriptor& descriptor, |
| 126 const std::string& host); |
138 | 127 |
139 // The thread used by the devtools handler to run server socket. | 128 // The thread used by the devtools handler to run server socket. |
140 base::Thread* thread_; | 129 base::Thread* thread_; |
141 std::string frontend_url_; | 130 std::string frontend_url_; |
142 std::string product_name_; | 131 std::string product_name_; |
143 std::string user_agent_; | 132 std::string user_agent_; |
144 ServerWrapper* server_wrapper_; | 133 ServerWrapper* server_wrapper_; |
145 scoped_ptr<net::IPEndPoint> server_ip_address_; | 134 scoped_ptr<net::IPEndPoint> server_ip_address_; |
146 typedef std::map<int, DevToolsAgentHostClientImpl*> ConnectionToClientMap; | 135 typedef std::map<int, DevToolsAgentHostClientImpl*> ConnectionToClientMap; |
147 ConnectionToClientMap connection_to_client_; | 136 ConnectionToClientMap connection_to_client_; |
148 const scoped_ptr<DevToolsHttpHandlerDelegate> delegate_; | 137 const scoped_ptr<DevToolsHttpHandlerDelegate> delegate_; |
149 content::DevToolsManagerDelegate* manager_delegate_; | |
150 ServerSocketFactory* socket_factory_; | 138 ServerSocketFactory* socket_factory_; |
151 typedef std::map<std::string, content::DevToolsTarget*> TargetMap; | 139 using DescriptorMap = |
152 TargetMap target_map_; | 140 std::map<std::string, devtools_discovery::DevToolsTargetDescriptor*>; |
| 141 DescriptorMap descriptor_map_; |
153 base::WeakPtrFactory<DevToolsHttpHandler> weak_factory_; | 142 base::WeakPtrFactory<DevToolsHttpHandler> weak_factory_; |
154 | 143 |
155 DISALLOW_COPY_AND_ASSIGN(DevToolsHttpHandler); | 144 DISALLOW_COPY_AND_ASSIGN(DevToolsHttpHandler); |
156 }; | 145 }; |
157 | 146 |
158 } // namespace devtools_http_handler | 147 } // namespace devtools_http_handler |
159 | 148 |
160 #endif // COMPONENTS_DEVTOOLS_HTTP_HANDLER_DEVTOOLS_HTTP_HANDLER_H_ | 149 #endif // COMPONENTS_DEVTOOLS_HTTP_HANDLER_DEVTOOLS_HTTP_HANDLER_H_ |
OLD | NEW |