| 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_tracing_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 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 void DevToolsHttpHandlerImpl::OnDiscoveryPageRequestUI(int connection_id) { | 583 void DevToolsHttpHandlerImpl::OnDiscoveryPageRequestUI(int connection_id) { |
| 582 std::string response = delegate_->GetDiscoveryPageHTML(); | 584 std::string response = delegate_->GetDiscoveryPageHTML(); |
| 583 Send200(connection_id, response, "text/html; charset=UTF-8"); | 585 Send200(connection_id, response, "text/html; charset=UTF-8"); |
| 584 } | 586 } |
| 585 | 587 |
| 586 void DevToolsHttpHandlerImpl::OnWebSocketRequestUI( | 588 void DevToolsHttpHandlerImpl::OnWebSocketRequestUI( |
| 587 int connection_id, | 589 int connection_id, |
| 588 const net::HttpServerRequestInfo& request) { | 590 const net::HttpServerRequestInfo& request) { |
| 589 if (!thread_.get()) | 591 if (!thread_.get()) |
| 590 return; | 592 return; |
| 593 std::string browser_prefix = "/devtools/browser"; |
| 594 size_t browser_pos = request.path.find(browser_prefix); |
| 595 if (browser_pos == 0) { |
| 596 if (browser_target_) { |
| 597 Send500(connection_id, "Another client already attached"); |
| 598 return; |
| 599 } |
| 600 browser_target_.reset(new DevToolsBrowserTarget(connection_id)); |
| 601 browser_target_->RegisterHandler(new DevToolsTracingHandler()); |
| 602 AcceptWebSocket(connection_id, request); |
| 603 return; |
| 604 } |
| 591 | 605 |
| 592 std::string prefix = "/devtools/page/"; | 606 std::string page_prefix = "/devtools/page/"; |
| 593 size_t pos = request.path.find(prefix); | 607 size_t pos = request.path.find(page_prefix); |
| 594 if (pos != 0) { | 608 if (pos != 0) { |
| 595 Send404(connection_id); | 609 Send404(connection_id); |
| 596 return; | 610 return; |
| 597 } | 611 } |
| 598 | 612 |
| 599 std::string page_id = request.path.substr(prefix.length()); | 613 std::string page_id = request.path.substr(page_prefix.length()); |
| 600 RenderViewHost* rvh = binding_->ForIdentifier(page_id); | 614 RenderViewHost* rvh = binding_->ForIdentifier(page_id); |
| 601 if (!rvh) { | 615 if (!rvh) { |
| 602 Send500(connection_id, "No such target id: " + page_id); | 616 Send500(connection_id, "No such target id: " + page_id); |
| 603 return; | 617 return; |
| 604 } | 618 } |
| 605 | 619 |
| 606 DevToolsManager* manager = DevToolsManager::GetInstance(); | 620 DevToolsManager* manager = DevToolsManager::GetInstance(); |
| 607 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( | 621 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
| 608 rvh); | 622 rvh); |
| 609 if (manager->GetDevToolsClientHostFor(agent)) { | 623 if (manager->GetDevToolsClientHostFor(agent)) { |
| 610 Send500(connection_id, | 624 Send500(connection_id, |
| 611 "Target with given id is being inspected: " + page_id); | 625 "Target with given id is being inspected: " + page_id); |
| 612 return; | 626 return; |
| 613 } | 627 } |
| 614 | 628 |
| 615 DevToolsClientHostImpl* client_host = | 629 DevToolsClientHostImpl* client_host = |
| 616 new DevToolsClientHostImpl(thread_->message_loop(), | 630 new DevToolsClientHostImpl(thread_->message_loop(), |
| 617 server_, | 631 server_, |
| 618 connection_id); | 632 connection_id); |
| 619 connection_to_client_host_ui_[connection_id] = client_host; | 633 connection_to_client_host_ui_[connection_id] = client_host; |
| 620 | 634 |
| 621 manager->RegisterDevToolsClientHostFor(agent, client_host); | 635 manager->RegisterDevToolsClientHostFor(agent, client_host); |
| 622 | 636 |
| 623 AcceptWebSocket(connection_id, request); | 637 AcceptWebSocket(connection_id, request); |
| 624 } | 638 } |
| 625 | 639 |
| 626 void DevToolsHttpHandlerImpl::OnWebSocketMessageUI( | 640 void DevToolsHttpHandlerImpl::OnWebSocketMessageUI( |
| 627 int connection_id, | 641 int connection_id, |
| 628 const std::string& data) { | 642 const std::string& data) { |
| 643 if (browser_target_ && connection_id == browser_target_->connection_id()) { |
| 644 std::string json_response = browser_target_->HandleMessage(data); |
| 645 |
| 646 thread_->message_loop()->PostTask( |
| 647 FROM_HERE, |
| 648 base::Bind(&net::HttpServer::SendOverWebSocket, |
| 649 server_.get(), |
| 650 connection_id, |
| 651 json_response)); |
| 652 return; |
| 653 } |
| 654 |
| 629 ConnectionToClientHostMap::iterator it = | 655 ConnectionToClientHostMap::iterator it = |
| 630 connection_to_client_host_ui_.find(connection_id); | 656 connection_to_client_host_ui_.find(connection_id); |
| 631 if (it == connection_to_client_host_ui_.end()) | 657 if (it == connection_to_client_host_ui_.end()) |
| 632 return; | 658 return; |
| 633 | 659 |
| 634 DevToolsManager* manager = DevToolsManager::GetInstance(); | 660 DevToolsManager* manager = DevToolsManager::GetInstance(); |
| 635 manager->DispatchOnInspectorBackend(it->second, data); | 661 manager->DispatchOnInspectorBackend(it->second, data); |
| 636 } | 662 } |
| 637 | 663 |
| 638 void DevToolsHttpHandlerImpl::OnCloseUI(int connection_id) { | 664 void DevToolsHttpHandlerImpl::OnCloseUI(int connection_id) { |
| 639 ConnectionToClientHostMap::iterator it = | 665 ConnectionToClientHostMap::iterator it = |
| 640 connection_to_client_host_ui_.find(connection_id); | 666 connection_to_client_host_ui_.find(connection_id); |
| 641 if (it != connection_to_client_host_ui_.end()) { | 667 if (it != connection_to_client_host_ui_.end()) { |
| 642 DevToolsClientHostImpl* client_host = | 668 DevToolsClientHostImpl* client_host = |
| 643 static_cast<DevToolsClientHostImpl*>(it->second); | 669 static_cast<DevToolsClientHostImpl*>(it->second); |
| 644 DevToolsManager::GetInstance()->ClientHostClosing(client_host); | 670 DevToolsManager::GetInstance()->ClientHostClosing(client_host); |
| 645 delete client_host; | 671 delete client_host; |
| 646 connection_to_client_host_ui_.erase(connection_id); | 672 connection_to_client_host_ui_.erase(connection_id); |
| 647 } | 673 } |
| 674 if (browser_target_ && browser_target_->connection_id() == connection_id) { |
| 675 browser_target_.reset(); |
| 676 return; |
| 677 } |
| 648 } | 678 } |
| 649 | 679 |
| 650 DevToolsHttpHandlerImpl::DevToolsHttpHandlerImpl( | 680 DevToolsHttpHandlerImpl::DevToolsHttpHandlerImpl( |
| 651 const net::StreamListenSocketFactory* socket_factory, | 681 const net::StreamListenSocketFactory* socket_factory, |
| 652 const std::string& frontend_url, | 682 const std::string& frontend_url, |
| 653 DevToolsHttpHandlerDelegate* delegate) | 683 DevToolsHttpHandlerDelegate* delegate) |
| 654 : overridden_frontend_url_(frontend_url), | 684 : overridden_frontend_url_(frontend_url), |
| 655 socket_factory_(socket_factory), | 685 socket_factory_(socket_factory), |
| 656 delegate_(delegate) { | 686 delegate_(delegate) { |
| 657 if (overridden_frontend_url_.empty()) | 687 if (overridden_frontend_url_.empty()) |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 page_info.id.c_str())); | 855 page_info.id.c_str())); |
| 826 std::string devtools_frontend_url = GetFrontendURLInternal( | 856 std::string devtools_frontend_url = GetFrontendURLInternal( |
| 827 page_info.id.c_str(), | 857 page_info.id.c_str(), |
| 828 host); | 858 host); |
| 829 dictionary->SetString("devtoolsFrontendUrl", devtools_frontend_url); | 859 dictionary->SetString("devtoolsFrontendUrl", devtools_frontend_url); |
| 830 } | 860 } |
| 831 return dictionary; | 861 return dictionary; |
| 832 } | 862 } |
| 833 | 863 |
| 834 } // namespace content | 864 } // namespace content |
| OLD | NEW |