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/devtools/devtools_http_handler_impl.h" | 5 #include "content/browser/devtools/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" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 int connection_id, | 76 int connection_id, |
77 DevToolsAgentHost* agent_host) | 77 DevToolsAgentHost* agent_host) |
78 : message_loop_(message_loop), | 78 : message_loop_(message_loop), |
79 server_(server), | 79 server_(server), |
80 connection_id_(connection_id), | 80 connection_id_(connection_id), |
81 agent_host_(agent_host) { | 81 agent_host_(agent_host) { |
82 agent_host_->AttachClient(this); | 82 agent_host_->AttachClient(this); |
83 } | 83 } |
84 | 84 |
85 virtual ~DevToolsAgentHostClientImpl() { | 85 virtual ~DevToolsAgentHostClientImpl() { |
86 if (agent_host_) | 86 if (agent_host_.get()) |
87 agent_host_->DetachClient(); | 87 agent_host_->DetachClient(); |
88 } | 88 } |
89 | 89 |
90 virtual void AgentHostClosed( | 90 virtual void AgentHostClosed( |
91 DevToolsAgentHost* agent_host, | 91 DevToolsAgentHost* agent_host, |
92 bool replaced_with_another_client) OVERRIDE { | 92 bool replaced_with_another_client) OVERRIDE { |
93 DCHECK(agent_host == agent_host_.get()); | 93 DCHECK(agent_host == agent_host_.get()); |
94 agent_host_ = NULL; | 94 agent_host_ = NULL; |
95 | 95 |
96 base::DictionaryValue notification; | 96 base::DictionaryValue notification; |
(...skipping 21 matching lines...) Expand all Loading... |
118 DCHECK(agent_host == agent_host_.get()); | 118 DCHECK(agent_host == agent_host_.get()); |
119 message_loop_->PostTask( | 119 message_loop_->PostTask( |
120 FROM_HERE, | 120 FROM_HERE, |
121 base::Bind(&net::HttpServer::SendOverWebSocket, | 121 base::Bind(&net::HttpServer::SendOverWebSocket, |
122 server_, | 122 server_, |
123 connection_id_, | 123 connection_id_, |
124 message)); | 124 message)); |
125 } | 125 } |
126 | 126 |
127 void OnMessage(const std::string& message) { | 127 void OnMessage(const std::string& message) { |
128 if (agent_host_) | 128 if (agent_host_.get()) |
129 agent_host_->DispatchProtocolMessage(message); | 129 agent_host_->DispatchProtocolMessage(message); |
130 } | 130 } |
131 | 131 |
132 private: | 132 private: |
133 base::MessageLoop* message_loop_; | 133 base::MessageLoop* message_loop_; |
134 net::HttpServer* server_; | 134 net::HttpServer* server_; |
135 int connection_id_; | 135 int connection_id_; |
136 scoped_refptr<DevToolsAgentHost> agent_host_; | 136 scoped_refptr<DevToolsAgentHost> agent_host_; |
137 }; | 137 }; |
138 | 138 |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 size_t pos = request.path.find(kPageUrlPrefix); | 601 size_t pos = request.path.find(kPageUrlPrefix); |
602 if (pos != 0) { | 602 if (pos != 0) { |
603 Send404(connection_id); | 603 Send404(connection_id); |
604 return; | 604 return; |
605 } | 605 } |
606 | 606 |
607 std::string page_id = request.path.substr(strlen(kPageUrlPrefix)); | 607 std::string page_id = request.path.substr(strlen(kPageUrlPrefix)); |
608 DevToolsTarget* target = GetTarget(page_id); | 608 DevToolsTarget* target = GetTarget(page_id); |
609 scoped_refptr<DevToolsAgentHost> agent = | 609 scoped_refptr<DevToolsAgentHost> agent = |
610 target ? target->GetAgentHost() : NULL; | 610 target ? target->GetAgentHost() : NULL; |
611 if (!agent) { | 611 if (!agent.get()) { |
612 Send500(connection_id, "No such target id: " + page_id); | 612 Send500(connection_id, "No such target id: " + page_id); |
613 return; | 613 return; |
614 } | 614 } |
615 | 615 |
616 if (agent->IsAttached()) { | 616 if (agent->IsAttached()) { |
617 Send500(connection_id, | 617 Send500(connection_id, |
618 "Target with given id is being inspected: " + page_id); | 618 "Target with given id is being inspected: " + page_id); |
619 return; | 619 return; |
620 } | 620 } |
621 | 621 |
622 DevToolsAgentHostClientImpl * client_host = new DevToolsAgentHostClientImpl( | 622 DevToolsAgentHostClientImpl* client_host = new DevToolsAgentHostClientImpl( |
623 thread_->message_loop(), server_.get(), connection_id, agent); | 623 thread_->message_loop(), server_.get(), connection_id, agent.get()); |
624 connection_to_client_ui_[connection_id] = client_host; | 624 connection_to_client_ui_[connection_id] = client_host; |
625 | 625 |
626 AcceptWebSocket(connection_id, request); | 626 AcceptWebSocket(connection_id, request); |
627 } | 627 } |
628 | 628 |
629 void DevToolsHttpHandlerImpl::OnWebSocketMessageUI( | 629 void DevToolsHttpHandlerImpl::OnWebSocketMessageUI( |
630 int connection_id, | 630 int connection_id, |
631 const std::string& data) { | 631 const std::string& data) { |
632 ConnectionToClientMap::iterator it = | 632 ConnectionToClientMap::iterator it = |
633 connection_to_client_ui_.find(connection_id); | 633 connection_to_client_ui_.find(connection_id); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 id.c_str(), | 818 id.c_str(), |
819 host); | 819 host); |
820 dictionary->SetString( | 820 dictionary->SetString( |
821 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); | 821 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); |
822 } | 822 } |
823 | 823 |
824 return dictionary; | 824 return dictionary; |
825 } | 825 } |
826 | 826 |
827 } // namespace content | 827 } // namespace content |
OLD | NEW |