This source file includes following definitions.
- host_id
- agent
- message
- current_routing_id_
- OnMessageReceived
- OnDispatchOnInspectorBackend
- AddSharedWorkerRouteOnMainThread
- RemoveSharedWorkerRouteOnMainThread
- AddSharedWorkerRoute
- RemoveSharedWorkerRoute
#include "content/renderer/devtools/devtools_agent_filter.h"
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "content/child/child_process.h"
#include "content/common/devtools_messages.h"
#include "content/renderer/devtools/devtools_agent.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/web/WebDevToolsAgent.h"
using blink::WebDevToolsAgent;
using blink::WebString;
namespace content {
namespace {
class MessageImpl : public WebDevToolsAgent::MessageDescriptor {
public:
MessageImpl(const std::string& message, int host_id)
: msg(message),
host_id(host_id) {
}
virtual ~MessageImpl() {}
virtual WebDevToolsAgent* agent() {
DevToolsAgent* agent = DevToolsAgent::FromHostId(host_id);
if (!agent)
return 0;
return agent->GetWebAgent();
}
virtual WebString message() { return WebString::fromUTF8(msg); }
private:
std::string msg;
int host_id;
};
}
DevToolsAgentFilter::DevToolsAgentFilter()
: message_handled_(false),
render_thread_loop_(base::MessageLoop::current()),
io_message_loop_proxy_(ChildProcess::current()->io_message_loop_proxy()),
current_routing_id_(0) {}
bool DevToolsAgentFilter::OnMessageReceived(const IPC::Message& message) {
message_handled_ = true;
current_routing_id_ = message.routing_id();
IPC_BEGIN_MESSAGE_MAP(DevToolsAgentFilter, message)
IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend,
OnDispatchOnInspectorBackend)
IPC_MESSAGE_UNHANDLED(message_handled_ = false)
IPC_END_MESSAGE_MAP()
return message_handled_;
}
DevToolsAgentFilter::~DevToolsAgentFilter() {}
void DevToolsAgentFilter::OnDispatchOnInspectorBackend(
const std::string& message) {
if (shared_worker_routes_.find(current_routing_id_) !=
shared_worker_routes_.end()) {
message_handled_ = false;
return;
}
if (!WebDevToolsAgent::shouldInterruptForMessage(
WebString::fromUTF8(message))) {
message_handled_ = false;
return;
}
WebDevToolsAgent::interruptAndDispatch(
new MessageImpl(message, current_routing_id_));
render_thread_loop_->PostTask(
FROM_HERE, base::Bind(&WebDevToolsAgent::processPendingMessages));
}
void DevToolsAgentFilter::AddSharedWorkerRouteOnMainThread(int32 routing_id) {
io_message_loop_proxy_->PostTask(
FROM_HERE,
base::Bind(&DevToolsAgentFilter::AddSharedWorkerRoute, this, routing_id));
}
void DevToolsAgentFilter::RemoveSharedWorkerRouteOnMainThread(
int32 routing_id) {
io_message_loop_proxy_->PostTask(
FROM_HERE,
base::Bind(
&DevToolsAgentFilter::RemoveSharedWorkerRoute, this, routing_id));
}
void DevToolsAgentFilter::AddSharedWorkerRoute(int32 routing_id) {
shared_worker_routes_.insert(routing_id);
}
void DevToolsAgentFilter::RemoveSharedWorkerRoute(int32 routing_id) {
shared_worker_routes_.erase(routing_id);
}
}