| OLD | NEW |
| 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/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 InstantSearchPrerenderer::GetForProfile(profile); | 371 InstantSearchPrerenderer::GetForProfile(profile); |
| 372 if (prerenderer && prerenderer->UsePrerenderedPage(url, params)) | 372 if (prerenderer && prerenderer->UsePrerenderedPage(url, params)) |
| 373 return true; | 373 return true; |
| 374 | 374 |
| 375 prerender::PrerenderManager* prerender_manager = | 375 prerender::PrerenderManager* prerender_manager = |
| 376 prerender::PrerenderManagerFactory::GetForProfile(profile); | 376 prerender::PrerenderManagerFactory::GetForProfile(profile); |
| 377 return prerender_manager && | 377 return prerender_manager && |
| 378 prerender_manager->MaybeUsePrerenderedPage(url, params); | 378 prerender_manager->MaybeUsePrerenderedPage(url, params); |
| 379 } | 379 } |
| 380 | 380 |
| 381 bool SwapInInstantNTP(chrome::NavigateParams* params, |
| 382 const GURL& url, |
| 383 content::WebContents* source_contents) { |
| 384 BrowserInstantController* instant = params->browser->instant_controller(); |
| 385 return instant && instant->MaybeSwapInInstantNTPContents( |
| 386 url, source_contents, ¶ms->target_contents); |
| 387 } |
| 388 |
| 381 chrome::HostDesktopType GetHostDesktop(Browser* browser) { | 389 chrome::HostDesktopType GetHostDesktop(Browser* browser) { |
| 382 if (browser) | 390 if (browser) |
| 383 return browser->host_desktop_type(); | 391 return browser->host_desktop_type(); |
| 384 return chrome::GetActiveDesktop(); | 392 return chrome::GetActiveDesktop(); |
| 385 } | 393 } |
| 386 | 394 |
| 387 } // namespace | 395 } // namespace |
| 388 | 396 |
| 389 namespace chrome { | 397 namespace chrome { |
| 390 | 398 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 base_transition == content::PAGE_TRANSITION_TYPED || | 575 base_transition == content::PAGE_TRANSITION_TYPED || |
| 568 base_transition == content::PAGE_TRANSITION_AUTO_BOOKMARK || | 576 base_transition == content::PAGE_TRANSITION_AUTO_BOOKMARK || |
| 569 base_transition == content::PAGE_TRANSITION_GENERATED || | 577 base_transition == content::PAGE_TRANSITION_GENERATED || |
| 570 base_transition == content::PAGE_TRANSITION_AUTO_TOPLEVEL || | 578 base_transition == content::PAGE_TRANSITION_AUTO_TOPLEVEL || |
| 571 base_transition == content::PAGE_TRANSITION_RELOAD || | 579 base_transition == content::PAGE_TRANSITION_RELOAD || |
| 572 base_transition == content::PAGE_TRANSITION_KEYWORD; | 580 base_transition == content::PAGE_TRANSITION_KEYWORD; |
| 573 | 581 |
| 574 // Check if this is a singleton tab that already exists | 582 // Check if this is a singleton tab that already exists |
| 575 int singleton_index = chrome::GetIndexOfSingletonTab(params); | 583 int singleton_index = chrome::GetIndexOfSingletonTab(params); |
| 576 | 584 |
| 577 // Did we use a prerender? | 585 // Did we use Instant's NTP contents or a prerender? |
| 578 bool swapped_in_prerender = false; | 586 bool swapped_in = false; |
| 579 | 587 |
| 580 // If no target WebContents was specified, we need to construct one if | 588 // If no target WebContents was specified, we need to construct one if |
| 581 // we are supposed to target a new tab; unless it's a singleton that already | 589 // we are supposed to target a new tab; unless it's a singleton that already |
| 582 // exists. | 590 // exists. |
| 583 if (!params->target_contents && singleton_index < 0) { | 591 if (!params->target_contents && singleton_index < 0) { |
| 584 GURL url; | 592 GURL url; |
| 585 if (params->url.is_empty()) { | 593 if (params->url.is_empty()) { |
| 586 url = params->browser->profile()->GetHomePage(); | 594 url = params->browser->profile()->GetHomePage(); |
| 587 params->transition = content::PageTransitionFromInt( | 595 params->transition = content::PageTransitionFromInt( |
| 588 params->transition | content::PAGE_TRANSITION_HOME_PAGE); | 596 params->transition | content::PAGE_TRANSITION_HOME_PAGE); |
| 589 } else { | 597 } else { |
| 590 url = params->url; | 598 url = params->url; |
| 591 } | 599 } |
| 592 | 600 |
| 593 if (params->disposition != CURRENT_TAB) { | 601 if (params->disposition != CURRENT_TAB) { |
| 594 params->target_contents = CreateTargetContents(*params, url); | 602 swapped_in = SwapInInstantNTP(params, url, NULL); |
| 603 if (!swapped_in) |
| 604 params->target_contents = CreateTargetContents(*params, url); |
| 595 | 605 |
| 596 // This function takes ownership of |params->target_contents| until it | 606 // This function takes ownership of |params->target_contents| until it |
| 597 // is added to a TabStripModel. | 607 // is added to a TabStripModel. |
| 598 target_contents_owner.TakeOwnership(); | 608 target_contents_owner.TakeOwnership(); |
| 599 } else { | 609 } else { |
| 600 // ... otherwise if we're loading in the current tab, the target is the | 610 // ... otherwise if we're loading in the current tab, the target is the |
| 601 // same as the source. | 611 // same as the source. |
| 602 DCHECK(params->source_contents); | 612 DCHECK(params->source_contents); |
| 603 params->target_contents = params->source_contents; | 613 swapped_in = SwapInInstantNTP(params, url, params->source_contents); |
| 614 if (!swapped_in) |
| 615 params->target_contents = params->source_contents; |
| 604 DCHECK(params->target_contents); | 616 DCHECK(params->target_contents); |
| 605 // Prerender expects |params->target_contents| to be attached to a browser | 617 // Prerender expects |params->target_contents| to be attached to a browser |
| 606 // window, so only call for CURRENT_TAB navigations. (Others are currently | 618 // window, so only call for CURRENT_TAB navigations. (Others are currently |
| 607 // unsupported because of session storage namespaces anyway.) | 619 // unsupported because of session storage namespaces anyway.) |
| 608 // Notice that this includes middle-clicking, since middle clicking | 620 // Notice that this includes middle-clicking, since middle clicking |
| 609 // translates into a chrome::Navigate call with no URL followed by a | 621 // translates into a chrome::Navigate call with no URL followed by a |
| 610 // CURRENT_TAB navigation. | 622 // CURRENT_TAB navigation. |
| 611 // TODO(tburkard): We can actually swap in in non-CURRENT_TAB cases, as | 623 // TODO(tburkard): We can actually swap in in non-CURRENT_TAB cases, as |
| 612 // long as the WebContents we swap into is part of a TabStrip model. | 624 // long as the WebContents we swap into is part of a TabStrip model. |
| 613 // Therefore, we should swap in regardless of CURRENT_TAB, and instead, | 625 // Therefore, we should swap in regardless of CURRENT_TAB, and instead, |
| 614 // check in the swapin function whether the WebContents is not in a | 626 // check in the swapin function whether the WebContents is not in a |
| 615 // TabStrip model, in which case we must not swap in. | 627 // TabStrip model, in which case we must not swap in. |
| 616 swapped_in_prerender = SwapInPrerender(url, params); | 628 if (!swapped_in) |
| 629 swapped_in = SwapInPrerender(url, params); |
| 617 } | 630 } |
| 618 | 631 |
| 619 if (user_initiated) | 632 if (user_initiated) |
| 620 params->target_contents->UserGestureDone(); | 633 params->target_contents->UserGestureDone(); |
| 621 | 634 |
| 622 if (!swapped_in_prerender) { | 635 if (!swapped_in) { |
| 623 // Try to handle non-navigational URLs that popup dialogs and such, these | 636 // Try to handle non-navigational URLs that popup dialogs and such, these |
| 624 // should not actually navigate. | 637 // should not actually navigate. |
| 625 if (!HandleNonNavigationAboutURL(url)) { | 638 if (!HandleNonNavigationAboutURL(url)) { |
| 626 // Perform the actual navigation, tracking whether it came from the | 639 // Perform the actual navigation, tracking whether it came from the |
| 627 // renderer. | 640 // renderer. |
| 628 | 641 |
| 629 LoadURLInContents(params->target_contents, url, params); | 642 LoadURLInContents(params->target_contents, url, params); |
| 630 // For prerender bookkeeping purposes, record that this pending navigate | 643 // For prerender bookkeeping purposes, record that this pending navigate |
| 631 // originated from chrome::Navigate. | 644 // originated from chrome::Navigate. |
| 632 content::NavigationEntry* entry = | 645 content::NavigationEntry* entry = |
| (...skipping 12 matching lines...) Expand all Loading... |
| 645 // If the user navigated from the omnibox, and the selected tab is going to | 658 // If the user navigated from the omnibox, and the selected tab is going to |
| 646 // lose focus, then make sure the focus for the source tab goes away from the | 659 // lose focus, then make sure the focus for the source tab goes away from the |
| 647 // omnibox. | 660 // omnibox. |
| 648 if (params->source_contents && | 661 if (params->source_contents && |
| 649 (params->disposition == NEW_FOREGROUND_TAB || | 662 (params->disposition == NEW_FOREGROUND_TAB || |
| 650 params->disposition == NEW_WINDOW) && | 663 params->disposition == NEW_WINDOW) && |
| 651 (params->tabstrip_add_types & TabStripModel::ADD_INHERIT_OPENER)) | 664 (params->tabstrip_add_types & TabStripModel::ADD_INHERIT_OPENER)) |
| 652 params->source_contents->GetView()->Focus(); | 665 params->source_contents->GetView()->Focus(); |
| 653 | 666 |
| 654 if (params->source_contents == params->target_contents || | 667 if (params->source_contents == params->target_contents || |
| 655 (swapped_in_prerender && params->disposition == CURRENT_TAB)) { | 668 (swapped_in && params->disposition == CURRENT_TAB)) { |
| 656 // The navigation occurred in the source tab. | 669 // The navigation occurred in the source tab. |
| 657 params->browser->UpdateUIForNavigationInTab(params->target_contents, | 670 params->browser->UpdateUIForNavigationInTab(params->target_contents, |
| 658 params->transition, | 671 params->transition, |
| 659 user_initiated); | 672 user_initiated); |
| 660 } else if (singleton_index == -1) { | 673 } else if (singleton_index == -1) { |
| 661 // If some non-default value is set for the index, we should tell the | 674 // If some non-default value is set for the index, we should tell the |
| 662 // TabStripModel to respect it. | 675 // TabStripModel to respect it. |
| 663 if (params->tabstrip_index != -1) | 676 if (params->tabstrip_index != -1) |
| 664 params->tabstrip_add_types |= TabStripModel::ADD_FORCE_INDEX; | 677 params->tabstrip_add_types |= TabStripModel::ADD_FORCE_INDEX; |
| 665 | 678 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 bool reverse_on_redirect = false; | 762 bool reverse_on_redirect = false; |
| 750 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( | 763 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( |
| 751 &rewritten_url, browser_context, &reverse_on_redirect); | 764 &rewritten_url, browser_context, &reverse_on_redirect); |
| 752 | 765 |
| 753 // Some URLs are mapped to uber subpages. Do not allow them in incognito. | 766 // Some URLs are mapped to uber subpages. Do not allow them in incognito. |
| 754 return !(rewritten_url.scheme() == chrome::kChromeUIScheme && | 767 return !(rewritten_url.scheme() == chrome::kChromeUIScheme && |
| 755 rewritten_url.host() == chrome::kChromeUIUberHost); | 768 rewritten_url.host() == chrome::kChromeUIUberHost); |
| 756 } | 769 } |
| 757 | 770 |
| 758 } // namespace chrome | 771 } // namespace chrome |
| OLD | NEW |