Chromium Code Reviews| Index: chrome/browser/ui/browser_navigator.cc |
| diff --git a/chrome/browser/ui/browser_navigator.cc b/chrome/browser/ui/browser_navigator.cc |
| index a3ad3eb1cb9d254318f4f02f6d93d67510e933c0..3568f65a9bd79c4e2d85f34fdeeb464d7e20b074 100644 |
| --- a/chrome/browser/ui/browser_navigator.cc |
| +++ b/chrome/browser/ui/browser_navigator.cc |
| @@ -21,10 +21,12 @@ |
| #include "chrome/browser/tab_contents/tab_util.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_finder.h" |
| +#include "chrome/browser/ui/browser_instant_controller.h" |
| #include "chrome/browser/ui/browser_tab_contents.h" |
| #include "chrome/browser/ui/browser_window.h" |
| #include "chrome/browser/ui/host_desktop.h" |
| #include "chrome/browser/ui/omnibox/location_bar.h" |
| +#include "chrome/browser/ui/search/search.h" |
| #include "chrome/browser/ui/singleton_tabs.h" |
| #include "chrome/browser/ui/status_bubble.h" |
| #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| @@ -309,6 +311,41 @@ class ScopedTargetContentsOwner { |
| DISALLOW_COPY_AND_ASSIGN(ScopedTargetContentsOwner); |
| }; |
| +content::WebContents* CreateTargetContents(const chrome::NavigateParams& params, |
| + const GURL& url) { |
| + WebContents::CreateParams create_params( |
| + params.browser->profile(), |
| + tab_util::GetSiteInstanceForNewTab(params.browser->profile(), url)); |
| + if (params.source_contents) { |
| + create_params.initial_size = |
| + params.source_contents->GetView()->GetContainerSize(); |
| + } |
| +#if defined(USE_AURA) |
| + if (params.browser->window() && |
| + params.browser->window()->GetNativeWindow()) { |
| + create_params.context = |
| + params.browser->window()->GetNativeWindow(); |
| + } |
| +#endif |
| + |
| + content::WebContents* target_contents = WebContents::Create(create_params); |
| + // New tabs can have WebUI URLs that will make calls back to arbitrary |
| + // tab helpers, so the entire set of tab helpers needs to be set up |
| + // immediately. |
| + BrowserNavigatorWebContentsAdoption::AttachTabHelpers(target_contents); |
| + extensions::TabHelper::FromWebContents(target_contents)-> |
| + SetExtensionAppById(params.extension_app_id); |
| + // TODO(sky): Figure out why this is needed. Without it we seem to get |
| + // failures in startup tests. |
| + // By default, content believes it is not hidden. When adding contents |
| + // in the background, tell it that it's hidden. |
| + if ((params.tabstrip_add_types & TabStripModel::ADD_ACTIVE) == 0) { |
| + // TabStripModel::AddWebContents invokes WasHidden if not foreground. |
| + target_contents->WasHidden(); |
| + } |
| + return target_contents; |
| +} |
| + |
| // If a prerendered page exists for |url|, replace the page at |target_contents| |
| // with it. |
| bool SwapInPrerender(WebContents* target_contents, const GURL& url) { |
| @@ -319,6 +356,18 @@ bool SwapInPrerender(WebContents* target_contents, const GURL& url) { |
| prerender_manager->MaybeUsePrerenderedPage(target_contents, url); |
| } |
| +bool SwapInInstantNTP(chrome::NavigateParams* params, |
|
sreeram
2013/02/07 21:17:50
I guess you can't do "const chrome::NavigateParams
samarth
2013/02/07 22:11:55
Exactly.
|
| + const GURL& url, |
| + content::WebContents* source_contents) { |
| + if (!chrome::search::IsInstantExtendedAPIEnabled(params->browser->profile())) |
| + return false; |
|
sreeram
2013/02/07 21:17:50
We don't need this check (and thus the include of
samarth
2013/02/07 22:11:55
Done.
|
| + |
| + chrome::BrowserInstantController* instant = |
| + params->browser->instant_controller(); |
| + return instant && instant->MaybeSwapInInstantNTPContents( |
| + url, source_contents, ¶ms->target_contents); |
| +} |
| + |
| } // namespace |
| namespace chrome { |
| @@ -466,6 +515,9 @@ void Navigate(NavigateParams* params) { |
| // Check if this is a singleton tab that already exists |
| int singleton_index = chrome::GetIndexOfSingletonTab(params); |
| + // Did we use Instant's NTP contents? |
| + bool swapped_in_instant = false; |
| + |
| // If no target WebContents was specified, we need to construct one if |
| // we are supposed to target a new tab; unless it's a singleton that already |
| // exists. |
| @@ -480,59 +532,39 @@ void Navigate(NavigateParams* params) { |
| } |
| if (params->disposition != CURRENT_TAB) { |
| - WebContents::CreateParams create_params( |
| - params->browser->profile(), |
| - tab_util::GetSiteInstanceForNewTab(params->browser->profile(), url)); |
| - if (params->source_contents) { |
| - create_params.initial_size = |
| - params->source_contents->GetView()->GetContainerSize(); |
| - } |
| -#if defined(USE_AURA) |
| - if (params->browser->window() && |
| - params->browser->window()->GetNativeWindow()) { |
| - create_params.context = |
| - params->browser->window()->GetNativeWindow(); |
| - } |
| -#endif |
| - params->target_contents = WebContents::Create(create_params); |
| - // New tabs can have WebUI URLs that will make calls back to arbitrary |
| - // tab helpers, so the entire set of tab helpers needs to be set up |
| - // immediately. |
| - BrowserNavigatorWebContentsAdoption::AttachTabHelpers( |
| - params->target_contents); |
| + swapped_in_instant = SwapInInstantNTP(params, url, NULL); |
| + if (!swapped_in_instant) |
| + params->target_contents = CreateTargetContents(*params, url); |
| + |
| // This function takes ownership of |params->target_contents| until it |
| // is added to a TabStripModel. |
| target_contents_owner.TakeOwnership(); |
| - extensions::TabHelper::FromWebContents(params->target_contents)-> |
| - SetExtensionAppById(params->extension_app_id); |
| - // TODO(sky): Figure out why this is needed. Without it we seem to get |
| - // failures in startup tests. |
| - // By default, content believes it is not hidden. When adding contents |
| - // in the background, tell it that it's hidden. |
| - if ((params->tabstrip_add_types & TabStripModel::ADD_ACTIVE) == 0) { |
| - // TabStripModel::AddWebContents invokes WasHidden if not foreground. |
| - params->target_contents->WasHidden(); |
| - } |
| } else { |
| // ... otherwise if we're loading in the current tab, the target is the |
| // same as the source. |
| - params->target_contents = params->source_contents; |
| + DCHECK(params->source_contents); |
| + swapped_in_instant = SwapInInstantNTP(params, url, |
| + params->source_contents); |
| + if (!swapped_in_instant) |
| + params->target_contents = params->source_contents; |
| DCHECK(params->target_contents); |
| } |
| if (user_initiated) |
| params->target_contents->UserGestureDone(); |
| - if (SwapInPrerender(params->target_contents, url)) |
| - return; |
| + if (!swapped_in_instant) { |
| + if (SwapInPrerender(params->target_contents, url)) |
| + return; |
| - // Try to handle non-navigational URLs that popup dialogs and such, these |
| - // should not actually navigate. |
| - if (!HandleNonNavigationAboutURL(url)) { |
| - // Perform the actual navigation, tracking whether it came from the |
| - // renderer. |
| + // Try to handle non-navigational URLs that popup dialogs and such, these |
| + // should not actually navigate. |
| + if (!HandleNonNavigationAboutURL(url)) { |
| + // Perform the actual navigation, tracking whether it came from the |
| + // renderer. |
| - LoadURLInContents(params->target_contents, url, params); |
| + LoadURLInContents(params->target_contents, url, params); |
| + } |
| } |
| } else { |
| // |target_contents| was specified non-NULL, and so we assume it has already |
| @@ -549,7 +581,8 @@ void Navigate(NavigateParams* params) { |
| (params->tabstrip_add_types & TabStripModel::ADD_INHERIT_OPENER)) |
| params->source_contents->Focus(); |
| - if (params->source_contents == params->target_contents) { |
| + if (params->source_contents == params->target_contents || |
| + (swapped_in_instant && params->disposition == CURRENT_TAB)) { |
| // The navigation occurred in the source tab. |
| params->browser->UpdateUIForNavigationInTab(params->target_contents, |
| params->transition, |