Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: trunk/src/chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.cc

Issue 264543002: Revert 267095 "Remove WebUI NTP on Android." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h" 5 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/sessions/tab_restore_service_delegate.h" 11 #include "chrome/browser/sessions/tab_restore_service_delegate.h"
12 #include "chrome/browser/sessions/tab_restore_service_factory.h" 12 #include "chrome/browser/sessions/tab_restore_service_factory.h"
13 #include "chrome/browser/ui/host_desktop.h" 13 #include "chrome/browser/ui/host_desktop.h"
14 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 14 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
15 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
16 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
17 #include "content/public/browser/web_contents_view.h" 17 #include "content/public/browser/web_contents_view.h"
18 #include "content/public/browser/web_ui.h" 18 #include "content/public/browser/web_ui.h"
19 #include "ui/base/webui/web_ui_util.h" 19 #include "ui/base/webui/web_ui_util.h"
20 20
21 #if defined(OS_ANDROID)
22 #include "chrome/browser/sessions/session_restore.h"
23 #endif
24
21 namespace { 25 namespace {
22 26
23 void TabToValue(const TabRestoreService::Tab& tab, 27 void TabToValue(const TabRestoreService::Tab& tab,
24 base::DictionaryValue* dictionary) { 28 base::DictionaryValue* dictionary) {
25 const sessions::SerializedNavigationEntry& current_navigation = 29 const sessions::SerializedNavigationEntry& current_navigation =
26 tab.navigations.at(tab.current_navigation_index); 30 tab.navigations.at(tab.current_navigation_index);
27 NewTabUI::SetUrlTitleAndDirection(dictionary, current_navigation.title(), 31 NewTabUI::SetUrlTitleAndDirection(dictionary, current_navigation.title(),
28 current_navigation.virtual_url()); 32 current_navigation.virtual_url());
29 dictionary->SetString("type", "tab"); 33 dictionary->SetString("type", "tab");
30 dictionary->SetDouble("timestamp", tab.timestamp.ToDoubleT()); 34 dictionary->SetDouble("timestamp", tab.timestamp.ToDoubleT());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 tab_restore_service_->RemoveObserver(this); 69 tab_restore_service_->RemoveObserver(this);
66 } 70 }
67 71
68 void RecentlyClosedTabsHandler::HandleReopenTab(const base::ListValue* args) { 72 void RecentlyClosedTabsHandler::HandleReopenTab(const base::ListValue* args) {
69 if (!tab_restore_service_) 73 if (!tab_restore_service_)
70 return; 74 return;
71 75
72 double session_to_restore = 0.0; 76 double session_to_restore = 0.0;
73 CHECK(args->GetDouble(0, &session_to_restore)); 77 CHECK(args->GetDouble(0, &session_to_restore));
74 78
79 #if defined(OS_ANDROID)
80 // Find and remove the corresponding tab entry from TabRestoreService.
81 // We take ownership of the returned tab.
82 scoped_ptr<TabRestoreService::Tab> tab_entry(
83 tab_restore_service_->RemoveTabEntryById(static_cast<int>(
84 session_to_restore)));
85 if (tab_entry.get() == NULL)
86 return;
87
88 // RestoreForeignSessionTab needs a SessionTab.
89 SessionTab session_tab;
90 session_tab.current_navigation_index = tab_entry->current_navigation_index;
91 session_tab.navigations = tab_entry->navigations;
92
93 SessionRestore::RestoreForeignSessionTab(web_ui()->GetWebContents(),
94 session_tab, NEW_FOREGROUND_TAB);
95 #else
75 double index = -1.0; 96 double index = -1.0;
76 CHECK(args->GetDouble(1, &index)); 97 CHECK(args->GetDouble(1, &index));
77 98
78 // There are actually less than 20 restore tab items displayed in the UI. 99 // There are actually less than 20 restore tab items displayed in the UI.
79 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SessionRestore", 100 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SessionRestore",
80 static_cast<int>(index), 20); 101 static_cast<int>(index), 20);
81 102
82 TabRestoreServiceDelegate* delegate = 103 TabRestoreServiceDelegate* delegate =
83 TabRestoreServiceDelegate::FindDelegateForWebContents( 104 TabRestoreServiceDelegate::FindDelegateForWebContents(
84 web_ui()->GetWebContents()); 105 web_ui()->GetWebContents());
85 if (!delegate) 106 if (!delegate)
86 return; 107 return;
87 chrome::HostDesktopType host_desktop_type = 108 chrome::HostDesktopType host_desktop_type =
88 chrome::GetHostDesktopTypeForNativeView( 109 chrome::GetHostDesktopTypeForNativeView(
89 web_ui()->GetWebContents()->GetView()->GetNativeView()); 110 web_ui()->GetWebContents()->GetView()->GetNativeView());
90 WindowOpenDisposition disposition = webui::GetDispositionFromClick(args, 2); 111 WindowOpenDisposition disposition = webui::GetDispositionFromClick(args, 2);
91 tab_restore_service_->RestoreEntryById(delegate, 112 tab_restore_service_->RestoreEntryById(delegate,
92 static_cast<int>(session_to_restore), 113 static_cast<int>(session_to_restore),
93 host_desktop_type, 114 host_desktop_type,
94 disposition); 115 disposition);
95 // The current tab has been nuked at this point; don't touch any member 116 // The current tab has been nuked at this point; don't touch any member
96 // variables. 117 // variables.
118 #endif
97 } 119 }
98 120
99 void RecentlyClosedTabsHandler::HandleClearRecentlyClosed( 121 void RecentlyClosedTabsHandler::HandleClearRecentlyClosed(
100 const base::ListValue* args) { 122 const base::ListValue* args) {
101 EnsureTabRestoreService(); 123 EnsureTabRestoreService();
102 if (tab_restore_service_) 124 if (tab_restore_service_)
103 tab_restore_service_->ClearEntries(); 125 tab_restore_service_->ClearEntries();
104 } 126 }
105 127
106 void RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs( 128 void RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs(
107 const base::ListValue* args) { 129 const base::ListValue* args) {
108 EnsureTabRestoreService(); 130 EnsureTabRestoreService();
109 if (tab_restore_service_) 131 if (tab_restore_service_)
110 TabRestoreServiceChanged(tab_restore_service_); 132 TabRestoreServiceChanged(tab_restore_service_);
111 } 133 }
112 134
113 void RecentlyClosedTabsHandler::TabRestoreServiceChanged( 135 void RecentlyClosedTabsHandler::TabRestoreServiceChanged(
114 TabRestoreService* service) { 136 TabRestoreService* service) {
115 base::ListValue list_value; 137 base::ListValue list_value;
116 const int max_count = 10; 138 const int max_count = 10;
117 int added_count = 0; 139 int added_count = 0;
118 // We filter the list of recently closed to only show 'interesting' entries, 140 // We filter the list of recently closed to only show 'interesting' entries,
119 // where an interesting entry is either a closed window or a closed tab 141 // where an interesting entry is either a closed window or a closed tab
120 // whose selected navigation is not the new tab ui. 142 // whose selected navigation is not the new tab ui.
121 for (TabRestoreService::Entries::const_iterator it = 143 for (TabRestoreService::Entries::const_iterator it =
122 service->entries().begin(); 144 service->entries().begin();
123 it != service->entries().end() && added_count < max_count; ++it) { 145 it != service->entries().end() && added_count < max_count; ++it) {
124 TabRestoreService::Entry* entry = *it; 146 TabRestoreService::Entry* entry = *it;
125 scoped_ptr<base::DictionaryValue> entry_dict(new base::DictionaryValue()); 147 scoped_ptr<base::DictionaryValue> entry_dict(new base::DictionaryValue());
(...skipping 28 matching lines...) Expand all
154 176
155 // TabRestoreServiceFactory::GetForProfile() can return NULL (i.e., when in 177 // TabRestoreServiceFactory::GetForProfile() can return NULL (i.e., when in
156 // Off the Record mode) 178 // Off the Record mode)
157 if (tab_restore_service_) { 179 if (tab_restore_service_) {
158 // This does nothing if the tabs have already been loaded or they 180 // This does nothing if the tabs have already been loaded or they
159 // shouldn't be loaded. 181 // shouldn't be loaded.
160 tab_restore_service_->LoadTabsFromLastSession(); 182 tab_restore_service_->LoadTabsFromLastSession();
161 tab_restore_service_->AddObserver(this); 183 tab_restore_service_->AddObserver(this);
162 } 184 }
163 } 185 }
OLDNEW
« no previous file with comments | « trunk/src/chrome/browser/ui/webui/ntp/ntp_resource_cache.h ('k') | trunk/src/chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698