summaryrefslogtreecommitdiffstats
path: root/chrome/browser/dom_ui
diff options
context:
space:
mode:
authorsky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-25 22:45:39 +0000
committersky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-25 22:45:39 +0000
commitd8375fdbe8d32ad3562152ecd53378383e393971 (patch)
tree8c8f3e524fb5e600095368e982e5730916259453 /chrome/browser/dom_ui
parentec9f22cd4e7151ab3c3eb6ba47885bd75d342ae3 (diff)
downloadchromium_src-d8375fdbe8d32ad3562152ecd53378383e393971.zip
chromium_src-d8375fdbe8d32ad3562152ecd53378383e393971.tar.gz
chromium_src-d8375fdbe8d32ad3562152ecd53378383e393971.tar.bz2
Changes tab restore service to handle restoring closed windows as a
single unit. Sadly I've written another ui test. Lets hope it isn't flakey. Glen is going to change the NTP to deal with this appropriately. BUG=4686 TEST=Try closing a window (with more than one window open), hitting control-shift-t, and make sure the window and all it's tabs comes back. Review URL: http://codereview.chromium.org/11377 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6003 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r--chrome/browser/dom_ui/new_tab_ui.cc98
-rw-r--r--chrome/browser/dom_ui/new_tab_ui.h10
2 files changed, 75 insertions, 33 deletions
diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc
index 729c9dc..5a87b2d 100644
--- a/chrome/browser/dom_ui/new_tab_ui.cc
+++ b/chrome/browser/dom_ui/new_tab_ui.cc
@@ -644,20 +644,10 @@ void RecentlyClosedTabsHandler::HandleReopenTab(const Value* content) {
std::wstring wstring_value;
if (string_value->GetAsString(&wstring_value)) {
int session_to_restore = _wtoi(wstring_value.c_str());
-
- const TabRestoreService::Tabs& tabs = tab_restore_service_->tabs();
- for (TabRestoreService::Tabs::const_iterator it = tabs.begin();
- it != tabs.end(); ++it) {
- if (it->id == session_to_restore) {
- TabRestoreService* tab_restore_service = tab_restore_service_;
- browser->ReplaceRestoredTab(
- it->navigations, it->current_navigation_index);
- tab_restore_service->RemoveHistoricalTabById(session_to_restore);
- // The current tab has been nuked at this point;
- // don't touch any member variables.
- break;
- }
- }
+ tab_restore_service_->RestoreEntryById(browser, session_to_restore,
+ true);
+ // The current tab has been nuked at this point; don't touch any member
+ // variables.
}
}
}
@@ -680,28 +670,28 @@ void RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs(
void RecentlyClosedTabsHandler::TabRestoreServiceChanged(
TabRestoreService* service) {
- const TabRestoreService::Tabs& tabs = service->tabs();
+ const TabRestoreService::Entries& entries = service->entries();
ListValue list_value;
int added_count = 0;
- // We filter the list of recently closed to only show 'interesting' tabs,
- // where an interesting tab navigation is not the new tab ui.
- for (TabRestoreService::Tabs::const_iterator it = tabs.begin();
- it != tabs.end() && added_count < 3; ++it) {
- if (it->navigations.empty())
- continue;
-
- const TabNavigation& navigator =
- it->navigations.at(it->current_navigation_index);
- if (navigator.url == NewTabUIURL())
- continue;
-
- DictionaryValue* dictionary = new DictionaryValue;
- SetURLAndTitle(dictionary, navigator.title, navigator.url);
- dictionary->SetInteger(L"sessionId", it->id);
-
- list_value.Append(dictionary);
- added_count++;
+ // We filter the list of recently closed to only show 'interesting' entries,
+ // where an interesting entry is either a closed window or a closed tab
+ // whose selected navigation is not the new tab ui.
+ for (TabRestoreService::Entries::const_iterator it = entries.begin();
+ it != entries.end() && added_count < 3; ++it) {
+ TabRestoreService::Entry* entry = *it;
+ DictionaryValue* value = new DictionaryValue();
+ if ((entry->type == TabRestoreService::TAB &&
+ TabToValue(*static_cast<TabRestoreService::Tab*>(entry), value)) ||
+ (entry->type == TabRestoreService::WINDOW &&
+ WindowToValue(*static_cast<TabRestoreService::Window*>(entry),
+ value))) {
+ value->SetInteger(L"sessionId", entry->id);
+ list_value.Append(value);
+ added_count++;
+ } else {
+ delete value;
+ }
}
dom_ui_host_->CallJavascriptFunction(L"recentlyClosedTabs", list_value);
}
@@ -711,6 +701,48 @@ void RecentlyClosedTabsHandler::TabRestoreServiceDestroyed(
tab_restore_service_ = NULL;
}
+bool RecentlyClosedTabsHandler::TabToValue(
+ const TabRestoreService::Tab& tab,
+ DictionaryValue* dictionary) {
+ if (tab.navigations.empty())
+ return false;
+
+ const TabNavigation& current_navigation =
+ tab.navigations.at(tab.current_navigation_index);
+ if (current_navigation.url == NewTabUIURL())
+ return false;
+
+ SetURLAndTitle(dictionary, current_navigation.title, current_navigation.url);
+ dictionary->SetString(L"type", L"tab");
+ return true;
+}
+
+bool RecentlyClosedTabsHandler::WindowToValue(
+ const TabRestoreService::Window& window,
+ DictionaryValue* dictionary) {
+ if (window.tabs.empty()) {
+ NOTREACHED();
+ return false;
+ }
+
+ ListValue* tab_values = new ListValue();
+ for (size_t i = 0; i < window.tabs.size(); ++i) {
+ DictionaryValue* tab_value = new DictionaryValue();
+ if (TabToValue(window.tabs[i], tab_value))
+ tab_values->Append(tab_value);
+ else
+ delete tab_value;
+ }
+ if (tab_values->GetSize() == 0) {
+ delete tab_values;
+ return false;
+ }
+
+ dictionary->SetString(L"type", L"window");
+ dictionary->Set(L"tabs", tab_values);
+ return true;
+}
+
///////////////////////////////////////////////////////////////////////////////
// HistoryHandler
diff --git a/chrome/browser/dom_ui/new_tab_ui.h b/chrome/browser/dom_ui/new_tab_ui.h
index ed31cde..814e73a 100644
--- a/chrome/browser/dom_ui/new_tab_ui.h
+++ b/chrome/browser/dom_ui/new_tab_ui.h
@@ -263,6 +263,16 @@ class RecentlyClosedTabsHandler : public DOMMessageHandler,
virtual void TabRestoreServiceDestroyed(TabRestoreService* service);
private:
+ // Converts a closed tab to the value sent down to the NTP. Returns true on
+ // success, false if the value shouldn't be sent down.
+ bool TabToValue(const TabRestoreService::Tab& tab,
+ DictionaryValue* dictionary);
+
+ // Converts a closed window to the value sent down to the NTP. Returns true
+ // on success, false if the value shouldn't be sent down.
+ bool WindowToValue(const TabRestoreService::Window& window,
+ DictionaryValue* dictionary);
+
DOMUIHost* dom_ui_host_;
/// TabRestoreService that we are observing.