diff options
Diffstat (limited to 'chromium/content/browser/devtools/devtools_agent_host_impl.cc')
-rw-r--r-- | chromium/content/browser/devtools/devtools_agent_host_impl.cc | 69 |
1 files changed, 46 insertions, 23 deletions
diff --git a/chromium/content/browser/devtools/devtools_agent_host_impl.cc b/chromium/content/browser/devtools/devtools_agent_host_impl.cc index a67148429f1..273ca40034c 100644 --- a/chromium/content/browser/devtools/devtools_agent_host_impl.cc +++ b/chromium/content/browser/devtools/devtools_agent_host_impl.cc @@ -8,6 +8,7 @@ #include <vector> #include "base/bind.h" +#include "base/json/json_reader.h" #include "base/json/json_writer.h" #include "base/lazy_instance.h" #include "base/observer_list.h" @@ -176,12 +177,13 @@ DevToolsSession* DevToolsAgentHostImpl::SessionByClient( } bool DevToolsAgentHostImpl::InnerAttachClient(DevToolsAgentHostClient* client, + TargetRegistry* registry, bool restricted) { scoped_refptr<DevToolsAgentHostImpl> protect(this); DevToolsSession* session = new DevToolsSession(this, client, restricted); sessions_.insert(session); session_by_client_[client].reset(session); - if (!AttachSession(session)) { + if (!AttachSession(session, registry)) { sessions_.erase(session); session_by_client_.erase(client); return false; @@ -198,14 +200,22 @@ bool DevToolsAgentHostImpl::InnerAttachClient(DevToolsAgentHostClient* client, void DevToolsAgentHostImpl::AttachClient(DevToolsAgentHostClient* client) { if (SessionByClient(client)) return; - InnerAttachClient(client, false /* restricted */); + InnerAttachClient(client, nullptr, false /* restricted */); +} + +void DevToolsAgentHostImpl::AttachSubtargetClient( + DevToolsAgentHostClient* client, + TargetRegistry* registry) { + if (SessionByClient(client)) + return; + InnerAttachClient(client, registry, false /* restricted */); } bool DevToolsAgentHostImpl::AttachRestrictedClient( DevToolsAgentHostClient* client) { if (SessionByClient(client)) return false; - return InnerAttachClient(client, true /* restricted */); + return InnerAttachClient(client, nullptr, true /* restricted */); } bool DevToolsAgentHostImpl::DetachClient(DevToolsAgentHostClient* client) { @@ -220,16 +230,29 @@ bool DevToolsAgentHostImpl::DetachClient(DevToolsAgentHostClient* client) { bool DevToolsAgentHostImpl::DispatchProtocolMessage( DevToolsAgentHostClient* client, const std::string& message) { + std::unique_ptr<base::Value> value = base::JSONReader::Read(message); + if (value && !value->is_dict()) + value.reset(); + return DispatchProtocolMessage( + client, message, static_cast<base::DictionaryValue*>(value.get())); +} + +bool DevToolsAgentHostImpl::DispatchProtocolMessage( + DevToolsAgentHostClient* client, + const std::string& message, + base::DictionaryValue* parsed_message) { DevToolsSession* session = SessionByClient(client); if (!session) return false; - DispatchProtocolMessage(session, message); + session->DispatchProtocolMessage(message, parsed_message); return true; } void DevToolsAgentHostImpl::InnerDetachClient(DevToolsAgentHostClient* client) { std::unique_ptr<DevToolsSession> session = std::move(session_by_client_[client]); + // Make sure we dispose session prior to reporting it to the host. + session->Dispose(); sessions_.erase(session.get()); session_by_client_.erase(client); DetachSession(session.get()); @@ -310,32 +333,24 @@ void DevToolsAgentHostImpl::ForceDetachAllSessions() { } } -void DevToolsAgentHostImpl::ForceDetachRestrictedSessions() { - if (sessions_.empty()) - return; +void DevToolsAgentHostImpl::ForceDetachRestrictedSessions( + const std::vector<DevToolsSession*>& restricted_sessions) { scoped_refptr<DevToolsAgentHostImpl> protect(this); - std::vector<DevToolsSession*> restricted; - for (DevToolsSession* session : sessions_) { - if (session->restricted()) - restricted.push_back(session); - } - for (DevToolsSession* session : restricted) { + + for (DevToolsSession* session : restricted_sessions) { DevToolsAgentHostClient* client = session->client(); DetachClient(client); client->AgentHostClosed(this); } } -bool DevToolsAgentHostImpl::AttachSession(DevToolsSession* session) { +bool DevToolsAgentHostImpl::AttachSession(DevToolsSession* session, + TargetRegistry* registry) { return false; } void DevToolsAgentHostImpl::DetachSession(DevToolsSession* session) {} -void DevToolsAgentHostImpl::DispatchProtocolMessage( - DevToolsSession* session, - const std::string& message) {} - // static void DevToolsAgentHost::DetachAllClients() { if (!g_devtools_instances.IsCreated()) @@ -343,11 +358,14 @@ void DevToolsAgentHost::DetachAllClients() { // Make a copy, since detaching may lead to agent destruction, which // removes it from the instances. - DevToolsMap copy = g_devtools_instances.Get(); - for (DevToolsMap::iterator it(copy.begin()); it != copy.end(); ++it) { - DevToolsAgentHostImpl* agent_host = it->second; - agent_host->ForceDetachAllSessions(); - } + std::vector<scoped_refptr<DevToolsAgentHostImpl>> copy; + for (DevToolsMap::iterator it(g_devtools_instances.Get().begin()); + it != g_devtools_instances.Get().end(); ++it) + copy.push_back(it->second); + for (std::vector<scoped_refptr<DevToolsAgentHostImpl>>::iterator it( + copy.begin()); + it != copy.end(); ++it) + it->get()->ForceDetachAllSessions(); } // static @@ -400,6 +418,11 @@ void DevToolsAgentHostImpl::NotifyDetached() { observer.DevToolsAgentHostDetached(this); } +void DevToolsAgentHostImpl::NotifyCrashed(base::TerminationStatus status) { + for (auto& observer : g_devtools_observers.Get()) + observer.DevToolsAgentHostCrashed(this, status); +} + void DevToolsAgentHostImpl::NotifyDestroyed() { DCHECK(g_devtools_instances.Get().find(id_) != g_devtools_instances.Get().end()); |