summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/browser.cc5
-rw-r--r--chrome/browser/browser.h3
-rw-r--r--chrome/browser/tabs/tab_strip_model.cc8
-rw-r--r--chrome/browser/tabs/tab_strip_model.h7
-rw-r--r--chrome/browser/tabs/tab_strip_model_unittest.cc2
-rw-r--r--chrome/browser/views/tabs/tab.cc2
6 files changed, 27 insertions, 0 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index 1963361..d29d7ce 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -576,6 +576,11 @@ void Browser::ReplaceRestoredTab(
restored_controller);
}
+bool Browser::CanRestoreTab() {
+ TabRestoreService* service = profile_->GetTabRestoreService();
+ return service && !service->entries().empty();
+}
+
void Browser::ShowSingleDOMUITab(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++) {
diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h
index 9db95d5..1cd85c3 100644
--- a/chrome/browser/browser.h
+++ b/chrome/browser/browser.h
@@ -250,6 +250,9 @@ class Browser : public TabStripModelDelegate,
const std::vector<TabNavigation>& navigations,
int selected_navigation);
+ // Returns true if a tab can be restored.
+ virtual bool CanRestoreTab();
+
// Show a DOMUI tab given a URL. If a tab with the same URL is already
// visible in this browser, it becomes selected. Otherwise a new tab is
// created.
diff --git a/chrome/browser/tabs/tab_strip_model.cc b/chrome/browser/tabs/tab_strip_model.cc
index 43ec063..52c056d 100644
--- a/chrome/browser/tabs/tab_strip_model.cc
+++ b/chrome/browser/tabs/tab_strip_model.cc
@@ -9,6 +9,7 @@
#include "base/string_util.h"
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/profile.h"
+#include "chrome/browser/sessions/tab_restore_service.h"
#include "chrome/browser/tabs/tab_strip_model_order_controller.h"
#include "chrome/browser/tab_contents/navigation_controller.h"
#include "chrome/browser/tab_contents/tab_contents.h"
@@ -422,6 +423,8 @@ bool TabStripModel::IsContextMenuCommandEnabled(
}
case CommandDuplicate:
return delegate_->CanDuplicateContentsAt(context_index);
+ case CommandRestoreTab:
+ return delegate_->CanRestoreTab();
default:
NOTREACHED();
}
@@ -475,6 +478,11 @@ void TabStripModel::ExecuteContextMenuCommand(
break;
}
+ case CommandRestoreTab: {
+ UserMetrics::RecordAction(L"TabContextMenu_RestoreTab", profile_);
+ delegate_->RestoreTab();
+ break;
+ }
default:
NOTREACHED();
}
diff --git a/chrome/browser/tabs/tab_strip_model.h b/chrome/browser/tabs/tab_strip_model.h
index 3386954..5530f8b 100644
--- a/chrome/browser/tabs/tab_strip_model.h
+++ b/chrome/browser/tabs/tab_strip_model.h
@@ -165,6 +165,12 @@ class TabStripModelDelegate {
// TabContents. If it returns false, there are no unload listeners and the
// TabStripModel can close the TabContents immediately.
virtual bool RunUnloadListenerBeforeClosing(TabContents* contents) = 0;
+
+ // Returns true if a tab can be restored.
+ virtual bool CanRestoreTab() = 0;
+
+ // Restores the last closed tab if CanRestoreTab would return true.
+ virtual void RestoreTab() = 0;
};
////////////////////////////////////////////////////////////////////////////////
@@ -403,6 +409,7 @@ class TabStripModel : public NotificationObserver {
CommandCloseOtherTabs,
CommandCloseTabsToRight,
CommandCloseTabsOpenedBy,
+ CommandRestoreTab,
CommandLast
};
diff --git a/chrome/browser/tabs/tab_strip_model_unittest.cc b/chrome/browser/tabs/tab_strip_model_unittest.cc
index 2ff6db6..056ff5f 100644
--- a/chrome/browser/tabs/tab_strip_model_unittest.cc
+++ b/chrome/browser/tabs/tab_strip_model_unittest.cc
@@ -54,6 +54,8 @@ class TabStripDummyDelegate : public TabStripModelDelegate {
virtual bool RunUnloadListenerBeforeClosing(TabContents* contents) {
return false;
}
+ virtual bool CanRestoreTab() { return false; }
+ virtual void RestoreTab() {}
private:
// A dummy TabContents we give to callers that expect us to actually build a
diff --git a/chrome/browser/views/tabs/tab.cc b/chrome/browser/views/tabs/tab.cc
index 32d3839..55f6895 100644
--- a/chrome/browser/views/tabs/tab.cc
+++ b/chrome/browser/views/tabs/tab.cc
@@ -47,6 +47,8 @@ class Tab::ContextMenuController : public views::MenuDelegate {
menu_->AppendMenuItemWithLabel(
TabStripModel::CommandCloseTabsOpenedBy,
l10n_util::GetString(IDS_TAB_CXMENU_CLOSETABSOPENEDBY));
+ menu_->AppendMenuItemWithLabel(
+ TabStripModel::CommandRestoreTab, l10n_util::GetString(IDS_RESTORE_TAB));
}
void RunMenuAt(int x, int y) {