| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/protocol/browser_handler.h" | 5 #include "content/browser/devtools/protocol/browser_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "content/browser/devtools/devtools_manager.h" | 10 #include "content/browser/devtools/devtools_manager.h" |
| 11 #include "content/public/browser/devtools_manager_delegate.h" | 11 #include "content/public/browser/devtools_manager_delegate.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 namespace devtools { | 14 namespace devtools { |
| 15 namespace browser { | 15 namespace browser { |
| 16 | 16 |
| 17 using Response = DevToolsProtocolClient::Response; | 17 using Response = DevToolsProtocolClient::Response; |
| 18 | 18 |
| 19 BrowserHandler::BrowserHandler() | 19 BrowserHandler::BrowserHandler() |
| 20 : weak_factory_(this) { | 20 : weak_factory_(this) { |
| 21 } | 21 } |
| 22 | 22 |
| 23 BrowserHandler::~BrowserHandler() { | 23 BrowserHandler::~BrowserHandler() { |
| 24 } | 24 } |
| 25 | 25 |
| 26 void BrowserHandler::SetClient(std::unique_ptr<Client> client) { | 26 void BrowserHandler::SetClient(std::unique_ptr<Client> client) { |
| 27 client_.swap(client); | 27 client_.swap(client); |
| 28 } | 28 } |
| 29 | 29 |
| 30 void BrowserHandler::Detached() { |
| 31 for (const auto& host : attached_hosts_) |
| 32 host->DetachClient(this); |
| 33 attached_hosts_.clear(); |
| 34 } |
| 35 |
| 30 Response BrowserHandler::CreateBrowserContext(std::string* out_context_id) { | 36 Response BrowserHandler::CreateBrowserContext(std::string* out_context_id) { |
| 31 // For layering reasons this needs to be handled by | 37 // For layering reasons this needs to be handled by |
| 32 // DevToolsManagerDelegate::HandleCommand. | 38 // DevToolsManagerDelegate::HandleCommand. |
| 33 return Response::ServerError("Not supported"); | 39 return Response::ServerError("Not supported"); |
| 34 } | 40 } |
| 35 | 41 |
| 36 Response BrowserHandler::DisposeBrowserContext(const std::string& context_id, | 42 Response BrowserHandler::DisposeBrowserContext(const std::string& context_id, |
| 37 bool* out_success) { | 43 bool* out_success) { |
| 38 // For layering reasons this needs to be handled by | 44 // For layering reasons this needs to be handled by |
| 39 // DevToolsManagerDelegate::HandleCommand. | 45 // DevToolsManagerDelegate::HandleCommand. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 Response BrowserHandler::SendMessage(const std::string& target_id, | 138 Response BrowserHandler::SendMessage(const std::string& target_id, |
| 133 const std::string& message) { | 139 const std::string& message) { |
| 134 scoped_refptr<DevToolsAgentHost> agent_host = | 140 scoped_refptr<DevToolsAgentHost> agent_host = |
| 135 DevToolsAgentHost::GetForId(target_id); | 141 DevToolsAgentHost::GetForId(target_id); |
| 136 if (!agent_host) | 142 if (!agent_host) |
| 137 return Response::ServerError("No target with given id found"); | 143 return Response::ServerError("No target with given id found"); |
| 138 agent_host->DispatchProtocolMessage(this, message); | 144 agent_host->DispatchProtocolMessage(this, message); |
| 139 return Response::OK(); | 145 return Response::OK(); |
| 140 } | 146 } |
| 141 | 147 |
| 148 Response BrowserHandler::SetRemoteLocations( |
| 149 const std::vector<std::unique_ptr<base::DictionaryValue>>& locations) { |
| 150 return Response::OK(); |
| 151 } |
| 152 |
| 142 void BrowserHandler::DispatchProtocolMessage( | 153 void BrowserHandler::DispatchProtocolMessage( |
| 143 DevToolsAgentHost* agent_host, const std::string& message) { | 154 DevToolsAgentHost* agent_host, const std::string& message) { |
| 144 client_->DispatchMessage(DispatchMessageParams::Create()-> | 155 client_->DispatchMessage(DispatchMessageParams::Create()-> |
| 145 set_target_id(agent_host->GetId())-> | 156 set_target_id(agent_host->GetId())-> |
| 146 set_message(message)); | 157 set_message(message)); |
| 147 } | 158 } |
| 148 | 159 |
| 149 void BrowserHandler::AgentHostClosed(DevToolsAgentHost* agent_host, | 160 void BrowserHandler::AgentHostClosed(DevToolsAgentHost* agent_host, |
| 150 bool replaced_with_another_client) { | 161 bool replaced_with_another_client) { |
| 151 auto it = std::find( | 162 auto it = std::find( |
| 152 attached_hosts_.begin(), attached_hosts_.end(), agent_host); | 163 attached_hosts_.begin(), attached_hosts_.end(), agent_host); |
| 153 if (it != attached_hosts_.end()) | 164 if (it != attached_hosts_.end()) |
| 154 attached_hosts_.erase(it); | 165 attached_hosts_.erase(it); |
| 155 } | 166 } |
| 156 | 167 |
| 157 } // namespace browser | 168 } // namespace browser |
| 158 } // namespace devtools | 169 } // namespace devtools |
| 159 } // namespace content | 170 } // namespace content |
| OLD | NEW |