Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1058)

Side by Side Diff: content/browser/renderer_host/render_view_host_impl.cc

Issue 30323002: [DRAFT] Create RenderFrameHostManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/render_view_host_impl.h" 5 #include "content/browser/renderer_host/render_view_host_impl.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 routing_id, 166 routing_id,
167 hidden), 167 hidden),
168 delegate_(delegate), 168 delegate_(delegate),
169 instance_(static_cast<SiteInstanceImpl*>(instance)), 169 instance_(static_cast<SiteInstanceImpl*>(instance)),
170 waiting_for_drag_context_response_(false), 170 waiting_for_drag_context_response_(false),
171 enabled_bindings_(0), 171 enabled_bindings_(0),
172 navigations_suspended_(false), 172 navigations_suspended_(false),
173 has_accessed_initial_document_(false), 173 has_accessed_initial_document_(false),
174 is_swapped_out_(swapped_out), 174 is_swapped_out_(swapped_out),
175 is_subframe_(false), 175 is_subframe_(false),
176 main_frame_id_(-1), 176 main_frame_routing_id_(main_frame_routing_id),
177 run_modal_reply_msg_(NULL), 177 run_modal_reply_msg_(NULL),
178 run_modal_opener_id_(MSG_ROUTING_NONE), 178 run_modal_opener_id_(MSG_ROUTING_NONE),
179 is_waiting_for_beforeunload_ack_(false), 179 is_waiting_for_beforeunload_ack_(false),
180 is_waiting_for_unload_ack_(false), 180 is_waiting_for_unload_ack_(false),
181 has_timed_out_on_unload_(false), 181 has_timed_out_on_unload_(false),
182 unload_ack_is_for_cross_site_transition_(false), 182 unload_ack_is_for_cross_site_transition_(false),
183 are_javascript_messages_suppressed_(false), 183 are_javascript_messages_suppressed_(false),
184 sudden_termination_allowed_(false), 184 sudden_termination_allowed_(false),
185 render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING) { 185 render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING) {
186 DCHECK(instance_.get()); 186 DCHECK(instance_.get());
187 CHECK(delegate_); // http://crbug.com/82827 187 CHECK(delegate_); // http://crbug.com/82827
188 188
189 if (main_frame_routing_id == MSG_ROUTING_NONE)
190 main_frame_routing_id = GetProcess()->GetNextRoutingID();
191
192 main_render_frame_host_.reset(
193 new RenderFrameHostImpl(this, delegate_->GetFrameTree(),
194 main_frame_routing_id, is_swapped_out_));
195
196 GetProcess()->EnableSendQueue(); 189 GetProcess()->EnableSendQueue();
197 190
198 if (!swapped_out) 191 if (!swapped_out)
199 instance_->increment_active_view_count(); 192 instance_->increment_active_view_count();
200 193
201 if (ResourceDispatcherHostImpl::Get()) { 194 if (ResourceDispatcherHostImpl::Get()) {
202 BrowserThread::PostTask( 195 BrowserThread::PostTask(
203 BrowserThread::IO, FROM_HERE, 196 BrowserThread::IO, FROM_HERE,
204 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostCreated, 197 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostCreated,
205 base::Unretained(ResourceDispatcherHostImpl::Get()), 198 base::Unretained(ResourceDispatcherHostImpl::Get()),
206 GetProcess()->GetID(), GetRoutingID())); 199 GetProcess()->GetID(), GetRoutingID()));
207 } 200 }
201 LOG(INFO) << "NEW RVH: process " << GetProcess()->GetID() <<
202 ", route " << GetRoutingID() << ", SID " <<
203 instance_->GetId() << ", site " << instance_->GetSiteURL();
208 204
209 #if defined(OS_ANDROID) 205 #if defined(OS_ANDROID)
210 media_player_manager_.reset(BrowserMediaPlayerManager::Create(this)); 206 media_player_manager_.reset(BrowserMediaPlayerManager::Create(this));
211 #endif 207 #endif
212 } 208 }
213 209
214 RenderViewHostImpl::~RenderViewHostImpl() { 210 RenderViewHostImpl::~RenderViewHostImpl() {
211 LOG(INFO) << "DELETE RVH: process " << GetProcess()->GetID() <<
212 ", route " << GetRoutingID() << ", SID " << instance_->GetId();
215 if (ResourceDispatcherHostImpl::Get()) { 213 if (ResourceDispatcherHostImpl::Get()) {
216 BrowserThread::PostTask( 214 BrowserThread::PostTask(
217 BrowserThread::IO, FROM_HERE, 215 BrowserThread::IO, FROM_HERE,
218 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostDeleted, 216 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostDeleted,
219 base::Unretained(ResourceDispatcherHostImpl::Get()), 217 base::Unretained(ResourceDispatcherHostImpl::Get()),
220 GetProcess()->GetID(), GetRoutingID())); 218 GetProcess()->GetID(), GetRoutingID()));
221 } 219 }
222 220
223 delegate_->RenderViewDeleted(this); 221 delegate_->RenderViewDeleted(this);
224 222
225 // Be sure to clean up any leftover state from cross-site requests. 223 // Be sure to clean up any leftover state from cross-site requests.
226 CrossSiteRequestManager::GetInstance()->SetHasPendingCrossSiteRequest( 224 CrossSiteRequestManager::GetInstance()->SetHasPendingCrossSiteRequest(
227 GetProcess()->GetID(), GetRoutingID(), false); 225 GetProcess()->GetID(), GetRoutingID(), false);
228 226
229 // If this was swapped out, it already decremented the active view 227 // If this was swapped out, it already decremented the active view
230 // count of the SiteInstance it belongs to. 228 // count of the SiteInstance it belongs to.
231 if (!is_swapped_out_) 229 if (!is_swapped_out_)
232 instance_->decrement_active_view_count(); 230 instance_->decrement_active_view_count();
233 } 231 }
234 232
235 RenderViewHostDelegate* RenderViewHostImpl::GetDelegate() const { 233 RenderViewHostDelegate* RenderViewHostImpl::GetDelegate() const {
236 return delegate_; 234 return delegate_;
237 } 235 }
238 236
239 SiteInstance* RenderViewHostImpl::GetSiteInstance() const { 237 SiteInstance* RenderViewHostImpl::GetSiteInstance() const {
240 return instance_.get(); 238 return instance_.get();
241 } 239 }
242 240
241 void RenderViewHostImpl::RegisterRenderFrameHost(
242 RenderFrameHostImpl* render_frame_host) {
243 LOG(INFO) << "RVH incrementing refcount with instance " <<
244 instance_->GetId() << " for " << instance_->GetSiteURL();
245 CHECK(rfh_list_.find(render_frame_host) == rfh_list_.end());
246 rfh_list_.insert(render_frame_host);
247 }
248
249 void RenderViewHostImpl::UnregisterRenderFrameHost(
250 RenderFrameHostImpl* render_frame_host) {
251 LOG(INFO) << "RVH decrementing refcount with instance " <<
252 instance_->GetId() << " for " << instance_->GetSiteURL();
253 CHECK(rfh_list_.find(render_frame_host) != rfh_list_.end());
254 rfh_list_.erase(render_frame_host);
255 if (rfh_list_.size() == 0)
256 Shutdown();
257 }
258
259 void RenderViewHostImpl::RegisterFrameID(int64 frame_id,
260 int64 frame_tree_node_id) {
261 frame_id_map_[frame_id] = frame_tree_node_id;
262 }
263
264 void RenderViewHostImpl::UnregisterFrameID(int64 frame_id) {
265 CHECK(HasFrameID(frame_id));
266 frame_id_map_.erase(frame_id);
267 }
268
269 bool RenderViewHostImpl::HasFrameID(int64 frame_id) const {
270 return frame_id_map_.find(frame_id) != frame_id_map_.end();
271 }
272
273 int64 RenderViewHostImpl::GetFrameTreeNodeID(int64 frame_id) {
274 return frame_id_map_[frame_id];
275 }
276
277 int64 RenderViewHostImpl::GetFrameIDForTesting(int64 frame_tree_node_id) const {
278 for (FrameIDMap::const_iterator iter = frame_id_map_.begin();
279 iter != frame_id_map_.end();
280 iter++) {
281 if (iter->second == frame_tree_node_id)
282 return iter->first;
283 }
284 return -1;
285 }
286
243 bool RenderViewHostImpl::CreateRenderView( 287 bool RenderViewHostImpl::CreateRenderView(
244 const string16& frame_name, 288 const string16& frame_name,
245 int opener_route_id, 289 int opener_route_id,
246 int32 max_page_id) { 290 int32 max_page_id) {
247 TRACE_EVENT0("renderer_host", "RenderViewHostImpl::CreateRenderView"); 291 TRACE_EVENT0("renderer_host", "RenderViewHostImpl::CreateRenderView");
248 DCHECK(!IsRenderViewLive()) << "Creating view twice"; 292 DCHECK(!IsRenderViewLive()) << "Creating view twice";
249 293
250 // The process may (if we're sharing a process with another host that already 294 // The process may (if we're sharing a process with another host that already
251 // initialized it) or may not (we have our own process or the old process 295 // initialized it) or may not (we have our own process or the old process
252 // crashed) have been initialized. Calling Init multiple times will be 296 // crashed) have been initialized. Calling Init multiple times will be
(...skipping 12 matching lines...) Expand all
265 // page ID it might be asked to render. 309 // page ID it might be asked to render.
266 int32 next_page_id = 1; 310 int32 next_page_id = 1;
267 if (max_page_id > -1) 311 if (max_page_id > -1)
268 next_page_id = max_page_id + 1; 312 next_page_id = max_page_id + 1;
269 313
270 ViewMsg_New_Params params; 314 ViewMsg_New_Params params;
271 params.renderer_preferences = 315 params.renderer_preferences =
272 delegate_->GetRendererPrefs(GetProcess()->GetBrowserContext()); 316 delegate_->GetRendererPrefs(GetProcess()->GetBrowserContext());
273 params.web_preferences = delegate_->GetWebkitPrefs(); 317 params.web_preferences = delegate_->GetWebkitPrefs();
274 params.view_id = GetRoutingID(); 318 params.view_id = GetRoutingID();
275 params.main_frame_routing_id = main_render_frame_host()->routing_id(); 319 params.main_frame_routing_id = main_frame_routing_id_;
276 params.surface_id = surface_id(); 320 params.surface_id = surface_id();
277 params.session_storage_namespace_id = 321 params.session_storage_namespace_id =
278 delegate_->GetSessionStorageNamespace(instance_)->id(); 322 delegate_->GetSessionStorageNamespace(instance_)->id();
279 params.frame_name = frame_name; 323 params.frame_name = frame_name;
280 // Ensure the RenderView sets its opener correctly. 324 // Ensure the RenderView sets its opener correctly.
281 params.opener_route_id = opener_route_id; 325 params.opener_route_id = opener_route_id;
282 params.swapped_out = is_swapped_out_; 326 params.swapped_out = is_swapped_out_;
283 params.hidden = is_hidden(); 327 params.hidden = is_hidden();
284 params.next_page_id = next_page_id; 328 params.next_page_id = next_page_id;
285 GetWebScreenInfo(&params.screen_info); 329 GetWebScreenInfo(&params.screen_info);
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 } 707 }
664 } 708 }
665 709
666 void RenderViewHostImpl::OnCrossSiteResponse( 710 void RenderViewHostImpl::OnCrossSiteResponse(
667 const GlobalRequestID& global_request_id, 711 const GlobalRequestID& global_request_id,
668 bool is_transfer, 712 bool is_transfer,
669 const std::vector<GURL>& transfer_url_chain, 713 const std::vector<GURL>& transfer_url_chain,
670 const Referrer& referrer, 714 const Referrer& referrer,
671 PageTransition page_transition, 715 PageTransition page_transition,
672 int64 frame_id) { 716 int64 frame_id) {
673 RenderViewHostDelegate::RendererManagement* manager = 717 FrameTreeNode* node = NULL;
674 delegate_->GetRendererManagementDelegate(); 718 if (frame_id != -1) {
719 CHECK(HasFrameID(frame_id));
720 int64 frame_tree_node_id = GetFrameTreeNodeID(frame_id);
721 node = delegate_->GetFrameTree()->FindByID(frame_tree_node_id);
722 }
723
724 // TODO(creis): We should always be able to get the RFHM for a frame_id,
725 // but today the frame_id is -1 for the main frame.
726 RenderViewHostDelegate::RendererManagement* manager = node ?
727 node->render_manager() : delegate_->GetRenderManager();
728 CHECK(manager);
675 if (manager) { 729 if (manager) {
676 manager->OnCrossSiteResponse(this, global_request_id, is_transfer, 730 manager->OnCrossSiteResponse(this, global_request_id, is_transfer,
677 transfer_url_chain, referrer, page_transition, 731 transfer_url_chain, referrer, page_transition,
678 frame_id); 732 frame_id);
679 } 733 }
680 } 734 }
681 735
682 void RenderViewHostImpl::SuppressDialogsUntilSwapOut() { 736 void RenderViewHostImpl::SuppressDialogsUntilSwapOut() {
683 Send(new ViewMsg_SuppressDialogsUntilSwapOut(GetRoutingID())); 737 Send(new ViewMsg_SuppressDialogsUntilSwapOut(GetRoutingID()));
684 } 738 }
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 // Kill the renderer. 1319 // Kill the renderer.
1266 RecordAction(UserMetricsAction("BadMessageTerminate_RVH")); 1320 RecordAction(UserMetricsAction("BadMessageTerminate_RVH"));
1267 GetProcess()->ReceivedBadMessage(); 1321 GetProcess()->ReceivedBadMessage();
1268 } 1322 }
1269 1323
1270 return handled; 1324 return handled;
1271 } 1325 }
1272 1326
1273 void RenderViewHostImpl::Init() { 1327 void RenderViewHostImpl::Init() {
1274 RenderWidgetHostImpl::Init(); 1328 RenderWidgetHostImpl::Init();
1275 main_render_frame_host()->Init(); 1329 // TODO(creis): The caller of this should call Init on the RFH as well.
1330 //main_render_frame_host()->Init();
1276 } 1331 }
1277 1332
1278 void RenderViewHostImpl::Shutdown() { 1333 void RenderViewHostImpl::Shutdown() {
1279 // If we are being run modally (see RunModal), then we need to cleanup. 1334 // If we are being run modally (see RunModal), then we need to cleanup.
1280 if (run_modal_reply_msg_) { 1335 if (run_modal_reply_msg_) {
1281 Send(run_modal_reply_msg_); 1336 Send(run_modal_reply_msg_);
1282 run_modal_reply_msg_ = NULL; 1337 run_modal_reply_msg_ = NULL;
1283 RenderViewHostImpl* opener = 1338 RenderViewHostImpl* opener =
1284 RenderViewHostImpl::FromID(GetProcess()->GetID(), run_modal_opener_id_); 1339 RenderViewHostImpl::FromID(GetProcess()->GetID(), run_modal_opener_id_);
1285 if (opener) { 1340 if (opener) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1375 delegate_->RenderViewReady(this); 1430 delegate_->RenderViewReady(this);
1376 } 1431 }
1377 1432
1378 void RenderViewHostImpl::OnRenderProcessGone(int status, int exit_code) { 1433 void RenderViewHostImpl::OnRenderProcessGone(int status, int exit_code) {
1379 // Keep the termination status so we can get at it later when we 1434 // Keep the termination status so we can get at it later when we
1380 // need to know why it died. 1435 // need to know why it died.
1381 render_view_termination_status_ = 1436 render_view_termination_status_ =
1382 static_cast<base::TerminationStatus>(status); 1437 static_cast<base::TerminationStatus>(status);
1383 1438
1384 // Reset state. 1439 // Reset state.
1385 main_frame_id_ = -1; 1440 frame_id_map_.clear();
1386 1441
1387 // Our base class RenderWidgetHost needs to reset some stuff. 1442 // Our base class RenderWidgetHost needs to reset some stuff.
1388 RendererExited(render_view_termination_status_, exit_code); 1443 RendererExited(render_view_termination_status_, exit_code);
1389 1444
1390 delegate_->RenderViewTerminated(this, 1445 delegate_->RenderViewTerminated(this,
1391 static_cast<base::TerminationStatus>(status), 1446 static_cast<base::TerminationStatus>(status),
1392 exit_code); 1447 exit_code);
1393 } 1448 }
1394 1449
1395 void RenderViewHostImpl::OnDidStartProvisionalLoadForFrame( 1450 void RenderViewHostImpl::OnDidStartProvisionalLoadForFrame(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1449 // Navigate message, then the renderer was navigating before it received the 1504 // Navigate message, then the renderer was navigating before it received the
1450 // unload request. It will either respond to the unload request soon or our 1505 // unload request. It will either respond to the unload request soon or our
1451 // timer will expire. Either way, we should ignore this message, because we 1506 // timer will expire. Either way, we should ignore this message, because we
1452 // have already committed to closing this renderer. 1507 // have already committed to closing this renderer.
1453 if (is_waiting_for_unload_ack_) 1508 if (is_waiting_for_unload_ack_)
1454 return; 1509 return;
1455 1510
1456 // Cache the main frame id, so we can use it for creating the frame tree 1511 // Cache the main frame id, so we can use it for creating the frame tree
1457 // root node when needed. 1512 // root node when needed.
1458 if (PageTransitionIsMainFrame(validated_params.transition)) { 1513 if (PageTransitionIsMainFrame(validated_params.transition)) {
1459 if (main_frame_id_ == -1) { 1514 int frame_tree_node_id =
1460 main_frame_id_ = validated_params.frame_id; 1515 delegate_->GetFrameTree()->root()->frame_tree_node_id();
1516 if (!HasFrameID(validated_params.frame_id)) {
1517 RegisterFrameID(validated_params.frame_id, frame_tree_node_id);
1461 } else { 1518 } else {
1462 // TODO(nasko): We plan to remove the usage of frame_id in navigation 1519 // TODO(nasko): We plan to remove the usage of frame_id in navigation
1463 // and move to routing ids. This is in place to ensure that a 1520 // and move to routing ids. This is in place to ensure that a
1464 // renderer is not misbehaving and sending us incorrect data. 1521 // renderer is not misbehaving and sending us incorrect data.
1465 DCHECK_EQ(main_frame_id_, validated_params.frame_id); 1522 DCHECK_EQ(frame_tree_node_id,
1523 GetFrameTreeNodeID(validated_params.frame_id));
1466 } 1524 }
1467 } 1525 }
1468 RenderProcessHost* process = GetProcess(); 1526 RenderProcessHost* process = GetProcess();
1469 1527
1470 // Attempts to commit certain off-limits URL should be caught more strictly 1528 // Attempts to commit certain off-limits URL should be caught more strictly
1471 // than our FilterURL checks below. If a renderer violates this policy, it 1529 // than our FilterURL checks below. If a renderer violates this policy, it
1472 // should be killed. 1530 // should be killed.
1473 if (!CanCommitURL(validated_params.url)) { 1531 if (!CanCommitURL(validated_params.url)) {
1474 VLOG(1) << "Blocked URL " << validated_params.url.spec(); 1532 VLOG(1) << "Blocked URL " << validated_params.url.spec();
1475 validated_params.url = GURL(kAboutBlankURL); 1533 validated_params.url = GURL(kAboutBlankURL);
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
1803 StopHangMonitorTimeout(); 1861 StopHangMonitorTimeout();
1804 // If this renderer navigated while the beforeunload request was in flight, we 1862 // If this renderer navigated while the beforeunload request was in flight, we
1805 // may have cleared this state in OnNavigate, in which case we can ignore 1863 // may have cleared this state in OnNavigate, in which case we can ignore
1806 // this message. 1864 // this message.
1807 if (!is_waiting_for_beforeunload_ack_ || is_swapped_out_) 1865 if (!is_waiting_for_beforeunload_ack_ || is_swapped_out_)
1808 return; 1866 return;
1809 1867
1810 is_waiting_for_beforeunload_ack_ = false; 1868 is_waiting_for_beforeunload_ack_ = false;
1811 1869
1812 RenderViewHostDelegate::RendererManagement* management_delegate = 1870 RenderViewHostDelegate::RendererManagement* management_delegate =
1813 delegate_->GetRendererManagementDelegate(); 1871 delegate_->GetRenderManager();
1814 if (management_delegate) { 1872 if (management_delegate) {
1815 base::TimeTicks before_unload_end_time; 1873 base::TimeTicks before_unload_end_time;
1816 if (!send_should_close_start_time_.is_null() && 1874 if (!send_should_close_start_time_.is_null() &&
1817 !renderer_before_unload_start_time.is_null() && 1875 !renderer_before_unload_start_time.is_null() &&
1818 !renderer_before_unload_end_time.is_null()) { 1876 !renderer_before_unload_end_time.is_null()) {
1819 // When passing TimeTicks across process boundaries, we need to compensate 1877 // When passing TimeTicks across process boundaries, we need to compensate
1820 // for any skew between the processes. Here we are converting the 1878 // for any skew between the processes. Here we are converting the
1821 // renderer's notion of before_unload_end_time to TimeTicks in the browser 1879 // renderer's notion of before_unload_end_time to TimeTicks in the browser
1822 // process. See comments in inter_process_time_ticks_converter.h for more. 1880 // process. See comments in inter_process_time_ticks_converter.h for more.
1823 InterProcessTimeTicksConverter converter( 1881 InterProcessTimeTicksConverter converter(
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
2267 2325
2268 const std::vector<base::FilePath>& file_paths = state.GetReferencedFiles(); 2326 const std::vector<base::FilePath>& file_paths = state.GetReferencedFiles();
2269 for (std::vector<base::FilePath>::const_iterator file = file_paths.begin(); 2327 for (std::vector<base::FilePath>::const_iterator file = file_paths.begin();
2270 file != file_paths.end(); ++file) { 2328 file != file_paths.end(); ++file) {
2271 if (!policy->CanReadFile(GetProcess()->GetID(), *file)) 2329 if (!policy->CanReadFile(GetProcess()->GetID(), *file))
2272 return false; 2330 return false;
2273 } 2331 }
2274 return true; 2332 return true;
2275 } 2333 }
2276 2334
2277 void RenderViewHostImpl::AttachToFrameTree() {
2278 FrameTree* frame_tree = delegate_->GetFrameTree();
2279
2280 frame_tree->SwapMainFrame(main_render_frame_host_.get());
2281 if (main_frame_id() != FrameTreeNode::kInvalidFrameId) {
2282 frame_tree->OnFirstNavigationAfterSwap(main_frame_id());
2283 }
2284 }
2285
2286 } // namespace content 2335 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698