| 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 |
| 29 namespace net { | 28 namespace net { |
| 30 class StreamListenSocketFactory; | 29 class StreamListenSocketFactory; |
| 31 class URLRequestContextGetter; | 30 class URLRequestContextGetter; |
| 32 } | 31 } |
| 33 | 32 |
| 34 namespace content { | 33 namespace content { |
| 35 | 34 |
| 36 class DevToolsBrowserTarget; | 35 class DevToolsBrowserTarget; |
| 37 class DevToolsClientHost; | 36 class DevToolsClientHost; |
| 38 | 37 |
| 39 class DevToolsHttpHandlerImpl | 38 class DevToolsHttpHandlerImpl |
| 40 : public DevToolsHttpHandler, | 39 : public DevToolsHttpHandler, |
| 41 public base::RefCountedThreadSafe<DevToolsHttpHandlerImpl>, | 40 public base::RefCountedThreadSafe<DevToolsHttpHandlerImpl>, |
| 42 public net::HttpServer::Delegate { | 41 public net::HttpServer::Delegate { |
| 43 private: | 42 private: |
| 44 friend class base::RefCountedThreadSafe<DevToolsHttpHandlerImpl>; | 43 friend class base::RefCountedThreadSafe<DevToolsHttpHandlerImpl>; |
| 45 friend class DevToolsHttpHandler; | 44 friend class DevToolsHttpHandler; |
| 46 | 45 |
| 46 typedef DevToolsHttpHandlerDelegate::Target Target; |
| 47 typedef DevToolsHttpHandlerDelegate::TargetList TargetList; |
| 48 |
| 47 // Takes ownership over |socket_factory|. | 49 // Takes ownership over |socket_factory|. |
| 48 DevToolsHttpHandlerImpl(const net::StreamListenSocketFactory* socket_factory, | 50 DevToolsHttpHandlerImpl(const net::StreamListenSocketFactory* socket_factory, |
| 49 const std::string& frontend_url, | 51 const std::string& frontend_url, |
| 50 DevToolsHttpHandlerDelegate* delegate); | 52 DevToolsHttpHandlerDelegate* delegate); |
| 51 virtual ~DevToolsHttpHandlerImpl(); | 53 virtual ~DevToolsHttpHandlerImpl(); |
| 52 void Start(); | 54 void Start(); |
| 53 | 55 |
| 54 // DevToolsHttpHandler implementation. | 56 // DevToolsHttpHandler implementation. |
| 55 virtual void Stop() OVERRIDE; | 57 virtual void Stop() OVERRIDE; |
| 56 virtual void SetDevToolsAgentHostBinding( | |
| 57 DevToolsAgentHostBinding* binding) OVERRIDE; | |
| 58 virtual GURL GetFrontendURL(DevToolsAgentHost* agent_host) OVERRIDE; | 58 virtual GURL GetFrontendURL(DevToolsAgentHost* agent_host) OVERRIDE; |
| 59 | 59 |
| 60 // net::HttpServer::Delegate implementation. | 60 // net::HttpServer::Delegate implementation. |
| 61 virtual void OnHttpRequest(int connection_id, | 61 virtual void OnHttpRequest(int connection_id, |
| 62 const net::HttpServerRequestInfo& info) OVERRIDE; | 62 const net::HttpServerRequestInfo& info) OVERRIDE; |
| 63 virtual void OnWebSocketRequest( | 63 virtual void OnWebSocketRequest( |
| 64 int connection_id, | 64 int connection_id, |
| 65 const net::HttpServerRequestInfo& info) OVERRIDE; | 65 const net::HttpServerRequestInfo& info) OVERRIDE; |
| 66 virtual void OnWebSocketMessage(int connection_id, | 66 virtual void OnWebSocketMessage(int connection_id, |
| 67 const std::string& data) OVERRIDE; | 67 const std::string& data) OVERRIDE; |
| 68 virtual void OnClose(int connection_id) OVERRIDE; | 68 virtual void OnClose(int connection_id) OVERRIDE; |
| 69 | 69 |
| 70 void OnJsonRequestUI(int connection_id, | 70 void OnJsonRequestUI(int connection_id, |
| 71 const net::HttpServerRequestInfo& info); | 71 const net::HttpServerRequestInfo& info); |
| 72 void OnThumbnailRequestUI(int connection_id, const GURL& page_url); | 72 void OnThumbnailRequestUI(int connection_id, const std::string& target_id); |
| 73 void OnDiscoveryPageRequestUI(int connection_id); | 73 void OnDiscoveryPageRequestUI(int connection_id); |
| 74 | 74 |
| 75 void OnWebSocketRequestUI(int connection_id, | 75 void OnWebSocketRequestUI(int connection_id, |
| 76 const net::HttpServerRequestInfo& info); | 76 const net::HttpServerRequestInfo& info); |
| 77 void OnWebSocketMessageUI(int connection_id, const std::string& data); | 77 void OnWebSocketMessageUI(int connection_id, const std::string& data); |
| 78 void OnCloseUI(int connection_id); | 78 void OnCloseUI(int connection_id); |
| 79 | 79 |
| 80 void ResetHandlerThread(); | 80 void ResetHandlerThread(); |
| 81 void ResetHandlerThreadAndRelease(); | 81 void ResetHandlerThreadAndRelease(); |
| 82 | 82 |
| 83 void CollectWorkerInfo(base::ListValue* target_list, std::string host); | 83 void SendTargetList(int connection_id, |
| 84 void SendTargetList(int connection_id, base::ListValue* target_list); | 84 const std::string& host, |
| 85 const TargetList& targets); |
| 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* Serialize(const Target& 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_refptr<DevToolsHttpHandlerDelegate> delegate_; |
| 129 DevToolsAgentHostBinding* binding_; | |
| 130 scoped_ptr<DevToolsAgentHostBinding> default_binding_; | |
| 131 scoped_refptr<DevToolsBrowserTarget> browser_target_; | 122 scoped_refptr<DevToolsBrowserTarget> browser_target_; |
| 132 DISALLOW_COPY_AND_ASSIGN(DevToolsHttpHandlerImpl); | 123 DISALLOW_COPY_AND_ASSIGN(DevToolsHttpHandlerImpl); |
| 133 }; | 124 }; |
| 134 | 125 |
| 135 } // namespace content | 126 } // namespace content |
| 136 | 127 |
| 137 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_HTTP_HANDLER_IMPL_H_ | 128 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_HTTP_HANDLER_IMPL_H_ |
| OLD | NEW |