Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(609)

Side by Side Diff: content/browser/debugger/devtools_http_handler_impl.cc

Issue 8554008: Add content API for DevTools HTTP handler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed unnecessary comment from the public interface Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "content/browser/debugger/devtools_http_protocol_handler.h" 5 #include "content/browser/debugger/devtools_http_handler_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/message_loop_proxy.h" 14 #include "base/message_loop_proxy.h"
15 #include "base/string_number_conversions.h" 15 #include "base/string_number_conversions.h"
16 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
17 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
18 #include "base/utf_string_conversions.h" 18 #include "base/utf_string_conversions.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "content/browser/tab_contents/tab_contents.h" 20 #include "content/browser/tab_contents/tab_contents.h"
21 #include "content/browser/tab_contents/tab_contents_observer.h" 21 #include "content/browser/tab_contents/tab_contents_observer.h"
22 #include "content/common/devtools_messages.h" 22 #include "content/common/devtools_messages.h"
23 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
24 #include "content/public/browser/devtools_agent_host_registry.h" 24 #include "content/public/browser/devtools_agent_host_registry.h"
25 #include "content/public/browser/devtools_client_host.h" 25 #include "content/public/browser/devtools_client_host.h"
26 #include "content/public/browser/devtools_http_handler_delegate.h"
26 #include "content/public/browser/devtools_manager.h" 27 #include "content/public/browser/devtools_manager.h"
27 #include "googleurl/src/gurl.h" 28 #include "googleurl/src/gurl.h"
28 #include "net/base/escape.h" 29 #include "net/base/escape.h"
29 #include "net/base/io_buffer.h" 30 #include "net/base/io_buffer.h"
30 #include "net/server/http_server_request_info.h" 31 #include "net/server/http_server_request_info.h"
31 #include "net/url_request/url_request_context.h" 32 #include "net/url_request/url_request_context.h"
32 33
33 using content::BrowserThread; 34 namespace content {
34 using content::DevToolsAgentHost;
35 using content::DevToolsAgentHostRegistry;
36 using content::DevToolsClientHost;
37 using content::DevToolsManager;
38 35
39 const int kBufferSize = 16 * 1024; 36 const int kBufferSize = 16 * 1024;
40 37
41 namespace { 38 namespace {
42 39
43 // An internal implementation of DevToolsClientHost that delegates 40 // An internal implementation of DevToolsClientHost that delegates
44 // messages sent for DevToolsClient to a DebuggerShell instance. 41 // messages sent for DevToolsClient to a DebuggerShell instance.
45 class DevToolsClientHostImpl : public DevToolsClientHost { 42 class DevToolsClientHostImpl : public DevToolsClientHost {
46 public: 43 public:
47 DevToolsClientHostImpl( 44 DevToolsClientHostImpl(
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 base::LeakyLazyInstanceTraits<TabContentsIDHelper::IdToTabContentsMap> > 128 base::LeakyLazyInstanceTraits<TabContentsIDHelper::IdToTabContentsMap> >
132 TabContentsIDHelper::id_to_tabcontents_ = LAZY_INSTANCE_INITIALIZER; 129 TabContentsIDHelper::id_to_tabcontents_ = LAZY_INSTANCE_INITIALIZER;
133 base::LazyInstance< 130 base::LazyInstance<
134 TabContentsIDHelper::TabContentsToIdMap, 131 TabContentsIDHelper::TabContentsToIdMap,
135 base::LeakyLazyInstanceTraits<TabContentsIDHelper::TabContentsToIdMap> > 132 base::LeakyLazyInstanceTraits<TabContentsIDHelper::TabContentsToIdMap> >
136 TabContentsIDHelper::tabcontents_to_id_ = LAZY_INSTANCE_INITIALIZER; 133 TabContentsIDHelper::tabcontents_to_id_ = LAZY_INSTANCE_INITIALIZER;
137 134
138 } // namespace 135 } // namespace
139 136
140 // static 137 // static
141 scoped_refptr<DevToolsHttpProtocolHandler> DevToolsHttpProtocolHandler::Start( 138 DevToolsHttpHandler* DevToolsHttpHandler::Start(
142 const std::string& ip, 139 const std::string& ip,
143 int port, 140 int port,
144 const std::string& frontend_url, 141 const std::string& frontend_url,
145 Delegate* delegate) { 142 DevToolsHttpHandlerDelegate* delegate) {
146 scoped_refptr<DevToolsHttpProtocolHandler> http_handler = 143 DevToolsHttpHandlerImpl* http_handler =
147 new DevToolsHttpProtocolHandler(ip, port, frontend_url, delegate); 144 new DevToolsHttpHandlerImpl(ip, port, frontend_url, delegate);
148 http_handler->Start(); 145 http_handler->Start();
149 return http_handler; 146 return http_handler;
150 } 147 }
151 148
152 DevToolsHttpProtocolHandler::~DevToolsHttpProtocolHandler() { 149 DevToolsHttpHandlerImpl::~DevToolsHttpHandlerImpl() {
153 // Stop() must be called prior to this being called 150 // Stop() must be called prior to this being called
154 DCHECK(server_.get() == NULL); 151 DCHECK(server_.get() == NULL);
155 } 152 }
156 153
157 void DevToolsHttpProtocolHandler::Start() { 154 void DevToolsHttpHandlerImpl::Start() {
158 BrowserThread::PostTask( 155 BrowserThread::PostTask(
159 BrowserThread::IO, FROM_HERE, 156 BrowserThread::IO, FROM_HERE,
160 base::Bind(&DevToolsHttpProtocolHandler::Init, this)); 157 base::Bind(&DevToolsHttpHandlerImpl::Init, this));
161 } 158 }
162 159
163 void DevToolsHttpProtocolHandler::Stop() { 160 void DevToolsHttpHandlerImpl::Stop() {
164 BrowserThread::PostTask( 161 BrowserThread::PostTask(
165 BrowserThread::IO, FROM_HERE, 162 BrowserThread::IO, FROM_HERE,
166 base::Bind(&DevToolsHttpProtocolHandler::Teardown, this)); 163 base::Bind(&DevToolsHttpHandlerImpl::Teardown, this));
164 protect_ptr_ = NULL;
167 } 165 }
168 166
169 void DevToolsHttpProtocolHandler::OnHttpRequest( 167 void DevToolsHttpHandlerImpl::OnHttpRequest(
170 int connection_id, 168 int connection_id,
171 const net::HttpServerRequestInfo& info) { 169 const net::HttpServerRequestInfo& info) {
172 if (info.path == "/json") { 170 if (info.path == "/json") {
173 // Pages discovery json request. 171 // Pages discovery json request.
174 BrowserThread::PostTask( 172 BrowserThread::PostTask(
175 BrowserThread::UI, 173 BrowserThread::UI,
176 FROM_HERE, 174 FROM_HERE,
177 base::Bind(&DevToolsHttpProtocolHandler::OnJsonRequestUI, 175 base::Bind(&DevToolsHttpHandlerImpl::OnJsonRequestUI,
178 this, 176 this,
179 connection_id, 177 connection_id,
180 info)); 178 info));
181 return; 179 return;
182 } 180 }
183 181
184 // Proxy static files from chrome-devtools://devtools/*. 182 // Proxy static files from chrome-devtools://devtools/*.
185 net::URLRequestContext* request_context = delegate_->GetURLRequestContext(); 183 net::URLRequestContext* request_context = delegate_->GetURLRequestContext();
186 if (!request_context) { 184 if (!request_context) {
187 server_->Send404(connection_id); 185 server_->Send404(connection_id);
(...skipping 15 matching lines...) Expand all
203 } else { 201 } else {
204 server_->Send404(connection_id); 202 server_->Send404(connection_id);
205 return; 203 return;
206 } 204 }
207 205
208 Bind(request, connection_id); 206 Bind(request, connection_id);
209 request->set_context(request_context); 207 request->set_context(request_context);
210 request->Start(); 208 request->Start();
211 } 209 }
212 210
213 void DevToolsHttpProtocolHandler::OnWebSocketRequest( 211 void DevToolsHttpHandlerImpl::OnWebSocketRequest(
214 int connection_id, 212 int connection_id,
215 const net::HttpServerRequestInfo& request) { 213 const net::HttpServerRequestInfo& request) {
216 BrowserThread::PostTask( 214 BrowserThread::PostTask(
217 BrowserThread::UI, 215 BrowserThread::UI,
218 FROM_HERE, 216 FROM_HERE,
219 base::Bind( 217 base::Bind(
220 &DevToolsHttpProtocolHandler::OnWebSocketRequestUI, 218 &DevToolsHttpHandlerImpl::OnWebSocketRequestUI,
221 this, 219 this,
222 connection_id, 220 connection_id,
223 request)); 221 request));
224 } 222 }
225 223
226 void DevToolsHttpProtocolHandler::OnWebSocketMessage( 224 void DevToolsHttpHandlerImpl::OnWebSocketMessage(
227 int connection_id, 225 int connection_id,
228 const std::string& data) { 226 const std::string& data) {
229 BrowserThread::PostTask( 227 BrowserThread::PostTask(
230 BrowserThread::UI, 228 BrowserThread::UI,
231 FROM_HERE, 229 FROM_HERE,
232 base::Bind( 230 base::Bind(
233 &DevToolsHttpProtocolHandler::OnWebSocketMessageUI, 231 &DevToolsHttpHandlerImpl::OnWebSocketMessageUI,
234 this, 232 this,
235 connection_id, 233 connection_id,
236 data)); 234 data));
237 } 235 }
238 236
239 void DevToolsHttpProtocolHandler::OnClose(int connection_id) { 237 void DevToolsHttpHandlerImpl::OnClose(int connection_id) {
240 ConnectionToRequestsMap::iterator it = 238 ConnectionToRequestsMap::iterator it =
241 connection_to_requests_io_.find(connection_id); 239 connection_to_requests_io_.find(connection_id);
242 if (it != connection_to_requests_io_.end()) { 240 if (it != connection_to_requests_io_.end()) {
243 // Dispose delegating socket. 241 // Dispose delegating socket.
244 for (std::set<net::URLRequest*>::iterator it2 = it->second.begin(); 242 for (std::set<net::URLRequest*>::iterator it2 = it->second.begin();
245 it2 != it->second.end(); ++it2) { 243 it2 != it->second.end(); ++it2) {
246 net::URLRequest* request = *it2; 244 net::URLRequest* request = *it2;
247 request->Cancel(); 245 request->Cancel();
248 request_to_connection_io_.erase(request); 246 request_to_connection_io_.erase(request);
249 request_to_buffer_io_.erase(request); 247 request_to_buffer_io_.erase(request);
250 delete request; 248 delete request;
251 } 249 }
252 connection_to_requests_io_.erase(connection_id); 250 connection_to_requests_io_.erase(connection_id);
253 } 251 }
254 252
255 BrowserThread::PostTask( 253 BrowserThread::PostTask(
256 BrowserThread::UI, 254 BrowserThread::UI,
257 FROM_HERE, 255 FROM_HERE,
258 base::Bind( 256 base::Bind(
259 &DevToolsHttpProtocolHandler::OnCloseUI, 257 &DevToolsHttpHandlerImpl::OnCloseUI,
260 this, 258 this,
261 connection_id)); 259 connection_id));
262 } 260 }
263 261
264 struct PageInfo 262 struct PageInfo
265 { 263 {
266 int id; 264 int id;
267 std::string url; 265 std::string url;
268 bool attached; 266 bool attached;
269 std::string title; 267 std::string title;
270 std::string thumbnail_url; 268 std::string thumbnail_url;
271 std::string favicon_url; 269 std::string favicon_url;
272 }; 270 };
273 typedef std::vector<PageInfo> PageList; 271 typedef std::vector<PageInfo> PageList;
274 272
275 static PageList GeneratePageList( 273 static PageList GeneratePageList(
276 DevToolsHttpProtocolHandler::Delegate* delegate, 274 DevToolsHttpHandlerDelegate* delegate,
277 int connection_id, 275 int connection_id,
278 const net::HttpServerRequestInfo& info) { 276 const net::HttpServerRequestInfo& info) {
279 typedef DevToolsHttpProtocolHandler::InspectableTabs Tabs; 277 typedef DevToolsHttpHandlerDelegate::InspectableTabs Tabs;
280 Tabs inspectable_tabs = delegate->GetInspectableTabs(); 278 Tabs inspectable_tabs = delegate->GetInspectableTabs();
281 279
282 PageList page_list; 280 PageList page_list;
283 for (Tabs::iterator it = inspectable_tabs.begin(); 281 for (Tabs::iterator it = inspectable_tabs.begin();
284 it != inspectable_tabs.end(); ++it) { 282 it != inspectable_tabs.end(); ++it) {
285 283
286 TabContents* tab_contents = *it; 284 TabContents* tab_contents = *it;
287 NavigationController& controller = tab_contents->controller(); 285 NavigationController& controller = tab_contents->controller();
288 286
289 NavigationEntry* entry = controller.GetActiveEntry(); 287 NavigationEntry* entry = controller.GetActiveEntry();
290 if (entry == NULL || !entry->url().is_valid()) 288 if (entry == NULL || !entry->url().is_valid())
291 continue; 289 continue;
292 290
293 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( 291 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost(
294 tab_contents->render_view_host()); 292 tab_contents->render_view_host());
295 DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> 293 DevToolsClientHost* client_host = DevToolsManager::GetInstance()->
296 GetDevToolsClientHostFor(agent); 294 GetDevToolsClientHostFor(agent);
297 PageInfo page_info; 295 PageInfo page_info;
298 page_info.id = TabContentsIDHelper::GetID(tab_contents); 296 page_info.id = TabContentsIDHelper::GetID(tab_contents);
299 page_info.attached = client_host != NULL; 297 page_info.attached = client_host != NULL;
300 page_info.url = entry->url().spec(); 298 page_info.url = entry->url().spec();
301 page_info.title = UTF16ToUTF8(net::EscapeForHTML(entry->title())); 299 page_info.title = UTF16ToUTF8(net::EscapeForHTML(entry->title()));
302 page_info.thumbnail_url = "/thumb/" + entry->url().spec(); 300 page_info.thumbnail_url = "/thumb/" + entry->url().spec();
303 page_info.favicon_url = entry->favicon().url().spec(); 301 page_info.favicon_url = entry->favicon().url().spec();
304 page_list.push_back(page_info); 302 page_list.push_back(page_info);
305 } 303 }
306 return page_list; 304 return page_list;
307 } 305 }
308 306
309 void DevToolsHttpProtocolHandler::OnJsonRequestUI( 307 void DevToolsHttpHandlerImpl::OnJsonRequestUI(
310 int connection_id, 308 int connection_id,
311 const net::HttpServerRequestInfo& info) { 309 const net::HttpServerRequestInfo& info) {
312 PageList page_list = GeneratePageList(delegate_.get(), 310 PageList page_list = GeneratePageList(delegate_.get(),
313 connection_id, info); 311 connection_id, info);
314 ListValue json_pages_list; 312 ListValue json_pages_list;
315 std::string host = info.headers["Host"]; 313 std::string host = info.headers["Host"];
316 for (PageList::iterator i = page_list.begin(); 314 for (PageList::iterator i = page_list.begin();
317 i != page_list.end(); ++i) { 315 i != page_list.end(); ++i) {
318 316
319 DictionaryValue* page_info = new DictionaryValue; 317 DictionaryValue* page_info = new DictionaryValue;
(...skipping 13 matching lines...) Expand all
333 host.c_str(), 331 host.c_str(),
334 i->id)); 332 i->id));
335 } 333 }
336 } 334 }
337 335
338 std::string response; 336 std::string response;
339 base::JSONWriter::Write(&json_pages_list, true, &response); 337 base::JSONWriter::Write(&json_pages_list, true, &response);
340 Send200(connection_id, response, "application/json; charset=UTF-8"); 338 Send200(connection_id, response, "application/json; charset=UTF-8");
341 } 339 }
342 340
343 void DevToolsHttpProtocolHandler::OnWebSocketRequestUI( 341 void DevToolsHttpHandlerImpl::OnWebSocketRequestUI(
344 int connection_id, 342 int connection_id,
345 const net::HttpServerRequestInfo& request) { 343 const net::HttpServerRequestInfo& request) {
346 std::string prefix = "/devtools/page/"; 344 std::string prefix = "/devtools/page/";
347 size_t pos = request.path.find(prefix); 345 size_t pos = request.path.find(prefix);
348 if (pos != 0) { 346 if (pos != 0) {
349 Send404(connection_id); 347 Send404(connection_id);
350 return; 348 return;
351 } 349 }
352 std::string page_id = request.path.substr(prefix.length()); 350 std::string page_id = request.path.substr(prefix.length());
353 int id = 0; 351 int id = 0;
(...skipping 18 matching lines...) Expand all
372 370
373 DevToolsClientHostImpl* client_host = 371 DevToolsClientHostImpl* client_host =
374 new DevToolsClientHostImpl(server_, connection_id); 372 new DevToolsClientHostImpl(server_, connection_id);
375 connection_to_client_host_ui_[connection_id] = client_host; 373 connection_to_client_host_ui_[connection_id] = client_host;
376 374
377 manager->RegisterDevToolsClientHostFor(agent, client_host); 375 manager->RegisterDevToolsClientHostFor(agent, client_host);
378 376
379 AcceptWebSocket(connection_id, request); 377 AcceptWebSocket(connection_id, request);
380 } 378 }
381 379
382 void DevToolsHttpProtocolHandler::OnWebSocketMessageUI( 380 void DevToolsHttpHandlerImpl::OnWebSocketMessageUI(
383 int connection_id, 381 int connection_id,
384 const std::string& data) { 382 const std::string& data) {
385 ConnectionToClientHostMap::iterator it = 383 ConnectionToClientHostMap::iterator it =
386 connection_to_client_host_ui_.find(connection_id); 384 connection_to_client_host_ui_.find(connection_id);
387 if (it == connection_to_client_host_ui_.end()) 385 if (it == connection_to_client_host_ui_.end())
388 return; 386 return;
389 387
390 DevToolsManager* manager = DevToolsManager::GetInstance(); 388 DevToolsManager* manager = DevToolsManager::GetInstance();
391 manager->DispatchOnInspectorBackend(it->second, data); 389 manager->DispatchOnInspectorBackend(it->second, data);
392 } 390 }
393 391
394 void DevToolsHttpProtocolHandler::OnCloseUI(int connection_id) { 392 void DevToolsHttpHandlerImpl::OnCloseUI(int connection_id) {
395 ConnectionToClientHostMap::iterator it = 393 ConnectionToClientHostMap::iterator it =
396 connection_to_client_host_ui_.find(connection_id); 394 connection_to_client_host_ui_.find(connection_id);
397 if (it != connection_to_client_host_ui_.end()) { 395 if (it != connection_to_client_host_ui_.end()) {
398 DevToolsClientHostImpl* client_host = 396 DevToolsClientHostImpl* client_host =
399 static_cast<DevToolsClientHostImpl*>(it->second); 397 static_cast<DevToolsClientHostImpl*>(it->second);
400 DevToolsManager::GetInstance()->ClientHostClosing(client_host); 398 DevToolsManager::GetInstance()->ClientHostClosing(client_host);
401 delete client_host; 399 delete client_host;
402 connection_to_client_host_ui_.erase(connection_id); 400 connection_to_client_host_ui_.erase(connection_id);
403 } 401 }
404 } 402 }
405 403
406 void DevToolsHttpProtocolHandler::OnResponseStarted(net::URLRequest* request) { 404 void DevToolsHttpHandlerImpl::OnResponseStarted(net::URLRequest* request) {
407 RequestToSocketMap::iterator it = request_to_connection_io_.find(request); 405 RequestToSocketMap::iterator it = request_to_connection_io_.find(request);
408 if (it == request_to_connection_io_.end()) 406 if (it == request_to_connection_io_.end())
409 return; 407 return;
410 408
411 int connection_id = it->second; 409 int connection_id = it->second;
412 410
413 std::string content_type; 411 std::string content_type;
414 request->GetMimeType(&content_type); 412 request->GetMimeType(&content_type);
415 413
416 if (request->status().is_success()) { 414 if (request->status().is_success()) {
(...skipping 11 matching lines...) Expand all
428 // Some servers may treat HEAD requests as GET requests. To free up the 426 // Some servers may treat HEAD requests as GET requests. To free up the
429 // network connection as soon as possible, signal that the request has 427 // network connection as soon as possible, signal that the request has
430 // completed immediately, without trying to read any data back (all we care 428 // completed immediately, without trying to read any data back (all we care
431 // about is the response code and headers, which we already have). 429 // about is the response code and headers, which we already have).
432 net::IOBuffer* buffer = request_to_buffer_io_[request].get(); 430 net::IOBuffer* buffer = request_to_buffer_io_[request].get();
433 if (request->status().is_success()) 431 if (request->status().is_success())
434 request->Read(buffer, kBufferSize, &bytes_read); 432 request->Read(buffer, kBufferSize, &bytes_read);
435 OnReadCompleted(request, bytes_read); 433 OnReadCompleted(request, bytes_read);
436 } 434 }
437 435
438 void DevToolsHttpProtocolHandler::OnReadCompleted(net::URLRequest* request, 436 void DevToolsHttpHandlerImpl::OnReadCompleted(net::URLRequest* request,
439 int bytes_read) { 437 int bytes_read) {
440 RequestToSocketMap::iterator it = request_to_connection_io_.find(request); 438 RequestToSocketMap::iterator it = request_to_connection_io_.find(request);
441 if (it == request_to_connection_io_.end()) 439 if (it == request_to_connection_io_.end())
442 return; 440 return;
443 441
444 int connection_id = it->second; 442 int connection_id = it->second;
445 443
446 net::IOBuffer* buffer = request_to_buffer_io_[request].get(); 444 net::IOBuffer* buffer = request_to_buffer_io_[request].get();
447 do { 445 do {
448 if (!request->status().is_success() || bytes_read <= 0) 446 if (!request->status().is_success() || bytes_read <= 0)
449 break; 447 break;
450 std::string chunk_size = base::StringPrintf("%X\r\n", bytes_read); 448 std::string chunk_size = base::StringPrintf("%X\r\n", bytes_read);
451 server_->Send(connection_id, chunk_size); 449 server_->Send(connection_id, chunk_size);
452 server_->Send(connection_id, buffer->data(), bytes_read); 450 server_->Send(connection_id, buffer->data(), bytes_read);
453 server_->Send(connection_id, "\r\n"); 451 server_->Send(connection_id, "\r\n");
454 } while (request->Read(buffer, kBufferSize, &bytes_read)); 452 } while (request->Read(buffer, kBufferSize, &bytes_read));
455 453
456 454
457 // See comments re: HEAD requests in OnResponseStarted(). 455 // See comments re: HEAD requests in OnResponseStarted().
458 if (!request->status().is_io_pending()) { 456 if (!request->status().is_io_pending()) {
459 server_->Send(connection_id, "0\r\n\r\n"); 457 server_->Send(connection_id, "0\r\n\r\n");
460 RequestCompleted(request); 458 RequestCompleted(request);
461 } 459 }
462 } 460 }
463 461
464 DevToolsHttpProtocolHandler::DevToolsHttpProtocolHandler( 462 DevToolsHttpHandlerImpl::DevToolsHttpHandlerImpl(
465 const std::string& ip, 463 const std::string& ip,
466 int port, 464 int port,
467 const std::string& frontend_host, 465 const std::string& frontend_host,
468 Delegate* delegate) 466 DevToolsHttpHandlerDelegate* delegate)
469 : ip_(ip), 467 : ip_(ip),
470 port_(port), 468 port_(port),
471 overridden_frontend_url_(frontend_host), 469 overridden_frontend_url_(frontend_host),
472 delegate_(delegate) { 470 delegate_(delegate),
471 ALLOW_THIS_IN_INITIALIZER_LIST(protect_ptr_(this)) {
473 if (overridden_frontend_url_.empty()) 472 if (overridden_frontend_url_.empty())
474 overridden_frontend_url_ = "/devtools/devtools.html"; 473 overridden_frontend_url_ = "/devtools/devtools.html";
475 } 474 }
476 475
477 void DevToolsHttpProtocolHandler::Init() { 476 void DevToolsHttpHandlerImpl::Init() {
478 server_ = new net::HttpServer(ip_, port_, this); 477 server_ = new net::HttpServer(ip_, port_, this);
479 } 478 }
480 479
481 // Run on I/O thread 480 // Run on I/O thread
482 void DevToolsHttpProtocolHandler::Teardown() { 481 void DevToolsHttpHandlerImpl::Teardown() {
483 server_ = NULL; 482 server_ = NULL;
484 } 483 }
485 484
486 void DevToolsHttpProtocolHandler::Bind(net::URLRequest* request, 485 void DevToolsHttpHandlerImpl::Bind(net::URLRequest* request,
487 int connection_id) { 486 int connection_id) {
488 request_to_connection_io_[request] = connection_id; 487 request_to_connection_io_[request] = connection_id;
489 ConnectionToRequestsMap::iterator it = 488 ConnectionToRequestsMap::iterator it =
490 connection_to_requests_io_.find(connection_id); 489 connection_to_requests_io_.find(connection_id);
491 if (it == connection_to_requests_io_.end()) { 490 if (it == connection_to_requests_io_.end()) {
492 std::pair<int, std::set<net::URLRequest*> > value( 491 std::pair<int, std::set<net::URLRequest*> > value(
493 connection_id, 492 connection_id,
494 std::set<net::URLRequest*>()); 493 std::set<net::URLRequest*>());
495 it = connection_to_requests_io_.insert(value).first; 494 it = connection_to_requests_io_.insert(value).first;
496 } 495 }
497 it->second.insert(request); 496 it->second.insert(request);
498 request_to_buffer_io_[request] = new net::IOBuffer(kBufferSize); 497 request_to_buffer_io_[request] = new net::IOBuffer(kBufferSize);
499 } 498 }
500 499
501 void DevToolsHttpProtocolHandler::RequestCompleted(net::URLRequest* request) { 500 void DevToolsHttpHandlerImpl::RequestCompleted(net::URLRequest* request) {
502 RequestToSocketMap::iterator it = request_to_connection_io_.find(request); 501 RequestToSocketMap::iterator it = request_to_connection_io_.find(request);
503 if (it == request_to_connection_io_.end()) 502 if (it == request_to_connection_io_.end())
504 return; 503 return;
505 504
506 int connection_id = it->second; 505 int connection_id = it->second;
507 request_to_connection_io_.erase(request); 506 request_to_connection_io_.erase(request);
508 ConnectionToRequestsMap::iterator it2 = 507 ConnectionToRequestsMap::iterator it2 =
509 connection_to_requests_io_.find(connection_id); 508 connection_to_requests_io_.find(connection_id);
510 it2->second.erase(request); 509 it2->second.erase(request);
511 request_to_buffer_io_.erase(request); 510 request_to_buffer_io_.erase(request);
512 delete request; 511 delete request;
513 } 512 }
514 513
515 void DevToolsHttpProtocolHandler::Send200(int connection_id, 514 void DevToolsHttpHandlerImpl::Send200(int connection_id,
516 const std::string& data, 515 const std::string& data,
517 const std::string& mime_type) { 516 const std::string& mime_type) {
518 BrowserThread::PostTask( 517 BrowserThread::PostTask(
519 BrowserThread::IO, FROM_HERE, 518 BrowserThread::IO, FROM_HERE,
520 base::Bind(&net::HttpServer::Send200, 519 base::Bind(&net::HttpServer::Send200,
521 server_.get(), 520 server_.get(),
522 connection_id, 521 connection_id,
523 data, 522 data,
524 mime_type)); 523 mime_type));
525 } 524 }
526 525
527 void DevToolsHttpProtocolHandler::Send404(int connection_id) { 526 void DevToolsHttpHandlerImpl::Send404(int connection_id) {
528 BrowserThread::PostTask( 527 BrowserThread::PostTask(
529 BrowserThread::IO, FROM_HERE, 528 BrowserThread::IO, FROM_HERE,
530 base::Bind(&net::HttpServer::Send404, server_.get(), connection_id)); 529 base::Bind(&net::HttpServer::Send404, server_.get(), connection_id));
531 } 530 }
532 531
533 void DevToolsHttpProtocolHandler::Send500(int connection_id, 532 void DevToolsHttpHandlerImpl::Send500(int connection_id,
534 const std::string& message) { 533 const std::string& message) {
535 BrowserThread::PostTask( 534 BrowserThread::PostTask(
536 BrowserThread::IO, FROM_HERE, 535 BrowserThread::IO, FROM_HERE,
537 base::Bind(&net::HttpServer::Send500, server_.get(), connection_id, 536 base::Bind(&net::HttpServer::Send500, server_.get(), connection_id,
538 message)); 537 message));
539 } 538 }
540 539
541 void DevToolsHttpProtocolHandler::AcceptWebSocket( 540 void DevToolsHttpHandlerImpl::AcceptWebSocket(
542 int connection_id, 541 int connection_id,
543 const net::HttpServerRequestInfo& request) { 542 const net::HttpServerRequestInfo& request) {
544 BrowserThread::PostTask( 543 BrowserThread::PostTask(
545 BrowserThread::IO, FROM_HERE, 544 BrowserThread::IO, FROM_HERE,
546 base::Bind(&net::HttpServer::AcceptWebSocket, server_.get(), 545 base::Bind(&net::HttpServer::AcceptWebSocket, server_.get(),
547 connection_id, request)); 546 connection_id, request));
548 } 547 }
548
549 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/debugger/devtools_http_handler_impl.h ('k') | content/browser/debugger/devtools_http_protocol_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698