1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/frame_host/render_frame_message_filter.h"
6
7 #include "content/browser/frame_host/render_frame_host_impl.h"
8 #include "content/browser/renderer_host/render_widget_helper.h"
9 #include "content/common/frame_messages.h"
10 #include "content/public/browser/browser_thread.h"
11
12 namespace content {
13
14 namespace {
15
CreateChildFrameOnUI(int process_id,int parent_render_frame_id,int64 parent_frame_id,int64 frame_id,const std::string & frame_name,int new_render_frame_id)16 void CreateChildFrameOnUI(int process_id,
17 int parent_render_frame_id,
18 int64 parent_frame_id,
19 int64 frame_id,
20 const std::string& frame_name,
21 int new_render_frame_id) {
22 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
23 RenderFrameHostImpl* render_frame_host =
24 RenderFrameHostImpl::FromID(process_id, parent_render_frame_id);
25 // Handles the RenderFrameHost being deleted on the UI thread while
26 // processing a subframe creation message.
27 if (render_frame_host) {
28 render_frame_host->OnCreateChildFrame(new_render_frame_id,
29 parent_frame_id, frame_id,
30 frame_name);
31 }
32 }
33
34 } // namespace
35
RenderFrameMessageFilter(int render_process_id,RenderWidgetHelper * render_widget_helper)36 RenderFrameMessageFilter::RenderFrameMessageFilter(
37 int render_process_id,
38 RenderWidgetHelper* render_widget_helper)
39 : render_process_id_(render_process_id),
40 render_widget_helper_(render_widget_helper) {
41 }
42
~RenderFrameMessageFilter()43 RenderFrameMessageFilter::~RenderFrameMessageFilter() {
44 }
45
OnMessageReceived(const IPC::Message & message,bool * message_was_ok)46 bool RenderFrameMessageFilter::OnMessageReceived(const IPC::Message& message,
47 bool* message_was_ok) {
48 bool handled = true;
49 IPC_BEGIN_MESSAGE_MAP_EX(RenderFrameMessageFilter, message, *message_was_ok)
50 IPC_MESSAGE_HANDLER(FrameHostMsg_CreateChildFrame, OnCreateChildFrame)
51 IPC_MESSAGE_UNHANDLED(handled = false)
52 IPC_END_MESSAGE_MAP_EX()
53
54 return handled;
55 }
56
OnCreateChildFrame(int parent_render_frame_id,int64 parent_frame_id,int64 frame_id,const std::string & frame_name,int * new_render_frame_id)57 void RenderFrameMessageFilter::OnCreateChildFrame(
58 int parent_render_frame_id,
59 int64 parent_frame_id,
60 int64 frame_id,
61 const std::string& frame_name,
62 int* new_render_frame_id) {
63 *new_render_frame_id = render_widget_helper_->GetNextRoutingID();
64 BrowserThread::PostTask(
65 BrowserThread::UI, FROM_HERE,
66 base::Bind(&CreateChildFrameOnUI, render_process_id_,
67 parent_render_frame_id, parent_frame_id, frame_id, frame_name,
68 *new_render_frame_id));
69 }
70
71 } // namespace content
72