| 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 CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_HTTP_HANDLER_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_HTTP_HANDLER_IMPL_H_ |
| 6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_HTTP_HANDLER_IMPL_H_ | 6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_HTTP_HANDLER_IMPL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 16 #include "content/public/browser/devtools_http_handler.h" | 16 #include "content/public/browser/devtools_http_handler.h" |
| 17 #include "content/public/browser/devtools_http_handler_delegate.h" | 17 #include "content/public/browser/devtools_http_handler_delegate.h" |
| 18 #include "content/public/browser/worker_service.h" | |
| 19 #include "net/http/http_status_code.h" | 18 #include "net/http/http_status_code.h" |
| 20 #include "net/server/http_server.h" | 19 #include "net/server/http_server.h" |
| 21 | 20 |
| 22 namespace base { | 21 namespace base { |
| 23 class DictionaryValue; | 22 class DictionaryValue; |
| 24 class ListValue; | 23 class ListValue; |
| 25 class Thread; | 24 class Thread; |
| 26 class Value; | 25 class Value; |
| 27 } | 26 } |
| 28 | 27 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 46 | 45 |
| 47 // Takes ownership over |socket_factory|. | 46 // Takes ownership over |socket_factory|. |
| 48 DevToolsHttpHandlerImpl(const net::StreamListenSocketFactory* socket_factory, | 47 DevToolsHttpHandlerImpl(const net::StreamListenSocketFactory* socket_factory, |
| 49 const std::string& frontend_url, | 48 const std::string& frontend_url, |
| 50 DevToolsHttpHandlerDelegate* delegate); | 49 DevToolsHttpHandlerDelegate* delegate); |
| 51 virtual ~DevToolsHttpHandlerImpl(); | 50 virtual ~DevToolsHttpHandlerImpl(); |
| 52 void Start(); | 51 void Start(); |
| 53 | 52 |
| 54 // DevToolsHttpHandler implementation. | 53 // DevToolsHttpHandler implementation. |
| 55 virtual void Stop() OVERRIDE; | 54 virtual void Stop() OVERRIDE; |
| 56 virtual void SetDevToolsAgentHostBinding( | 55 virtual GURL GetFrontendURL() OVERRIDE; |
| 57 DevToolsAgentHostBinding* binding) OVERRIDE; | |
| 58 virtual GURL GetFrontendURL(DevToolsAgentHost* agent_host) OVERRIDE; | |
| 59 | 56 |
| 60 // net::HttpServer::Delegate implementation. | 57 // net::HttpServer::Delegate implementation. |
| 61 virtual void OnHttpRequest(int connection_id, | 58 virtual void OnHttpRequest(int connection_id, |
| 62 const net::HttpServerRequestInfo& info) OVERRIDE; | 59 const net::HttpServerRequestInfo& info) OVERRIDE; |
| 63 virtual void OnWebSocketRequest( | 60 virtual void OnWebSocketRequest( |
| 64 int connection_id, | 61 int connection_id, |
| 65 const net::HttpServerRequestInfo& info) OVERRIDE; | 62 const net::HttpServerRequestInfo& info) OVERRIDE; |
| 66 virtual void OnWebSocketMessage(int connection_id, | 63 virtual void OnWebSocketMessage(int connection_id, |
| 67 const std::string& data) OVERRIDE; | 64 const std::string& data) OVERRIDE; |
| 68 virtual void OnClose(int connection_id) OVERRIDE; | 65 virtual void OnClose(int connection_id) OVERRIDE; |
| 69 | 66 |
| 70 void OnJsonRequestUI(int connection_id, | 67 void OnJsonRequestUI(int connection_id, |
| 71 const net::HttpServerRequestInfo& info); | 68 const net::HttpServerRequestInfo& info); |
| 72 void OnThumbnailRequestUI(int connection_id, const GURL& page_url); | 69 void OnThumbnailRequestUI(int connection_id, const GURL& page_url); |
| 73 void OnDiscoveryPageRequestUI(int connection_id); | 70 void OnDiscoveryPageRequestUI(int connection_id); |
| 74 | 71 |
| 75 void OnWebSocketRequestUI(int connection_id, | 72 void OnWebSocketRequestUI(int connection_id, |
| 76 const net::HttpServerRequestInfo& info); | 73 const net::HttpServerRequestInfo& info); |
| 77 void OnWebSocketMessageUI(int connection_id, const std::string& data); | 74 void OnWebSocketMessageUI(int connection_id, const std::string& data); |
| 78 void OnCloseUI(int connection_id); | 75 void OnCloseUI(int connection_id); |
| 79 | 76 |
| 80 void ResetHandlerThread(); | 77 void ResetHandlerThread(); |
| 81 void ResetHandlerThreadAndRelease(); | 78 void ResetHandlerThreadAndRelease(); |
| 82 | 79 |
| 83 void CollectWorkerInfo(base::ListValue* target_list, std::string host); | 80 void OnTargetListReceived( |
| 84 void SendTargetList(int connection_id, base::ListValue* target_list); | 81 int connection_id, |
| 82 const std::string& host, |
| 83 const DevToolsHttpHandlerDelegate::TargetList& targets); |
| 84 |
| 85 DevToolsTarget* GetTarget(const std::string& id); |
| 85 | 86 |
| 86 void Init(); | 87 void Init(); |
| 87 void Teardown(); | 88 void Teardown(); |
| 88 | 89 |
| 89 void StartHandlerThread(); | 90 void StartHandlerThread(); |
| 90 void StopHandlerThread(); | 91 void StopHandlerThread(); |
| 91 | 92 |
| 92 void SendJson(int connection_id, | 93 void SendJson(int connection_id, |
| 93 net::HttpStatusCode status_code, | 94 net::HttpStatusCode status_code, |
| 94 base::Value* value, | 95 base::Value* value, |
| 95 const std::string& message); | 96 const std::string& message); |
| 96 void Send200(int connection_id, | 97 void Send200(int connection_id, |
| 97 const std::string& data, | 98 const std::string& data, |
| 98 const std::string& mime_type); | 99 const std::string& mime_type); |
| 99 void Send404(int connection_id); | 100 void Send404(int connection_id); |
| 100 void Send500(int connection_id, | 101 void Send500(int connection_id, |
| 101 const std::string& message); | 102 const std::string& message); |
| 102 void AcceptWebSocket(int connection_id, | 103 void AcceptWebSocket(int connection_id, |
| 103 const net::HttpServerRequestInfo& request); | 104 const net::HttpServerRequestInfo& request); |
| 104 | 105 |
| 105 // Returns the front end url without the host at the beginning. | 106 // Returns the front end url without the host at the beginning. |
| 106 std::string GetFrontendURLInternal(const std::string rvh_id, | 107 std::string GetFrontendURLInternal(const std::string target_id, |
| 107 const std::string& host); | 108 const std::string& host); |
| 108 | 109 |
| 109 base::DictionaryValue* SerializePageInfo(RenderViewHost* rvh, | 110 base::DictionaryValue* SerializeTarget(const DevToolsTarget& target, |
| 110 const std::string& host); | 111 const std::string& host); |
| 111 | |
| 112 base::DictionaryValue* SerializeWorkerInfo( | |
| 113 const WorkerService::WorkerInfo& worker, | |
| 114 const std::string& host); | |
| 115 | |
| 116 void SerializeDebuggerURLs(base::DictionaryValue* dictionary, | |
| 117 const std::string& id, | |
| 118 const std::string& host); | |
| 119 | 112 |
| 120 // The thread used by the devtools handler to run server socket. | 113 // The thread used by the devtools handler to run server socket. |
| 121 scoped_ptr<base::Thread> thread_; | 114 scoped_ptr<base::Thread> thread_; |
| 122 | 115 |
| 123 std::string overridden_frontend_url_; | 116 std::string overridden_frontend_url_; |
| 124 scoped_ptr<const net::StreamListenSocketFactory> socket_factory_; | 117 scoped_ptr<const net::StreamListenSocketFactory> socket_factory_; |
| 125 scoped_refptr<net::HttpServer> server_; | 118 scoped_refptr<net::HttpServer> server_; |
| 126 typedef std::map<int, DevToolsClientHost*> ConnectionToClientHostMap; | 119 typedef std::map<int, DevToolsClientHost*> ConnectionToClientHostMap; |
| 127 ConnectionToClientHostMap connection_to_client_host_ui_; | 120 ConnectionToClientHostMap connection_to_client_host_ui_; |
| 128 scoped_ptr<DevToolsHttpHandlerDelegate> delegate_; | 121 scoped_ptr<DevToolsHttpHandlerDelegate> delegate_; |
| 129 DevToolsAgentHostBinding* binding_; | 122 typedef std::map<std::string, scoped_refptr<DevToolsTarget> > TargetMap; |
| 130 scoped_ptr<DevToolsAgentHostBinding> default_binding_; | 123 TargetMap target_map_; |
| 131 scoped_refptr<DevToolsBrowserTarget> browser_target_; | 124 scoped_refptr<DevToolsBrowserTarget> browser_target_; |
| 132 DISALLOW_COPY_AND_ASSIGN(DevToolsHttpHandlerImpl); | 125 DISALLOW_COPY_AND_ASSIGN(DevToolsHttpHandlerImpl); |
| 133 }; | 126 }; |
| 134 | 127 |
| 135 } // namespace content | 128 } // namespace content |
| 136 | 129 |
| 137 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_HTTP_HANDLER_IMPL_H_ | 130 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_HTTP_HANDLER_IMPL_H_ |
| OLD | NEW |