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