OLD | NEW |
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 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1203 if (extension && selected_contents && | 1203 if (extension && selected_contents && |
1204 selected_contents->GetURL().GetOrigin() == | 1204 selected_contents->GetURL().GetOrigin() == |
1205 GURL(chrome::kChromeUINewTabURL).GetOrigin()) { | 1205 GURL(chrome::kChromeUINewTabURL).GetOrigin()) { |
1206 // If the |url| is within an app's web extent and it was typed into the | 1206 // If the |url| is within an app's web extent and it was typed into the |
1207 // omnibox of an NTP page, interpret as an app launch and close the NTP | 1207 // omnibox of an NTP page, interpret as an app launch and close the NTP |
1208 // tab. | 1208 // tab. |
1209 Browser::OpenApplication(profile(), extension, | 1209 Browser::OpenApplication(profile(), extension, |
1210 extension->launch_container()); | 1210 extension->launch_container()); |
1211 CloseTabContents(selected_contents); | 1211 CloseTabContents(selected_contents); |
1212 return; | 1212 return; |
1213 } else if (tabstrip_model()->IsTabPinned(selected_index())) { | |
1214 // To make pinned tabs feel more permanent any requests from the omnibox | |
1215 // to open a url in the current tab with a host different from the current | |
1216 // host of the pinned tab result in creating a new tab. We allow changes | |
1217 // to the path so that the user can trigger reloads or fix up parts of the | |
1218 // url without spawning a new tab. | |
1219 if (!selected_contents || | |
1220 url.host() != selected_contents->GetURL().host()) | |
1221 open_disposition = NEW_FOREGROUND_TAB; | |
1222 } | 1213 } |
1223 } | 1214 } |
| 1215 |
1224 OpenURLAtIndex(NULL, url, GURL(), | 1216 OpenURLAtIndex(NULL, url, GURL(), |
1225 open_disposition, | 1217 open_disposition, |
1226 location_bar->GetPageTransition(), -1, true); | 1218 location_bar->GetPageTransition(), -1, true); |
1227 } | 1219 } |
1228 | 1220 |
1229 void Browser::Stop() { | 1221 void Browser::Stop() { |
1230 UserMetrics::RecordAction(UserMetricsAction("Stop"), profile_); | 1222 UserMetrics::RecordAction(UserMetricsAction("Stop"), profile_); |
1231 GetSelectedTabContents()->Stop(); | 1223 GetSelectedTabContents()->Stop(); |
1232 } | 1224 } |
1233 | 1225 |
(...skipping 2329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3563 } | 3555 } |
3564 | 3556 |
3565 // If our source tab is an app tab, don't allow normal web content to | 3557 // If our source tab is an app tab, don't allow normal web content to |
3566 // overwrite it. | 3558 // overwrite it. |
3567 if (source->extension_app() && *disposition == CURRENT_TAB) | 3559 if (source->extension_app() && *disposition == CURRENT_TAB) |
3568 *disposition = NEW_FOREGROUND_TAB; | 3560 *disposition = NEW_FOREGROUND_TAB; |
3569 | 3561 |
3570 return false; | 3562 return false; |
3571 } | 3563 } |
3572 | 3564 |
| 3565 // static |
| 3566 WindowOpenDisposition Browser::AdjustWindowOpenDispositionForTab( |
| 3567 bool is_pinned, |
| 3568 const GURL& url, |
| 3569 const GURL& referrer, |
| 3570 PageTransition::Type transition, |
| 3571 WindowOpenDisposition original_disposition) { |
| 3572 if (!is_pinned || |
| 3573 original_disposition != CURRENT_TAB || |
| 3574 (transition != PageTransition::AUTO_BOOKMARK && |
| 3575 transition != PageTransition::LINK)) { |
| 3576 return original_disposition; |
| 3577 } |
| 3578 |
| 3579 bool url_is_http_or_https = |
| 3580 url.SchemeIs(chrome::kHttpScheme) || |
| 3581 url.SchemeIs(chrome::kHttpsScheme); |
| 3582 bool referrer_is_http_or_https = |
| 3583 referrer.SchemeIs(chrome::kHttpScheme) || |
| 3584 referrer.SchemeIs(chrome::kHttpsScheme); |
| 3585 bool scheme_matches = |
| 3586 (url.scheme() == referrer.scheme()) || |
| 3587 (url_is_http_or_https && referrer_is_http_or_https); |
| 3588 |
| 3589 // If the host and scheme are the same, then we allow the link to open in |
| 3590 // the current tab, to make the page feel more web-appy. |
| 3591 if (url.host() == referrer.host() && scheme_matches) |
| 3592 return original_disposition; |
| 3593 |
| 3594 return NEW_FOREGROUND_TAB; |
| 3595 } |
| 3596 |
3573 void Browser::OpenURLAtIndex(TabContents* source, | 3597 void Browser::OpenURLAtIndex(TabContents* source, |
3574 const GURL& url, | 3598 const GURL& url, |
3575 const GURL& referrer, | 3599 const GURL& referrer, |
3576 WindowOpenDisposition disposition, | 3600 WindowOpenDisposition disposition, |
3577 PageTransition::Type transition, | 3601 PageTransition::Type transition, |
3578 int index, | 3602 int index, |
3579 bool force_index) { | 3603 bool force_index) { |
3580 // TODO(beng): Move all this code into a separate helper that has unit tests. | 3604 // TODO(beng): Move all this code into a separate helper that has unit tests. |
3581 | 3605 |
3582 // No code for these yet | 3606 // No code for these yet |
3583 DCHECK((disposition != NEW_POPUP) && (disposition != SAVE_TO_DISK)); | 3607 DCHECK((disposition != NEW_POPUP) && (disposition != SAVE_TO_DISK)); |
3584 | 3608 |
3585 TabContents* current_tab = source ? source : GetSelectedTabContents(); | 3609 TabContents* current_tab = source ? source : GetSelectedTabContents(); |
3586 bool source_tab_was_frontmost = (current_tab == GetSelectedTabContents()); | 3610 bool source_tab_was_frontmost = (current_tab == GetSelectedTabContents()); |
3587 TabContents* new_contents = NULL; | 3611 TabContents* new_contents = NULL; |
3588 | 3612 |
3589 // Opening a bookmark counts as a user gesture, so we don't need to avoid | 3613 // Opening a bookmark counts as a user gesture, so we don't need to avoid |
3590 // carpet-bombing here. | 3614 // carpet-bombing here. |
3591 PageTransition::Type baseTransitionType = | 3615 PageTransition::Type baseTransitionType = |
3592 PageTransition::StripQualifier(transition); | 3616 PageTransition::StripQualifier(transition); |
3593 if ((baseTransitionType == PageTransition::TYPED || | 3617 if ((baseTransitionType == PageTransition::TYPED || |
3594 baseTransitionType == PageTransition::AUTO_BOOKMARK) && | 3618 baseTransitionType == PageTransition::AUTO_BOOKMARK) && |
3595 current_tab != NULL) { | 3619 current_tab != NULL) { |
3596 RenderViewHostDelegate::BrowserIntegration* delegate = current_tab; | 3620 RenderViewHostDelegate::BrowserIntegration* delegate = current_tab; |
3597 delegate->OnUserGesture(); | 3621 delegate->OnUserGesture(); |
3598 } | 3622 } |
3599 | 3623 |
3600 if (current_tab && IsPinned(current_tab) && | 3624 transition = AdjustWindowOpenDispositionForTab( |
3601 transition == PageTransition::AUTO_BOOKMARK && | 3625 current_tab && IsPinned(current_tab), |
3602 disposition == CURRENT_TAB) { | 3626 url, |
3603 disposition = NEW_FOREGROUND_TAB; | 3627 referrer, |
3604 } | 3628 transition, |
| 3629 disposition); |
3605 | 3630 |
3606 if (HandleCrossAppNavigation(current_tab, url, referrer, &disposition, | 3631 if (HandleCrossAppNavigation(current_tab, url, referrer, &disposition, |
3607 transition)) { | 3632 transition)) { |
3608 // If the source tab was brand new, we can be left with an empty tab which | 3633 // If the source tab was brand new, we can be left with an empty tab which |
3609 // looks ugly. Close it. It is still kinda ugly to have a tab flash visible | 3634 // looks ugly. Close it. It is still kinda ugly to have a tab flash visible |
3610 // for a second, then disappear. But I think it is better than having a | 3635 // for a second, then disappear. But I think it is better than having a |
3611 // dead tab just hang around. | 3636 // dead tab just hang around. |
3612 if (source->controller().entry_count() == 0) | 3637 if (source->controller().entry_count() == 0) |
3613 CloseTabContents(source); | 3638 CloseTabContents(source); |
3614 return; | 3639 return; |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3857 } | 3882 } |
3858 | 3883 |
3859 bool Browser::IsPinned(TabContents* source) { | 3884 bool Browser::IsPinned(TabContents* source) { |
3860 int index = tabstrip_model_.GetIndexOfTabContents(source); | 3885 int index = tabstrip_model_.GetIndexOfTabContents(source); |
3861 if (index == TabStripModel::kNoTab) { | 3886 if (index == TabStripModel::kNoTab) { |
3862 NOTREACHED() << "IsPinned called for tab not in our strip"; | 3887 NOTREACHED() << "IsPinned called for tab not in our strip"; |
3863 return false; | 3888 return false; |
3864 } | 3889 } |
3865 return tabstrip_model_.IsTabPinned(index); | 3890 return tabstrip_model_.IsTabPinned(index); |
3866 } | 3891 } |
OLD | NEW |