Index: chrome/browser/ui/browser.cc |
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc |
index 372865aa49703110b448b32288af0a3a20fde7f8..272f257159245dca917614e038f2ec1e458d0948 100644 |
--- a/chrome/browser/ui/browser.cc |
+++ b/chrome/browser/ui/browser.cc |
@@ -40,6 +40,7 @@ |
#include "chrome/browser/download/download_shelf.h" |
#include "chrome/browser/download/download_started_animation.h" |
#include "chrome/browser/download/save_package.h" |
+#include "chrome/browser/event_disposition.h" |
#include "chrome/browser/extensions/crx_installer.h" |
#include "chrome/browser/extensions/extension_browser_event_router.h" |
#include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" |
@@ -1192,11 +1193,15 @@ bool Browser::CanRestoreTab() { |
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; |
} |
@@ -1269,7 +1274,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); |
@@ -1277,15 +1282,35 @@ bool Browser::ShouldOpenNewTabForWindowDisposition( |
TabContents* Browser::GetOrCloneTabForDisposition( |
WindowOpenDisposition disposition) { |
+ return GetOrCloneTabWrapperForDisposition(disposition)->tab_contents(); |
+} |
+ |
+TabContentsWrapper* Browser::GetOrCloneTabWrapperForDisposition( |
+ WindowOpenDisposition disposition) { |
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) { |
+ 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() { |
@@ -1352,21 +1377,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) { |
@@ -2496,6 +2530,22 @@ bool Browser::ExecuteCommandIfEnabled(int id) { |
return false; |
} |
+bool Browser::ExecuteContextMenuCommand(int id, int event_flags) { |
+ switch (id) { |
+ case IDC_BACK: |
+ GoBack(browser::DispositionFromEventFlags(event_flags)); |
+ return true; |
+ case IDC_FORWARD: |
+ GoForward(browser::DispositionFromEventFlags(event_flags)); |
+ return true; |
+ case IDC_RELOAD: |
+ Reload(browser::DispositionFromEventFlags(event_flags)); |
+ return true; |
+ } |
+ |
+ return false; |
+} |
+ |
bool Browser::IsReservedCommandOrKey(int command_id, |
const NativeWebKeyboardEvent& event) { |
#if defined(OS_CHROMEOS) |