Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1024)

Unified Diff: chrome/browser/ui/browser_navigator.cc

Issue 11824050: InstantExtended: Committed NTP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Undo to fix blacklisting. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/browser_instant_controller.cc ('k') | chrome/browser/ui/search/search_tab_helper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..5b290b0715f87c5f1e0b4cb2bee6e4d8f9d02c26 100644
--- a/chrome/browser/ui/browser_navigator.cc
+++ b/chrome/browser/ui/browser_navigator.cc
@@ -21,6 +21,7 @@
#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"
@@ -309,6 +310,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 +355,15 @@ bool SwapInPrerender(WebContents* target_contents, const GURL& url) {
prerender_manager->MaybeUsePrerenderedPage(target_contents, url);
}
+bool SwapInInstantNTP(chrome::NavigateParams* params,
+ const GURL& url,
+ content::WebContents* source_contents) {
+ chrome::BrowserInstantController* instant =
+ params->browser->instant_controller();
+ return instant && instant->MaybeSwapInInstantNTPContents(
+ url, source_contents, &params->target_contents);
+}
+
} // namespace
namespace chrome {
@@ -466,6 +511,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 +528,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 +577,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,
« no previous file with comments | « chrome/browser/ui/browser_instant_controller.cc ('k') | chrome/browser/ui/search/search_tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698