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