navigator_impl.cc revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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/navigator_impl.h" 6 7#include "base/command_line.h" 8#include "content/browser/frame_host/frame_tree.h" 9#include "content/browser/frame_host/frame_tree_node.h" 10#include "content/browser/frame_host/navigation_controller_impl.h" 11#include "content/browser/frame_host/navigation_entry_impl.h" 12#include "content/browser/frame_host/navigator_delegate.h" 13#include "content/browser/frame_host/render_frame_host_impl.h" 14#include "content/browser/renderer_host/render_view_host_impl.h" 15#include "content/browser/site_instance_impl.h" 16#include "content/browser/webui/web_ui_controller_factory_registry.h" 17#include "content/browser/webui/web_ui_impl.h" 18#include "content/common/frame_messages.h" 19#include "content/common/view_messages.h" 20#include "content/public/browser/browser_context.h" 21#include "content/public/browser/content_browser_client.h" 22#include "content/public/browser/global_request_id.h" 23#include "content/public/browser/invalidate_type.h" 24#include "content/public/browser/navigation_controller.h" 25#include "content/public/browser/navigation_details.h" 26#include "content/public/browser/page_navigator.h" 27#include "content/public/browser/render_view_host.h" 28#include "content/public/common/bindings_policy.h" 29#include "content/public/common/content_client.h" 30#include "content/public/common/content_switches.h" 31#include "content/public/common/url_constants.h" 32#include "content/public/common/url_utils.h" 33 34namespace content { 35 36namespace { 37 38FrameMsg_Navigate_Type::Value GetNavigationType( 39 BrowserContext* browser_context, const NavigationEntryImpl& entry, 40 NavigationController::ReloadType reload_type) { 41 switch (reload_type) { 42 case NavigationControllerImpl::RELOAD: 43 return FrameMsg_Navigate_Type::RELOAD; 44 case NavigationControllerImpl::RELOAD_IGNORING_CACHE: 45 return FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE; 46 case NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL: 47 return FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL; 48 case NavigationControllerImpl::NO_RELOAD: 49 break; // Fall through to rest of function. 50 } 51 52 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates 53 // between |RESTORE_WITH_POST| and |RESTORE|. 54 if (entry.restore_type() == 55 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY) { 56 if (entry.GetHasPostData()) 57 return FrameMsg_Navigate_Type::RESTORE_WITH_POST; 58 return FrameMsg_Navigate_Type::RESTORE; 59 } 60 61 return FrameMsg_Navigate_Type::NORMAL; 62} 63 64void MakeNavigateParams(const NavigationEntryImpl& entry, 65 const NavigationControllerImpl& controller, 66 NavigationController::ReloadType reload_type, 67 FrameMsg_Navigate_Params* params) { 68 params->page_id = entry.GetPageID(); 69 params->should_clear_history_list = entry.should_clear_history_list(); 70 params->should_replace_current_entry = entry.should_replace_entry(); 71 if (entry.should_clear_history_list()) { 72 // Set the history list related parameters to the same values a 73 // NavigationController would return before its first navigation. This will 74 // fully clear the RenderView's view of the session history. 75 params->pending_history_list_offset = -1; 76 params->current_history_list_offset = -1; 77 params->current_history_list_length = 0; 78 } else { 79 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry); 80 params->current_history_list_offset = 81 controller.GetLastCommittedEntryIndex(); 82 params->current_history_list_length = controller.GetEntryCount(); 83 } 84 params->url = entry.GetURL(); 85 if (!entry.GetBaseURLForDataURL().is_empty()) { 86 params->base_url_for_data_url = entry.GetBaseURLForDataURL(); 87 params->history_url_for_data_url = entry.GetVirtualURL(); 88 } 89 params->referrer = entry.GetReferrer(); 90 params->transition = entry.GetTransitionType(); 91 params->page_state = entry.GetPageState(); 92 params->navigation_type = 93 GetNavigationType(controller.GetBrowserContext(), entry, reload_type); 94 params->request_time = base::Time::Now(); 95 params->extra_headers = entry.extra_headers(); 96 params->transferred_request_child_id = 97 entry.transferred_global_request_id().child_id; 98 params->transferred_request_request_id = 99 entry.transferred_global_request_id().request_id; 100 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent(); 101 // Avoid downloading when in view-source mode. 102 params->allow_download = !entry.IsViewSourceMode(); 103 params->is_post = entry.GetHasPostData(); 104 if (entry.GetBrowserInitiatedPostData()) { 105 params->browser_initiated_post_data.assign( 106 entry.GetBrowserInitiatedPostData()->front(), 107 entry.GetBrowserInitiatedPostData()->front() + 108 entry.GetBrowserInitiatedPostData()->size()); 109 } 110 111 params->redirects = entry.redirect_chain(); 112 113 params->can_load_local_resources = entry.GetCanLoadLocalResources(); 114 params->frame_to_navigate = entry.GetFrameToNavigate(); 115} 116 117RenderFrameHostManager* GetRenderManager(RenderFrameHostImpl* rfh) { 118 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) 119 return rfh->frame_tree_node()->render_manager(); 120 121 return rfh->frame_tree_node()->frame_tree()->root()->render_manager(); 122} 123 124} // namespace 125 126 127NavigatorImpl::NavigatorImpl( 128 NavigationControllerImpl* navigation_controller, 129 NavigatorDelegate* delegate) 130 : controller_(navigation_controller), 131 delegate_(delegate) { 132} 133 134void NavigatorImpl::DidStartProvisionalLoad( 135 RenderFrameHostImpl* render_frame_host, 136 int parent_routing_id, 137 bool is_main_frame, 138 const GURL& url) { 139 bool is_error_page = (url.spec() == kUnreachableWebDataURL); 140 bool is_iframe_srcdoc = (url.spec() == kAboutSrcDocURL); 141 GURL validated_url(url); 142 RenderProcessHost* render_process_host = render_frame_host->GetProcess(); 143 render_process_host->FilterURL(false, &validated_url); 144 145 // TODO(creis): This is a hack for now, until we mirror the frame tree and do 146 // cross-process subframe navigations in actual subframes. As a result, we 147 // can currently only support a single cross-process subframe per RVH. 148 NavigationEntryImpl* pending_entry = 149 NavigationEntryImpl::FromNavigationEntry(controller_->GetPendingEntry()); 150 if (pending_entry && 151 pending_entry->frame_tree_node_id() != -1 && 152 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) 153 is_main_frame = false; 154 155 if (is_main_frame) { 156 // If there is no browser-initiated pending entry for this navigation and it 157 // is not for the error URL, create a pending entry using the current 158 // SiteInstance, and ensure the address bar updates accordingly. We don't 159 // know the referrer or extra headers at this point, but the referrer will 160 // be set properly upon commit. 161 bool has_browser_initiated_pending_entry = pending_entry && 162 !pending_entry->is_renderer_initiated(); 163 if (!has_browser_initiated_pending_entry && !is_error_page) { 164 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( 165 controller_->CreateNavigationEntry(validated_url, 166 content::Referrer(), 167 content::PAGE_TRANSITION_LINK, 168 true /* is_renderer_initiated */, 169 std::string(), 170 controller_->GetBrowserContext())); 171 entry->set_site_instance( 172 static_cast<SiteInstanceImpl*>( 173 render_frame_host->render_view_host()->GetSiteInstance())); 174 // TODO(creis): If there's a pending entry already, find a safe way to 175 // update it instead of replacing it and copying over things like this. 176 if (pending_entry) { 177 entry->set_transferred_global_request_id( 178 pending_entry->transferred_global_request_id()); 179 entry->set_should_replace_entry(pending_entry->should_replace_entry()); 180 entry->set_redirect_chain(pending_entry->redirect_chain()); 181 } 182 controller_->SetPendingEntry(entry); 183 if (delegate_) 184 delegate_->NotifyChangedNavigationState(content::INVALIDATE_TYPE_URL); 185 } 186 } 187 188 if (delegate_) { 189 // Notify the observer about the start of the provisional load. 190 delegate_->DidStartProvisionalLoad( 191 render_frame_host, parent_routing_id, is_main_frame, 192 validated_url, is_error_page, is_iframe_srcdoc); 193 } 194} 195 196 197void NavigatorImpl::DidFailProvisionalLoadWithError( 198 RenderFrameHostImpl* render_frame_host, 199 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) { 200 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec() 201 << ", error_code: " << params.error_code 202 << ", error_description: " << params.error_description 203 << ", is_main_frame: " << params.is_main_frame 204 << ", showing_repost_interstitial: " << 205 params.showing_repost_interstitial 206 << ", frame_id: " << render_frame_host->GetRoutingID(); 207 GURL validated_url(params.url); 208 RenderProcessHost* render_process_host = render_frame_host->GetProcess(); 209 render_process_host->FilterURL(false, &validated_url); 210 211 if (net::ERR_ABORTED == params.error_code) { 212 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials. 213 // This means that the interstitial won't be torn down properly, which is 214 // bad. But if we have an interstitial, go back to another tab type, and 215 // then load the same interstitial again, we could end up getting the first 216 // interstitial's "failed" message (as a result of the cancel) when we're on 217 // the second one. We can't tell this apart, so we think we're tearing down 218 // the current page which will cause a crash later on. 219 // 220 // http://code.google.com/p/chromium/issues/detail?id=2855 221 // Because this will not tear down the interstitial properly, if "back" is 222 // back to another tab type, the interstitial will still be somewhat alive 223 // in the previous tab type. If you navigate somewhere that activates the 224 // tab with the interstitial again, you'll see a flash before the new load 225 // commits of the interstitial page. 226 FrameTreeNode* root = 227 render_frame_host->frame_tree_node()->frame_tree()->root(); 228 if (root->render_manager()->interstitial_page() != NULL) { 229 LOG(WARNING) << "Discarding message during interstitial."; 230 return; 231 } 232 233 // We used to cancel the pending renderer here for cross-site downloads. 234 // However, it's not safe to do that because the download logic repeatedly 235 // looks for this WebContents based on a render ID. Instead, we just 236 // leave the pending renderer around until the next navigation event 237 // (Navigate, DidNavigate, etc), which will clean it up properly. 238 // 239 // TODO(creis): Find a way to cancel any pending RFH here. 240 } 241 242 // Do not usually clear the pending entry if one exists, so that the user's 243 // typed URL is not lost when a navigation fails or is aborted. However, in 244 // cases that we don't show the pending entry (e.g., renderer-initiated 245 // navigations in an existing tab), we don't keep it around. That prevents 246 // spoofs on in-page navigations that don't go through 247 // DidStartProvisionalLoadForFrame. 248 // In general, we allow the view to clear the pending entry and typed URL if 249 // the user requests (e.g., hitting Escape with focus in the address bar). 250 // Note: don't touch the transient entry, since an interstitial may exist. 251 if (controller_->GetPendingEntry() != controller_->GetVisibleEntry()) 252 controller_->DiscardPendingEntry(); 253 254 delegate_->DidFailProvisionalLoadWithError(render_frame_host, params); 255} 256 257void NavigatorImpl::DidFailLoadWithError( 258 RenderFrameHostImpl* render_frame_host, 259 const GURL& url, 260 bool is_main_frame, 261 int error_code, 262 const base::string16& error_description) { 263 delegate_->DidFailLoadWithError( 264 render_frame_host, url, is_main_frame, error_code, 265 error_description); 266} 267 268void NavigatorImpl::DidRedirectProvisionalLoad( 269 RenderFrameHostImpl* render_frame_host, 270 int32 page_id, 271 const GURL& source_url, 272 const GURL& target_url) { 273 // TODO(creis): Remove this method and have the pre-rendering code listen to 274 // WebContentsObserver::DidGetRedirectForResourceRequest instead. 275 // See http://crbug.com/78512. 276 GURL validated_source_url(source_url); 277 GURL validated_target_url(target_url); 278 RenderProcessHost* render_process_host = render_frame_host->GetProcess(); 279 render_process_host->FilterURL(false, &validated_source_url); 280 render_process_host->FilterURL(false, &validated_target_url); 281 NavigationEntry* entry; 282 if (page_id == -1) { 283 entry = controller_->GetPendingEntry(); 284 } else { 285 entry = controller_->GetEntryWithPageID( 286 render_frame_host->GetSiteInstance(), page_id); 287 } 288 if (!entry || entry->GetURL() != validated_source_url) 289 return; 290 291 delegate_->DidRedirectProvisionalLoad( 292 render_frame_host, validated_target_url); 293} 294 295bool NavigatorImpl::NavigateToEntry( 296 RenderFrameHostImpl* render_frame_host, 297 const NavigationEntryImpl& entry, 298 NavigationController::ReloadType reload_type) { 299 TRACE_EVENT0("browser", "NavigatorImpl::NavigateToEntry"); 300 301 // The renderer will reject IPC messages with URLs longer than 302 // this limit, so don't attempt to navigate with a longer URL. 303 if (entry.GetURL().spec().size() > GetMaxURLChars()) { 304 LOG(WARNING) << "Refusing to load URL as it exceeds " << GetMaxURLChars() 305 << " characters."; 306 return false; 307 } 308 309 // Use entry->frame_tree_node_id() to pick which RenderFrameHostManager to 310 // use when --site-per-process is used. 311 RenderFrameHostManager* manager = 312 render_frame_host->frame_tree_node()->render_manager(); 313 if (entry.frame_tree_node_id() != -1 && 314 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) { 315 int64 frame_tree_node_id = entry.frame_tree_node_id(); 316 manager = render_frame_host->frame_tree_node()->frame_tree()->FindByID( 317 frame_tree_node_id)->render_manager(); 318 } 319 320 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); 321 if (!dest_render_frame_host) 322 return false; // Unable to create the desired RenderFrameHost. 323 324 // Make sure no code called via RFHM::Navigate clears the pending entry. 325 CHECK_EQ(controller_->GetPendingEntry(), &entry); 326 327 // For security, we should never send non-Web-UI URLs to a Web UI renderer. 328 // Double check that here. 329 int enabled_bindings = 330 dest_render_frame_host->render_view_host()->GetEnabledBindings(); 331 bool is_allowed_in_web_ui_renderer = 332 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( 333 controller_->GetBrowserContext(), entry.GetURL()); 334 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && 335 !is_allowed_in_web_ui_renderer) { 336 // Log the URL to help us diagnose any future failures of this CHECK. 337 GetContentClient()->SetActiveURL(entry.GetURL()); 338 CHECK(0); 339 } 340 341 // Notify observers that we will navigate in this RenderFrame. 342 if (delegate_) 343 delegate_->AboutToNavigateRenderFrame(dest_render_frame_host); 344 345 // Used for page load time metrics. 346 current_load_start_ = base::TimeTicks::Now(); 347 348 // Navigate in the desired RenderFrameHost. 349 // TODO(creis): As a temporary hack, we currently do cross-process subframe 350 // navigations in a top-level frame of the new process. Thus, we don't yet 351 // need to store the correct frame ID in FrameMsg_Navigate_Params. 352 FrameMsg_Navigate_Params navigate_params; 353 MakeNavigateParams(entry, *controller_, reload_type, &navigate_params); 354 dest_render_frame_host->Navigate(navigate_params); 355 356 // Make sure no code called via RFH::Navigate clears the pending entry. 357 CHECK_EQ(controller_->GetPendingEntry(), &entry); 358 359 if (entry.GetPageID() == -1) { 360 // HACK!! This code suppresses javascript: URLs from being added to 361 // session history, which is what we want to do for javascript: URLs that 362 // do not generate content. What we really need is a message from the 363 // renderer telling us that a new page was not created. The same message 364 // could be used for mailto: URLs and the like. 365 if (entry.GetURL().SchemeIs(kJavaScriptScheme)) 366 return false; 367 } 368 369 // Notify observers about navigation. 370 if (delegate_) { 371 delegate_->DidStartNavigationToPendingEntry(render_frame_host, 372 entry.GetURL(), 373 reload_type); 374 } 375 376 return true; 377} 378 379bool NavigatorImpl::NavigateToPendingEntry( 380 RenderFrameHostImpl* render_frame_host, 381 NavigationController::ReloadType reload_type) { 382 return NavigateToEntry( 383 render_frame_host, 384 *NavigationEntryImpl::FromNavigationEntry(controller_->GetPendingEntry()), 385 reload_type); 386} 387 388base::TimeTicks NavigatorImpl::GetCurrentLoadStart() { 389 return current_load_start_; 390} 391 392void NavigatorImpl::DidNavigate( 393 RenderFrameHostImpl* render_frame_host, 394 const FrameHostMsg_DidCommitProvisionalLoad_Params& input_params) { 395 FrameHostMsg_DidCommitProvisionalLoad_Params params(input_params); 396 FrameTree* frame_tree = render_frame_host->frame_tree_node()->frame_tree(); 397 RenderViewHostImpl* rvh = render_frame_host->render_view_host(); 398 bool use_site_per_process = 399 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess); 400 401 // When using --site-per-process, look up the FrameTreeNode ID that the 402 // renderer-specific frame ID corresponds to. 403 int64 frame_tree_node_id = frame_tree->root()->frame_tree_node_id(); 404 if (use_site_per_process) { 405 frame_tree_node_id = 406 render_frame_host->frame_tree_node()->frame_tree_node_id(); 407 408 // TODO(creis): In the short term, cross-process subframe navigations are 409 // happening in the pending RenderViewHost's top-level frame. (We need to 410 // both mirror the frame tree and get the navigation to occur in the correct 411 // subframe to fix this.) Until then, we should check whether we have a 412 // pending NavigationEntry with a frame ID and if so, treat the 413 // cross-process "main frame" navigation as a subframe navigation. This 414 // limits us to a single cross-process subframe per RVH, and it affects 415 // NavigateToEntry, NavigatorImpl::DidStartProvisionalLoad, and 416 // OnDidFinishLoad. 417 NavigationEntryImpl* pending_entry = 418 NavigationEntryImpl::FromNavigationEntry( 419 controller_->GetPendingEntry()); 420 int root_ftn_id = frame_tree->root()->frame_tree_node_id(); 421 if (pending_entry && 422 pending_entry->frame_tree_node_id() != -1 && 423 pending_entry->frame_tree_node_id() != root_ftn_id) { 424 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; 425 frame_tree_node_id = pending_entry->frame_tree_node_id(); 426 } 427 } 428 429 if (PageTransitionIsMainFrame(params.transition)) { 430 // When overscroll navigation gesture is enabled, a screenshot of the page 431 // in its current state is taken so that it can be used during the 432 // nav-gesture. It is necessary to take the screenshot here, before calling 433 // RenderFrameHostManager::DidNavigateMainFrame, because that can change 434 // WebContents::GetRenderViewHost to return the new host, instead of the one 435 // that may have just been swapped out. 436 if (delegate_ && delegate_->CanOverscrollContent()) 437 controller_->TakeScreenshot(); 438 439 if (!use_site_per_process) 440 frame_tree->root()->render_manager()->DidNavigateMainFrame(rvh); 441 } 442 443 // When using --site-per-process, we notify the RFHM for all navigations, 444 // not just main frame navigations. 445 if (use_site_per_process) { 446 FrameTreeNode* frame = frame_tree->FindByID(frame_tree_node_id); 447 // TODO(creis): Rename to DidNavigateFrame. 448 frame->render_manager()->DidNavigateMainFrame(rvh); 449 } 450 451 // Update the site of the SiteInstance if it doesn't have one yet, unless 452 // assigning a site is not necessary for this URL. In that case, the 453 // SiteInstance can still be considered unused until a navigation to a real 454 // page. 455 SiteInstanceImpl* site_instance = 456 static_cast<SiteInstanceImpl*>(render_frame_host->GetSiteInstance()); 457 if (!site_instance->HasSite() && 458 ShouldAssignSiteForURL(params.url)) { 459 site_instance->SetSite(params.url); 460 } 461 462 // Need to update MIME type here because it's referred to in 463 // UpdateNavigationCommands() called by RendererDidNavigate() to 464 // determine whether or not to enable the encoding menu. 465 // It's updated only for the main frame. For a subframe, 466 // RenderView::UpdateURL does not set params.contents_mime_type. 467 // (see http://code.google.com/p/chromium/issues/detail?id=2929 ) 468 // TODO(jungshik): Add a test for the encoding menu to avoid 469 // regressing it again. 470 // TODO(nasko): Verify the correctness of the above comment, since some of the 471 // code doesn't exist anymore. Also, move this code in the 472 // PageTransitionIsMainFrame code block above. 473 if (PageTransitionIsMainFrame(params.transition) && delegate_) 474 delegate_->SetMainFrameMimeType(params.contents_mime_type); 475 476 LoadCommittedDetails details; 477 bool did_navigate = controller_->RendererDidNavigate(render_frame_host, 478 params, &details); 479 480 // For now, keep track of each frame's URL in its FrameTreeNode. This lets 481 // us estimate our process count for implementing OOP iframes. 482 // TODO(creis): Remove this when we track which pages commit in each frame. 483 render_frame_host->frame_tree_node()->set_current_url(params.url); 484 485 // Send notification about committed provisional loads. This notification is 486 // different from the NAV_ENTRY_COMMITTED notification which doesn't include 487 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations. 488 if (details.type != NAVIGATION_TYPE_NAV_IGNORE && delegate_) { 489 // For AUTO_SUBFRAME navigations, an event for the main frame is generated 490 // that is not recorded in the navigation history. For the purpose of 491 // tracking navigation events, we treat this event as a sub frame navigation 492 // event. 493 bool is_main_frame = did_navigate ? details.is_main_frame : false; 494 PageTransition transition_type = params.transition; 495 // Whether or not a page transition was triggered by going backward or 496 // forward in the history is only stored in the navigation controller's 497 // entry list. 498 if (did_navigate && 499 (controller_->GetLastCommittedEntry()->GetTransitionType() & 500 PAGE_TRANSITION_FORWARD_BACK)) { 501 transition_type = PageTransitionFromInt( 502 params.transition | PAGE_TRANSITION_FORWARD_BACK); 503 } 504 505 delegate_->DidCommitProvisionalLoad(render_frame_host, 506 params.frame_unique_name, 507 is_main_frame, 508 params.url, 509 transition_type); 510 } 511 512 if (!did_navigate) 513 return; // No navigation happened. 514 515 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen 516 // for the appropriate notification (best) or you can add it to 517 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if 518 // necessary, please). 519 520 // Run post-commit tasks. 521 if (delegate_) { 522 if (details.is_main_frame) 523 delegate_->DidNavigateMainFramePostCommit(details, params); 524 525 delegate_->DidNavigateAnyFramePostCommit( 526 render_frame_host, details, params); 527 } 528} 529 530bool NavigatorImpl::ShouldAssignSiteForURL(const GURL& url) { 531 // about:blank should not "use up" a new SiteInstance. The SiteInstance can 532 // still be used for a normal web site. 533 if (url == GURL(kAboutBlankURL)) 534 return false; 535 536 // The embedder will then have the opportunity to determine if the URL 537 // should "use up" the SiteInstance. 538 return GetContentClient()->browser()->ShouldAssignSiteForURL(url); 539} 540 541void NavigatorImpl::RequestOpenURL( 542 RenderFrameHostImpl* render_frame_host, 543 const GURL& url, 544 const Referrer& referrer, 545 WindowOpenDisposition disposition, 546 bool should_replace_current_entry, 547 bool user_gesture) { 548 SiteInstance* current_site_instance = 549 GetRenderManager(render_frame_host)->current_frame_host()-> 550 GetSiteInstance(); 551 // If this came from a swapped out RenderViewHost, we only allow the request 552 // if we are still in the same BrowsingInstance. 553 if (render_frame_host->render_view_host()->IsSwappedOut() && 554 !render_frame_host->GetSiteInstance()->IsRelatedSiteInstance( 555 current_site_instance)) { 556 return; 557 } 558 559 // Delegate to RequestTransferURL because this is just the generic 560 // case where |old_request_id| is empty. 561 // TODO(creis): Pass the redirect_chain into this method to support client 562 // redirects. http://crbug.com/311721. 563 std::vector<GURL> redirect_chain; 564 RequestTransferURL( 565 render_frame_host, url, redirect_chain, referrer, PAGE_TRANSITION_LINK, 566 disposition, GlobalRequestID(), 567 should_replace_current_entry, user_gesture); 568} 569 570void NavigatorImpl::RequestTransferURL( 571 RenderFrameHostImpl* render_frame_host, 572 const GURL& url, 573 const std::vector<GURL>& redirect_chain, 574 const Referrer& referrer, 575 PageTransition page_transition, 576 WindowOpenDisposition disposition, 577 const GlobalRequestID& transferred_global_request_id, 578 bool should_replace_current_entry, 579 bool user_gesture) { 580 GURL dest_url(url); 581 SiteInstance* current_site_instance = 582 GetRenderManager(render_frame_host)->current_frame_host()-> 583 GetSiteInstance(); 584 if (!GetContentClient()->browser()->ShouldAllowOpenURL( 585 current_site_instance, url)) { 586 dest_url = GURL(kAboutBlankURL); 587 } 588 589 int64 frame_tree_node_id = -1; 590 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) { 591 frame_tree_node_id = 592 render_frame_host->frame_tree_node()->frame_tree_node_id(); 593 } 594 OpenURLParams params( 595 dest_url, referrer, frame_tree_node_id, disposition, page_transition, 596 true /* is_renderer_initiated */); 597 if (redirect_chain.size() > 0) 598 params.redirect_chain = redirect_chain; 599 params.transferred_global_request_id = transferred_global_request_id; 600 params.should_replace_current_entry = should_replace_current_entry; 601 params.user_gesture = user_gesture; 602 603 if (GetRenderManager(render_frame_host)->web_ui()) { 604 // Web UI pages sometimes want to override the page transition type for 605 // link clicks (e.g., so the new tab page can specify AUTO_BOOKMARK for 606 // automatically generated suggestions). We don't override other types 607 // like TYPED because they have different implications (e.g., autocomplete). 608 if (PageTransitionCoreTypeIs(params.transition, PAGE_TRANSITION_LINK)) 609 params.transition = 610 GetRenderManager(render_frame_host)->web_ui()-> 611 GetLinkTransitionType(); 612 613 // Note also that we hide the referrer for Web UI pages. We don't really 614 // want web sites to see a referrer of "chrome://blah" (and some 615 // chrome: URLs might have search terms or other stuff we don't want to 616 // send to the site), so we send no referrer. 617 params.referrer = Referrer(); 618 619 // Navigations in Web UI pages count as browser-initiated navigations. 620 params.is_renderer_initiated = false; 621 } 622 623 if (delegate_) 624 delegate_->RequestOpenURL(render_frame_host, params); 625} 626 627} // namespace content 628