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

Side by Side Diff: chrome/browser/browser.cc

Issue 3161037: Remove attempt to be smart about where to open navigations (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: wherps Created 10 years, 4 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
« no previous file with comments | « chrome/browser/browser.h ('k') | chrome/browser/browser_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/browser.h" 5 #include "chrome/browser/browser.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <shellapi.h> 8 #include <shellapi.h>
9 #include <windows.h> 9 #include <windows.h>
10 #endif // OS_WIN 10 #endif // OS_WIN
(...skipping 1262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 selected_contents->GetURL().GetOrigin() == 1273 selected_contents->GetURL().GetOrigin() ==
1274 GURL(chrome::kChromeUINewTabURL).GetOrigin()) { 1274 GURL(chrome::kChromeUINewTabURL).GetOrigin()) {
1275 // If the |url| is within an app's web extent and it was typed into the 1275 // If the |url| is within an app's web extent and it was typed into the
1276 // omnibox of an NTP page, interpret as an app launch and close the NTP 1276 // omnibox of an NTP page, interpret as an app launch and close the NTP
1277 // tab. 1277 // tab.
1278 Browser::OpenApplication(profile(), extension, 1278 Browser::OpenApplication(profile(), extension,
1279 extension->launch_container()); 1279 extension->launch_container());
1280 CloseTabContents(selected_contents); 1280 CloseTabContents(selected_contents);
1281 return; 1281 return;
1282 } 1282 }
1283
1284 if (selected_contents) {
1285 // For the purposes of changing the window open disposition, the referrer
1286 // is the current tab's URL.
1287 open_disposition = AdjustWindowOpenDispositionForTab(
1288 IsPinned(selected_contents),
1289 url,
1290 selected_contents->GetURL(),
1291 location_bar->GetPageTransition(),
1292 open_disposition);
1293 }
1294 } 1283 }
1295 1284
1296 // Use ADD_INHERIT_OPENER so that all pages opened by the omnibox at least 1285 // Use ADD_INHERIT_OPENER so that all pages opened by the omnibox at least
1297 // inherit the opener. In some cases the tabstrip will determine the group 1286 // inherit the opener. In some cases the tabstrip will determine the group
1298 // should be inherited, in which case the group is inherited instead of the 1287 // should be inherited, in which case the group is inherited instead of the
1299 // opener. 1288 // opener.
1300 OpenURLAtIndex(NULL, url, GURL(), open_disposition, 1289 OpenURLAtIndex(NULL, url, GURL(), open_disposition,
1301 location_bar->GetPageTransition(), -1, 1290 location_bar->GetPageTransition(), -1,
1302 TabStripModel::ADD_FORCE_INDEX | 1291 TabStripModel::ADD_FORCE_INDEX |
1303 TabStripModel::ADD_INHERIT_OPENER); 1292 TabStripModel::ADD_INHERIT_OPENER);
(...skipping 2468 matching lines...) Expand 10 before | Expand all | Expand 10 after
3772 3761
3773 // static 3762 // static
3774 Browser* Browser::GetOrCreateTabbedBrowser(Profile* profile) { 3763 Browser* Browser::GetOrCreateTabbedBrowser(Profile* profile) {
3775 Browser* browser = BrowserList::FindBrowserWithType(profile, TYPE_NORMAL, 3764 Browser* browser = BrowserList::FindBrowserWithType(profile, TYPE_NORMAL,
3776 false); 3765 false);
3777 if (!browser) 3766 if (!browser)
3778 browser = Browser::Create(profile); 3767 browser = Browser::Create(profile);
3779 return browser; 3768 return browser;
3780 } 3769 }
3781 3770
3782 // static
3783 WindowOpenDisposition Browser::AdjustWindowOpenDispositionForTab(
3784 bool is_pinned,
3785 const GURL& url,
3786 const GURL& referrer,
3787 PageTransition::Type transition,
3788 WindowOpenDisposition original_disposition) {
3789 if (!is_pinned ||
3790 original_disposition != CURRENT_TAB ||
3791 (transition != PageTransition::AUTO_BOOKMARK &&
3792 transition != PageTransition::LINK &&
3793 transition != PageTransition::TYPED)) {
3794 return original_disposition;
3795 }
3796
3797 bool url_is_http_or_https =
3798 url.SchemeIs(chrome::kHttpScheme) ||
3799 url.SchemeIs(chrome::kHttpsScheme);
3800 bool referrer_is_http_or_https =
3801 referrer.SchemeIs(chrome::kHttpScheme) ||
3802 referrer.SchemeIs(chrome::kHttpsScheme);
3803 bool scheme_matches =
3804 (url.scheme() == referrer.scheme()) ||
3805 (url_is_http_or_https && referrer_is_http_or_https);
3806
3807 // If the host and scheme are the same, then we allow the link to open in
3808 // the current tab, to make the page feel more web-appy.
3809 if (url.host() == referrer.host() && scheme_matches)
3810 return original_disposition;
3811
3812 return NEW_FOREGROUND_TAB;
3813 }
3814
3815 void Browser::OpenURLAtIndex(TabContents* source, 3771 void Browser::OpenURLAtIndex(TabContents* source,
3816 const GURL& url, 3772 const GURL& url,
3817 const GURL& referrer, 3773 const GURL& referrer,
3818 WindowOpenDisposition disposition, 3774 WindowOpenDisposition disposition,
3819 PageTransition::Type transition, 3775 PageTransition::Type transition,
3820 int index, 3776 int index,
3821 int add_types) { 3777 int add_types) {
3822 // TODO(beng): Move all this code into a separate helper that has unit tests. 3778 // TODO(beng): Move all this code into a separate helper that has unit tests.
3823 3779
3824 // No code for these yet 3780 // No code for these yet
3825 DCHECK((disposition != NEW_POPUP) && (disposition != SAVE_TO_DISK)); 3781 DCHECK((disposition != NEW_POPUP) && (disposition != SAVE_TO_DISK));
3826 3782
3827 TabContents* current_tab = source ? source : GetSelectedTabContents(); 3783 TabContents* current_tab = source ? source : GetSelectedTabContents();
3828 bool source_tab_was_frontmost = (current_tab == GetSelectedTabContents()); 3784 bool source_tab_was_frontmost = (current_tab == GetSelectedTabContents());
3829 TabContents* new_contents = NULL; 3785 TabContents* new_contents = NULL;
3830 3786
3831 // Opening a bookmark counts as a user gesture, so we don't need to avoid 3787 // Opening a bookmark counts as a user gesture, so we don't need to avoid
3832 // carpet-bombing here. 3788 // carpet-bombing here.
3833 PageTransition::Type baseTransitionType = 3789 PageTransition::Type baseTransitionType =
3834 PageTransition::StripQualifier(transition); 3790 PageTransition::StripQualifier(transition);
3835 if ((baseTransitionType == PageTransition::TYPED || 3791 if ((baseTransitionType == PageTransition::TYPED ||
3836 baseTransitionType == PageTransition::AUTO_BOOKMARK) && 3792 baseTransitionType == PageTransition::AUTO_BOOKMARK) &&
3837 current_tab != NULL) { 3793 current_tab != NULL) {
3838 RenderViewHostDelegate::BrowserIntegration* delegate = current_tab; 3794 RenderViewHostDelegate::BrowserIntegration* delegate = current_tab;
3839 delegate->OnUserGesture(); 3795 delegate->OnUserGesture();
3840 } 3796 }
3841 3797
3842 disposition = AdjustWindowOpenDispositionForTab(
3843 current_tab && IsPinned(current_tab),
3844 url,
3845 referrer,
3846 transition,
3847 disposition);
3848
3849 // If the URL is part of the same web site, then load it in the same 3798 // If the URL is part of the same web site, then load it in the same
3850 // SiteInstance (and thus the same process). This is an optimization to 3799 // SiteInstance (and thus the same process). This is an optimization to
3851 // reduce process overhead; it is not necessary for compatibility. (That is, 3800 // reduce process overhead; it is not necessary for compatibility. (That is,
3852 // the new tab will not have script connections to the previous tab, so it 3801 // the new tab will not have script connections to the previous tab, so it
3853 // does not need to be part of the same SiteInstance or BrowsingInstance.) 3802 // does not need to be part of the same SiteInstance or BrowsingInstance.)
3854 // Default to loading in a new SiteInstance and BrowsingInstance. 3803 // Default to loading in a new SiteInstance and BrowsingInstance.
3855 // TODO(creis): should this apply to applications? 3804 // TODO(creis): should this apply to applications?
3856 SiteInstance* instance = NULL; 3805 SiteInstance* instance = NULL;
3857 // Don't use this logic when "--process-per-tab" is specified. 3806 // Don't use this logic when "--process-per-tab" is specified.
3858 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerTab)) { 3807 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerTab)) {
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
4082 } 4031 }
4083 4032
4084 void Browser::TabRestoreServiceDestroyed(TabRestoreService* service) { 4033 void Browser::TabRestoreServiceDestroyed(TabRestoreService* service) {
4085 if (!tab_restore_service_) 4034 if (!tab_restore_service_)
4086 return; 4035 return;
4087 4036
4088 DCHECK_EQ(tab_restore_service_, service); 4037 DCHECK_EQ(tab_restore_service_, service);
4089 tab_restore_service_->RemoveObserver(this); 4038 tab_restore_service_->RemoveObserver(this);
4090 tab_restore_service_ = NULL; 4039 tab_restore_service_ = NULL;
4091 } 4040 }
4092
4093 bool Browser::IsPinned(TabContents* source) {
4094 int index = tabstrip_model_.GetIndexOfTabContents(source);
4095 if (index == TabStripModel::kNoTab) {
4096 NOTREACHED() << "IsPinned called for tab not in our strip";
4097 return false;
4098 }
4099 return tabstrip_model_.IsTabPinned(index);
4100 }
OLDNEW
« no previous file with comments | « chrome/browser/browser.h ('k') | chrome/browser/browser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698