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