| 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 CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_HTTP_HANDLER_H_ |
| 6 #define COMPONENTS_DEVTOOLS_HTTP_HANDLER_DEVTOOLS_HTTP_HANDLER_H_ | 6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_HTTP_HANDLER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "content/public/browser/devtools_agent_host.h" | 15 #include "content/public/browser/devtools_agent_host.h" |
| 16 #include "net/http/http_status_code.h" | 16 #include "net/http/http_status_code.h" |
| 17 | 17 |
| 18 class GURL; | 18 class GURL; |
| 19 | 19 |
| 20 namespace base { | 20 namespace base { |
| 21 class DictionaryValue; | 21 class DictionaryValue; |
| 22 class Thread; | 22 class Thread; |
| 23 class Value; | 23 class Value; |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace content { | 26 namespace content { |
| 27 class DevToolsManagerDelegate; |
| 27 class DevToolsSocketFactory; | 28 class DevToolsSocketFactory; |
| 28 } | 29 } |
| 29 | 30 |
| 30 namespace net { | 31 namespace net { |
| 31 class IPEndPoint; | 32 class IPEndPoint; |
| 32 class HttpServerRequestInfo; | 33 class HttpServerRequestInfo; |
| 33 class ServerSocket; | 34 class ServerSocket; |
| 34 } | 35 } |
| 35 | 36 |
| 36 namespace devtools_http_handler { | 37 namespace content { |
| 37 | 38 |
| 38 class DevToolsAgentHostClientImpl; | 39 class DevToolsAgentHostClientImpl; |
| 39 class DevToolsHttpHandlerDelegate; | 40 class DevToolsHttpHandlerDelegate; |
| 40 class ServerWrapper; | 41 class ServerWrapper; |
| 41 | 42 |
| 42 // This class is used for managing DevTools remote debugging server. | 43 // This class is used for managing DevTools remote debugging server. |
| 43 // Clients can connect to the specified ip:port and start debugging | 44 // Clients can connect to the specified ip:port and start debugging |
| 44 // this browser. | 45 // this browser. |
| 45 class DevToolsHttpHandler { | 46 class DevToolsHttpHandler { |
| 46 public: | 47 public: |
| 47 // Takes ownership over |socket_factory| and |delegate|. | 48 // Takes ownership over |socket_factory|. |
| 48 // If |frontend_url| is empty, assumes it's bundled, and uses | 49 // If |frontend_url| is empty, assumes it's bundled, and uses |
| 49 // |delegate->GetFrontendResource()|. | 50 // |delegate->GetFrontendResource()|. |
| 50 // |delegate| is only accessed on UI thread. | 51 // |delegate| is only accessed on UI thread. |
| 51 // If |active_port_output_directory| is non-empty, it is assumed the | 52 // If |active_port_output_directory| is non-empty, it is assumed the |
| 52 // socket_factory was initialized with an ephemeral port (0). The | 53 // socket_factory was initialized with an ephemeral port (0). The |
| 53 // port selected by the OS will be written to a well-known file in | 54 // port selected by the OS will be written to a well-known file in |
| 54 // the output directory. | 55 // the output directory. |
| 55 DevToolsHttpHandler( | 56 DevToolsHttpHandler( |
| 56 std::unique_ptr<content::DevToolsSocketFactory> server_socket_factory, | 57 DevToolsManagerDelegate* delegate, |
| 58 std::unique_ptr<DevToolsSocketFactory> server_socket_factory, |
| 57 const std::string& frontend_url, | 59 const std::string& frontend_url, |
| 58 DevToolsHttpHandlerDelegate* delegate, | |
| 59 const base::FilePath& active_port_output_directory, | 60 const base::FilePath& active_port_output_directory, |
| 60 const base::FilePath& debug_frontend_dir, | 61 const base::FilePath& debug_frontend_dir, |
| 61 const std::string& product_name, | 62 const std::string& product_name, |
| 62 const std::string& user_agent); | 63 const std::string& user_agent); |
| 63 ~DevToolsHttpHandler(); | 64 ~DevToolsHttpHandler(); |
| 64 | 65 |
| 65 private: | 66 private: |
| 66 friend class ServerWrapper; | 67 friend class ServerWrapper; |
| 67 friend void ServerStartedOnUI( | 68 friend void ServerStartedOnUI( |
| 68 base::WeakPtr<DevToolsHttpHandler> handler, | 69 base::WeakPtr<DevToolsHttpHandler> handler, |
| 69 base::Thread* thread, | 70 base::Thread* thread, |
| 70 ServerWrapper* server_wrapper, | 71 ServerWrapper* server_wrapper, |
| 71 content::DevToolsSocketFactory* socket_factory, | 72 DevToolsSocketFactory* socket_factory, |
| 72 std::unique_ptr<net::IPEndPoint> ip_address); | 73 std::unique_ptr<net::IPEndPoint> ip_address); |
| 73 | 74 |
| 74 void OnJsonRequest(int connection_id, | 75 void OnJsonRequest(int connection_id, |
| 75 const net::HttpServerRequestInfo& info); | 76 const net::HttpServerRequestInfo& info); |
| 76 void OnDiscoveryPageRequest(int connection_id); | 77 void OnDiscoveryPageRequest(int connection_id); |
| 77 void OnFrontendResourceRequest(int connection_id, const std::string& path); | 78 void OnFrontendResourceRequest(int connection_id, const std::string& path); |
| 78 void OnWebSocketRequest(int connection_id, | 79 void OnWebSocketRequest(int connection_id, |
| 79 const net::HttpServerRequestInfo& info); | 80 const net::HttpServerRequestInfo& info); |
| 80 void OnWebSocketMessage(int connection_id, const std::string& data); | 81 void OnWebSocketMessage(int connection_id, const std::string& data); |
| 81 void OnClose(int connection_id); | 82 void OnClose(int connection_id); |
| 82 | 83 |
| 83 void ServerStarted(base::Thread* thread, | 84 void ServerStarted(base::Thread* thread, |
| 84 ServerWrapper* server_wrapper, | 85 ServerWrapper* server_wrapper, |
| 85 content::DevToolsSocketFactory* socket_factory, | 86 DevToolsSocketFactory* socket_factory, |
| 86 std::unique_ptr<net::IPEndPoint> ip_address); | 87 std::unique_ptr<net::IPEndPoint> ip_address); |
| 87 | 88 |
| 88 scoped_refptr<content::DevToolsAgentHost> GetAgentHost( | 89 scoped_refptr<DevToolsAgentHost> GetAgentHost( |
| 89 const std::string& target_id); | 90 const std::string& target_id); |
| 90 | 91 |
| 91 void SendJson(int connection_id, | 92 void SendJson(int connection_id, |
| 92 net::HttpStatusCode status_code, | 93 net::HttpStatusCode status_code, |
| 93 base::Value* value, | 94 base::Value* value, |
| 94 const std::string& message); | 95 const std::string& message); |
| 95 void Send200(int connection_id, | 96 void Send200(int connection_id, |
| 96 const std::string& data, | 97 const std::string& data, |
| 97 const std::string& mime_type); | 98 const std::string& mime_type); |
| 98 void Send404(int connection_id); | 99 void Send404(int connection_id); |
| 99 void Send500(int connection_id, | 100 void Send500(int connection_id, |
| 100 const std::string& message); | 101 const std::string& message); |
| 101 void AcceptWebSocket(int connection_id, | 102 void AcceptWebSocket(int connection_id, |
| 102 const net::HttpServerRequestInfo& request); | 103 const net::HttpServerRequestInfo& request); |
| 103 | 104 |
| 104 // Returns the front end url without the host at the beginning. | 105 // Returns the front end url without the host at the beginning. |
| 105 std::string GetFrontendURLInternal(const std::string& target_id, | 106 std::string GetFrontendURLInternal(const std::string& target_id, |
| 106 const std::string& host); | 107 const std::string& host); |
| 107 | 108 |
| 108 std::unique_ptr<base::DictionaryValue> SerializeDescriptor( | 109 std::unique_ptr<base::DictionaryValue> SerializeDescriptor( |
| 109 scoped_refptr<content::DevToolsAgentHost> agent_host, | 110 scoped_refptr<DevToolsAgentHost> agent_host, |
| 110 const std::string& host); | 111 const std::string& host); |
| 111 | 112 |
| 112 // The thread used by the devtools handler to run server socket. | 113 // The thread used by the devtools handler to run server socket. |
| 113 base::Thread* thread_; | 114 base::Thread* thread_; |
| 114 std::string frontend_url_; | 115 std::string frontend_url_; |
| 115 std::string product_name_; | 116 std::string product_name_; |
| 116 std::string user_agent_; | 117 std::string user_agent_; |
| 117 ServerWrapper* server_wrapper_; | 118 ServerWrapper* server_wrapper_; |
| 118 std::unique_ptr<net::IPEndPoint> server_ip_address_; | 119 std::unique_ptr<net::IPEndPoint> server_ip_address_; |
| 119 typedef std::map<int, DevToolsAgentHostClientImpl*> ConnectionToClientMap; | 120 typedef std::map<int, DevToolsAgentHostClientImpl*> ConnectionToClientMap; |
| 120 ConnectionToClientMap connection_to_client_; | 121 ConnectionToClientMap connection_to_client_; |
| 121 const std::unique_ptr<DevToolsHttpHandlerDelegate> delegate_; | 122 DevToolsManagerDelegate* delegate_; |
| 122 content::DevToolsSocketFactory* socket_factory_; | 123 DevToolsSocketFactory* socket_factory_; |
| 123 using DescriptorMap = | 124 using DescriptorMap = |
| 124 std::map<std::string, scoped_refptr<content::DevToolsAgentHost>>; | 125 std::map<std::string, scoped_refptr<DevToolsAgentHost>>; |
| 125 DescriptorMap agent_host_map_; | 126 DescriptorMap agent_host_map_; |
| 126 base::WeakPtrFactory<DevToolsHttpHandler> weak_factory_; | 127 base::WeakPtrFactory<DevToolsHttpHandler> weak_factory_; |
| 127 | 128 |
| 128 DISALLOW_COPY_AND_ASSIGN(DevToolsHttpHandler); | 129 DISALLOW_COPY_AND_ASSIGN(DevToolsHttpHandler); |
| 129 }; | 130 }; |
| 130 | 131 |
| 131 } // namespace devtools_http_handler | 132 } // namespace content |
| 132 | 133 |
| 133 #endif // COMPONENTS_DEVTOOLS_HTTP_HANDLER_DEVTOOLS_HTTP_HANDLER_H_ | 134 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_HTTP_HANDLER_H_ |
| OLD | NEW |