summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/back_forward_menu_model.cc20
-rw-r--r--chrome/browser/back_forward_menu_model.h6
-rw-r--r--chrome/browser/browser.cc71
-rw-r--r--chrome/browser/browser.h9
-rw-r--r--chrome/browser/cocoa/back_forward_menu_controller.mm5
5 files changed, 71 insertions, 40 deletions
diff --git a/chrome/browser/back_forward_menu_model.cc b/chrome/browser/back_forward_menu_model.cc
index 7d54e94..e1bc742 100644
--- a/chrome/browser/back_forward_menu_model.cc
+++ b/chrome/browser/back_forward_menu_model.cc
@@ -127,14 +127,20 @@ void BackForwardMenuModel::HighlightChangedTo(int index) {
}
void BackForwardMenuModel::ActivatedAt(int index) {
- NavigationController& controller = GetTabContents()->controller();
+ ActivatedAtWithDisposition(index, CURRENT_TAB);
+}
+
+void BackForwardMenuModel::ActivatedAtWithDisposition(
+ int index,
+ WindowOpenDisposition disposition) {
+ Profile* profile = browser_->profile();
DCHECK(!IsSeparator(index));
// Execute the command for the last item: "Show Full History".
if (index == GetItemCount() - 1) {
UserMetrics::RecordComputedAction(BuildActionName("ShowFullHistory", -1),
- controller.profile());
+ profile);
browser_->ShowSingletonTab(GURL(chrome::kChromeUIHistoryURL));
return;
}
@@ -142,18 +148,18 @@ void BackForwardMenuModel::ActivatedAt(int index) {
// Log whether it was a history or chapter click.
if (index < GetHistoryItemCount()) {
UserMetrics::RecordComputedAction(
- BuildActionName("HistoryClick", index), controller.profile());
+ BuildActionName("HistoryClick", index), profile);
} else {
UserMetrics::RecordComputedAction(
BuildActionName("ChapterClick", index - GetHistoryItemCount() - 1),
- controller.profile());
+ profile);
}
int controller_index = MenuIndexToNavEntryIndex(index);
- if (controller_index >= 0 && controller_index < controller.entry_count())
- controller.GoToIndex(controller_index);
- else
+ if (!browser_->NavigateToIndexWithDisposition(controller_index,
+ disposition)) {
NOTREACHED();
+ }
}
void BackForwardMenuModel::MenuWillShow() {
diff --git a/chrome/browser/back_forward_menu_model.h b/chrome/browser/back_forward_menu_model.h
index 18c73d5..adcbff0 100644
--- a/chrome/browser/back_forward_menu_model.h
+++ b/chrome/browser/back_forward_menu_model.h
@@ -11,6 +11,7 @@
#include "base/basictypes.h"
#include "base/string16.h"
#include "testing/gtest/include/gtest/gtest_prod.h" // For FRIEND_TEST
+#include "webkit/glue/window_open_disposition.h"
class Browser;
class SkBitmap;
@@ -56,6 +57,11 @@ class BackForwardMenuModel : public menus::MenuModel {
virtual MenuModel* GetSubmenuModelAt(int index) const;
virtual void HighlightChangedTo(int index);
virtual void ActivatedAt(int index);
+
+ // Navigates to the corresponding history item, opening it in a new tab
+ // if necessary.
+ void ActivatedAtWithDisposition(int index,
+ WindowOpenDisposition disposition);
virtual void MenuWillShow();
// Is the item at |index| a separator?
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index bc3972a..af98839 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -788,6 +788,19 @@ bool Browser::CanRestoreTab() {
return service && !service->entries().empty();
}
+bool Browser::NavigateToIndexWithDisposition(int index,
+ WindowOpenDisposition disp) {
+ NavigationController& controller =
+ GetOrCloneNavigationControllerForDisposition(disp);
+
+ if (index >= 0 && index < controller.entry_count()) {
+ controller.GoToIndex(index);
+ return true;
+ } else {
+ return false;
+ }
+}
+
void Browser::ShowSingletonTab(const GURL& url) {
// See if we already have a tab with the given URL and select it if so.
for (int i = 0; i < tabstrip_model_.count(); i++) {
@@ -842,49 +855,43 @@ void Browser::UpdateCommandsForFullscreenMode(bool is_fullscreen) {
///////////////////////////////////////////////////////////////////////////////
// Browser, Assorted browser commands:
+NavigationController& Browser::GetOrCloneNavigationControllerForDisposition(
+ WindowOpenDisposition disposition) {
+ TabContents* current_tab = GetSelectedTabContents();
+ if (disposition == NEW_FOREGROUND_TAB ||
+ disposition == NEW_BACKGROUND_TAB) {
+ TabContents* cloned = current_tab->Clone();
+ tabstrip_model_.AddTabContents(cloned, -1, false,
+ PageTransition::LINK,
+ disposition == NEW_FOREGROUND_TAB);
+ return cloned->controller();
+ } else {
+ // Default disposition is CURRENT_TAB.
+ return current_tab->controller();
+ }
+}
+
void Browser::GoBack(WindowOpenDisposition disposition) {
UserMetrics::RecordAction("Back", profile_);
TabContents* current_tab = GetSelectedTabContents();
if (current_tab->controller().CanGoBack()) {
- NavigationController* controller = NULL;
- if (disposition == NEW_FOREGROUND_TAB ||
- disposition == NEW_BACKGROUND_TAB) {
- TabContents* cloned = GetSelectedTabContents()->Clone();
- tabstrip_model_.AddTabContents(cloned, -1, false,
- PageTransition::LINK,
- disposition == NEW_FOREGROUND_TAB);
- if (current_tab->interstitial_page()) {
- // The interstitial won't be copied to the new tab, so we don't need to
- // go back.
- return;
- }
- controller = &cloned->controller();
- } else {
- // Default disposition is CURRENT_TAB.
- controller = &current_tab->controller();
+ NavigationController& controller =
+ GetOrCloneNavigationControllerForDisposition(disposition);
+ // The interstitial won't be copied to the new tab, so we don't need to
+ // go back.
+ if (!current_tab->interstitial_page()) {
+ controller.GoBack();
}
- controller->GoBack();
}
}
-void Browser::GoForward(WindowOpenDisposition disp) {
- // TODO(brettw) this is mostly duplicated from GoBack, these should have a
- // common backend or something.
+void Browser::GoForward(WindowOpenDisposition disposition) {
UserMetrics::RecordAction("Forward", profile_);
if (GetSelectedTabContents()->controller().CanGoForward()) {
- NavigationController* controller = 0;
- if (disp == NEW_FOREGROUND_TAB || disp == NEW_BACKGROUND_TAB) {
- TabContents* cloned = GetSelectedTabContents()->Clone();
- tabstrip_model_.AddTabContents(cloned, -1, false,
- PageTransition::LINK,
- disp == NEW_FOREGROUND_TAB);
- controller = &cloned->controller();
- } else {
- // Default disposition is CURRENT_TAB.
- controller = &GetSelectedTabContents()->controller();
- }
- controller->GoForward();
+ NavigationController& controller =
+ GetOrCloneNavigationControllerForDisposition(disposition);
+ controller.GoForward();
}
}
diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h
index 0082504..37e62505 100644
--- a/chrome/browser/browser.h
+++ b/chrome/browser/browser.h
@@ -349,6 +349,10 @@ class Browser : public TabStripModelDelegate,
// Returns true if a tab can be restored.
virtual bool CanRestoreTab();
+ // Navigate to an index in the tab history, opening a new tab depending on the
+ // disposition.
+ bool NavigateToIndexWithDisposition(int index, WindowOpenDisposition disp);
+
// Show a given a URL. If a tab with the same URL (ignoring the ref) is
// already visible in this browser, it becomes selected. Otherwise a new tab
// is created.
@@ -797,6 +801,11 @@ class Browser : public TabStripModelDelegate,
// Shared code between Reload() and ReloadAll().
void ReloadInternal(bool ignore_cache);
+ // Depending on the disposition, return the |NavigationController| for the
+ // current tab or clone the current tab and return its |NavigationController|.
+ NavigationController& GetOrCloneNavigationControllerForDisposition(
+ WindowOpenDisposition disp);
+
// Data members /////////////////////////////////////////////////////////////
NotificationRegistrar registrar_;
diff --git a/chrome/browser/cocoa/back_forward_menu_controller.mm b/chrome/browser/cocoa/back_forward_menu_controller.mm
index 41585bc..2fca91d 100644
--- a/chrome/browser/cocoa/back_forward_menu_controller.mm
+++ b/chrome/browser/cocoa/back_forward_menu_controller.mm
@@ -9,6 +9,7 @@
#include "base/sys_string_conversions.h"
#include "chrome/browser/back_forward_menu_model.h"
#import "chrome/browser/cocoa/delayedmenu_button.h"
+#import "chrome/browser/cocoa/event_utils.h"
#include "skia/ext/skia_utils_mac.h"
#include "third_party/skia/include/core/SkBitmap.h"
@@ -93,7 +94,9 @@ using gfx::SkBitmapToNSImage;
- (void)executeMenuItem:(id)sender {
DCHECK([sender isKindOfClass:[NSMenuItem class]]);
int menuID = [sender tag];
- model_->ActivatedAt(menuID);
+ model_->ActivatedAtWithDisposition(
+ menuID,
+ event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]));
}
@end // @implementation BackForwardMenuController