blob: f9643248a0bb2be36520df23e6c98936aa8084dc (
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
79
80
81
82
83
84
85
86
87
88
89
|
// Copyright 2014 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.
#include "content/renderer/render_frame_proxy.h"
#include <map>
#include "base/lazy_instance.h"
#include "content/common/frame_messages.h"
#include "content/common/swapped_out_messages.h"
#include "content/renderer/render_frame_impl.h"
#include "content/renderer/render_thread_impl.h"
#include "content/renderer/render_view_impl.h"
namespace content {
namespace {
typedef std::map<int, RenderFrameProxy*> RoutingIDProxyMap;
static base::LazyInstance<RoutingIDProxyMap> g_routing_id_proxy_map =
LAZY_INSTANCE_INITIALIZER;
} // namespace
// static
RenderFrameProxy* RenderFrameProxy::CreateFrameProxy(int routing_id,
int frame_routing_id) {
DCHECK_NE(routing_id, MSG_ROUTING_NONE);
RenderFrameProxy* proxy = new RenderFrameProxy(routing_id, frame_routing_id);
return proxy;
}
// static
RenderFrameProxy* RenderFrameProxy::FromRoutingID(int32 routing_id) {
RoutingIDProxyMap* proxies = g_routing_id_proxy_map.Pointer();
RoutingIDProxyMap::iterator it = proxies->find(routing_id);
return it == proxies->end() ? NULL : it->second;
}
RenderFrameProxy::RenderFrameProxy(int routing_id, int frame_routing_id)
: routing_id_(routing_id),
frame_routing_id_(frame_routing_id) {
std::pair<RoutingIDProxyMap::iterator, bool> result =
g_routing_id_proxy_map.Get().insert(std::make_pair(routing_id_, this));
CHECK(result.second) << "Inserting a duplicate item.";
RenderThread::Get()->AddRoute(routing_id_, this);
render_frame_ = RenderFrameImpl::FromRoutingID(frame_routing_id);
CHECK(render_frame_);
}
RenderFrameProxy::~RenderFrameProxy() {
RenderThread::Get()->RemoveRoute(routing_id_);
g_routing_id_proxy_map.Get().erase(routing_id_);
}
bool RenderFrameProxy::OnMessageReceived(const IPC::Message& msg) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(RenderFrameProxy, msg)
IPC_MESSAGE_HANDLER(FrameMsg_DeleteProxy, OnDeleteProxy)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
if (!handled)
return render_frame_->OnMessageReceived(msg);
return handled;
}
bool RenderFrameProxy::Send(IPC::Message* message) {
if (!SwappedOutMessages::CanSendWhileSwappedOut(message)) {
delete message;
return false;
}
message->set_routing_id(routing_id_);
return RenderThread::Get()->Send(message);
}
void RenderFrameProxy::OnDeleteProxy() {
RenderFrameImpl* render_frame =
RenderFrameImpl::FromRoutingID(frame_routing_id_);
CHECK(render_frame);
render_frame->set_render_frame_proxy(NULL);
delete this;
}
} // namespace
|