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

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: Misc fixes Created 7 years 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 routing_id, 191 routing_id,
192 hidden), 192 hidden),
193 delegate_(delegate), 193 delegate_(delegate),
194 instance_(static_cast<SiteInstanceImpl*>(instance)), 194 instance_(static_cast<SiteInstanceImpl*>(instance)),
195 waiting_for_drag_context_response_(false), 195 waiting_for_drag_context_response_(false),
196 enabled_bindings_(0), 196 enabled_bindings_(0),
197 navigations_suspended_(false), 197 navigations_suspended_(false),
198 has_accessed_initial_document_(false), 198 has_accessed_initial_document_(false),
199 is_swapped_out_(swapped_out), 199 is_swapped_out_(swapped_out),
200 is_subframe_(false), 200 is_subframe_(false),
201 main_frame_id_(-1),
202 main_frame_routing_id_(main_frame_routing_id), 201 main_frame_routing_id_(main_frame_routing_id),
203 run_modal_reply_msg_(NULL), 202 run_modal_reply_msg_(NULL),
204 run_modal_opener_id_(MSG_ROUTING_NONE), 203 run_modal_opener_id_(MSG_ROUTING_NONE),
205 is_waiting_for_beforeunload_ack_(false), 204 is_waiting_for_beforeunload_ack_(false),
206 is_waiting_for_unload_ack_(false), 205 is_waiting_for_unload_ack_(false),
207 has_timed_out_on_unload_(false), 206 has_timed_out_on_unload_(false),
208 unload_ack_is_for_cross_site_transition_(false), 207 unload_ack_is_for_cross_site_transition_(false),
209 are_javascript_messages_suppressed_(false), 208 are_javascript_messages_suppressed_(false),
210 sudden_termination_allowed_(false), 209 sudden_termination_allowed_(false),
211 render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING), 210 render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING),
212 virtual_keyboard_requested_(false) { 211 virtual_keyboard_requested_(false) {
213 DCHECK(instance_.get()); 212 DCHECK(instance_.get());
214 CHECK(delegate_); // http://crbug.com/82827 213 CHECK(delegate_); // http://crbug.com/82827
215 214
216 GetProcess()->EnableSendQueue(); 215 GetProcess()->EnableSendQueue();
217 216
218 if (!swapped_out) 217 if (!swapped_out)
219 instance_->increment_active_view_count(); 218 instance_->increment_active_view_count();
220 219
221 if (ResourceDispatcherHostImpl::Get()) { 220 if (ResourceDispatcherHostImpl::Get()) {
222 BrowserThread::PostTask( 221 BrowserThread::PostTask(
223 BrowserThread::IO, FROM_HERE, 222 BrowserThread::IO, FROM_HERE,
224 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostCreated, 223 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostCreated,
225 base::Unretained(ResourceDispatcherHostImpl::Get()), 224 base::Unretained(ResourceDispatcherHostImpl::Get()),
226 GetProcess()->GetID(), GetRoutingID())); 225 GetProcess()->GetID(), GetRoutingID()));
227 } 226 }
227 LOG(INFO) << "NEW RVH: process " << GetProcess()->GetID() <<
228 ", route " << GetRoutingID() << ", SID " <<
229 instance_->GetId() << ", site " << instance_->GetSiteURL();
228 230
229 #if defined(OS_ANDROID) 231 #if defined(OS_ANDROID)
230 media_player_manager_.reset(BrowserMediaPlayerManager::Create(this)); 232 media_player_manager_.reset(BrowserMediaPlayerManager::Create(this));
231 #endif 233 #endif
232 } 234 }
233 235
234 RenderViewHostImpl::~RenderViewHostImpl() { 236 RenderViewHostImpl::~RenderViewHostImpl() {
237 LOG(INFO) << "DELETE RVH: process " << GetProcess()->GetID() <<
238 ", route " << GetRoutingID() << ", SID " << instance_->GetId();
235 if (ResourceDispatcherHostImpl::Get()) { 239 if (ResourceDispatcherHostImpl::Get()) {
236 BrowserThread::PostTask( 240 BrowserThread::PostTask(
237 BrowserThread::IO, FROM_HERE, 241 BrowserThread::IO, FROM_HERE,
238 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostDeleted, 242 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostDeleted,
239 base::Unretained(ResourceDispatcherHostImpl::Get()), 243 base::Unretained(ResourceDispatcherHostImpl::Get()),
240 GetProcess()->GetID(), GetRoutingID())); 244 GetProcess()->GetID(), GetRoutingID()));
241 } 245 }
242 246
243 delegate_->RenderViewDeleted(this); 247 delegate_->RenderViewDeleted(this);
244 248
245 // Be sure to clean up any leftover state from cross-site requests. 249 // Be sure to clean up any leftover state from cross-site requests.
246 CrossSiteRequestManager::GetInstance()->SetHasPendingCrossSiteRequest( 250 CrossSiteRequestManager::GetInstance()->SetHasPendingCrossSiteRequest(
247 GetProcess()->GetID(), GetRoutingID(), false); 251 GetProcess()->GetID(), GetRoutingID(), false);
248 252
249 // If this was swapped out, it already decremented the active view 253 // If this was swapped out, it already decremented the active view
250 // count of the SiteInstance it belongs to. 254 // count of the SiteInstance it belongs to.
251 if (!is_swapped_out_) 255 if (!is_swapped_out_)
252 instance_->decrement_active_view_count(); 256 instance_->decrement_active_view_count();
253 } 257 }
254 258
255 RenderViewHostDelegate* RenderViewHostImpl::GetDelegate() const { 259 RenderViewHostDelegate* RenderViewHostImpl::GetDelegate() const {
256 return delegate_; 260 return delegate_;
257 } 261 }
258 262
259 SiteInstance* RenderViewHostImpl::GetSiteInstance() const { 263 SiteInstance* RenderViewHostImpl::GetSiteInstance() const {
260 return instance_.get(); 264 return instance_.get();
261 } 265 }
262 266
267 void RenderViewHostImpl::RegisterFrameID(int64 frame_id,
268 int64 frame_tree_node_id) {
269 frame_id_map_[frame_id] = frame_tree_node_id;
270 }
271
272 void RenderViewHostImpl::UnregisterFrameID(int64 frame_id) {
273 CHECK(HasFrameID(frame_id));
274 frame_id_map_.erase(frame_id);
275 }
276
277 bool RenderViewHostImpl::HasFrameID(int64 frame_id) const {
278 return frame_id_map_.find(frame_id) != frame_id_map_.end();
279 }
280
281 int64 RenderViewHostImpl::GetFrameTreeNodeID(int64 frame_id) {
282 return frame_id_map_[frame_id];
283 }
284
285 int64 RenderViewHostImpl::GetFrameIDForTesting(int64 frame_tree_node_id) const {
286 for (FrameIDMap::const_iterator iter = frame_id_map_.begin();
287 iter != frame_id_map_.end();
288 iter++) {
289 if (iter->second == frame_tree_node_id)
290 return iter->first;
291 }
292 return -1;
293 }
294
263 bool RenderViewHostImpl::CreateRenderView( 295 bool RenderViewHostImpl::CreateRenderView(
264 const base::string16& frame_name, 296 const base::string16& frame_name,
265 int opener_route_id, 297 int opener_route_id,
266 int32 max_page_id) { 298 int32 max_page_id) {
267 TRACE_EVENT0("renderer_host", "RenderViewHostImpl::CreateRenderView"); 299 TRACE_EVENT0("renderer_host", "RenderViewHostImpl::CreateRenderView");
268 DCHECK(!IsRenderViewLive()) << "Creating view twice"; 300 DCHECK(!IsRenderViewLive()) << "Creating view twice";
269 301
270 // The process may (if we're sharing a process with another host that already 302 // The process may (if we're sharing a process with another host that already
271 // initialized it) or may not (we have our own process or the old process 303 // initialized it) or may not (we have our own process or the old process
272 // crashed) have been initialized. Calling Init multiple times will be 304 // crashed) have been initialized. Calling Init multiple times will be
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 } 727 }
696 728
697 void RenderViewHostImpl::OnCrossSiteResponse( 729 void RenderViewHostImpl::OnCrossSiteResponse(
698 const GlobalRequestID& global_request_id, 730 const GlobalRequestID& global_request_id,
699 bool is_transfer, 731 bool is_transfer,
700 const std::vector<GURL>& transfer_url_chain, 732 const std::vector<GURL>& transfer_url_chain,
701 const Referrer& referrer, 733 const Referrer& referrer,
702 PageTransition page_transition, 734 PageTransition page_transition,
703 int64 frame_id, 735 int64 frame_id,
704 bool should_replace_current_entry) { 736 bool should_replace_current_entry) {
705 RenderViewHostDelegate::RendererManagement* manager = 737 FrameTreeNode* node = NULL;
706 delegate_->GetRendererManagementDelegate(); 738 if (frame_id != -1) {
739 CHECK(HasFrameID(frame_id));
740 int64 frame_tree_node_id = GetFrameTreeNodeID(frame_id);
741 node = delegate_->GetFrameTree()->FindByID(frame_tree_node_id);
742 }
743
744 // TODO(creis): We should always be able to get the RFHM for a frame_id,
745 // but today the frame_id is -1 for the main frame.
746 RenderViewHostDelegate::RendererManagement* manager = node ?
747 node->render_manager() : delegate_->GetRendererManagementDelegate();
748 CHECK(manager);
707 if (manager) { 749 if (manager) {
708 manager->OnCrossSiteResponse(this, global_request_id, is_transfer, 750 manager->OnCrossSiteResponse(this, global_request_id, is_transfer,
709 transfer_url_chain, referrer, page_transition, 751 transfer_url_chain, referrer, page_transition,
710 frame_id, should_replace_current_entry); 752 frame_id, should_replace_current_entry);
711 } 753 }
712 } 754 }
713 755
714 void RenderViewHostImpl::SuppressDialogsUntilSwapOut() { 756 void RenderViewHostImpl::SuppressDialogsUntilSwapOut() {
715 Send(new ViewMsg_SuppressDialogsUntilSwapOut(GetRoutingID())); 757 Send(new ViewMsg_SuppressDialogsUntilSwapOut(GetRoutingID()));
716 } 758 }
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 1450
1409 void RenderViewHostImpl::OnRenderProcessGone(int status, int exit_code) { 1451 void RenderViewHostImpl::OnRenderProcessGone(int status, int exit_code) {
1410 // Keep the termination status so we can get at it later when we 1452 // Keep the termination status so we can get at it later when we
1411 // need to know why it died. 1453 // need to know why it died.
1412 render_view_termination_status_ = 1454 render_view_termination_status_ =
1413 static_cast<base::TerminationStatus>(status); 1455 static_cast<base::TerminationStatus>(status);
1414 1456
1415 // Reset frame tree state. 1457 // Reset frame tree state.
1416 // TODO(creis): Once subframes can be in different processes, we'll need to 1458 // TODO(creis): Once subframes can be in different processes, we'll need to
1417 // clear just the FrameTreeNodes affected by the crash (and their subtrees). 1459 // clear just the FrameTreeNodes affected by the crash (and their subtrees).
1418 main_frame_id_ = -1;
1419 delegate_->GetFrameTree()->ResetForMainFrameSwap(); 1460 delegate_->GetFrameTree()->ResetForMainFrameSwap();
1461 frame_id_map_.clear();
1420 1462
1421 // Our base class RenderWidgetHost needs to reset some stuff. 1463 // Our base class RenderWidgetHost needs to reset some stuff.
1422 RendererExited(render_view_termination_status_, exit_code); 1464 RendererExited(render_view_termination_status_, exit_code);
1423 1465
1424 delegate_->RenderViewTerminated(this, 1466 delegate_->RenderViewTerminated(this,
1425 static_cast<base::TerminationStatus>(status), 1467 static_cast<base::TerminationStatus>(status),
1426 exit_code); 1468 exit_code);
1427 } 1469 }
1428 1470
1429 void RenderViewHostImpl::OnDidStartProvisionalLoadForFrame( 1471 void RenderViewHostImpl::OnDidStartProvisionalLoadForFrame(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1482 // Navigate message, then the renderer was navigating before it received the 1524 // Navigate message, then the renderer was navigating before it received the
1483 // unload request. It will either respond to the unload request soon or our 1525 // unload request. It will either respond to the unload request soon or our
1484 // timer will expire. Either way, we should ignore this message, because we 1526 // timer will expire. Either way, we should ignore this message, because we
1485 // have already committed to closing this renderer. 1527 // have already committed to closing this renderer.
1486 if (is_waiting_for_unload_ack_) 1528 if (is_waiting_for_unload_ack_)
1487 return; 1529 return;
1488 1530
1489 // Cache the main frame id, so we can use it for creating the frame tree 1531 // Cache the main frame id, so we can use it for creating the frame tree
1490 // root node when needed. 1532 // root node when needed.
1491 if (PageTransitionIsMainFrame(validated_params.transition)) { 1533 if (PageTransitionIsMainFrame(validated_params.transition)) {
1492 if (main_frame_id_ == -1) { 1534 int frame_tree_node_id =
1493 main_frame_id_ = validated_params.frame_id; 1535 delegate_->GetFrameTree()->root()->frame_tree_node_id();
1536 if (!HasFrameID(validated_params.frame_id)) {
1537 RegisterFrameID(validated_params.frame_id, frame_tree_node_id);
1494 } else { 1538 } else {
1495 // TODO(nasko): We plan to remove the usage of frame_id in navigation 1539 // TODO(nasko): We plan to remove the usage of frame_id in navigation
1496 // and move to routing ids. This is in place to ensure that a 1540 // and move to routing ids. This is in place to ensure that a
1497 // renderer is not misbehaving and sending us incorrect data. 1541 // renderer is not misbehaving and sending us incorrect data.
1498 DCHECK_EQ(main_frame_id_, validated_params.frame_id); 1542 DCHECK_EQ(frame_tree_node_id,
1543 GetFrameTreeNodeID(validated_params.frame_id));
1499 } 1544 }
1500 } 1545 }
1501 RenderProcessHost* process = GetProcess(); 1546 RenderProcessHost* process = GetProcess();
1502 1547
1503 // Attempts to commit certain off-limits URL should be caught more strictly 1548 // Attempts to commit certain off-limits URL should be caught more strictly
1504 // than our FilterURL checks below. If a renderer violates this policy, it 1549 // than our FilterURL checks below. If a renderer violates this policy, it
1505 // should be killed. 1550 // should be killed.
1506 if (!CanCommitURL(validated_params.url)) { 1551 if (!CanCommitURL(validated_params.url)) {
1507 VLOG(1) << "Blocked URL " << validated_params.url.spec(); 1552 VLOG(1) << "Blocked URL " << validated_params.url.spec();
1508 validated_params.url = GURL(kAboutBlankURL); 1553 validated_params.url = GURL(kAboutBlankURL);
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
2313 for (std::vector<base::FilePath>::const_iterator file = file_paths.begin(); 2358 for (std::vector<base::FilePath>::const_iterator file = file_paths.begin();
2314 file != file_paths.end(); ++file) { 2359 file != file_paths.end(); ++file) {
2315 if (!policy->CanReadFile(GetProcess()->GetID(), *file)) 2360 if (!policy->CanReadFile(GetProcess()->GetID(), *file))
2316 return false; 2361 return false;
2317 } 2362 }
2318 return true; 2363 return true;
2319 } 2364 }
2320 2365
2321 void RenderViewHostImpl::AttachToFrameTree() { 2366 void RenderViewHostImpl::AttachToFrameTree() {
2322 FrameTree* frame_tree = delegate_->GetFrameTree(); 2367 FrameTree* frame_tree = delegate_->GetFrameTree();
2323
2324 frame_tree->ResetForMainFrameSwap(); 2368 frame_tree->ResetForMainFrameSwap();
2325 if (main_frame_id() != FrameTreeNode::kInvalidFrameId) {
2326 frame_tree->OnFirstNavigationAfterSwap(main_frame_id());
2327 }
2328 } 2369 }
2329 2370
2330 } // namespace content 2371 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_view_host_impl.h ('k') | content/browser/security_exploit_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698