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

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: 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 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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 WebContents* ReleaseOwnership() { 303 WebContents* ReleaseOwnership() {
303 return target_contents_owner_.release(); 304 return target_contents_owner_.release();
304 } 305 }
305 306
306 private: 307 private:
307 chrome::NavigateParams* params_; 308 chrome::NavigateParams* params_;
308 scoped_ptr<WebContents> target_contents_owner_; 309 scoped_ptr<WebContents> target_contents_owner_;
309 DISALLOW_COPY_AND_ASSIGN(ScopedTargetContentsOwner); 310 DISALLOW_COPY_AND_ASSIGN(ScopedTargetContentsOwner);
310 }; 311 };
311 312
313 content::WebContents* CreateTargetContents(const chrome::NavigateParams& params,
314 const GURL& url) {
315 WebContents::CreateParams create_params(
316 params.browser->profile(),
317 tab_util::GetSiteInstanceForNewTab(params.browser->profile(), url));
318 if (params.source_contents) {
319 create_params.initial_size =
320 params.source_contents->GetView()->GetContainerSize();
321 }
322 #if defined(USE_AURA)
323 if (params.browser->window() &&
324 params.browser->window()->GetNativeWindow()) {
325 create_params.context =
326 params.browser->window()->GetNativeWindow();
327 }
328 #endif
329
330 content::WebContents* target_contents = WebContents::Create(create_params);
331 // New tabs can have WebUI URLs that will make calls back to arbitrary
332 // tab helpers, so the entire set of tab helpers needs to be set up
333 // immediately.
334 BrowserNavigatorWebContentsAdoption::AttachTabHelpers(target_contents);
335 extensions::TabHelper::FromWebContents(target_contents)->
336 SetExtensionAppById(params.extension_app_id);
337 // TODO(sky): Figure out why this is needed. Without it we seem to get
338 // failures in startup tests.
339 // By default, content believes it is not hidden. When adding contents
340 // in the background, tell it that it's hidden.
341 if ((params.tabstrip_add_types & TabStripModel::ADD_ACTIVE) == 0) {
342 // TabStripModel::AddWebContents invokes WasHidden if not foreground.
343 target_contents->WasHidden();
344 }
345 return target_contents;
346 }
347
312 // If a prerendered page exists for |url|, replace the page at |target_contents| 348 // If a prerendered page exists for |url|, replace the page at |target_contents|
313 // with it. 349 // with it.
314 bool SwapInPrerender(WebContents* target_contents, const GURL& url) { 350 bool SwapInPrerender(WebContents* target_contents, const GURL& url) {
315 prerender::PrerenderManager* prerender_manager = 351 prerender::PrerenderManager* prerender_manager =
316 prerender::PrerenderManagerFactory::GetForProfile( 352 prerender::PrerenderManagerFactory::GetForProfile(
317 Profile::FromBrowserContext(target_contents->GetBrowserContext())); 353 Profile::FromBrowserContext(target_contents->GetBrowserContext()));
318 return prerender_manager && 354 return prerender_manager &&
319 prerender_manager->MaybeUsePrerenderedPage(target_contents, url); 355 prerender_manager->MaybeUsePrerenderedPage(target_contents, url);
320 } 356 }
321 357
358 bool SwapInInstantNTP(chrome::NavigateParams* params,
359 const GURL& url,
360 content::WebContents* source_contents) {
361 chrome::BrowserInstantController* instant =
362 params->browser->instant_controller();
363 return instant && instant->MaybeSwapInInstantNTPContents(
364 url, source_contents, &params->target_contents);
365 }
366
322 } // namespace 367 } // namespace
323 368
324 namespace chrome { 369 namespace chrome {
325 370
326 NavigateParams::NavigateParams(Browser* a_browser, 371 NavigateParams::NavigateParams(Browser* a_browser,
327 const GURL& a_url, 372 const GURL& a_url,
328 content::PageTransition a_transition) 373 content::PageTransition a_transition)
329 : url(a_url), 374 : url(a_url),
330 target_contents(NULL), 375 target_contents(NULL),
331 source_contents(NULL), 376 source_contents(NULL),
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 base_transition == content::PAGE_TRANSITION_TYPED || 504 base_transition == content::PAGE_TRANSITION_TYPED ||
460 base_transition == content::PAGE_TRANSITION_AUTO_BOOKMARK || 505 base_transition == content::PAGE_TRANSITION_AUTO_BOOKMARK ||
461 base_transition == content::PAGE_TRANSITION_GENERATED || 506 base_transition == content::PAGE_TRANSITION_GENERATED ||
462 base_transition == content::PAGE_TRANSITION_AUTO_TOPLEVEL || 507 base_transition == content::PAGE_TRANSITION_AUTO_TOPLEVEL ||
463 base_transition == content::PAGE_TRANSITION_RELOAD || 508 base_transition == content::PAGE_TRANSITION_RELOAD ||
464 base_transition == content::PAGE_TRANSITION_KEYWORD; 509 base_transition == content::PAGE_TRANSITION_KEYWORD;
465 510
466 // Check if this is a singleton tab that already exists 511 // Check if this is a singleton tab that already exists
467 int singleton_index = chrome::GetIndexOfSingletonTab(params); 512 int singleton_index = chrome::GetIndexOfSingletonTab(params);
468 513
514 // Did we use Instant's NTP contents?
515 bool swapped_in_instant = false;
516
469 // If no target WebContents was specified, we need to construct one if 517 // 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 518 // we are supposed to target a new tab; unless it's a singleton that already
471 // exists. 519 // exists.
472 if (!params->target_contents && singleton_index < 0) { 520 if (!params->target_contents && singleton_index < 0) {
473 GURL url; 521 GURL url;
474 if (params->url.is_empty()) { 522 if (params->url.is_empty()) {
475 url = params->browser->profile()->GetHomePage(); 523 url = params->browser->profile()->GetHomePage();
476 params->transition = content::PageTransitionFromInt( 524 params->transition = content::PageTransitionFromInt(
477 params->transition | content::PAGE_TRANSITION_HOME_PAGE); 525 params->transition | content::PAGE_TRANSITION_HOME_PAGE);
478 } else { 526 } else {
479 url = params->url; 527 url = params->url;
480 } 528 }
481 529
482 if (params->disposition != CURRENT_TAB) { 530 if (params->disposition != CURRENT_TAB) {
483 WebContents::CreateParams create_params( 531 swapped_in_instant = SwapInInstantNTP(params, url, NULL);
484 params->browser->profile(), 532 if (!swapped_in_instant)
485 tab_util::GetSiteInstanceForNewTab(params->browser->profile(), url)); 533 params->target_contents = CreateTargetContents(*params, url);
486 if (params->source_contents) { 534
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 535 // This function takes ownership of |params->target_contents| until it
504 // is added to a TabStripModel. 536 // is added to a TabStripModel.
505 target_contents_owner.TakeOwnership(); 537 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 { 538 } else {
517 // ... otherwise if we're loading in the current tab, the target is the 539 // ... otherwise if we're loading in the current tab, the target is the
518 // same as the source. 540 // same as the source.
519 params->target_contents = params->source_contents; 541 DCHECK(params->source_contents);
542 swapped_in_instant = SwapInInstantNTP(params, url,
543 params->source_contents);
544 if (!swapped_in_instant)
545 params->target_contents = params->source_contents;
520 DCHECK(params->target_contents); 546 DCHECK(params->target_contents);
521 } 547 }
522 548
523 if (user_initiated) 549 if (user_initiated)
524 params->target_contents->UserGestureDone(); 550 params->target_contents->UserGestureDone();
525 551
526 if (SwapInPrerender(params->target_contents, url)) 552 if (!swapped_in_instant) {
527 return; 553 if (SwapInPrerender(params->target_contents, url))
554 return;
528 555
529 // Try to handle non-navigational URLs that popup dialogs and such, these 556 // Try to handle non-navigational URLs that popup dialogs and such, these
530 // should not actually navigate. 557 // should not actually navigate.
531 if (!HandleNonNavigationAboutURL(url)) { 558 if (!HandleNonNavigationAboutURL(url)) {
532 // Perform the actual navigation, tracking whether it came from the 559 // Perform the actual navigation, tracking whether it came from the
533 // renderer. 560 // renderer.
534 561
535 LoadURLInContents(params->target_contents, url, params); 562 LoadURLInContents(params->target_contents, url, params);
563 }
536 } 564 }
537 } else { 565 } else {
538 // |target_contents| was specified non-NULL, and so we assume it has already 566 // |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 567 // been navigated appropriately. We need to do nothing more other than
540 // add it to the appropriate tabstrip. 568 // add it to the appropriate tabstrip.
541 } 569 }
542 570
543 // If the user navigated from the omnibox, and the selected tab is going to 571 // 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 572 // lose focus, then make sure the focus for the source tab goes away from the
545 // omnibox. 573 // omnibox.
546 if (params->source_contents && 574 if (params->source_contents &&
547 (params->disposition == NEW_FOREGROUND_TAB || 575 (params->disposition == NEW_FOREGROUND_TAB ||
548 params->disposition == NEW_WINDOW) && 576 params->disposition == NEW_WINDOW) &&
549 (params->tabstrip_add_types & TabStripModel::ADD_INHERIT_OPENER)) 577 (params->tabstrip_add_types & TabStripModel::ADD_INHERIT_OPENER))
550 params->source_contents->Focus(); 578 params->source_contents->Focus();
551 579
552 if (params->source_contents == params->target_contents) { 580 if (params->source_contents == params->target_contents ||
581 (swapped_in_instant && params->disposition == CURRENT_TAB)) {
553 // The navigation occurred in the source tab. 582 // The navigation occurred in the source tab.
554 params->browser->UpdateUIForNavigationInTab(params->target_contents, 583 params->browser->UpdateUIForNavigationInTab(params->target_contents,
555 params->transition, 584 params->transition,
556 user_initiated); 585 user_initiated);
557 } else if (singleton_index == -1) { 586 } else if (singleton_index == -1) {
558 // If some non-default value is set for the index, we should tell the 587 // If some non-default value is set for the index, we should tell the
559 // TabStripModel to respect it. 588 // TabStripModel to respect it.
560 if (params->tabstrip_index != -1) 589 if (params->tabstrip_index != -1)
561 params->tabstrip_add_types |= TabStripModel::ADD_FORCE_INDEX; 590 params->tabstrip_add_types |= TabStripModel::ADD_FORCE_INDEX;
562 591
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 bool reverse_on_redirect = false; 645 bool reverse_on_redirect = false;
617 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( 646 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
618 &rewritten_url, browser_context, &reverse_on_redirect); 647 &rewritten_url, browser_context, &reverse_on_redirect);
619 648
620 // Some URLs are mapped to uber subpages. Do not allow them in incognito. 649 // Some URLs are mapped to uber subpages. Do not allow them in incognito.
621 return !(rewritten_url.scheme() == chrome::kChromeUIScheme && 650 return !(rewritten_url.scheme() == chrome::kChromeUIScheme &&
622 rewritten_url.host() == chrome::kChromeUIUberHost); 651 rewritten_url.host() == chrome::kChromeUIUberHost);
623 } 652 }
624 653
625 } // namespace chrome 654 } // namespace chrome
OLDNEW
« 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