Chromium Code Reviews| Index: chrome/browser/ui/browser.cc |
| diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc |
| index c72bcdff28cb28335a6db373cff2e05af168f6a4..1c718834f51c3d933ab6faeffb1e89c3bf01ec3f 100644 |
| --- a/chrome/browser/ui/browser.cc |
| +++ b/chrome/browser/ui/browser.cc |
| @@ -1180,11 +1180,15 @@ bool Browser::CanRestoreTab() { |
|
Ben Goodger (Google)
2011/05/31 16:00:00
I am beginning to feel like all of this code shoul
shinyak (Google)
2011/06/09 02:29:04
I leave it as is now. I would like to do refactori
|
| bool Browser::NavigateToIndexWithDisposition(int index, |
| WindowOpenDisposition disp) { |
| - NavigationController& controller = |
| - GetOrCloneTabForDisposition(disp)->controller(); |
| + TabContentsWrapper* tab = GetOrCloneTabWrapperForDisposition(disp); |
| + |
| + NavigationController& controller = tab->controller(); |
| if (index < 0 || index >= controller.entry_count()) |
| return false; |
| controller.GoToIndex(index); |
| + |
| + CreateNewBrowserForDisposition(tab, disp); |
| + |
| return true; |
| } |
| @@ -1257,7 +1261,7 @@ void Browser::UpdateCommandsForFullscreenMode(bool is_fullscreen) { |
| /////////////////////////////////////////////////////////////////////////////// |
| // Browser, Assorted browser commands: |
| -bool Browser::ShouldOpenNewTabForWindowDisposition( |
| +bool Browser::ShouldOpenNewTabForDisposition( |
| WindowOpenDisposition disposition) { |
| return (disposition == NEW_FOREGROUND_TAB || |
| disposition == NEW_BACKGROUND_TAB); |
| @@ -1265,15 +1269,37 @@ bool Browser::ShouldOpenNewTabForWindowDisposition( |
| TabContents* Browser::GetOrCloneTabForDisposition( |
| WindowOpenDisposition disposition) { |
| + return GetOrCloneTabWrapperForDisposition(disposition)->tab_contents(); |
| +} |
| + |
| +TabContentsWrapper* Browser::GetOrCloneTabWrapperForDisposition( |
| + WindowOpenDisposition disposition) |
|
Ben Goodger (Google)
2011/05/31 16:00:00
nit: curly-brace at the end of this line, not the
shinyak (Google)
2011/06/09 02:29:04
Done.
|
| +{ |
| TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); |
| - if (ShouldOpenNewTabForWindowDisposition(disposition)) { |
| - current_tab = current_tab->Clone(); |
| + |
| + if (disposition == NEW_WINDOW) |
| + return current_tab->Clone(); |
| + |
| + if (ShouldOpenNewTabForDisposition(disposition)) { |
| + TabContentsWrapper* new_tab = current_tab->Clone(); |
| tab_handler_->GetTabStripModel()->AddTabContents( |
| - current_tab, -1, PageTransition::LINK, |
| + new_tab, -1, PageTransition::LINK, |
| disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_ACTIVE : |
| TabStripModel::ADD_NONE); |
| + return new_tab; |
| + } |
| + |
| + return current_tab; |
| +} |
| + |
| +void Browser::CreateNewBrowserForDisposition(TabContentsWrapper* tab_contents, |
| + WindowOpenDisposition disposition) |
| +{ |
|
Ben Goodger (Google)
2011/05/31 16:00:00
curly brace to previous line
shinyak (Google)
2011/06/09 02:29:04
Done.
|
| + if (disposition == NEW_WINDOW) { |
| + Browser* browser = Create(profile_); |
| + browser->AddTab(tab_contents, PageTransition::LINK); |
| + browser->window()->Show(); |
| } |
| - return current_tab->tab_contents(); |
| } |
| void Browser::UpdateTabStripModelInsertionPolicy() { |
| @@ -1340,21 +1366,30 @@ void Browser::GoBack(WindowOpenDisposition disposition) { |
| UserMetrics::RecordAction(UserMetricsAction("Back")); |
| TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); |
| - if (current_tab->controller().CanGoBack()) { |
| - TabContents* new_tab = GetOrCloneTabForDisposition(disposition); |
| - // If we are on an interstitial page and clone the tab, it won't be copied |
| - // to the new tab, so we don't need to go back. |
| - if (current_tab->tab_contents()->showing_interstitial_page() && |
| - (new_tab != current_tab->tab_contents())) |
| - return; |
| - new_tab->controller().GoBack(); |
| - } |
| + if (!current_tab->controller().CanGoBack()) |
| + return; |
| + |
| + TabContentsWrapper* new_tab = GetOrCloneTabWrapperForDisposition(disposition); |
| + if (current_tab->tab_contents()->showing_interstitial_page() && |
| + (new_tab != current_tab)) |
| + return; |
| + |
| + new_tab->controller().GoBack(); |
| + |
| + CreateNewBrowserForDisposition(new_tab, disposition); |
| } |
| void Browser::GoForward(WindowOpenDisposition disposition) { |
| UserMetrics::RecordAction(UserMetricsAction("Forward")); |
| - if (GetSelectedTabContentsWrapper()->controller().CanGoForward()) |
| - GetOrCloneTabForDisposition(disposition)->controller().GoForward(); |
| + |
| + TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); |
| + if (!current_tab->controller().CanGoForward()) |
| + return; |
| + |
| + TabContentsWrapper* new_tab = GetOrCloneTabWrapperForDisposition(disposition); |
| + new_tab->controller().GoForward(); |
| + |
| + CreateNewBrowserForDisposition(new_tab, disposition); |
| } |
| void Browser::Reload(WindowOpenDisposition disposition) { |