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

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()),
(...skipping 27 matching lines...) Expand all
233 } 226 }
234 227
235 RenderViewHostDelegate* RenderViewHostImpl::GetDelegate() const { 228 RenderViewHostDelegate* RenderViewHostImpl::GetDelegate() const {
236 return delegate_; 229 return delegate_;
237 } 230 }
238 231
239 SiteInstance* RenderViewHostImpl::GetSiteInstance() const { 232 SiteInstance* RenderViewHostImpl::GetSiteInstance() const {
240 return instance_.get(); 233 return instance_.get();
241 } 234 }
242 235
236 void RenderViewHostImpl::RegisterFrameTreeNodeID(int64 frame_id,
237 int64 frame_tree_node_id) {
238 frame_id_map_[frame_id] = frame_tree_node_id;
239 }
240
241 bool RenderViewHostImpl::HasFrameTreeNodeID(int64 frame_id) const {
242 return frame_id_map_.find(frame_id) != frame_id_map_.end();
243 }
244
245 int64 RenderViewHostImpl::GetFrameTreeNodeID(int64 frame_id) {
246 return frame_id_map_[frame_id];
247 }
248
243 bool RenderViewHostImpl::CreateRenderView( 249 bool RenderViewHostImpl::CreateRenderView(
244 const string16& frame_name, 250 const string16& frame_name,
245 int opener_route_id, 251 int opener_route_id,
246 int32 max_page_id) { 252 int32 max_page_id) {
247 TRACE_EVENT0("renderer_host", "RenderViewHostImpl::CreateRenderView"); 253 TRACE_EVENT0("renderer_host", "RenderViewHostImpl::CreateRenderView");
248 DCHECK(!IsRenderViewLive()) << "Creating view twice"; 254 DCHECK(!IsRenderViewLive()) << "Creating view twice";
249 255
250 // The process may (if we're sharing a process with another host that already 256 // 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 257 // 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 258 // 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. 271 // page ID it might be asked to render.
266 int32 next_page_id = 1; 272 int32 next_page_id = 1;
267 if (max_page_id > -1) 273 if (max_page_id > -1)
268 next_page_id = max_page_id + 1; 274 next_page_id = max_page_id + 1;
269 275
270 ViewMsg_New_Params params; 276 ViewMsg_New_Params params;
271 params.renderer_preferences = 277 params.renderer_preferences =
272 delegate_->GetRendererPrefs(GetProcess()->GetBrowserContext()); 278 delegate_->GetRendererPrefs(GetProcess()->GetBrowserContext());
273 params.web_preferences = delegate_->GetWebkitPrefs(); 279 params.web_preferences = delegate_->GetWebkitPrefs();
274 params.view_id = GetRoutingID(); 280 params.view_id = GetRoutingID();
275 params.main_frame_routing_id = main_render_frame_host()->routing_id(); 281 params.main_frame_routing_id = main_frame_routing_id_;
276 params.surface_id = surface_id(); 282 params.surface_id = surface_id();
277 params.session_storage_namespace_id = 283 params.session_storage_namespace_id =
278 delegate_->GetSessionStorageNamespace(instance_)->id(); 284 delegate_->GetSessionStorageNamespace(instance_)->id();
279 params.frame_name = frame_name; 285 params.frame_name = frame_name;
280 // Ensure the RenderView sets its opener correctly. 286 // Ensure the RenderView sets its opener correctly.
281 params.opener_route_id = opener_route_id; 287 params.opener_route_id = opener_route_id;
282 params.swapped_out = is_swapped_out_; 288 params.swapped_out = is_swapped_out_;
283 params.hidden = is_hidden(); 289 params.hidden = is_hidden();
284 params.next_page_id = next_page_id; 290 params.next_page_id = next_page_id;
285 GetWebScreenInfo(&params.screen_info); 291 GetWebScreenInfo(&params.screen_info);
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 unload_ack_is_for_cross_site_transition_ = for_cross_site_transition; 654 unload_ack_is_for_cross_site_transition_ = for_cross_site_transition;
649 // Increment the in-flight event count, to ensure that input events won't 655 // Increment the in-flight event count, to ensure that input events won't
650 // cancel the timeout timer. 656 // cancel the timeout timer.
651 increment_in_flight_event_count(); 657 increment_in_flight_event_count();
652 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); 658 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS));
653 send_should_close_start_time_ = base::TimeTicks::Now(); 659 send_should_close_start_time_ = base::TimeTicks::Now();
654 Send(new ViewMsg_ShouldClose(GetRoutingID())); 660 Send(new ViewMsg_ShouldClose(GetRoutingID()));
655 } 661 }
656 } 662 }
657 663
664 void RenderViewHostImpl::OnCrossSiteResponse(
665 const GlobalRequestID& global_request_id,
666 bool is_transfer,
667 const std::vector<GURL>& transfer_url_chain,
668 const Referrer& referrer,
669 PageTransition page_transition,
670 int64 frame_id) {
671 FrameTreeNode* node = delegate_->GetFrameTree()->FindByID(frame_id);
672
673 // TODO(creis): We should always be able to get the RFHM for a frame_id,
674 // but today the frame_id is -1 for the main frame.
675 RenderViewHostDelegate::RendererManagement* manager = node ?
676 node->render_manager() : delegate_->GetRenderManager();
677 CHECK(manager);
678 manager->OnCrossSiteResponse(this, global_request_id, is_transfer,
679 transfer_url_chain, referrer, page_transition,
680 frame_id);
681 }
682
658 void RenderViewHostImpl::SwapOut() { 683 void RenderViewHostImpl::SwapOut() {
659 // This will be set back to false in OnSwapOutACK, just before we replace 684 // This will be set back to false in OnSwapOutACK, just before we replace
660 // this RVH with the pending RVH. 685 // this RVH with the pending RVH.
661 is_waiting_for_unload_ack_ = true; 686 is_waiting_for_unload_ack_ = true;
662 // Start the hang monitor in case the renderer hangs in the unload handler. 687 // Start the hang monitor in case the renderer hangs in the unload handler.
663 // Increment the in-flight event count, to ensure that input events won't 688 // Increment the in-flight event count, to ensure that input events won't
664 // cancel the timeout timer. 689 // cancel the timeout timer.
665 increment_in_flight_event_count(); 690 increment_in_flight_event_count();
666 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); 691 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS));
667 692
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 // Kill the renderer. 1262 // Kill the renderer.
1238 RecordAction(UserMetricsAction("BadMessageTerminate_RVH")); 1263 RecordAction(UserMetricsAction("BadMessageTerminate_RVH"));
1239 GetProcess()->ReceivedBadMessage(); 1264 GetProcess()->ReceivedBadMessage();
1240 } 1265 }
1241 1266
1242 return handled; 1267 return handled;
1243 } 1268 }
1244 1269
1245 void RenderViewHostImpl::Init() { 1270 void RenderViewHostImpl::Init() {
1246 RenderWidgetHostImpl::Init(); 1271 RenderWidgetHostImpl::Init();
1247 main_render_frame_host()->Init(); 1272 // TODO(creis): The caller of this should call Init on the RFH as well.
1273 //main_render_frame_host()->Init();
1248 } 1274 }
1249 1275
1250 void RenderViewHostImpl::Shutdown() { 1276 void RenderViewHostImpl::Shutdown() {
1251 // If we are being run modally (see RunModal), then we need to cleanup. 1277 // If we are being run modally (see RunModal), then we need to cleanup.
1252 if (run_modal_reply_msg_) { 1278 if (run_modal_reply_msg_) {
1253 Send(run_modal_reply_msg_); 1279 Send(run_modal_reply_msg_);
1254 run_modal_reply_msg_ = NULL; 1280 run_modal_reply_msg_ = NULL;
1255 RenderViewHostImpl* opener = 1281 RenderViewHostImpl* opener =
1256 RenderViewHostImpl::FromID(GetProcess()->GetID(), run_modal_opener_id_); 1282 RenderViewHostImpl::FromID(GetProcess()->GetID(), run_modal_opener_id_);
1257 if (opener) { 1283 if (opener) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 delegate_->RenderViewReady(this); 1373 delegate_->RenderViewReady(this);
1348 } 1374 }
1349 1375
1350 void RenderViewHostImpl::OnRenderProcessGone(int status, int exit_code) { 1376 void RenderViewHostImpl::OnRenderProcessGone(int status, int exit_code) {
1351 // Keep the termination status so we can get at it later when we 1377 // Keep the termination status so we can get at it later when we
1352 // need to know why it died. 1378 // need to know why it died.
1353 render_view_termination_status_ = 1379 render_view_termination_status_ =
1354 static_cast<base::TerminationStatus>(status); 1380 static_cast<base::TerminationStatus>(status);
1355 1381
1356 // Reset state. 1382 // Reset state.
1357 main_frame_id_ = -1; 1383 frame_id_map_.clear();
1358 1384
1359 // Our base class RenderWidgetHost needs to reset some stuff. 1385 // Our base class RenderWidgetHost needs to reset some stuff.
1360 RendererExited(render_view_termination_status_, exit_code); 1386 RendererExited(render_view_termination_status_, exit_code);
1361 1387
1362 delegate_->RenderViewTerminated(this, 1388 delegate_->RenderViewTerminated(this,
1363 static_cast<base::TerminationStatus>(status), 1389 static_cast<base::TerminationStatus>(status),
1364 exit_code); 1390 exit_code);
1365 } 1391 }
1366 1392
1367 void RenderViewHostImpl::OnDidStartProvisionalLoadForFrame( 1393 void RenderViewHostImpl::OnDidStartProvisionalLoadForFrame(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 // Navigate message, then the renderer was navigating before it received the 1447 // Navigate message, then the renderer was navigating before it received the
1422 // unload request. It will either respond to the unload request soon or our 1448 // unload request. It will either respond to the unload request soon or our
1423 // timer will expire. Either way, we should ignore this message, because we 1449 // timer will expire. Either way, we should ignore this message, because we
1424 // have already committed to closing this renderer. 1450 // have already committed to closing this renderer.
1425 if (is_waiting_for_unload_ack_) 1451 if (is_waiting_for_unload_ack_)
1426 return; 1452 return;
1427 1453
1428 // Cache the main frame id, so we can use it for creating the frame tree 1454 // Cache the main frame id, so we can use it for creating the frame tree
1429 // root node when needed. 1455 // root node when needed.
1430 if (PageTransitionIsMainFrame(validated_params.transition)) { 1456 if (PageTransitionIsMainFrame(validated_params.transition)) {
1431 if (main_frame_id_ == -1) { 1457 int frame_tree_node_id =
1432 main_frame_id_ = validated_params.frame_id; 1458 delegate_->GetFrameTree()->root()->frame_tree_node_id();
1459 if (!HasFrameTreeNodeID(validated_params.frame_id)) {
1460 RegisterFrameTreeNodeID(validated_params.frame_id, frame_tree_node_id);
1433 } else { 1461 } else {
1434 // TODO(nasko): We plan to remove the usage of frame_id in navigation 1462 // TODO(nasko): We plan to remove the usage of frame_id in navigation
1435 // and move to routing ids. This is in place to ensure that a 1463 // and move to routing ids. This is in place to ensure that a
1436 // renderer is not misbehaving and sending us incorrect data. 1464 // renderer is not misbehaving and sending us incorrect data.
1437 DCHECK_EQ(main_frame_id_, validated_params.frame_id); 1465 DCHECK_EQ(frame_tree_node_id, validated_params.frame_id);
1438 } 1466 }
1439 } 1467 }
1440 RenderProcessHost* process = GetProcess(); 1468 RenderProcessHost* process = GetProcess();
1441 1469
1442 // Attempts to commit certain off-limits URL should be caught more strictly 1470 // Attempts to commit certain off-limits URL should be caught more strictly
1443 // than our FilterURL checks below. If a renderer violates this policy, it 1471 // than our FilterURL checks below. If a renderer violates this policy, it
1444 // should be killed. 1472 // should be killed.
1445 if (!CanCommitURL(validated_params.url)) { 1473 if (!CanCommitURL(validated_params.url)) {
1446 VLOG(1) << "Blocked URL " << validated_params.url.spec(); 1474 VLOG(1) << "Blocked URL " << validated_params.url.spec();
1447 validated_params.url = GURL(kAboutBlankURL); 1475 validated_params.url = GURL(kAboutBlankURL);
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
1775 StopHangMonitorTimeout(); 1803 StopHangMonitorTimeout();
1776 // If this renderer navigated while the beforeunload request was in flight, we 1804 // If this renderer navigated while the beforeunload request was in flight, we
1777 // may have cleared this state in OnNavigate, in which case we can ignore 1805 // may have cleared this state in OnNavigate, in which case we can ignore
1778 // this message. 1806 // this message.
1779 if (!is_waiting_for_beforeunload_ack_ || is_swapped_out_) 1807 if (!is_waiting_for_beforeunload_ack_ || is_swapped_out_)
1780 return; 1808 return;
1781 1809
1782 is_waiting_for_beforeunload_ack_ = false; 1810 is_waiting_for_beforeunload_ack_ = false;
1783 1811
1784 RenderViewHostDelegate::RendererManagement* management_delegate = 1812 RenderViewHostDelegate::RendererManagement* management_delegate =
1785 delegate_->GetRendererManagementDelegate(); 1813 delegate_->GetRenderManager();
1786 if (management_delegate) { 1814 if (management_delegate) {
1787 base::TimeTicks before_unload_end_time; 1815 base::TimeTicks before_unload_end_time;
1788 if (!send_should_close_start_time_.is_null() && 1816 if (!send_should_close_start_time_.is_null() &&
1789 !renderer_before_unload_start_time.is_null() && 1817 !renderer_before_unload_start_time.is_null() &&
1790 !renderer_before_unload_end_time.is_null()) { 1818 !renderer_before_unload_end_time.is_null()) {
1791 // When passing TimeTicks across process boundaries, we need to compensate 1819 // When passing TimeTicks across process boundaries, we need to compensate
1792 // for any skew between the processes. Here we are converting the 1820 // for any skew between the processes. Here we are converting the
1793 // renderer's notion of before_unload_end_time to TimeTicks in the browser 1821 // renderer's notion of before_unload_end_time to TimeTicks in the browser
1794 // process. See comments in inter_process_time_ticks_converter.h for more. 1822 // process. See comments in inter_process_time_ticks_converter.h for more.
1795 InterProcessTimeTicksConverter converter( 1823 InterProcessTimeTicksConverter converter(
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
2239 2267
2240 const std::vector<base::FilePath>& file_paths = state.GetReferencedFiles(); 2268 const std::vector<base::FilePath>& file_paths = state.GetReferencedFiles();
2241 for (std::vector<base::FilePath>::const_iterator file = file_paths.begin(); 2269 for (std::vector<base::FilePath>::const_iterator file = file_paths.begin();
2242 file != file_paths.end(); ++file) { 2270 file != file_paths.end(); ++file) {
2243 if (!policy->CanReadFile(GetProcess()->GetID(), *file)) 2271 if (!policy->CanReadFile(GetProcess()->GetID(), *file))
2244 return false; 2272 return false;
2245 } 2273 }
2246 return true; 2274 return true;
2247 } 2275 }
2248 2276
2249 void RenderViewHostImpl::AttachToFrameTree() {
2250 FrameTree* frame_tree = delegate_->GetFrameTree();
2251
2252 frame_tree->SwapMainFrame(main_render_frame_host_.get());
2253 if (main_frame_id() != FrameTreeNode::kInvalidFrameId) {
2254 frame_tree->OnFirstNavigationAfterSwap(main_frame_id());
2255 }
2256 }
2257
2258 } // namespace content 2277 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_view_host_impl.h ('k') | content/browser/web_contents/web_contents_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698