OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/tab_contents/tab_contents.h" | 5 #include "content/browser/tab_contents/tab_contents.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 FOR_EACH_OBSERVER(TabContentsObserver, observers_, | 564 FOR_EACH_OBSERVER(TabContentsObserver, observers_, |
565 DidOpenURL(params.url, params.referrer, | 565 DidOpenURL(params.url, params.referrer, |
566 params.disposition, params.transition)); | 566 params.disposition, params.transition)); |
567 return new_contents; | 567 return new_contents; |
568 } | 568 } |
569 return NULL; | 569 return NULL; |
570 } | 570 } |
571 | 571 |
572 bool TabContents::NavigateToPendingEntry( | 572 bool TabContents::NavigateToPendingEntry( |
573 NavigationController::ReloadType reload_type) { | 573 NavigationController::ReloadType reload_type) { |
574 return NavigateToEntry(*controller_.pending_entry(), reload_type); | 574 return NavigateToEntry(controller_.pending_entry(), reload_type); |
575 } | 575 } |
576 | 576 |
577 bool TabContents::NavigateToEntry( | 577 bool TabContents::NavigateToEntry( |
578 const NavigationEntry& entry, | 578 NavigationEntry* entry, |
579 NavigationController::ReloadType reload_type) { | 579 NavigationController::ReloadType reload_type) { |
580 // The renderer will reject IPC messages with URLs longer than | 580 // The renderer will reject IPC messages with URLs longer than |
581 // this limit, so don't attempt to navigate with a longer URL. | 581 // this limit, so don't attempt to navigate with a longer URL. |
582 if (entry.url().spec().size() > content::kMaxURLChars) | 582 if (entry->url().spec().size() > content::kMaxURLChars) |
583 return false; | 583 return false; |
584 | 584 |
585 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry); | 585 RenderViewHost* dest_render_view_host = render_manager_.Navigate(*entry); |
586 if (!dest_render_view_host) | 586 if (!dest_render_view_host) |
587 return false; // Unable to create the desired render view host. | 587 return false; // Unable to create the desired render view host. |
588 | 588 |
| 589 // If we were forced to swap the entry's existing SiteInstance, we need to |
| 590 // update it before the navigation begins so that we can find it when the |
| 591 // navigation commits. |
| 592 if (entry->site_instance() && |
| 593 entry->site_instance() != dest_render_view_host->site_instance()) |
| 594 entry->set_site_instance(dest_render_view_host->site_instance()); |
| 595 |
589 // For security, we should never send non-Web-UI URLs to a Web UI renderer. | 596 // For security, we should never send non-Web-UI URLs to a Web UI renderer. |
590 // Double check that here. | 597 // Double check that here. |
591 int enabled_bindings = dest_render_view_host->enabled_bindings(); | 598 int enabled_bindings = dest_render_view_host->enabled_bindings(); |
592 bool is_allowed_in_web_ui_renderer = content::GetContentClient()-> | 599 bool is_allowed_in_web_ui_renderer = content::GetContentClient()-> |
593 browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(browser_context(), | 600 browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(browser_context(), |
594 entry.url()); | 601 entry->url()); |
595 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) || | 602 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) || |
596 is_allowed_in_web_ui_renderer); | 603 is_allowed_in_web_ui_renderer); |
597 | 604 |
598 // Tell DevTools agent that it is attached prior to the navigation. | 605 // Tell DevTools agent that it is attached prior to the navigation. |
599 DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); | 606 DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); |
600 if (devtools_manager) { // NULL in unit tests. | 607 if (devtools_manager) { // NULL in unit tests. |
601 devtools_manager->OnNavigatingToPendingEntry(render_view_host(), | 608 devtools_manager->OnNavigatingToPendingEntry(render_view_host(), |
602 dest_render_view_host, | 609 dest_render_view_host, |
603 entry.url()); | 610 entry->url()); |
604 } | 611 } |
605 | 612 |
606 // Used for page load time metrics. | 613 // Used for page load time metrics. |
607 current_load_start_ = base::TimeTicks::Now(); | 614 current_load_start_ = base::TimeTicks::Now(); |
608 | 615 |
609 // Navigate in the desired RenderViewHost. | 616 // Navigate in the desired RenderViewHost. |
610 ViewMsg_Navigate_Params navigate_params; | 617 ViewMsg_Navigate_Params navigate_params; |
611 MakeNavigateParams(entry, controller_, delegate_, reload_type, | 618 MakeNavigateParams(*entry, controller_, delegate_, reload_type, |
612 &navigate_params); | 619 &navigate_params); |
613 dest_render_view_host->Navigate(navigate_params); | 620 dest_render_view_host->Navigate(navigate_params); |
614 | 621 |
615 if (entry.page_id() == -1) { | 622 if (entry->page_id() == -1) { |
616 // HACK!! This code suppresses javascript: URLs from being added to | 623 // HACK!! This code suppresses javascript: URLs from being added to |
617 // session history, which is what we want to do for javascript: URLs that | 624 // session history, which is what we want to do for javascript: URLs that |
618 // do not generate content. What we really need is a message from the | 625 // do not generate content. What we really need is a message from the |
619 // renderer telling us that a new page was not created. The same message | 626 // renderer telling us that a new page was not created. The same message |
620 // could be used for mailto: URLs and the like. | 627 // could be used for mailto: URLs and the like. |
621 if (entry.url().SchemeIs(chrome::kJavaScriptScheme)) | 628 if (entry->url().SchemeIs(chrome::kJavaScriptScheme)) |
622 return false; | 629 return false; |
623 } | 630 } |
624 | 631 |
625 // Notify observers about navigation. | 632 // Notify observers about navigation. |
626 FOR_EACH_OBSERVER(TabContentsObserver, | 633 FOR_EACH_OBSERVER(TabContentsObserver, |
627 observers_, | 634 observers_, |
628 NavigateToPendingEntry(entry.url(), reload_type)); | 635 NavigateToPendingEntry(entry->url(), reload_type)); |
629 | 636 |
630 if (delegate_) | 637 if (delegate_) |
631 delegate_->DidNavigateToPendingEntry(this); | 638 delegate_->DidNavigateToPendingEntry(this); |
632 | 639 |
633 return true; | 640 return true; |
634 } | 641 } |
635 | 642 |
636 void TabContents::SetHistoryLengthAndPrune(const SiteInstance* site_instance, | 643 void TabContents::SetHistoryLengthAndPrune(const SiteInstance* site_instance, |
637 int history_length, | 644 int history_length, |
638 int32 minimum_page_id) { | 645 int32 minimum_page_id) { |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1068 NavigationEntry* entry = controller_.GetEntryAtOffset(offset); | 1075 NavigationEntry* entry = controller_.GetEntryAtOffset(offset); |
1069 if (!entry) | 1076 if (!entry) |
1070 return; | 1077 return; |
1071 // Note that we don't call NavigationController::GotToOffset() as we don't | 1078 // Note that we don't call NavigationController::GotToOffset() as we don't |
1072 // want to create a pending navigation entry (it might end up lingering | 1079 // want to create a pending navigation entry (it might end up lingering |
1073 // http://crbug.com/51680). | 1080 // http://crbug.com/51680). |
1074 entry->set_transition_type( | 1081 entry->set_transition_type( |
1075 content::PageTransitionFromInt( | 1082 content::PageTransitionFromInt( |
1076 entry->transition_type() | | 1083 entry->transition_type() | |
1077 content::PAGE_TRANSITION_FORWARD_BACK)); | 1084 content::PAGE_TRANSITION_FORWARD_BACK)); |
1078 NavigateToEntry(*entry, NavigationController::NO_RELOAD); | 1085 NavigateToEntry(entry, NavigationController::NO_RELOAD); |
1079 | 1086 |
1080 // If the entry is being restored and doesn't have a SiteInstance yet, fill | 1087 // If the entry is being restored and doesn't have a SiteInstance yet, fill |
1081 // it in now that we know. This allows us to find the entry when it commits. | 1088 // it in now that we know. This allows us to find the entry when it commits. |
1082 if (!entry->site_instance() && | 1089 if (!entry->site_instance() && |
1083 entry->restore_type() != NavigationEntry::RESTORE_NONE) { | 1090 entry->restore_type() != NavigationEntry::RESTORE_NONE) { |
1084 entry->set_site_instance(GetPendingSiteInstance()); | 1091 entry->set_site_instance(GetPendingSiteInstance()); |
1085 } | 1092 } |
1086 } | 1093 } |
1087 } | 1094 } |
1088 | 1095 |
(...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1999 | 2006 |
2000 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 2007 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
2001 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 2008 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
2002 rwh_view->SetSize(view()->GetContainerSize()); | 2009 rwh_view->SetSize(view()->GetContainerSize()); |
2003 } | 2010 } |
2004 | 2011 |
2005 bool TabContents::GotResponseToLockMouseRequest(bool allowed) { | 2012 bool TabContents::GotResponseToLockMouseRequest(bool allowed) { |
2006 return render_view_host() ? | 2013 return render_view_host() ? |
2007 render_view_host()->GotResponseToLockMouseRequest(allowed) : false; | 2014 render_view_host()->GotResponseToLockMouseRequest(allowed) : false; |
2008 } | 2015 } |
OLD | NEW |