blob: 24909914ef6d85da6de94b6494cfd3af3dc23198 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_SESSION_H_
#define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_SESSION_H_
#include "base/containers/flat_map.h"
#include "base/memory/weak_ptr.h"
#include "base/values.h"
#include "content/browser/devtools/devtools_agent_host_impl.h"
#include "content/browser/devtools/protocol/devtools_domain_handler.h"
#include "content/browser/devtools/protocol/protocol.h"
namespace content {
class DevToolsAgentHostClient;
class RenderFrameHostImpl;
class DevToolsSession : public protocol::FrontendChannel {
public:
DevToolsSession(DevToolsAgentHostImpl* agent_host,
DevToolsAgentHostClient* client,
int session_id);
~DevToolsSession() override;
int session_id() const { return session_id_; }
void AddHandler(std::unique_ptr<protocol::DevToolsDomainHandler> handler);
void SetRenderFrameHost(RenderFrameHostImpl* host);
void SetFallThroughForNotFound(bool value);
protocol::Response::Status Dispatch(
const std::string& message,
int* call_id,
std::string* method);
// Only used by DevToolsAgentHostImpl.
DevToolsAgentHostClient* client() const { return client_; }
template <typename Handler>
static std::vector<Handler*> HandlersForAgentHost(
DevToolsAgentHostImpl* agent_host,
const std::string& name) {
std::vector<Handler*> result;
if (agent_host->sessions_.empty())
return result;
for (const auto& session : agent_host->sessions_) {
auto it = session->handlers_.find(name);
if (it != session->handlers_.end())
result.push_back(static_cast<Handler*>(it->second.get()));
}
return result;
}
private:
void sendResponse(std::unique_ptr<base::DictionaryValue> response);
// protocol::FrontendChannel implementation.
void sendProtocolResponse(
int call_id,
std::unique_ptr<protocol::Serializable> message) override;
void sendProtocolNotification(
std::unique_ptr<protocol::Serializable> message) override;
void flushProtocolNotifications() override;
DevToolsAgentHostImpl* agent_host_;
DevToolsAgentHostClient* client_;
int session_id_;
base::flat_map<std::string, std::unique_ptr<protocol::DevToolsDomainHandler>>
handlers_;
RenderFrameHostImpl* host_;
std::unique_ptr<protocol::UberDispatcher> dispatcher_;
base::WeakPtrFactory<DevToolsSession> weak_factory_;
};
} // namespace content
#endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_SESSION_H_
|