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

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: Optimized includes Created 9 years, 1 month 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/devtools_agent_host_registry.h" 24 #include "content/public/browser/devtools/devtools_agent_host_registry.h"
25 #include "content/public/browser/devtools/devtools_client_host.h" 25 #include "content/public/browser/devtools/devtools_client_host.h"
26 #include "content/public/browser/devtools/devtools_http_handler.h"
27 #include "content/public/browser/devtools/devtools_http_handler_delegate.h"
26 #include "content/public/browser/devtools/devtools_manager.h" 28 #include "content/public/browser/devtools/devtools_manager.h"
27 #include "googleurl/src/gurl.h" 29 #include "googleurl/src/gurl.h"
28 #include "net/base/escape.h" 30 #include "net/base/escape.h"
29 #include "net/base/io_buffer.h" 31 #include "net/base/io_buffer.h"
30 #include "net/server/http_server_request_info.h" 32 #include "net/server/http_server_request_info.h"
31 #include "net/url_request/url_request_context.h" 33 #include "net/url_request/url_request_context.h"
32 34
33 using content::BrowserThread; 35 namespace content {
34 using content::DevToolsAgentHost;
35 using content::DevToolsAgentHostRegistry;
36 using content::DevToolsClientHost;
37 using content::DevToolsManager;
38 36
39 const int kBufferSize = 16 * 1024; 37 const int kBufferSize = 16 * 1024;
40 38
41 namespace { 39 namespace {
42 40
43 // An internal implementation of DevToolsClientHost that delegates 41 // An internal implementation of DevToolsClientHost that delegates
44 // messages sent for DevToolsClient to a DebuggerShell instance. 42 // messages sent for DevToolsClient to a DebuggerShell instance.
45 class DevToolsClientHostImpl : public DevToolsClientHost { 43 class DevToolsClientHostImpl : public DevToolsClientHost {
46 public: 44 public:
47 DevToolsClientHostImpl( 45 DevToolsClientHostImpl(
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 base::LeakyLazyInstanceTraits<TabContentsIDHelper::IdToTabContentsMap> > 141 base::LeakyLazyInstanceTraits<TabContentsIDHelper::IdToTabContentsMap> >
144 TabContentsIDHelper::id_to_tabcontents_ = LAZY_INSTANCE_INITIALIZER; 142 TabContentsIDHelper::id_to_tabcontents_ = LAZY_INSTANCE_INITIALIZER;
145 base::LazyInstance< 143 base::LazyInstance<
146 TabContentsIDHelper::TabContentsToIdMap, 144 TabContentsIDHelper::TabContentsToIdMap,
147 base::LeakyLazyInstanceTraits<TabContentsIDHelper::TabContentsToIdMap> > 145 base::LeakyLazyInstanceTraits<TabContentsIDHelper::TabContentsToIdMap> >
148 TabContentsIDHelper::tabcontents_to_id_ = LAZY_INSTANCE_INITIALIZER; 146 TabContentsIDHelper::tabcontents_to_id_ = LAZY_INSTANCE_INITIALIZER;
149 147
150 } // namespace 148 } // namespace
151 149
152 // static 150 // static
153 scoped_refptr<DevToolsHttpProtocolHandler> DevToolsHttpProtocolHandler::Start( 151 scoped_refptr<DevToolsHttpHandler> DevToolsHttpHandler::Start(
154 const std::string& ip, 152 const std::string& ip,
155 int port, 153 int port,
156 const std::string& frontend_url, 154 const std::string& frontend_url,
157 Delegate* delegate) { 155 DevToolsHttpHandlerDelegate* delegate) {
158 scoped_refptr<DevToolsHttpProtocolHandler> http_handler = 156 scoped_refptr<DevToolsHttpHandlerImpl> http_handler =
159 new DevToolsHttpProtocolHandler(ip, port, frontend_url, delegate); 157 new DevToolsHttpHandlerImpl(ip, port, frontend_url, delegate);
160 http_handler->Start(); 158 http_handler->Start();
161 return http_handler; 159 return http_handler;
162 } 160 }
163 161
164 DevToolsHttpProtocolHandler::~DevToolsHttpProtocolHandler() { 162 DevToolsHttpHandlerImpl::~DevToolsHttpHandlerImpl() {
165 // Stop() must be called prior to this being called 163 // Stop() must be called prior to this being called
166 DCHECK(server_.get() == NULL); 164 DCHECK(server_.get() == NULL);
167 } 165 }
168 166
169 void DevToolsHttpProtocolHandler::Start() { 167 void DevToolsHttpHandlerImpl::Start() {
170 BrowserThread::PostTask( 168 BrowserThread::PostTask(
171 BrowserThread::IO, FROM_HERE, 169 BrowserThread::IO, FROM_HERE,
172 base::Bind(&DevToolsHttpProtocolHandler::Init, this)); 170 base::Bind(&DevToolsHttpHandlerImpl::Init, this));
173 } 171 }
174 172
175 void DevToolsHttpProtocolHandler::Stop() { 173 void DevToolsHttpHandlerImpl::Stop() {
176 BrowserThread::PostTask( 174 BrowserThread::PostTask(
177 BrowserThread::IO, FROM_HERE, 175 BrowserThread::IO, FROM_HERE,
178 base::Bind(&DevToolsHttpProtocolHandler::Teardown, this)); 176 base::Bind(&DevToolsHttpHandlerImpl::Teardown, this));
179 } 177 }
180 178
181 void DevToolsHttpProtocolHandler::OnHttpRequest( 179 void DevToolsHttpHandlerImpl::OnHttpRequest(
182 int connection_id, 180 int connection_id,
183 const net::HttpServerRequestInfo& info) { 181 const net::HttpServerRequestInfo& info) {
184 if (info.path == "/json") { 182 if (info.path == "/json") {
185 // Pages discovery json request. 183 // Pages discovery json request.
186 BrowserThread::PostTask( 184 BrowserThread::PostTask(
187 BrowserThread::UI, 185 BrowserThread::UI,
188 FROM_HERE, 186 FROM_HERE,
189 base::Bind(&DevToolsHttpProtocolHandler::OnJsonRequestUI, 187 base::Bind(&DevToolsHttpHandlerImpl::OnJsonRequestUI,
190 this, 188 this,
191 connection_id, 189 connection_id,
192 info)); 190 info));
193 return; 191 return;
194 } 192 }
195 193
196 // Proxy static files from chrome-devtools://devtools/*. 194 // Proxy static files from chrome-devtools://devtools/*.
197 net::URLRequestContext* request_context = delegate_->GetURLRequestContext(); 195 net::URLRequestContext* request_context = delegate_->GetURLRequestContext();
198 if (!request_context) { 196 if (!request_context) {
199 server_->Send404(connection_id); 197 server_->Send404(connection_id);
(...skipping 15 matching lines...) Expand all
215 } else { 213 } else {
216 server_->Send404(connection_id); 214 server_->Send404(connection_id);
217 return; 215 return;
218 } 216 }
219 217
220 Bind(request, connection_id); 218 Bind(request, connection_id);
221 request->set_context(request_context); 219 request->set_context(request_context);
222 request->Start(); 220 request->Start();
223 } 221 }
224 222
225 void DevToolsHttpProtocolHandler::OnWebSocketRequest( 223 void DevToolsHttpHandlerImpl::OnWebSocketRequest(
226 int connection_id, 224 int connection_id,
227 const net::HttpServerRequestInfo& request) { 225 const net::HttpServerRequestInfo& request) {
228 BrowserThread::PostTask( 226 BrowserThread::PostTask(
229 BrowserThread::UI, 227 BrowserThread::UI,
230 FROM_HERE, 228 FROM_HERE,
231 base::Bind( 229 base::Bind(
232 &DevToolsHttpProtocolHandler::OnWebSocketRequestUI, 230 &DevToolsHttpHandlerImpl::OnWebSocketRequestUI,
233 this, 231 this,
234 connection_id, 232 connection_id,
235 request)); 233 request));
236 } 234 }
237 235
238 void DevToolsHttpProtocolHandler::OnWebSocketMessage( 236 void DevToolsHttpHandlerImpl::OnWebSocketMessage(
239 int connection_id, 237 int connection_id,
240 const std::string& data) { 238 const std::string& data) {
241 BrowserThread::PostTask( 239 BrowserThread::PostTask(
242 BrowserThread::UI, 240 BrowserThread::UI,
243 FROM_HERE, 241 FROM_HERE,
244 base::Bind( 242 base::Bind(
245 &DevToolsHttpProtocolHandler::OnWebSocketMessageUI, 243 &DevToolsHttpHandlerImpl::OnWebSocketMessageUI,
246 this, 244 this,
247 connection_id, 245 connection_id,
248 data)); 246 data));
249 } 247 }
250 248
251 void DevToolsHttpProtocolHandler::OnClose(int connection_id) { 249 void DevToolsHttpHandlerImpl::OnClose(int connection_id) {
252 ConnectionToRequestsMap::iterator it = 250 ConnectionToRequestsMap::iterator it =
253 connection_to_requests_io_.find(connection_id); 251 connection_to_requests_io_.find(connection_id);
254 if (it != connection_to_requests_io_.end()) { 252 if (it != connection_to_requests_io_.end()) {
255 // Dispose delegating socket. 253 // Dispose delegating socket.
256 for (std::set<net::URLRequest*>::iterator it2 = it->second.begin(); 254 for (std::set<net::URLRequest*>::iterator it2 = it->second.begin();
257 it2 != it->second.end(); ++it2) { 255 it2 != it->second.end(); ++it2) {
258 net::URLRequest* request = *it2; 256 net::URLRequest* request = *it2;
259 request->Cancel(); 257 request->Cancel();
260 request_to_connection_io_.erase(request); 258 request_to_connection_io_.erase(request);
261 request_to_buffer_io_.erase(request); 259 request_to_buffer_io_.erase(request);
262 delete request; 260 delete request;
263 } 261 }
264 connection_to_requests_io_.erase(connection_id); 262 connection_to_requests_io_.erase(connection_id);
265 } 263 }
266 264
267 BrowserThread::PostTask( 265 BrowserThread::PostTask(
268 BrowserThread::UI, 266 BrowserThread::UI,
269 FROM_HERE, 267 FROM_HERE,
270 base::Bind( 268 base::Bind(
271 &DevToolsHttpProtocolHandler::OnCloseUI, 269 &DevToolsHttpHandlerImpl::OnCloseUI,
272 this, 270 this,
273 connection_id)); 271 connection_id));
274 } 272 }
275 273
276 struct PageInfo 274 struct PageInfo
277 { 275 {
278 int id; 276 int id;
279 std::string url; 277 std::string url;
280 bool attached; 278 bool attached;
281 std::string title; 279 std::string title;
282 std::string thumbnail_url; 280 std::string thumbnail_url;
283 std::string favicon_url; 281 std::string favicon_url;
284 }; 282 };
285 typedef std::vector<PageInfo> PageList; 283 typedef std::vector<PageInfo> PageList;
286 284
287 static PageList GeneratePageList( 285 static PageList GeneratePageList(
288 DevToolsHttpProtocolHandler::Delegate* delegate, 286 DevToolsHttpHandlerDelegate* delegate,
289 int connection_id, 287 int connection_id,
290 const net::HttpServerRequestInfo& info) { 288 const net::HttpServerRequestInfo& info) {
291 typedef DevToolsHttpProtocolHandler::InspectableTabs Tabs; 289 typedef DevToolsHttpHandlerDelegate::InspectableTabs Tabs;
292 Tabs inspectable_tabs = delegate->GetInspectableTabs(); 290 Tabs inspectable_tabs = delegate->GetInspectableTabs();
293 291
294 PageList page_list; 292 PageList page_list;
295 for (Tabs::iterator it = inspectable_tabs.begin(); 293 for (Tabs::iterator it = inspectable_tabs.begin();
296 it != inspectable_tabs.end(); ++it) { 294 it != inspectable_tabs.end(); ++it) {
297 295
298 TabContents* tab_contents = *it; 296 TabContents* tab_contents = *it;
299 NavigationController& controller = tab_contents->controller(); 297 NavigationController& controller = tab_contents->controller();
300 298
301 NavigationEntry* entry = controller.GetActiveEntry(); 299 NavigationEntry* entry = controller.GetActiveEntry();
302 if (entry == NULL || !entry->url().is_valid()) 300 if (entry == NULL || !entry->url().is_valid())
303 continue; 301 continue;
304 302
305 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( 303 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost(
306 tab_contents->render_view_host()); 304 tab_contents->render_view_host());
307 DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> 305 DevToolsClientHost* client_host = DevToolsManager::GetInstance()->
308 GetDevToolsClientHostFor(agent); 306 GetDevToolsClientHostFor(agent);
309 PageInfo page_info; 307 PageInfo page_info;
310 page_info.id = TabContentsIDHelper::GetID(tab_contents); 308 page_info.id = TabContentsIDHelper::GetID(tab_contents);
311 page_info.attached = client_host != NULL; 309 page_info.attached = client_host != NULL;
312 page_info.url = entry->url().spec(); 310 page_info.url = entry->url().spec();
313 page_info.title = UTF16ToUTF8(net::EscapeForHTML(entry->title())); 311 page_info.title = UTF16ToUTF8(net::EscapeForHTML(entry->title()));
314 page_info.thumbnail_url = "/thumb/" + entry->url().spec(); 312 page_info.thumbnail_url = "/thumb/" + entry->url().spec();
315 page_info.favicon_url = entry->favicon().url().spec(); 313 page_info.favicon_url = entry->favicon().url().spec();
316 page_list.push_back(page_info); 314 page_list.push_back(page_info);
317 } 315 }
318 return page_list; 316 return page_list;
319 } 317 }
320 318
321 void DevToolsHttpProtocolHandler::OnJsonRequestUI( 319 void DevToolsHttpHandlerImpl::OnJsonRequestUI(
322 int connection_id, 320 int connection_id,
323 const net::HttpServerRequestInfo& info) { 321 const net::HttpServerRequestInfo& info) {
324 PageList page_list = GeneratePageList(delegate_.get(), 322 PageList page_list = GeneratePageList(delegate_.get(),
325 connection_id, info); 323 connection_id, info);
326 ListValue json_pages_list; 324 ListValue json_pages_list;
327 std::string host = info.headers["Host"]; 325 std::string host = info.headers["Host"];
328 for (PageList::iterator i = page_list.begin(); 326 for (PageList::iterator i = page_list.begin();
329 i != page_list.end(); ++i) { 327 i != page_list.end(); ++i) {
330 328
331 DictionaryValue* page_info = new DictionaryValue; 329 DictionaryValue* page_info = new DictionaryValue;
(...skipping 13 matching lines...) Expand all
345 host.c_str(), 343 host.c_str(),
346 i->id)); 344 i->id));
347 } 345 }
348 } 346 }
349 347
350 std::string response; 348 std::string response;
351 base::JSONWriter::Write(&json_pages_list, true, &response); 349 base::JSONWriter::Write(&json_pages_list, true, &response);
352 Send200(connection_id, response, "application/json; charset=UTF-8"); 350 Send200(connection_id, response, "application/json; charset=UTF-8");
353 } 351 }
354 352
355 void DevToolsHttpProtocolHandler::OnWebSocketRequestUI( 353 void DevToolsHttpHandlerImpl::OnWebSocketRequestUI(
356 int connection_id, 354 int connection_id,
357 const net::HttpServerRequestInfo& request) { 355 const net::HttpServerRequestInfo& request) {
358 std::string prefix = "/devtools/page/"; 356 std::string prefix = "/devtools/page/";
359 size_t pos = request.path.find(prefix); 357 size_t pos = request.path.find(prefix);
360 if (pos != 0) { 358 if (pos != 0) {
361 Send404(connection_id); 359 Send404(connection_id);
362 return; 360 return;
363 } 361 }
364 std::string page_id = request.path.substr(prefix.length()); 362 std::string page_id = request.path.substr(prefix.length());
365 int id = 0; 363 int id = 0;
(...skipping 21 matching lines...) Expand all
387 connection_to_client_host_ui_[connection_id] = client_host; 385 connection_to_client_host_ui_[connection_id] = client_host;
388 386
389 manager->RegisterDevToolsClientHostFor(agent, client_host); 387 manager->RegisterDevToolsClientHostFor(agent, client_host);
390 manager->ForwardToDevToolsAgent( 388 manager->ForwardToDevToolsAgent(
391 client_host, 389 client_host,
392 DevToolsAgentMsg_FrontendLoaded(MSG_ROUTING_NONE)); 390 DevToolsAgentMsg_FrontendLoaded(MSG_ROUTING_NONE));
393 391
394 AcceptWebSocket(connection_id, request); 392 AcceptWebSocket(connection_id, request);
395 } 393 }
396 394
397 void DevToolsHttpProtocolHandler::OnWebSocketMessageUI( 395 void DevToolsHttpHandlerImpl::OnWebSocketMessageUI(
398 int connection_id, 396 int connection_id,
399 const std::string& data) { 397 const std::string& data) {
400 ConnectionToClientHostMap::iterator it = 398 ConnectionToClientHostMap::iterator it =
401 connection_to_client_host_ui_.find(connection_id); 399 connection_to_client_host_ui_.find(connection_id);
402 if (it == connection_to_client_host_ui_.end()) 400 if (it == connection_to_client_host_ui_.end())
403 return; 401 return;
404 402
405 DevToolsManager* manager = DevToolsManager::GetInstance(); 403 DevToolsManager* manager = DevToolsManager::GetInstance();
406 manager->ForwardToDevToolsAgent( 404 manager->ForwardToDevToolsAgent(
407 it->second, 405 it->second,
408 DevToolsAgentMsg_DispatchOnInspectorBackend(MSG_ROUTING_NONE, data)); 406 DevToolsAgentMsg_DispatchOnInspectorBackend(MSG_ROUTING_NONE, data));
409 } 407 }
410 408
411 void DevToolsHttpProtocolHandler::OnCloseUI(int connection_id) { 409 void DevToolsHttpHandlerImpl::OnCloseUI(int connection_id) {
412 ConnectionToClientHostMap::iterator it = 410 ConnectionToClientHostMap::iterator it =
413 connection_to_client_host_ui_.find(connection_id); 411 connection_to_client_host_ui_.find(connection_id);
414 if (it != connection_to_client_host_ui_.end()) { 412 if (it != connection_to_client_host_ui_.end()) {
415 DevToolsClientHostImpl* client_host = 413 DevToolsClientHostImpl* client_host =
416 static_cast<DevToolsClientHostImpl*>(it->second); 414 static_cast<DevToolsClientHostImpl*>(it->second);
417 client_host->NotifyCloseListener(); 415 client_host->NotifyCloseListener();
418 delete client_host; 416 delete client_host;
419 connection_to_client_host_ui_.erase(connection_id); 417 connection_to_client_host_ui_.erase(connection_id);
420 } 418 }
421 } 419 }
422 420
423 void DevToolsHttpProtocolHandler::OnResponseStarted(net::URLRequest* request) { 421 void DevToolsHttpHandlerImpl::OnResponseStarted(net::URLRequest* request) {
424 RequestToSocketMap::iterator it = request_to_connection_io_.find(request); 422 RequestToSocketMap::iterator it = request_to_connection_io_.find(request);
425 if (it == request_to_connection_io_.end()) 423 if (it == request_to_connection_io_.end())
426 return; 424 return;
427 425
428 int connection_id = it->second; 426 int connection_id = it->second;
429 427
430 std::string content_type; 428 std::string content_type;
431 request->GetMimeType(&content_type); 429 request->GetMimeType(&content_type);
432 430
433 if (request->status().is_success()) { 431 if (request->status().is_success()) {
(...skipping 11 matching lines...) Expand all
445 // Some servers may treat HEAD requests as GET requests. To free up the 443 // Some servers may treat HEAD requests as GET requests. To free up the
446 // network connection as soon as possible, signal that the request has 444 // network connection as soon as possible, signal that the request has
447 // completed immediately, without trying to read any data back (all we care 445 // completed immediately, without trying to read any data back (all we care
448 // about is the response code and headers, which we already have). 446 // about is the response code and headers, which we already have).
449 net::IOBuffer* buffer = request_to_buffer_io_[request].get(); 447 net::IOBuffer* buffer = request_to_buffer_io_[request].get();
450 if (request->status().is_success()) 448 if (request->status().is_success())
451 request->Read(buffer, kBufferSize, &bytes_read); 449 request->Read(buffer, kBufferSize, &bytes_read);
452 OnReadCompleted(request, bytes_read); 450 OnReadCompleted(request, bytes_read);
453 } 451 }
454 452
455 void DevToolsHttpProtocolHandler::OnReadCompleted(net::URLRequest* request, 453 void DevToolsHttpHandlerImpl::OnReadCompleted(net::URLRequest* request,
456 int bytes_read) { 454 int bytes_read) {
457 RequestToSocketMap::iterator it = request_to_connection_io_.find(request); 455 RequestToSocketMap::iterator it = request_to_connection_io_.find(request);
458 if (it == request_to_connection_io_.end()) 456 if (it == request_to_connection_io_.end())
459 return; 457 return;
460 458
461 int connection_id = it->second; 459 int connection_id = it->second;
462 460
463 net::IOBuffer* buffer = request_to_buffer_io_[request].get(); 461 net::IOBuffer* buffer = request_to_buffer_io_[request].get();
464 do { 462 do {
465 if (!request->status().is_success() || bytes_read <= 0) 463 if (!request->status().is_success() || bytes_read <= 0)
466 break; 464 break;
467 std::string chunk_size = base::StringPrintf("%X\r\n", bytes_read); 465 std::string chunk_size = base::StringPrintf("%X\r\n", bytes_read);
468 server_->Send(connection_id, chunk_size); 466 server_->Send(connection_id, chunk_size);
469 server_->Send(connection_id, buffer->data(), bytes_read); 467 server_->Send(connection_id, buffer->data(), bytes_read);
470 server_->Send(connection_id, "\r\n"); 468 server_->Send(connection_id, "\r\n");
471 } while (request->Read(buffer, kBufferSize, &bytes_read)); 469 } while (request->Read(buffer, kBufferSize, &bytes_read));
472 470
473 471
474 // See comments re: HEAD requests in OnResponseStarted(). 472 // See comments re: HEAD requests in OnResponseStarted().
475 if (!request->status().is_io_pending()) { 473 if (!request->status().is_io_pending()) {
476 server_->Send(connection_id, "0\r\n\r\n"); 474 server_->Send(connection_id, "0\r\n\r\n");
477 RequestCompleted(request); 475 RequestCompleted(request);
478 } 476 }
479 } 477 }
480 478
481 DevToolsHttpProtocolHandler::DevToolsHttpProtocolHandler( 479 DevToolsHttpHandlerImpl::DevToolsHttpHandlerImpl(
482 const std::string& ip, 480 const std::string& ip,
483 int port, 481 int port,
484 const std::string& frontend_host, 482 const std::string& frontend_host,
485 Delegate* delegate) 483 DevToolsHttpHandlerDelegate* delegate)
486 : ip_(ip), 484 : ip_(ip),
487 port_(port), 485 port_(port),
488 overridden_frontend_url_(frontend_host), 486 overridden_frontend_url_(frontend_host),
489 delegate_(delegate) { 487 delegate_(delegate) {
490 if (overridden_frontend_url_.empty()) 488 if (overridden_frontend_url_.empty())
491 overridden_frontend_url_ = "/devtools/devtools.html"; 489 overridden_frontend_url_ = "/devtools/devtools.html";
492 } 490 }
493 491
494 void DevToolsHttpProtocolHandler::Init() { 492 void DevToolsHttpHandlerImpl::Init() {
495 server_ = new net::HttpServer(ip_, port_, this); 493 server_ = new net::HttpServer(ip_, port_, this);
496 } 494 }
497 495
498 // Run on I/O thread 496 // Run on I/O thread
499 void DevToolsHttpProtocolHandler::Teardown() { 497 void DevToolsHttpHandlerImpl::Teardown() {
500 server_ = NULL; 498 server_ = NULL;
501 } 499 }
502 500
503 void DevToolsHttpProtocolHandler::Bind(net::URLRequest* request, 501 void DevToolsHttpHandlerImpl::Bind(net::URLRequest* request,
504 int connection_id) { 502 int connection_id) {
505 request_to_connection_io_[request] = connection_id; 503 request_to_connection_io_[request] = connection_id;
506 ConnectionToRequestsMap::iterator it = 504 ConnectionToRequestsMap::iterator it =
507 connection_to_requests_io_.find(connection_id); 505 connection_to_requests_io_.find(connection_id);
508 if (it == connection_to_requests_io_.end()) { 506 if (it == connection_to_requests_io_.end()) {
509 std::pair<int, std::set<net::URLRequest*> > value( 507 std::pair<int, std::set<net::URLRequest*> > value(
510 connection_id, 508 connection_id,
511 std::set<net::URLRequest*>()); 509 std::set<net::URLRequest*>());
512 it = connection_to_requests_io_.insert(value).first; 510 it = connection_to_requests_io_.insert(value).first;
513 } 511 }
514 it->second.insert(request); 512 it->second.insert(request);
515 request_to_buffer_io_[request] = new net::IOBuffer(kBufferSize); 513 request_to_buffer_io_[request] = new net::IOBuffer(kBufferSize);
516 } 514 }
517 515
518 void DevToolsHttpProtocolHandler::RequestCompleted(net::URLRequest* request) { 516 void DevToolsHttpHandlerImpl::RequestCompleted(net::URLRequest* request) {
519 RequestToSocketMap::iterator it = request_to_connection_io_.find(request); 517 RequestToSocketMap::iterator it = request_to_connection_io_.find(request);
520 if (it == request_to_connection_io_.end()) 518 if (it == request_to_connection_io_.end())
521 return; 519 return;
522 520
523 int connection_id = it->second; 521 int connection_id = it->second;
524 request_to_connection_io_.erase(request); 522 request_to_connection_io_.erase(request);
525 ConnectionToRequestsMap::iterator it2 = 523 ConnectionToRequestsMap::iterator it2 =
526 connection_to_requests_io_.find(connection_id); 524 connection_to_requests_io_.find(connection_id);
527 it2->second.erase(request); 525 it2->second.erase(request);
528 request_to_buffer_io_.erase(request); 526 request_to_buffer_io_.erase(request);
529 delete request; 527 delete request;
530 } 528 }
531 529
532 void DevToolsHttpProtocolHandler::Send200(int connection_id, 530 void DevToolsHttpHandlerImpl::Send200(int connection_id,
533 const std::string& data, 531 const std::string& data,
534 const std::string& mime_type) { 532 const std::string& mime_type) {
535 BrowserThread::PostTask( 533 BrowserThread::PostTask(
536 BrowserThread::IO, FROM_HERE, 534 BrowserThread::IO, FROM_HERE,
537 base::Bind(&net::HttpServer::Send200, 535 base::Bind(&net::HttpServer::Send200,
538 server_.get(), 536 server_.get(),
539 connection_id, 537 connection_id,
540 data, 538 data,
541 mime_type)); 539 mime_type));
542 } 540 }
543 541
544 void DevToolsHttpProtocolHandler::Send404(int connection_id) { 542 void DevToolsHttpHandlerImpl::Send404(int connection_id) {
545 BrowserThread::PostTask( 543 BrowserThread::PostTask(
546 BrowserThread::IO, FROM_HERE, 544 BrowserThread::IO, FROM_HERE,
547 base::Bind(&net::HttpServer::Send404, server_.get(), connection_id)); 545 base::Bind(&net::HttpServer::Send404, server_.get(), connection_id));
548 } 546 }
549 547
550 void DevToolsHttpProtocolHandler::Send500(int connection_id, 548 void DevToolsHttpHandlerImpl::Send500(int connection_id,
551 const std::string& message) { 549 const std::string& message) {
552 BrowserThread::PostTask( 550 BrowserThread::PostTask(
553 BrowserThread::IO, FROM_HERE, 551 BrowserThread::IO, FROM_HERE,
554 base::Bind(&net::HttpServer::Send500, server_.get(), connection_id, 552 base::Bind(&net::HttpServer::Send500, server_.get(), connection_id,
555 message)); 553 message));
556 } 554 }
557 555
558 void DevToolsHttpProtocolHandler::AcceptWebSocket( 556 void DevToolsHttpHandlerImpl::AcceptWebSocket(
559 int connection_id, 557 int connection_id,
560 const net::HttpServerRequestInfo& request) { 558 const net::HttpServerRequestInfo& request) {
561 BrowserThread::PostTask( 559 BrowserThread::PostTask(
562 BrowserThread::IO, FROM_HERE, 560 BrowserThread::IO, FROM_HERE,
563 base::Bind(&net::HttpServer::AcceptWebSocket, server_.get(), 561 base::Bind(&net::HttpServer::AcceptWebSocket, server_.get(),
564 connection_id, request)); 562 connection_id, request));
565 } 563 }
564
565 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698