Chromium Code Reviews| 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 #include "content/browser/debugger/devtools_http_handler_impl.h" | 5 #include "content/browser/debugger/devtools_http_handler_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/message_loop_proxy.h" | 16 #include "base/message_loop_proxy.h" |
| 17 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
| 18 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
| 19 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
| 20 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
| 21 #include "base/values.h" | 21 #include "base/values.h" |
| 22 #include "content/browser/debugger/devtools_browser_target.h" | |
| 23 #include "content/browser/debugger/devtools_trace_domain_handler.h" | |
| 22 #include "content/browser/web_contents/web_contents_impl.h" | 24 #include "content/browser/web_contents/web_contents_impl.h" |
| 23 #include "content/common/devtools_messages.h" | 25 #include "content/common/devtools_messages.h" |
| 24 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/devtools_agent_host_registry.h" | 27 #include "content/public/browser/devtools_agent_host_registry.h" |
| 26 #include "content/public/browser/devtools_client_host.h" | 28 #include "content/public/browser/devtools_client_host.h" |
| 27 #include "content/public/browser/devtools_http_handler_delegate.h" | 29 #include "content/public/browser/devtools_http_handler_delegate.h" |
| 28 #include "content/public/browser/devtools_manager.h" | 30 #include "content/public/browser/devtools_manager.h" |
| 29 #include "content/public/browser/favicon_status.h" | 31 #include "content/public/browser/favicon_status.h" |
| 30 #include "content/public/browser/navigation_entry.h" | 32 #include "content/public/browser/navigation_entry.h" |
| 31 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 BrowserThread::PostTask( | 303 BrowserThread::PostTask( |
| 302 BrowserThread::UI, | 304 BrowserThread::UI, |
| 303 FROM_HERE, | 305 FROM_HERE, |
| 304 base::Bind(&DevToolsHttpHandlerImpl::OnThumbnailRequestUI, | 306 base::Bind(&DevToolsHttpHandlerImpl::OnThumbnailRequestUI, |
| 305 this, | 307 this, |
| 306 connection_id, | 308 connection_id, |
| 307 info)); | 309 info)); |
| 308 return; | 310 return; |
| 309 } | 311 } |
| 310 | 312 |
| 313 if (info.path.find("/trace/") == 0) { | |
|
pfeldman
2012/12/12 20:17:12
nuke
bulach
2012/12/13 17:36:23
Done.
| |
| 314 // Trace request. | |
| 315 BrowserThread::PostTask( | |
| 316 BrowserThread::UI, | |
| 317 FROM_HERE, | |
| 318 base::Bind(&DevToolsHttpHandlerImpl::OnTraceRequestUI, | |
| 319 this, | |
| 320 connection_id, | |
| 321 info)); | |
| 322 return; | |
| 323 } | |
| 324 | |
| 311 if (info.path == "" || info.path == "/") { | 325 if (info.path == "" || info.path == "/") { |
| 312 // Discovery page request. | 326 // Discovery page request. |
| 313 BrowserThread::PostTask( | 327 BrowserThread::PostTask( |
| 314 BrowserThread::UI, | 328 BrowserThread::UI, |
| 315 FROM_HERE, | 329 FROM_HERE, |
| 316 base::Bind(&DevToolsHttpHandlerImpl::OnDiscoveryPageRequestUI, | 330 base::Bind(&DevToolsHttpHandlerImpl::OnDiscoveryPageRequestUI, |
| 317 this, | 331 this, |
| 318 connection_id)); | 332 connection_id)); |
| 319 return; | 333 return; |
| 320 } | 334 } |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 } | 585 } |
| 572 | 586 |
| 573 std::string page_url = info.path.substr(prefix.length()); | 587 std::string page_url = info.path.substr(prefix.length()); |
| 574 std::string data = delegate_->GetPageThumbnailData(GURL(page_url)); | 588 std::string data = delegate_->GetPageThumbnailData(GURL(page_url)); |
| 575 if (!data.empty()) | 589 if (!data.empty()) |
| 576 Send200(connection_id, data, "image/png"); | 590 Send200(connection_id, data, "image/png"); |
| 577 else | 591 else |
| 578 Send404(connection_id); | 592 Send404(connection_id); |
| 579 } | 593 } |
| 580 | 594 |
| 595 void DevToolsHttpHandlerImpl::OnTraceRequestUI( | |
| 596 int connection_id, | |
| 597 const net::HttpServerRequestInfo& info) { | |
| 598 /* | |
| 599 std::string prefix = "/trace/"; | |
| 600 size_t pos = info.path.find(prefix); | |
| 601 if (pos != 0) { | |
| 602 Send404(connection_id); | |
| 603 return; | |
| 604 } | |
| 605 | |
| 606 std::string command = info.path.substr(prefix.length()); | |
| 607 | |
| 608 std::string response("ok"); | |
| 609 if (command == "start") { | |
| 610 // TODO(bulach): capture categories somehow. | |
| 611 std::string categories; | |
| 612 devtools_trace_handler_.BeginTracing(categories); | |
| 613 } else if (command == "stop") | |
| 614 devtools_trace_handler_.EndTracingAsync(); | |
| 615 else if (command == "has_completed") { | |
| 616 response = devtools_trace_handler_.has_completed() ? | |
| 617 "ok" : "pending"; | |
| 618 } else if (command == "get") { | |
| 619 if (devtools_trace_handler_.has_completed()) { | |
| 620 Send200( | |
| 621 connection_id, devtools_trace_handler_.GetAndResetTrace(), | |
| 622 "binary/octet-stream"); | |
| 623 return; | |
| 624 } | |
| 625 Send404(connection_id); | |
| 626 return; | |
| 627 } | |
| 628 Send200(connection_id, response, "text/html; charset=UTF-8"); | |
| 629 */ | |
| 630 } | |
| 631 | |
| 581 void DevToolsHttpHandlerImpl::OnDiscoveryPageRequestUI(int connection_id) { | 632 void DevToolsHttpHandlerImpl::OnDiscoveryPageRequestUI(int connection_id) { |
| 582 std::string response = delegate_->GetDiscoveryPageHTML(); | 633 std::string response = delegate_->GetDiscoveryPageHTML(); |
| 583 Send200(connection_id, response, "text/html; charset=UTF-8"); | 634 Send200(connection_id, response, "text/html; charset=UTF-8"); |
| 584 } | 635 } |
| 585 | 636 |
| 586 void DevToolsHttpHandlerImpl::OnWebSocketRequestUI( | 637 void DevToolsHttpHandlerImpl::OnWebSocketRequestUI( |
| 587 int connection_id, | 638 int connection_id, |
| 588 const net::HttpServerRequestInfo& request) { | 639 const net::HttpServerRequestInfo& request) { |
| 589 if (!thread_.get()) | 640 if (!thread_.get()) |
| 590 return; | 641 return; |
| 591 | 642 |
| 592 std::string prefix = "/devtools/page/"; | 643 std::string browser_prefix = "/devtools/browser/"; |
|
pfeldman
2012/12/12 20:17:12
No need for the trailing slash here
bulach
2012/12/13 17:36:23
Done.
| |
| 593 size_t pos = request.path.find(prefix); | 644 size_t browser_pos = request.path.find(browser_prefix); |
| 645 if (browser_pos == 0) { | |
| 646 browser_target_.reset(new DevToolsBrowserTarget(connection_id)); | |
| 647 browser_target_->RegisterHandler(new DevToolsTraceDomainHandler()); | |
| 648 AcceptWebSocket(connection_id, request); | |
| 649 return; | |
| 650 } | |
| 651 | |
| 652 | |
| 653 std::string page_prefix = "/devtools/page/"; | |
| 654 size_t pos = request.path.find(page_prefix); | |
| 594 if (pos != 0) { | 655 if (pos != 0) { |
| 595 Send404(connection_id); | 656 Send404(connection_id); |
| 596 return; | 657 return; |
| 597 } | 658 } |
| 598 | 659 |
| 599 std::string page_id = request.path.substr(prefix.length()); | 660 std::string page_id = request.path.substr(page_prefix.length()); |
| 600 RenderViewHost* rvh = binding_->ForIdentifier(page_id); | 661 RenderViewHost* rvh = binding_->ForIdentifier(page_id); |
| 601 if (!rvh) { | 662 if (!rvh) { |
| 602 Send500(connection_id, "No such target id: " + page_id); | 663 Send500(connection_id, "No such target id: " + page_id); |
| 603 return; | 664 return; |
| 604 } | 665 } |
| 605 | 666 |
| 606 DevToolsManager* manager = DevToolsManager::GetInstance(); | 667 DevToolsManager* manager = DevToolsManager::GetInstance(); |
| 607 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( | 668 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
| 608 rvh); | 669 rvh); |
| 609 if (manager->GetDevToolsClientHostFor(agent)) { | 670 if (manager->GetDevToolsClientHostFor(agent)) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 624 } | 685 } |
| 625 | 686 |
| 626 void DevToolsHttpHandlerImpl::OnWebSocketMessageUI( | 687 void DevToolsHttpHandlerImpl::OnWebSocketMessageUI( |
| 627 int connection_id, | 688 int connection_id, |
| 628 const std::string& data) { | 689 const std::string& data) { |
| 629 ConnectionToClientHostMap::iterator it = | 690 ConnectionToClientHostMap::iterator it = |
| 630 connection_to_client_host_ui_.find(connection_id); | 691 connection_to_client_host_ui_.find(connection_id); |
| 631 if (it == connection_to_client_host_ui_.end()) | 692 if (it == connection_to_client_host_ui_.end()) |
| 632 return; | 693 return; |
| 633 | 694 |
| 695 if (browser_target_ && connection_id == browser_target_->connection_id()) { | |
| 696 browser_target_->OnWebSocketMessage(connection_id, data, this); | |
| 697 return; | |
| 698 } | |
| 699 | |
| 634 DevToolsManager* manager = DevToolsManager::GetInstance(); | 700 DevToolsManager* manager = DevToolsManager::GetInstance(); |
| 635 manager->DispatchOnInspectorBackend(it->second, data); | 701 manager->DispatchOnInspectorBackend(it->second, data); |
| 636 } | 702 } |
| 637 | 703 |
| 638 void DevToolsHttpHandlerImpl::OnCloseUI(int connection_id) { | 704 void DevToolsHttpHandlerImpl::OnCloseUI(int connection_id) { |
| 639 ConnectionToClientHostMap::iterator it = | 705 ConnectionToClientHostMap::iterator it = |
| 640 connection_to_client_host_ui_.find(connection_id); | 706 connection_to_client_host_ui_.find(connection_id); |
| 641 if (it != connection_to_client_host_ui_.end()) { | 707 if (it != connection_to_client_host_ui_.end()) { |
|
pfeldman
2012/12/12 20:17:12
You should delete browser_target_ here.
bulach
2012/12/13 17:36:23
Done.
| |
| 642 DevToolsClientHostImpl* client_host = | 708 DevToolsClientHostImpl* client_host = |
| 643 static_cast<DevToolsClientHostImpl*>(it->second); | 709 static_cast<DevToolsClientHostImpl*>(it->second); |
| 644 DevToolsManager::GetInstance()->ClientHostClosing(client_host); | 710 DevToolsManager::GetInstance()->ClientHostClosing(client_host); |
| 645 delete client_host; | 711 delete client_host; |
| 646 connection_to_client_host_ui_.erase(connection_id); | 712 connection_to_client_host_ui_.erase(connection_id); |
| 647 } | 713 } |
| 648 } | 714 } |
| 649 | 715 |
| 650 DevToolsHttpHandlerImpl::DevToolsHttpHandlerImpl( | 716 DevToolsHttpHandlerImpl::DevToolsHttpHandlerImpl( |
| 651 const net::StreamListenSocketFactory* socket_factory, | 717 const net::StreamListenSocketFactory* socket_factory, |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 825 page_info.id.c_str())); | 891 page_info.id.c_str())); |
| 826 std::string devtools_frontend_url = GetFrontendURLInternal( | 892 std::string devtools_frontend_url = GetFrontendURLInternal( |
| 827 page_info.id.c_str(), | 893 page_info.id.c_str(), |
| 828 host); | 894 host); |
| 829 dictionary->SetString("devtoolsFrontendUrl", devtools_frontend_url); | 895 dictionary->SetString("devtoolsFrontendUrl", devtools_frontend_url); |
| 830 } | 896 } |
| 831 return dictionary; | 897 return dictionary; |
| 832 } | 898 } |
| 833 | 899 |
| 834 } // namespace content | 900 } // namespace content |
| OLD | NEW |