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
90
91
|
// Copyright 2013 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/browser/renderer_host/render_frame_host_impl.h"
#include "base/containers/hash_tables.h"
#include "base/lazy_instance.h"
#include "content/browser/renderer_host/frame_tree.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/common/frame_messages.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
namespace content {
// The (process id, routing id) pair that identifies one RenderFrame.
typedef std::pair<int32, int32> RenderFrameHostID;
typedef base::hash_map<RenderFrameHostID, RenderFrameHostImpl*>
RoutingIDFrameMap;
static base::LazyInstance<RoutingIDFrameMap> g_routing_id_frame_map =
LAZY_INSTANCE_INITIALIZER;
// static
RenderFrameHostImpl* RenderFrameHostImpl::FromID(
int process_id, int routing_id) {
RoutingIDFrameMap* frames = g_routing_id_frame_map.Pointer();
RoutingIDFrameMap::iterator it = frames->find(
RenderFrameHostID(process_id, routing_id));
return it == frames->end() ? NULL : it->second;
}
RenderFrameHostImpl::RenderFrameHostImpl(
RenderViewHostImpl* render_view_host,
FrameTree* frame_tree,
int routing_id,
bool is_swapped_out)
: render_view_host_(render_view_host),
frame_tree_(frame_tree),
routing_id_(routing_id),
is_swapped_out_(is_swapped_out) {
GetProcess()->AddRoute(routing_id_, this);
g_routing_id_frame_map.Get().insert(std::make_pair(
RenderFrameHostID(GetProcess()->GetID(), routing_id_),
this));
}
RenderFrameHostImpl::~RenderFrameHostImpl() {
GetProcess()->RemoveRoute(routing_id_);
g_routing_id_frame_map.Get().erase(
RenderFrameHostID(GetProcess()->GetID(), routing_id_));
}
bool RenderFrameHostImpl::Send(IPC::Message* message) {
return GetProcess()->Send(message);
}
bool RenderFrameHostImpl::OnMessageReceived(const IPC::Message &msg) {
bool handled = true;
bool msg_is_ok = true;
IPC_BEGIN_MESSAGE_MAP_EX(RenderFrameHostImpl, msg, msg_is_ok)
IPC_MESSAGE_HANDLER(FrameHostMsg_Detach, OnDetach)
IPC_END_MESSAGE_MAP_EX()
return handled;
}
void RenderFrameHostImpl::Init() {
GetProcess()->ResumeRequestsForView(routing_id());
}
RenderProcessHost* RenderFrameHostImpl::GetProcess() const {
// TODO(nasko): This should return its own process, once we have working
// cross-process navigation for subframes.
return render_view_host_->GetProcess();
}
void RenderFrameHostImpl::OnCreateChildFrame(int new_frame_routing_id,
int64 parent_frame_id,
int64 frame_id,
const std::string& frame_name) {
frame_tree_->AddFrame(new_frame_routing_id, parent_frame_id, frame_id,
frame_name);
}
void RenderFrameHostImpl::OnDetach(int64 parent_frame_id, int64 frame_id) {
frame_tree_->RemoveFrame(parent_frame_id, frame_id);
}
} // namespace content
|