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

Side by Side 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: Rebase. 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/ui/browser_navigator.h" 5 #include "chrome/browser/ui/browser_navigator.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/browser_about_handler.h" 12 #include "chrome/browser/browser_about_handler.h"
13 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/tab_helper.h" 14 #include "chrome/browser/extensions/tab_helper.h"
15 #include "chrome/browser/google/google_url_tracker.h" 15 #include "chrome/browser/google/google_url_tracker.h"
16 #include "chrome/browser/prefs/incognito_mode_prefs.h" 16 #include "chrome/browser/prefs/incognito_mode_prefs.h"
17 #include "chrome/browser/prefs/pref_service.h" 17 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/browser/prerender/prerender_manager.h" 18 #include "chrome/browser/prerender/prerender_manager.h"
19 #include "chrome/browser/prerender/prerender_manager_factory.h" 19 #include "chrome/browser/prerender/prerender_manager_factory.h"
20 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/tab_contents/tab_util.h" 21 #include "chrome/browser/tab_contents/tab_util.h"
22 #include "chrome/browser/ui/browser.h" 22 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_finder.h" 23 #include "chrome/browser/ui/browser_finder.h"
24 #include "chrome/browser/ui/browser_instant_controller.h"
24 #include "chrome/browser/ui/browser_tab_contents.h" 25 #include "chrome/browser/ui/browser_tab_contents.h"
25 #include "chrome/browser/ui/browser_window.h" 26 #include "chrome/browser/ui/browser_window.h"
26 #include "chrome/browser/ui/host_desktop.h" 27 #include "chrome/browser/ui/host_desktop.h"
27 #include "chrome/browser/ui/omnibox/location_bar.h" 28 #include "chrome/browser/ui/omnibox/location_bar.h"
28 #include "chrome/browser/ui/singleton_tabs.h" 29 #include "chrome/browser/ui/singleton_tabs.h"
29 #include "chrome/browser/ui/status_bubble.h" 30 #include "chrome/browser/ui/status_bubble.h"
30 #include "chrome/browser/ui/tabs/tab_strip_model.h" 31 #include "chrome/browser/ui/tabs/tab_strip_model.h"
31 #include "chrome/browser/web_applications/web_app.h" 32 #include "chrome/browser/web_applications/web_app.h"
32 #include "chrome/common/chrome_notification_types.h" 33 #include "chrome/common/chrome_notification_types.h"
33 #include "chrome/common/extensions/extension.h" 34 #include "chrome/common/extensions/extension.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 case NEW_FOREGROUND_TAB: 222 case NEW_FOREGROUND_TAB:
222 case SINGLETON_TAB: 223 case SINGLETON_TAB:
223 params->tabstrip_add_types |= TabStripModel::ADD_ACTIVE; 224 params->tabstrip_add_types |= TabStripModel::ADD_ACTIVE;
224 break; 225 break;
225 226
226 default: 227 default:
227 break; 228 break;
228 } 229 }
229 } 230 }
230 231
232 GURL NormalizeURL(chrome::NavigateParams* params) {
233 if (params->url.is_empty()) {
dhollowa 2013/01/22 22:34:58 nit: Slight preference for: if (!params...) \n ret
samarth 2013/01/25 21:08:40 Not relevant anymore.
234 params->transition = content::PageTransitionFromInt(
235 params->transition | content::PAGE_TRANSITION_HOME_PAGE);
236 return params->browser->profile()->GetHomePage();
237 }
238 return params->url;
239 }
240
231 // Obtain the profile used by the code that originated the Navigate() request. 241 // Obtain the profile used by the code that originated the Navigate() request.
232 Profile* GetSourceProfile(chrome::NavigateParams* params) { 242 Profile* GetSourceProfile(chrome::NavigateParams* params) {
233 if (params->source_contents) { 243 if (params->source_contents) {
234 return Profile::FromBrowserContext( 244 return Profile::FromBrowserContext(
235 params->source_contents->GetBrowserContext()); 245 params->source_contents->GetBrowserContext());
236 } 246 }
237 247
238 return params->initiating_profile; 248 return params->initiating_profile;
239 } 249 }
240 250
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 WebContents* ReleaseOwnership() { 312 WebContents* ReleaseOwnership() {
303 return target_contents_owner_.release(); 313 return target_contents_owner_.release();
304 } 314 }
305 315
306 private: 316 private:
307 chrome::NavigateParams* params_; 317 chrome::NavigateParams* params_;
308 scoped_ptr<WebContents> target_contents_owner_; 318 scoped_ptr<WebContents> target_contents_owner_;
309 DISALLOW_COPY_AND_ASSIGN(ScopedTargetContentsOwner); 319 DISALLOW_COPY_AND_ASSIGN(ScopedTargetContentsOwner);
310 }; 320 };
311 321
322 content::WebContents* CreateTargetContents(chrome::NavigateParams* params,
323 const GURL& url) {
324 WebContents::CreateParams create_params(
325 params->browser->profile(),
326 tab_util::GetSiteInstanceForNewTab(params->browser->profile(), url));
327 if (params->source_contents) {
328 create_params.initial_size =
329 params->source_contents->GetView()->GetContainerSize();
330 }
331 #if defined(USE_AURA)
332 if (params->browser->window() &&
333 params->browser->window()->GetNativeWindow()) {
334 create_params.context =
335 params->browser->window()->GetNativeWindow();
336 }
337 #endif
338
339 content::WebContents* target_contents = WebContents::Create(create_params);
340 // New tabs can have WebUI URLs that will make calls back to arbitrary
341 // tab helpers, so the entire set of tab helpers needs to be set up
342 // immediately.
343 BrowserNavigatorWebContentsAdoption::AttachTabHelpers(target_contents);
344 extensions::TabHelper::FromWebContents(target_contents)->
345 SetExtensionAppById(params->extension_app_id);
346 // TODO(sky): Figure out why this is needed. Without it we seem to get
347 // failures in startup tests.
348 // By default, content believes it is not hidden. When adding contents
349 // in the background, tell it that it's hidden.
350 if ((params->tabstrip_add_types & TabStripModel::ADD_ACTIVE) == 0) {
351 // TabStripModel::AddWebContents invokes WasHidden if not foreground.
352 target_contents->WasHidden();
353 }
354 return target_contents;
355 }
356
312 // If a prerendered page exists for |url|, replace the page at |target_contents| 357 // If a prerendered page exists for |url|, replace the page at |target_contents|
313 // with it. 358 // with it.
314 bool SwapInPrerender(WebContents* target_contents, const GURL& url) { 359 bool SwapInPrerender(WebContents* target_contents, const GURL& url) {
315 prerender::PrerenderManager* prerender_manager = 360 prerender::PrerenderManager* prerender_manager =
316 prerender::PrerenderManagerFactory::GetForProfile( 361 prerender::PrerenderManagerFactory::GetForProfile(
317 Profile::FromBrowserContext(target_contents->GetBrowserContext())); 362 Profile::FromBrowserContext(target_contents->GetBrowserContext()));
318 return prerender_manager && 363 return prerender_manager &&
319 prerender_manager->MaybeUsePrerenderedPage(target_contents, url); 364 prerender_manager->MaybeUsePrerenderedPage(target_contents, url);
320 } 365 }
321 366
367 bool SwapInInstantNTP(chrome::NavigateParams* params,
368 const GURL& url,
369 content::WebContents* source_contents) {
370 chrome::BrowserInstantController* instant =
371 params->browser->instant_controller();
372 return instant && instant->MaybeSwapInInstantContents(
373 url, source_contents, &params->target_contents);
374 }
375
322 } // namespace 376 } // namespace
323 377
324 namespace chrome { 378 namespace chrome {
325 379
326 NavigateParams::NavigateParams(Browser* a_browser, 380 NavigateParams::NavigateParams(Browser* a_browser,
327 const GURL& a_url, 381 const GURL& a_url,
328 content::PageTransition a_transition) 382 content::PageTransition a_transition)
329 : url(a_url), 383 : url(a_url),
330 target_contents(NULL), 384 target_contents(NULL),
331 source_contents(NULL), 385 source_contents(NULL),
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 base_transition == content::PAGE_TRANSITION_TYPED || 513 base_transition == content::PAGE_TRANSITION_TYPED ||
460 base_transition == content::PAGE_TRANSITION_AUTO_BOOKMARK || 514 base_transition == content::PAGE_TRANSITION_AUTO_BOOKMARK ||
461 base_transition == content::PAGE_TRANSITION_GENERATED || 515 base_transition == content::PAGE_TRANSITION_GENERATED ||
462 base_transition == content::PAGE_TRANSITION_AUTO_TOPLEVEL || 516 base_transition == content::PAGE_TRANSITION_AUTO_TOPLEVEL ||
463 base_transition == content::PAGE_TRANSITION_RELOAD || 517 base_transition == content::PAGE_TRANSITION_RELOAD ||
464 base_transition == content::PAGE_TRANSITION_KEYWORD; 518 base_transition == content::PAGE_TRANSITION_KEYWORD;
465 519
466 // Check if this is a singleton tab that already exists 520 // Check if this is a singleton tab that already exists
467 int singleton_index = chrome::GetIndexOfSingletonTab(params); 521 int singleton_index = chrome::GetIndexOfSingletonTab(params);
468 522
523 // Did we use Instant's NTP contents?
524 bool swapped_in_instant = false;
525
469 // If no target WebContents was specified, we need to construct one if 526 // If no target WebContents was specified, we need to construct one if
470 // we are supposed to target a new tab; unless it's a singleton that already 527 // we are supposed to target a new tab; unless it's a singleton that already
471 // exists. 528 // exists.
472 if (!params->target_contents && singleton_index < 0) { 529 if (!params->target_contents && singleton_index < 0) {
473 GURL url; 530 GURL url;
474 if (params->url.is_empty()) { 531 if (params->url.is_empty()) {
475 url = params->browser->profile()->GetHomePage(); 532 url = params->browser->profile()->GetHomePage();
476 params->transition = content::PageTransitionFromInt( 533 params->transition = content::PageTransitionFromInt(
477 params->transition | content::PAGE_TRANSITION_HOME_PAGE); 534 params->transition | content::PAGE_TRANSITION_HOME_PAGE);
478 } else { 535 } else {
479 url = params->url; 536 url = params->url;
480 } 537 }
481 538
482 if (params->disposition != CURRENT_TAB) { 539 if (params->disposition != CURRENT_TAB) {
483 WebContents::CreateParams create_params( 540 swapped_in_instant = SwapInInstantNTP(params, url, NULL);
484 params->browser->profile(), 541 if (!swapped_in_instant)
485 tab_util::GetSiteInstanceForNewTab(params->browser->profile(), url)); 542 params->target_contents = CreateTargetContents(params, url);
486 if (params->source_contents) { 543
487 create_params.initial_size =
488 params->source_contents->GetView()->GetContainerSize();
489 }
490 #if defined(USE_AURA)
491 if (params->browser->window() &&
492 params->browser->window()->GetNativeWindow()) {
493 create_params.context =
494 params->browser->window()->GetNativeWindow();
495 }
496 #endif
497 params->target_contents = WebContents::Create(create_params);
498 // New tabs can have WebUI URLs that will make calls back to arbitrary
499 // tab helpers, so the entire set of tab helpers needs to be set up
500 // immediately.
501 BrowserNavigatorWebContentsAdoption::AttachTabHelpers(
502 params->target_contents);
503 // This function takes ownership of |params->target_contents| until it 544 // This function takes ownership of |params->target_contents| until it
504 // is added to a TabStripModel. 545 // is added to a TabStripModel.
505 target_contents_owner.TakeOwnership(); 546 target_contents_owner.TakeOwnership();
506 extensions::TabHelper::FromWebContents(params->target_contents)->
507 SetExtensionAppById(params->extension_app_id);
508 // TODO(sky): Figure out why this is needed. Without it we seem to get
509 // failures in startup tests.
510 // By default, content believes it is not hidden. When adding contents
511 // in the background, tell it that it's hidden.
512 if ((params->tabstrip_add_types & TabStripModel::ADD_ACTIVE) == 0) {
513 // TabStripModel::AddWebContents invokes WasHidden if not foreground.
514 params->target_contents->WasHidden();
515 }
516 } else { 547 } else {
517 // ... otherwise if we're loading in the current tab, the target is the 548 // ... otherwise if we're loading in the current tab, the target is the
518 // same as the source. 549 // same as the source.
519 params->target_contents = params->source_contents; 550 DCHECK(params->source_contents);
551 swapped_in_instant = SwapInInstantNTP(params, url,
552 params->source_contents);
553 if (!swapped_in_instant)
554 params->target_contents = params->source_contents;
520 DCHECK(params->target_contents); 555 DCHECK(params->target_contents);
521 } 556 }
522 557
523 if (user_initiated) 558 if (user_initiated)
524 params->target_contents->UserGestureDone(); 559 params->target_contents->UserGestureDone();
525 560
526 if (SwapInPrerender(params->target_contents, url)) 561 if (!swapped_in_instant) {
527 return; 562 if (SwapInPrerender(params->target_contents, url))
563 return;
528 564
529 // Try to handle non-navigational URLs that popup dialogs and such, these 565 // Try to handle non-navigational URLs that popup dialogs and such, these
530 // should not actually navigate. 566 // should not actually navigate.
531 if (!HandleNonNavigationAboutURL(url)) { 567 if (!HandleNonNavigationAboutURL(url)) {
532 // Perform the actual navigation, tracking whether it came from the 568 // Perform the actual navigation, tracking whether it came from the
533 // renderer. 569 // renderer.
534 570
535 LoadURLInContents(params->target_contents, url, params); 571 LoadURLInContents(params->target_contents, url, params);
572 }
536 } 573 }
537 } else { 574 } else {
538 // |target_contents| was specified non-NULL, and so we assume it has already 575 // |target_contents| was specified non-NULL, and so we assume it has already
539 // been navigated appropriately. We need to do nothing more other than 576 // been navigated appropriately. We need to do nothing more other than
540 // add it to the appropriate tabstrip. 577 // add it to the appropriate tabstrip.
541 } 578 }
542 579
543 // If the user navigated from the omnibox, and the selected tab is going to 580 // If the user navigated from the omnibox, and the selected tab is going to
544 // lose focus, then make sure the focus for the source tab goes away from the 581 // lose focus, then make sure the focus for the source tab goes away from the
545 // omnibox. 582 // omnibox.
546 if (params->source_contents && 583 if (params->source_contents &&
547 (params->disposition == NEW_FOREGROUND_TAB || 584 (params->disposition == NEW_FOREGROUND_TAB ||
548 params->disposition == NEW_WINDOW) && 585 params->disposition == NEW_WINDOW) &&
549 (params->tabstrip_add_types & TabStripModel::ADD_INHERIT_OPENER)) 586 (params->tabstrip_add_types & TabStripModel::ADD_INHERIT_OPENER))
550 params->source_contents->Focus(); 587 params->source_contents->Focus();
551 588
552 if (params->source_contents == params->target_contents) { 589 if (params->source_contents == params->target_contents ||
590 (swapped_in_instant && params->disposition == CURRENT_TAB)) {
553 // The navigation occurred in the source tab. 591 // The navigation occurred in the source tab.
554 params->browser->UpdateUIForNavigationInTab(params->target_contents, 592 params->browser->UpdateUIForNavigationInTab(params->target_contents,
555 params->transition, 593 params->transition,
556 user_initiated); 594 user_initiated);
557 } else if (singleton_index == -1) { 595 } else if (singleton_index == -1) {
558 // If some non-default value is set for the index, we should tell the 596 // If some non-default value is set for the index, we should tell the
559 // TabStripModel to respect it. 597 // TabStripModel to respect it.
560 if (params->tabstrip_index != -1) 598 if (params->tabstrip_index != -1)
561 params->tabstrip_add_types |= TabStripModel::ADD_FORCE_INDEX; 599 params->tabstrip_add_types |= TabStripModel::ADD_FORCE_INDEX;
562 600
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 bool reverse_on_redirect = false; 654 bool reverse_on_redirect = false;
617 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( 655 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
618 &rewritten_url, browser_context, &reverse_on_redirect); 656 &rewritten_url, browser_context, &reverse_on_redirect);
619 657
620 // Some URLs are mapped to uber subpages. Do not allow them in incognito. 658 // Some URLs are mapped to uber subpages. Do not allow them in incognito.
621 return !(rewritten_url.scheme() == chrome::kChromeUIScheme && 659 return !(rewritten_url.scheme() == chrome::kChromeUIScheme &&
622 rewritten_url.host() == chrome::kChromeUIUberHost); 660 rewritten_url.host() == chrome::kChromeUIUberHost);
623 } 661 }
624 662
625 } // namespace chrome 663 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698