| 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 <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 { |
| 27 class DevToolsSocketFactory; |
| 28 } |
| 29 |
| 26 namespace net { | 30 namespace net { |
| 27 class IPEndPoint; | 31 class IPEndPoint; |
| 28 class HttpServerRequestInfo; | 32 class HttpServerRequestInfo; |
| 29 class ServerSocket; | 33 class ServerSocket; |
| 30 } | 34 } |
| 31 | 35 |
| 32 namespace devtools_http_handler { | 36 namespace devtools_http_handler { |
| 33 | 37 |
| 34 class DevToolsAgentHostClientImpl; | 38 class DevToolsAgentHostClientImpl; |
| 35 class DevToolsHttpHandlerDelegate; | 39 class DevToolsHttpHandlerDelegate; |
| 36 class ServerWrapper; | 40 class ServerWrapper; |
| 37 | 41 |
| 38 // This class is used for managing DevTools remote debugging server. | 42 // This class is used for managing DevTools remote debugging server. |
| 39 // Clients can connect to the specified ip:port and start debugging | 43 // Clients can connect to the specified ip:port and start debugging |
| 40 // this browser. | 44 // this browser. |
| 41 class DevToolsHttpHandler { | 45 class DevToolsHttpHandler { |
| 42 public: | 46 public: |
| 43 | |
| 44 // Factory of net::ServerSocket. This is to separate instantiating dev tools | |
| 45 // and instantiating server sockets. | |
| 46 // All methods including destructor are called on a separate thread | |
| 47 // different from any BrowserThread instance. | |
| 48 class ServerSocketFactory { | |
| 49 public: | |
| 50 virtual ~ServerSocketFactory() {} | |
| 51 | |
| 52 // Returns a new instance of ServerSocket or nullptr if an error occurred. | |
| 53 virtual std::unique_ptr<net::ServerSocket> CreateForHttpServer(); | |
| 54 | |
| 55 // Creates a named socket for reversed tethering implementation (used with | |
| 56 // remote debugging, primarily for mobile). | |
| 57 virtual std::unique_ptr<net::ServerSocket> CreateForTethering( | |
| 58 std::string* out_name); | |
| 59 }; | |
| 60 | |
| 61 // Takes ownership over |socket_factory| and |delegate|. | 47 // Takes ownership over |socket_factory| and |delegate|. |
| 62 // If |frontend_url| is empty, assumes it's bundled, and uses | 48 // If |frontend_url| is empty, assumes it's bundled, and uses |
| 63 // |delegate->GetFrontendResource()|. | 49 // |delegate->GetFrontendResource()|. |
| 64 // |delegate| is only accessed on UI thread. | 50 // |delegate| is only accessed on UI thread. |
| 65 // If |active_port_output_directory| is non-empty, it is assumed the | 51 // If |active_port_output_directory| is non-empty, it is assumed the |
| 66 // socket_factory was initialized with an ephemeral port (0). The | 52 // socket_factory was initialized with an ephemeral port (0). The |
| 67 // port selected by the OS will be written to a well-known file in | 53 // port selected by the OS will be written to a well-known file in |
| 68 // the output directory. | 54 // the output directory. |
| 69 DevToolsHttpHandler( | 55 DevToolsHttpHandler( |
| 70 std::unique_ptr<ServerSocketFactory> server_socket_factory, | 56 std::unique_ptr<content::DevToolsSocketFactory> server_socket_factory, |
| 71 const std::string& frontend_url, | 57 const std::string& frontend_url, |
| 72 DevToolsHttpHandlerDelegate* delegate, | 58 DevToolsHttpHandlerDelegate* delegate, |
| 73 const base::FilePath& active_port_output_directory, | 59 const base::FilePath& active_port_output_directory, |
| 74 const base::FilePath& debug_frontend_dir, | 60 const base::FilePath& debug_frontend_dir, |
| 75 const std::string& product_name, | 61 const std::string& product_name, |
| 76 const std::string& user_agent); | 62 const std::string& user_agent); |
| 77 ~DevToolsHttpHandler(); | 63 ~DevToolsHttpHandler(); |
| 78 | 64 |
| 79 // Returns the URL for the file at |path| in frontend. | |
| 80 GURL GetFrontendURL(const std::string& path); | |
| 81 | |
| 82 private: | 65 private: |
| 83 friend class ServerWrapper; | 66 friend class ServerWrapper; |
| 84 friend void ServerStartedOnUI( | 67 friend void ServerStartedOnUI( |
| 85 base::WeakPtr<DevToolsHttpHandler> handler, | 68 base::WeakPtr<DevToolsHttpHandler> handler, |
| 86 base::Thread* thread, | 69 base::Thread* thread, |
| 87 ServerWrapper* server_wrapper, | 70 ServerWrapper* server_wrapper, |
| 88 DevToolsHttpHandler::ServerSocketFactory* socket_factory, | 71 content::DevToolsSocketFactory* socket_factory, |
| 89 std::unique_ptr<net::IPEndPoint> ip_address); | 72 std::unique_ptr<net::IPEndPoint> ip_address); |
| 90 | 73 |
| 91 void OnJsonRequest(int connection_id, | 74 void OnJsonRequest(int connection_id, |
| 92 const net::HttpServerRequestInfo& info); | 75 const net::HttpServerRequestInfo& info); |
| 93 void OnThumbnailRequest(int connection_id, const std::string& target_id); | |
| 94 void OnDiscoveryPageRequest(int connection_id); | 76 void OnDiscoveryPageRequest(int connection_id); |
| 95 void OnFrontendResourceRequest(int connection_id, const std::string& path); | 77 void OnFrontendResourceRequest(int connection_id, const std::string& path); |
| 96 void OnWebSocketRequest(int connection_id, | 78 void OnWebSocketRequest(int connection_id, |
| 97 const net::HttpServerRequestInfo& info); | 79 const net::HttpServerRequestInfo& info); |
| 98 void OnWebSocketMessage(int connection_id, const std::string& data); | 80 void OnWebSocketMessage(int connection_id, const std::string& data); |
| 99 void OnClose(int connection_id); | 81 void OnClose(int connection_id); |
| 100 | 82 |
| 101 void ServerStarted(base::Thread* thread, | 83 void ServerStarted(base::Thread* thread, |
| 102 ServerWrapper* server_wrapper, | 84 ServerWrapper* server_wrapper, |
| 103 ServerSocketFactory* socket_factory, | 85 content::DevToolsSocketFactory* socket_factory, |
| 104 std::unique_ptr<net::IPEndPoint> ip_address); | 86 std::unique_ptr<net::IPEndPoint> ip_address); |
| 105 | 87 |
| 106 scoped_refptr<content::DevToolsAgentHost> GetAgentHost( | 88 scoped_refptr<content::DevToolsAgentHost> GetAgentHost( |
| 107 const std::string& target_id); | 89 const std::string& target_id); |
| 108 | 90 |
| 109 void SendJson(int connection_id, | 91 void SendJson(int connection_id, |
| 110 net::HttpStatusCode status_code, | 92 net::HttpStatusCode status_code, |
| 111 base::Value* value, | 93 base::Value* value, |
| 112 const std::string& message); | 94 const std::string& message); |
| 113 void Send200(int connection_id, | 95 void Send200(int connection_id, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 130 // The thread used by the devtools handler to run server socket. | 112 // The thread used by the devtools handler to run server socket. |
| 131 base::Thread* thread_; | 113 base::Thread* thread_; |
| 132 std::string frontend_url_; | 114 std::string frontend_url_; |
| 133 std::string product_name_; | 115 std::string product_name_; |
| 134 std::string user_agent_; | 116 std::string user_agent_; |
| 135 ServerWrapper* server_wrapper_; | 117 ServerWrapper* server_wrapper_; |
| 136 std::unique_ptr<net::IPEndPoint> server_ip_address_; | 118 std::unique_ptr<net::IPEndPoint> server_ip_address_; |
| 137 typedef std::map<int, DevToolsAgentHostClientImpl*> ConnectionToClientMap; | 119 typedef std::map<int, DevToolsAgentHostClientImpl*> ConnectionToClientMap; |
| 138 ConnectionToClientMap connection_to_client_; | 120 ConnectionToClientMap connection_to_client_; |
| 139 const std::unique_ptr<DevToolsHttpHandlerDelegate> delegate_; | 121 const std::unique_ptr<DevToolsHttpHandlerDelegate> delegate_; |
| 140 ServerSocketFactory* socket_factory_; | 122 content::DevToolsSocketFactory* socket_factory_; |
| 141 using DescriptorMap = | 123 using DescriptorMap = |
| 142 std::map<std::string, scoped_refptr<content::DevToolsAgentHost>>; | 124 std::map<std::string, scoped_refptr<content::DevToolsAgentHost>>; |
| 143 DescriptorMap agent_host_map_; | 125 DescriptorMap agent_host_map_; |
| 144 base::WeakPtrFactory<DevToolsHttpHandler> weak_factory_; | 126 base::WeakPtrFactory<DevToolsHttpHandler> weak_factory_; |
| 145 | 127 |
| 146 DISALLOW_COPY_AND_ASSIGN(DevToolsHttpHandler); | 128 DISALLOW_COPY_AND_ASSIGN(DevToolsHttpHandler); |
| 147 }; | 129 }; |
| 148 | 130 |
| 149 } // namespace devtools_http_handler | 131 } // namespace devtools_http_handler |
| 150 | 132 |
| 151 #endif // COMPONENTS_DEVTOOLS_HTTP_HANDLER_DEVTOOLS_HTTP_HANDLER_H_ | 133 #endif // COMPONENTS_DEVTOOLS_HTTP_HANDLER_DEVTOOLS_HTTP_HANDLER_H_ |
| OLD | NEW |