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

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: Update Created 7 years, 11 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
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..90d9587ab4e53c73751d8acbda17b691a78fb70e 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"
@@ -228,6 +229,15 @@ void NormalizeDisposition(chrome::NavigateParams* params) {
}
}
+GURL NormalizeURL(chrome::NavigateParams* params) {
+ if (params->url.is_empty()) {
+ params->transition = content::PageTransitionFromInt(
+ params->transition | content::PAGE_TRANSITION_HOME_PAGE);
+ return params->browser->profile()->GetHomePage();
+ }
+ return params->url;
+}
+
// Obtain the profile used by the code that originated the Navigate() request.
Profile* GetSourceProfile(chrome::NavigateParams* params) {
if (params->source_contents) {
@@ -309,6 +319,41 @@ class ScopedTargetContentsOwner {
DISALLOW_COPY_AND_ASSIGN(ScopedTargetContentsOwner);
};
+content::WebContents* CreateTargetContents(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) {
@@ -466,73 +511,49 @@ 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.
if (!params->target_contents && singleton_index < 0) {
- GURL url;
- if (params->url.is_empty()) {
- url = params->browser->profile()->GetHomePage();
- params->transition = content::PageTransitionFromInt(
- params->transition | content::PAGE_TRANSITION_HOME_PAGE);
- } else {
- url = params->url;
- }
-
+ GURL url = NormalizeURL(params);
Jered 2013/01/14 18:22:34 I think the inline block was clearer here, or Norm
samarth 2013/01/22 15:59:06 Yeah agreed. I'd factored it out because I needed
+ BrowserInstantController* instant = params->browser->instant_controller();
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 = instant && instant->MaybeSwapInInstantContents(
Jered 2013/01/14 18:22:34 if (instant) swapped_in_instant = ...
samarth 2013/01/22 15:59:06 Done.
+ url, NULL, &params->target_contents);
+ 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 = instant && instant->MaybeSwapInInstantContents(
+ url, params->source_contents, &params->target_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 +570,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,

Powered by Google App Engine
This is Rietveld 408576698