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 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 browser_target_.reset(new DevToolsBrowserTarget(connection_id)); | |
pfeldman
2012/12/14 10:39:33
if (browser_target_) {
Send500();
return;
}
bulach
2012/12/14 16:03:52
Done.
| |
597 browser_target_->RegisterHandler("Trace", new DevToolsTraceDomainHandler()); | |
598 AcceptWebSocket(connection_id, request); | |
599 return; | |
600 } | |
591 | 601 |
592 std::string prefix = "/devtools/page/"; | 602 std::string page_prefix = "/devtools/page/"; |
593 size_t pos = request.path.find(prefix); | 603 size_t pos = request.path.find(page_prefix); |
594 if (pos != 0) { | 604 if (pos != 0) { |
595 Send404(connection_id); | 605 Send404(connection_id); |
596 return; | 606 return; |
597 } | 607 } |
598 | 608 |
599 std::string page_id = request.path.substr(prefix.length()); | 609 std::string page_id = request.path.substr(page_prefix.length()); |
600 RenderViewHost* rvh = binding_->ForIdentifier(page_id); | 610 RenderViewHost* rvh = binding_->ForIdentifier(page_id); |
601 if (!rvh) { | 611 if (!rvh) { |
602 Send500(connection_id, "No such target id: " + page_id); | 612 Send500(connection_id, "No such target id: " + page_id); |
603 return; | 613 return; |
604 } | 614 } |
605 | 615 |
606 DevToolsManager* manager = DevToolsManager::GetInstance(); | 616 DevToolsManager* manager = DevToolsManager::GetInstance(); |
607 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( | 617 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
608 rvh); | 618 rvh); |
609 if (manager->GetDevToolsClientHostFor(agent)) { | 619 if (manager->GetDevToolsClientHostFor(agent)) { |
610 Send500(connection_id, | 620 Send500(connection_id, |
611 "Target with given id is being inspected: " + page_id); | 621 "Target with given id is being inspected: " + page_id); |
612 return; | 622 return; |
613 } | 623 } |
614 | 624 |
615 DevToolsClientHostImpl* client_host = | 625 DevToolsClientHostImpl* client_host = |
616 new DevToolsClientHostImpl(thread_->message_loop(), | 626 new DevToolsClientHostImpl(thread_->message_loop(), |
617 server_, | 627 server_, |
618 connection_id); | 628 connection_id); |
619 connection_to_client_host_ui_[connection_id] = client_host; | 629 connection_to_client_host_ui_[connection_id] = client_host; |
620 | 630 |
621 manager->RegisterDevToolsClientHostFor(agent, client_host); | 631 manager->RegisterDevToolsClientHostFor(agent, client_host); |
622 | 632 |
623 AcceptWebSocket(connection_id, request); | 633 AcceptWebSocket(connection_id, request); |
624 } | 634 } |
625 | 635 |
626 void DevToolsHttpHandlerImpl::OnWebSocketMessageUI( | 636 void DevToolsHttpHandlerImpl::OnWebSocketMessageUI( |
627 int connection_id, | 637 int connection_id, |
628 const std::string& data) { | 638 const std::string& data) { |
639 if (browser_target_ && connection_id == browser_target_->connection_id()) { | |
640 scoped_ptr<base::Value> response(browser_target_->OnWebSocketMessage( | |
641 connection_id, data)); | |
pfeldman
2012/12/14 10:39:33
format: stack these?
bulach
2012/12/14 16:03:52
fits one line without the extra params.
| |
642 | |
643 // Serialize response. | |
644 std::string json_response; | |
645 if (response) { | |
646 base::JSONWriter::WriteWithOptions(response.get(), | |
pfeldman
2012/12/14 10:39:33
It is strange that parsing and serialization takes
bulach
2012/12/14 16:03:52
good point! done..
| |
647 base::JSONWriter::OPTIONS_PRETTY_PRINT, | |
648 &json_response); | |
649 } | |
650 | |
651 thread_->message_loop()->PostTask( | |
652 FROM_HERE, | |
653 base::Bind(&net::HttpServer::SendOverWebSocket, | |
654 server_.get(), | |
655 connection_id, | |
656 json_response)); | |
657 return; | |
658 } | |
659 | |
629 ConnectionToClientHostMap::iterator it = | 660 ConnectionToClientHostMap::iterator it = |
630 connection_to_client_host_ui_.find(connection_id); | 661 connection_to_client_host_ui_.find(connection_id); |
631 if (it == connection_to_client_host_ui_.end()) | 662 if (it == connection_to_client_host_ui_.end()) |
632 return; | 663 return; |
633 | 664 |
634 DevToolsManager* manager = DevToolsManager::GetInstance(); | 665 DevToolsManager* manager = DevToolsManager::GetInstance(); |
635 manager->DispatchOnInspectorBackend(it->second, data); | 666 manager->DispatchOnInspectorBackend(it->second, data); |
636 } | 667 } |
637 | 668 |
638 void DevToolsHttpHandlerImpl::OnCloseUI(int connection_id) { | 669 void DevToolsHttpHandlerImpl::OnCloseUI(int connection_id) { |
639 ConnectionToClientHostMap::iterator it = | 670 ConnectionToClientHostMap::iterator it = |
640 connection_to_client_host_ui_.find(connection_id); | 671 connection_to_client_host_ui_.find(connection_id); |
641 if (it != connection_to_client_host_ui_.end()) { | 672 if (it != connection_to_client_host_ui_.end()) { |
642 DevToolsClientHostImpl* client_host = | 673 DevToolsClientHostImpl* client_host = |
643 static_cast<DevToolsClientHostImpl*>(it->second); | 674 static_cast<DevToolsClientHostImpl*>(it->second); |
644 DevToolsManager::GetInstance()->ClientHostClosing(client_host); | 675 DevToolsManager::GetInstance()->ClientHostClosing(client_host); |
645 delete client_host; | 676 delete client_host; |
646 connection_to_client_host_ui_.erase(connection_id); | 677 connection_to_client_host_ui_.erase(connection_id); |
647 } | 678 } |
679 if (browser_target_ && browser_target_->connection_id() == connection_id) { | |
680 browser_target_.reset(); | |
681 return; | |
682 } | |
648 } | 683 } |
649 | 684 |
650 DevToolsHttpHandlerImpl::DevToolsHttpHandlerImpl( | 685 DevToolsHttpHandlerImpl::DevToolsHttpHandlerImpl( |
651 const net::StreamListenSocketFactory* socket_factory, | 686 const net::StreamListenSocketFactory* socket_factory, |
652 const std::string& frontend_url, | 687 const std::string& frontend_url, |
653 DevToolsHttpHandlerDelegate* delegate) | 688 DevToolsHttpHandlerDelegate* delegate) |
654 : overridden_frontend_url_(frontend_url), | 689 : overridden_frontend_url_(frontend_url), |
655 socket_factory_(socket_factory), | 690 socket_factory_(socket_factory), |
656 delegate_(delegate) { | 691 delegate_(delegate) { |
657 if (overridden_frontend_url_.empty()) | 692 if (overridden_frontend_url_.empty()) |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
825 page_info.id.c_str())); | 860 page_info.id.c_str())); |
826 std::string devtools_frontend_url = GetFrontendURLInternal( | 861 std::string devtools_frontend_url = GetFrontendURLInternal( |
827 page_info.id.c_str(), | 862 page_info.id.c_str(), |
828 host); | 863 host); |
829 dictionary->SetString("devtoolsFrontendUrl", devtools_frontend_url); | 864 dictionary->SetString("devtoolsFrontendUrl", devtools_frontend_url); |
830 } | 865 } |
831 return dictionary; | 866 return dictionary; |
832 } | 867 } |
833 | 868 |
834 } // namespace content | 869 } // namespace content |
OLD | NEW |