navigator_impl.cc revision 23730a6e56a168d1879203e4b3819bb36e3d8f1f
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 if (delegate_) 255 delegate_->DidFailProvisionalLoadWithError(render_frame_host, params); 256} 257 258void NavigatorImpl::DidFailLoadWithError( 259 RenderFrameHostImpl* render_frame_host, 260 const GURL& url, 261 bool is_main_frame, 262 int error_code, 263 const base::string16& error_description) { 264 if (delegate_) { 265 delegate_->DidFailLoadWithError( 266 render_frame_host, url, is_main_frame, error_code, 267 error_description); 268 } 269} 270 271void NavigatorImpl::DidRedirectProvisionalLoad( 272 RenderFrameHostImpl* render_frame_host, 273 int32 page_id, 274 const GURL& source_url, 275 const GURL& target_url) { 276 // TODO(creis): Remove this method and have the pre-rendering code listen to 277 // WebContentsObserver::DidGetRedirectForResourceRequest instead. 278 // See http://crbug.com/78512. 279 GURL validated_source_url(source_url); 280 GURL validated_target_url(target_url); 281 RenderProcessHost* render_process_host = render_frame_host->GetProcess(); 282 render_process_host->FilterURL(false, &validated_source_url); 283 render_process_host->FilterURL(false, &validated_target_url); 284 NavigationEntry* entry; 285 if (page_id == -1) { 286 entry = controller_->GetPendingEntry(); 287 } else { 288 entry = controller_->GetEntryWithPageID( 289 render_frame_host->GetSiteInstance(), page_id); 290 } 291 if (!entry || entry->GetURL() != validated_source_url) 292 return; 293 294 if (delegate_) { 295 delegate_->DidRedirectProvisionalLoad( 296 render_frame_host, validated_target_url); 297 } 298} 299 300bool NavigatorImpl::NavigateToEntry( 301 RenderFrameHostImpl* render_frame_host, 302 const NavigationEntryImpl& entry, 303 NavigationController::ReloadType reload_type) { 304 TRACE_EVENT0("browser", "NavigatorImpl::NavigateToEntry"); 305 306 // The renderer will reject IPC messages with URLs longer than 307 // this limit, so don't attempt to navigate with a longer URL. 308 if (entry.GetURL().spec().size() > GetMaxURLChars()) { 309 LOG(WARNING) << "Refusing to load URL as it exceeds " << GetMaxURLChars() 310 << " characters."; 311 return false; 312 } 313 314 // Use entry->frame_tree_node_id() to pick which RenderFrameHostManager to 315 // use when --site-per-process is used. 316 RenderFrameHostManager* manager = 317 render_frame_host->frame_tree_node()->render_manager(); 318 if (entry.frame_tree_node_id() != -1 && 319 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) { 320 int64 frame_tree_node_id = entry.frame_tree_node_id(); 321 manager = render_frame_host->frame_tree_node()->frame_tree()->FindByID( 322 frame_tree_node_id)->render_manager(); 323 } 324 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 // TODO(creis): As a temporary hack, we currently do cross-process subframe 355 // navigations in a top-level frame of the new process. Thus, we don't yet 356 // need to store the correct frame ID in FrameMsg_Navigate_Params. 357 FrameMsg_Navigate_Params navigate_params; 358 MakeNavigateParams(entry, *controller_, reload_type, &navigate_params); 359 dest_render_frame_host->Navigate(navigate_params); 360 361 // Make sure no code called via RFH::Navigate clears the pending entry. 362 CHECK_EQ(controller_->GetPendingEntry(), &entry); 363 364 if (entry.GetPageID() == -1) { 365 // HACK!! This code suppresses javascript: URLs from being added to 366 // session history, which is what we want to do for javascript: URLs that 367 // do not generate content. What we really need is a message from the 368 // renderer telling us that a new page was not created. The same message 369 // could be used for mailto: URLs and the like. 370 if (entry.GetURL().SchemeIs(kJavaScriptScheme)) 371 return false; 372 } 373 374 // Notify observers about navigation. 375 if (delegate_) { 376 delegate_->DidStartNavigationToPendingEntry(render_frame_host, 377 entry.GetURL(), 378 reload_type); 379 } 380 381 return true; 382} 383 384bool NavigatorImpl::NavigateToPendingEntry( 385 RenderFrameHostImpl* render_frame_host, 386 NavigationController::ReloadType reload_type) { 387 return NavigateToEntry( 388 render_frame_host, 389 *NavigationEntryImpl::FromNavigationEntry(controller_->GetPendingEntry()), 390 reload_type); 391} 392 393base::TimeTicks NavigatorImpl::GetCurrentLoadStart() { 394 return current_load_start_; 395} 396 397void NavigatorImpl::DidNavigate( 398 RenderFrameHostImpl* render_frame_host, 399 const FrameHostMsg_DidCommitProvisionalLoad_Params& input_params) { 400 FrameHostMsg_DidCommitProvisionalLoad_Params params(input_params); 401 FrameTree* frame_tree = render_frame_host->frame_tree_node()->frame_tree(); 402 RenderViewHostImpl* rvh = render_frame_host->render_view_host(); 403 bool use_site_per_process = 404 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess); 405 406 // When using --site-per-process, look up the FrameTreeNode ID that the 407 // renderer-specific frame ID corresponds to. 408 int64 frame_tree_node_id = frame_tree->root()->frame_tree_node_id(); 409 if (use_site_per_process) { 410 frame_tree_node_id = 411 render_frame_host->frame_tree_node()->frame_tree_node_id(); 412 413 // TODO(creis): In the short term, cross-process subframe navigations are 414 // happening in the pending RenderViewHost's top-level frame. (We need to 415 // both mirror the frame tree and get the navigation to occur in the correct 416 // subframe to fix this.) Until then, we should check whether we have a 417 // pending NavigationEntry with a frame ID and if so, treat the 418 // cross-process "main frame" navigation as a subframe navigation. This 419 // limits us to a single cross-process subframe per RVH, and it affects 420 // NavigateToEntry, NavigatorImpl::DidStartProvisionalLoad, and 421 // OnDidFinishLoad. 422 NavigationEntryImpl* pending_entry = 423 NavigationEntryImpl::FromNavigationEntry( 424 controller_->GetPendingEntry()); 425 int root_ftn_id = frame_tree->root()->frame_tree_node_id(); 426 if (pending_entry && 427 pending_entry->frame_tree_node_id() != -1 && 428 pending_entry->frame_tree_node_id() != root_ftn_id) { 429 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; 430 frame_tree_node_id = pending_entry->frame_tree_node_id(); 431 } 432 } 433 434 if (PageTransitionIsMainFrame(params.transition)) { 435 // When overscroll navigation gesture is enabled, a screenshot of the page 436 // in its current state is taken so that it can be used during the 437 // nav-gesture. It is necessary to take the screenshot here, before calling 438 // RenderFrameHostManager::DidNavigateMainFrame, because that can change 439 // WebContents::GetRenderViewHost to return the new host, instead of the one 440 // that may have just been swapped out. 441 if (delegate_ && delegate_->CanOverscrollContent()) 442 controller_->TakeScreenshot(); 443 444 if (!use_site_per_process) 445 frame_tree->root()->render_manager()->DidNavigateMainFrame(rvh); 446 } 447 448 // When using --site-per-process, we notify the RFHM for all navigations, 449 // not just main frame navigations. 450 if (use_site_per_process) { 451 FrameTreeNode* frame = frame_tree->FindByID(frame_tree_node_id); 452 // TODO(creis): Rename to DidNavigateFrame. 453 frame->render_manager()->DidNavigateMainFrame(rvh); 454 } 455 456 // Update the site of the SiteInstance if it doesn't have one yet, unless 457 // assigning a site is not necessary for this URL. In that case, the 458 // SiteInstance can still be considered unused until a navigation to a real 459 // page. 460 SiteInstanceImpl* site_instance = 461 static_cast<SiteInstanceImpl*>(render_frame_host->GetSiteInstance()); 462 if (!site_instance->HasSite() && 463 ShouldAssignSiteForURL(params.url)) { 464 site_instance->SetSite(params.url); 465 } 466 467 // Need to update MIME type here because it's referred to in 468 // UpdateNavigationCommands() called by RendererDidNavigate() to 469 // determine whether or not to enable the encoding menu. 470 // It's updated only for the main frame. For a subframe, 471 // RenderView::UpdateURL does not set params.contents_mime_type. 472 // (see http://code.google.com/p/chromium/issues/detail?id=2929 ) 473 // TODO(jungshik): Add a test for the encoding menu to avoid 474 // regressing it again. 475 // TODO(nasko): Verify the correctness of the above comment, since some of the 476 // code doesn't exist anymore. Also, move this code in the 477 // PageTransitionIsMainFrame code block above. 478 if (PageTransitionIsMainFrame(params.transition) && delegate_) 479 delegate_->SetMainFrameMimeType(params.contents_mime_type); 480 481 LoadCommittedDetails details; 482 bool did_navigate = controller_->RendererDidNavigate(render_frame_host, 483 params, &details); 484 485 // For now, keep track of each frame's URL in its FrameTreeNode. This lets 486 // us estimate our process count for implementing OOP iframes. 487 // TODO(creis): Remove this when we track which pages commit in each frame. 488 render_frame_host->frame_tree_node()->set_current_url(params.url); 489 490 // Send notification about committed provisional loads. This notification is 491 // different from the NAV_ENTRY_COMMITTED notification which doesn't include 492 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations. 493 if (details.type != NAVIGATION_TYPE_NAV_IGNORE && delegate_) { 494 // For AUTO_SUBFRAME navigations, an event for the main frame is generated 495 // that is not recorded in the navigation history. For the purpose of 496 // tracking navigation events, we treat this event as a sub frame navigation 497 // event. 498 bool is_main_frame = did_navigate ? details.is_main_frame : false; 499 PageTransition transition_type = params.transition; 500 // Whether or not a page transition was triggered by going backward or 501 // forward in the history is only stored in the navigation controller's 502 // entry list. 503 if (did_navigate && 504 (controller_->GetLastCommittedEntry()->GetTransitionType() & 505 PAGE_TRANSITION_FORWARD_BACK)) { 506 transition_type = PageTransitionFromInt( 507 params.transition | PAGE_TRANSITION_FORWARD_BACK); 508 } 509 510 delegate_->DidCommitProvisionalLoad(render_frame_host, 511 params.frame_unique_name, 512 is_main_frame, 513 params.url, 514 transition_type); 515 } 516 517 if (!did_navigate) 518 return; // No navigation happened. 519 520 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen 521 // for the appropriate notification (best) or you can add it to 522 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if 523 // necessary, please). 524 525 // Run post-commit tasks. 526 if (delegate_) { 527 if (details.is_main_frame) 528 delegate_->DidNavigateMainFramePostCommit(details, params); 529 530 delegate_->DidNavigateAnyFramePostCommit( 531 render_frame_host, details, params); 532 } 533} 534 535bool NavigatorImpl::ShouldAssignSiteForURL(const GURL& url) { 536 // about:blank should not "use up" a new SiteInstance. The SiteInstance can 537 // still be used for a normal web site. 538 if (url == GURL(kAboutBlankURL)) 539 return false; 540 541 // The embedder will then have the opportunity to determine if the URL 542 // should "use up" the SiteInstance. 543 return GetContentClient()->browser()->ShouldAssignSiteForURL(url); 544} 545 546void NavigatorImpl::RequestOpenURL( 547 RenderFrameHostImpl* render_frame_host, 548 const GURL& url, 549 const Referrer& referrer, 550 WindowOpenDisposition disposition, 551 bool should_replace_current_entry, 552 bool user_gesture) { 553 SiteInstance* current_site_instance = 554 GetRenderManager(render_frame_host)->current_frame_host()-> 555 GetSiteInstance(); 556 // If this came from a swapped out RenderViewHost, we only allow the request 557 // if we are still in the same BrowsingInstance. 558 if (render_frame_host->render_view_host()->IsSwappedOut() && 559 !render_frame_host->GetSiteInstance()->IsRelatedSiteInstance( 560 current_site_instance)) { 561 return; 562 } 563 564 // Delegate to RequestTransferURL because this is just the generic 565 // case where |old_request_id| is empty. 566 // TODO(creis): Pass the redirect_chain into this method to support client 567 // redirects. http://crbug.com/311721. 568 std::vector<GURL> redirect_chain; 569 RequestTransferURL( 570 render_frame_host, url, redirect_chain, referrer, PAGE_TRANSITION_LINK, 571 disposition, GlobalRequestID(), 572 should_replace_current_entry, user_gesture); 573} 574 575void NavigatorImpl::RequestTransferURL( 576 RenderFrameHostImpl* render_frame_host, 577 const GURL& url, 578 const std::vector<GURL>& redirect_chain, 579 const Referrer& referrer, 580 PageTransition page_transition, 581 WindowOpenDisposition disposition, 582 const GlobalRequestID& transferred_global_request_id, 583 bool should_replace_current_entry, 584 bool user_gesture) { 585 GURL dest_url(url); 586 SiteInstance* current_site_instance = 587 GetRenderManager(render_frame_host)->current_frame_host()-> 588 GetSiteInstance(); 589 if (!GetContentClient()->browser()->ShouldAllowOpenURL( 590 current_site_instance, url)) { 591 dest_url = GURL(kAboutBlankURL); 592 } 593 594 int64 frame_tree_node_id = -1; 595 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) { 596 frame_tree_node_id = 597 render_frame_host->frame_tree_node()->frame_tree_node_id(); 598 } 599 OpenURLParams params( 600 dest_url, referrer, frame_tree_node_id, disposition, page_transition, 601 true /* is_renderer_initiated */); 602 if (redirect_chain.size() > 0) 603 params.redirect_chain = redirect_chain; 604 params.transferred_global_request_id = transferred_global_request_id; 605 params.should_replace_current_entry = should_replace_current_entry; 606 params.user_gesture = user_gesture; 607 608 if (GetRenderManager(render_frame_host)->web_ui()) { 609 // Web UI pages sometimes want to override the page transition type for 610 // link clicks (e.g., so the new tab page can specify AUTO_BOOKMARK for 611 // automatically generated suggestions). We don't override other types 612 // like TYPED because they have different implications (e.g., autocomplete). 613 if (PageTransitionCoreTypeIs(params.transition, PAGE_TRANSITION_LINK)) 614 params.transition = 615 GetRenderManager(render_frame_host)->web_ui()-> 616 GetLinkTransitionType(); 617 618 // Note also that we hide the referrer for Web UI pages. We don't really 619 // want web sites to see a referrer of "chrome://blah" (and some 620 // chrome: URLs might have search terms or other stuff we don't want to 621 // send to the site), so we send no referrer. 622 params.referrer = Referrer(); 623 624 // Navigations in Web UI pages count as browser-initiated navigations. 625 params.is_renderer_initiated = false; 626 } 627 628 if (delegate_) 629 delegate_->RequestOpenURL(render_frame_host, params); 630} 631 632} // namespace content 633