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 CONTENT_BROWSER_DEBUGGER_DEVTOOLS_HTTP_HANDLER_IMPL_H_ | |
6 #define CONTENT_BROWSER_DEBUGGER_DEVTOOLS_HTTP_HANDLER_IMPL_H_ | |
7 | |
8 #include <map> | |
9 #include <set> | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "content/common/content_export.h" | |
16 #include "content/public/browser/devtools_http_handler.h" | |
17 #include "content/public/browser/devtools_http_handler_delegate.h" | |
18 #include "content/public/browser/notification_observer.h" | |
19 #include "content/public/browser/notification_registrar.h" | |
20 #include "net/server/http_server.h" | |
21 | |
22 namespace base { | |
23 class DictionaryValue; | |
24 class Thread; | |
25 class Value; | |
26 } | |
27 | |
28 namespace net { | |
29 class StreamListenSocketFactory; | |
30 class URLRequestContextGetter; | |
31 } | |
32 | |
33 namespace content { | |
34 | |
35 class DevToolsBrowserTarget; | |
36 class DevToolsClientHost; | |
37 class RenderViewHost; | |
38 | |
39 class DevToolsHttpHandlerImpl | |
40 : public DevToolsHttpHandler, | |
41 public NotificationObserver, | |
42 public base::RefCountedThreadSafe<DevToolsHttpHandlerImpl>, | |
43 public net::HttpServer::Delegate { | |
44 private: | |
45 struct PageInfo; | |
46 typedef std::vector<PageInfo> PageList; | |
47 friend class base::RefCountedThreadSafe<DevToolsHttpHandlerImpl>; | |
48 friend class DevToolsHttpHandler; | |
49 | |
50 static bool SortPageListByTime(const PageInfo& info1, const PageInfo& info2); | |
51 | |
52 // Takes ownership over |socket_factory|. | |
53 DevToolsHttpHandlerImpl(const net::StreamListenSocketFactory* socket_factory, | |
54 const std::string& frontend_url, | |
55 DevToolsHttpHandlerDelegate* delegate); | |
56 virtual ~DevToolsHttpHandlerImpl(); | |
57 void Start(); | |
58 | |
59 // DevToolsHttpHandler implementation. | |
60 virtual void Stop() OVERRIDE; | |
61 virtual void SetRenderViewHostBinding( | |
62 RenderViewHostBinding* binding) OVERRIDE; | |
63 virtual GURL GetFrontendURL(RenderViewHost* render_view_host) OVERRIDE; | |
64 | |
65 // NotificationObserver implementation. | |
66 virtual void Observe(int type, | |
67 const NotificationSource& source, | |
68 const NotificationDetails& details) OVERRIDE; | |
69 | |
70 // net::HttpServer::Delegate implementation. | |
71 virtual void OnHttpRequest(int connection_id, | |
72 const net::HttpServerRequestInfo& info) OVERRIDE; | |
73 virtual void OnWebSocketRequest( | |
74 int connection_id, | |
75 const net::HttpServerRequestInfo& info) OVERRIDE; | |
76 virtual void OnWebSocketMessage(int connection_id, | |
77 const std::string& data) OVERRIDE; | |
78 virtual void OnClose(int connection_id) OVERRIDE; | |
79 | |
80 void OnJsonRequestUI(int connection_id, | |
81 const net::HttpServerRequestInfo& info); | |
82 void OnThumbnailRequestUI(int connection_id, | |
83 const net::HttpServerRequestInfo& info); | |
84 void OnDiscoveryPageRequestUI(int connection_id); | |
85 | |
86 void OnWebSocketRequestUI(int connection_id, | |
87 const net::HttpServerRequestInfo& info); | |
88 void OnWebSocketMessageUI(int connection_id, const std::string& data); | |
89 void OnCloseUI(int connection_id); | |
90 | |
91 void ResetHandlerThread(); | |
92 void ResetHandlerThreadAndRelease(); | |
93 | |
94 void Init(); | |
95 void Teardown(); | |
96 | |
97 void StartHandlerThread(); | |
98 void StopHandlerThread(); | |
99 | |
100 void SendJson(int connection_id, | |
101 net::HttpStatusCode status_code, | |
102 base::Value* value, | |
103 const std::string& message, | |
104 const std::string& jsonp); | |
105 void Send200(int connection_id, | |
106 const std::string& data, | |
107 const std::string& mime_type); | |
108 void Send404(int connection_id); | |
109 void Send500(int connection_id, | |
110 const std::string& message); | |
111 void AcceptWebSocket(int connection_id, | |
112 const net::HttpServerRequestInfo& request); | |
113 | |
114 PageList GeneratePageList(); | |
115 | |
116 // Returns the front end url without the host at the beginning. | |
117 std::string GetFrontendURLInternal(const std::string rvh_id, | |
118 const std::string& host); | |
119 | |
120 PageInfo CreatePageInfo(RenderViewHost* rvh); | |
121 | |
122 base::DictionaryValue* SerializePageInfo(const PageInfo& page_info, | |
123 const std::string& host); | |
124 | |
125 // The thread used by the devtools handler to run server socket. | |
126 scoped_ptr<base::Thread> thread_; | |
127 | |
128 std::string overridden_frontend_url_; | |
129 scoped_ptr<const net::StreamListenSocketFactory> socket_factory_; | |
130 scoped_refptr<net::HttpServer> server_; | |
131 typedef std::map<int, DevToolsClientHost*> ConnectionToClientHostMap; | |
132 ConnectionToClientHostMap connection_to_client_host_ui_; | |
133 scoped_ptr<DevToolsHttpHandlerDelegate> delegate_; | |
134 RenderViewHostBinding* binding_; | |
135 scoped_ptr<RenderViewHostBinding> default_binding_; | |
136 NotificationRegistrar registrar_; | |
137 scoped_ptr<DevToolsBrowserTarget> browser_target_; | |
138 DISALLOW_COPY_AND_ASSIGN(DevToolsHttpHandlerImpl); | |
139 }; | |
140 | |
141 } // namespace content | |
142 | |
143 #endif // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_HTTP_HANDLER_IMPL_H_ | |
OLD | NEW |