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

Side by Side Diff: chrome/browser/ui/webui/md_history_ui.cc

Issue 2280513002: MD History: promote menu button to show clear browsing data in narrow mode (Closed)
Patch Set: !showingSearch_ Created 4 years, 3 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/md_history_ui.h" 5 #include "chrome/browser/ui/webui/md_history_ui.h"
6 6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
7 #include "base/command_line.h" 9 #include "base/command_line.h"
8 #include "build/build_config.h" 10 #include "build/build_config.h"
9 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/signin/signin_manager_factory.h" 12 #include "chrome/browser/signin/signin_manager_factory.h"
11 #include "chrome/browser/ui/webui/browsing_history_handler.h" 13 #include "chrome/browser/ui/webui/browsing_history_handler.h"
12 #include "chrome/browser/ui/webui/foreign_session_handler.h" 14 #include "chrome/browser/ui/webui/foreign_session_handler.h"
13 #include "chrome/browser/ui/webui/history_login_handler.h" 15 #include "chrome/browser/ui/webui/history_login_handler.h"
14 #include "chrome/browser/ui/webui/metrics_handler.h" 16 #include "chrome/browser/ui/webui/metrics_handler.h"
15 #include "chrome/common/chrome_features.h" 17 #include "chrome/common/chrome_features.h"
16 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
18 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
19 #include "chrome/grit/browser_resources.h" 21 #include "chrome/grit/browser_resources.h"
20 #include "chrome/grit/generated_resources.h" 22 #include "chrome/grit/generated_resources.h"
21 #include "chrome/grit/locale_settings.h" 23 #include "chrome/grit/locale_settings.h"
22 #include "chrome/grit/theme_resources.h" 24 #include "chrome/grit/theme_resources.h"
23 #include "components/grit/components_scaled_resources.h" 25 #include "components/grit/components_scaled_resources.h"
26 #include "components/pref_registry/pref_registry_syncable.h"
24 #include "components/prefs/pref_service.h" 27 #include "components/prefs/pref_service.h"
25 #include "components/search/search.h" 28 #include "components/search/search.h"
26 #include "components/signin/core/browser/signin_manager.h" 29 #include "components/signin/core/browser/signin_manager.h"
27 #include "components/strings/grit/components_strings.h" 30 #include "components/strings/grit/components_strings.h"
28 #include "content/public/browser/web_ui.h" 31 #include "content/public/browser/web_ui.h"
29 #include "content/public/browser/web_ui_data_source.h" 32 #include "content/public/browser/web_ui_data_source.h"
30 #include "ui/base/l10n/l10n_util.h" 33 #include "ui/base/l10n/l10n_util.h"
31 #include "ui/base/resource/resource_bundle.h" 34 #include "ui/base/resource/resource_bundle.h"
32 35
33 namespace { 36 namespace {
34 37
35 content::WebUIDataSource* CreateMdHistoryUIHTMLSource(Profile* profile) { 38 content::WebUIDataSource* CreateMdHistoryUIHTMLSource(Profile* profile) {
36 PrefService* prefs = profile->GetPrefs();
37
38 content::WebUIDataSource* source = 39 content::WebUIDataSource* source =
39 content::WebUIDataSource::Create(chrome::kChromeUIHistoryHost); 40 content::WebUIDataSource::Create(chrome::kChromeUIHistoryHost);
40 41
41 // Localized strings (alphabetical order). 42 // Localized strings (alphabetical order).
42 source->AddLocalizedString("bookmarked", IDS_HISTORY_ENTRY_BOOKMARKED); 43 source->AddLocalizedString("bookmarked", IDS_HISTORY_ENTRY_BOOKMARKED);
43 source->AddLocalizedString("cancel", IDS_CANCEL); 44 source->AddLocalizedString("cancel", IDS_CANCEL);
44 source->AddLocalizedString("clearBrowsingData", 45 source->AddLocalizedString("clearBrowsingData",
45 IDS_CLEAR_BROWSING_DATA_TITLE); 46 IDS_CLEAR_BROWSING_DATA_TITLE);
46 source->AddLocalizedString("clearSearch", IDS_MD_HISTORY_CLEAR_SEARCH); 47 source->AddLocalizedString("clearSearch", IDS_MD_HISTORY_CLEAR_SEARCH);
47 source->AddLocalizedString("collapseSessionButton", 48 source->AddLocalizedString("collapseSessionButton",
(...skipping 10 matching lines...) Expand all
58 IDS_HISTORY_OTHER_SESSIONS_EXPAND_SESSION); 59 IDS_HISTORY_OTHER_SESSIONS_EXPAND_SESSION);
59 source->AddLocalizedString("foundSearchResults", 60 source->AddLocalizedString("foundSearchResults",
60 IDS_HISTORY_FOUND_SEARCH_RESULTS); 61 IDS_HISTORY_FOUND_SEARCH_RESULTS);
61 source->AddLocalizedString("historyInterval", IDS_HISTORY_INTERVAL); 62 source->AddLocalizedString("historyInterval", IDS_HISTORY_INTERVAL);
62 source->AddLocalizedString("historyMenuButton", 63 source->AddLocalizedString("historyMenuButton",
63 IDS_MD_HISTORY_HISTORY_MENU_DESCRIPTION); 64 IDS_MD_HISTORY_HISTORY_MENU_DESCRIPTION);
64 source->AddLocalizedString("historyMenuItem", 65 source->AddLocalizedString("historyMenuItem",
65 IDS_MD_HISTORY_HISTORY_MENU_ITEM); 66 IDS_MD_HISTORY_HISTORY_MENU_ITEM);
66 source->AddLocalizedString("itemsSelected", IDS_MD_HISTORY_ITEMS_SELECTED); 67 source->AddLocalizedString("itemsSelected", IDS_MD_HISTORY_ITEMS_SELECTED);
67 source->AddLocalizedString("loading", IDS_HISTORY_LOADING); 68 source->AddLocalizedString("loading", IDS_HISTORY_LOADING);
69 source->AddLocalizedString("menuPromo", IDS_HISTORY_MENU_PROMO);
68 source->AddLocalizedString("moreActionsButton", 70 source->AddLocalizedString("moreActionsButton",
69 IDS_HISTORY_ACTION_MENU_DESCRIPTION); 71 IDS_HISTORY_ACTION_MENU_DESCRIPTION);
70 source->AddLocalizedString("moreFromSite", IDS_HISTORY_MORE_FROM_SITE); 72 source->AddLocalizedString("moreFromSite", IDS_HISTORY_MORE_FROM_SITE);
71 source->AddLocalizedString("openAll", IDS_HISTORY_OTHER_SESSIONS_OPEN_ALL); 73 source->AddLocalizedString("openAll", IDS_HISTORY_OTHER_SESSIONS_OPEN_ALL);
72 source->AddLocalizedString("openTabsMenuItem", 74 source->AddLocalizedString("openTabsMenuItem",
73 IDS_MD_HISTORY_OPEN_TABS_MENU_ITEM); 75 IDS_MD_HISTORY_OPEN_TABS_MENU_ITEM);
74 source->AddLocalizedString("noResults", IDS_HISTORY_NO_RESULTS); 76 source->AddLocalizedString("noResults", IDS_HISTORY_NO_RESULTS);
75 source->AddLocalizedString("noSearchResults", IDS_HISTORY_NO_SEARCH_RESULTS); 77 source->AddLocalizedString("noSearchResults", IDS_HISTORY_NO_SEARCH_RESULTS);
76 source->AddLocalizedString("noSyncedResults", 78 source->AddLocalizedString("noSyncedResults",
77 IDS_MD_HISTORY_NO_SYNCED_RESULTS); 79 IDS_MD_HISTORY_NO_SYNCED_RESULTS);
(...skipping 16 matching lines...) Expand all
94 IDS_MD_HISTORY_SIGN_IN_PROMO_DESC); 96 IDS_MD_HISTORY_SIGN_IN_PROMO_DESC);
95 source->AddLocalizedString("title", IDS_HISTORY_TITLE); 97 source->AddLocalizedString("title", IDS_HISTORY_TITLE);
96 98
97 source->AddString( 99 source->AddString(
98 "sidebarFooter", 100 "sidebarFooter",
99 l10n_util::GetStringFUTF16( 101 l10n_util::GetStringFUTF16(
100 IDS_HISTORY_OTHER_FORMS_OF_HISTORY, 102 IDS_HISTORY_OTHER_FORMS_OF_HISTORY,
101 l10n_util::GetStringUTF16( 103 l10n_util::GetStringUTF16(
102 IDS_SETTINGS_CLEAR_DATA_WEB_HISTORY_URL_IN_HISTORY))); 104 IDS_SETTINGS_CLEAR_DATA_WEB_HISTORY_URL_IN_HISTORY)));
103 105
106 PrefService* prefs = profile->GetPrefs();
104 bool allow_deleting_history = 107 bool allow_deleting_history =
105 prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory); 108 prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory);
106 source->AddBoolean("allowDeletingHistory", allow_deleting_history); 109 source->AddBoolean("allowDeletingHistory", allow_deleting_history);
107 110
111 source->AddBoolean("showMenuPromo",
112 !prefs->GetBoolean(prefs::kMdHistoryMenuPromoShown));
113
108 bool group_by_domain = base::CommandLine::ForCurrentProcess()->HasSwitch( 114 bool group_by_domain = base::CommandLine::ForCurrentProcess()->HasSwitch(
109 switches::kHistoryEnableGroupByDomain) || profile->IsSupervised(); 115 switches::kHistoryEnableGroupByDomain) || profile->IsSupervised();
110 source->AddBoolean("groupByDomain", group_by_domain); 116 source->AddBoolean("groupByDomain", group_by_domain);
111 117
112 source->AddBoolean("isGuestSession", profile->IsGuestSession()); 118 source->AddBoolean("isGuestSession", profile->IsGuestSession());
113 119
114 SigninManagerBase* signin_manager = 120 SigninManagerBase* signin_manager =
115 SigninManagerFactory::GetForProfile(profile); 121 SigninManagerFactory::GetForProfile(profile);
116 bool is_authenticated = signin_manager != nullptr && 122 bool is_authenticated = signin_manager != nullptr &&
117 signin_manager->IsAuthenticated(); 123 signin_manager->IsAuthenticated();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 MdHistoryUI::MdHistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { 200 MdHistoryUI::MdHistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) {
195 Profile* profile = Profile::FromWebUI(web_ui); 201 Profile* profile = Profile::FromWebUI(web_ui);
196 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); 202 web_ui->AddMessageHandler(new BrowsingHistoryHandler());
197 web_ui->AddMessageHandler(new MetricsHandler()); 203 web_ui->AddMessageHandler(new MetricsHandler());
198 204
199 if (search::IsInstantExtendedAPIEnabled()) { 205 if (search::IsInstantExtendedAPIEnabled()) {
200 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); 206 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler());
201 web_ui->AddMessageHandler(new HistoryLoginHandler()); 207 web_ui->AddMessageHandler(new HistoryLoginHandler());
202 } 208 }
203 209
204 content::WebUIDataSource::Add(profile, CreateMdHistoryUIHTMLSource(profile)); 210 data_source_ = CreateMdHistoryUIHTMLSource(profile);
211 content::WebUIDataSource::Add(profile, data_source_);
212
213 web_ui->RegisterMessageCallback("menuPromoShown",
214 base::Bind(&MdHistoryUI::HandleMenuPromoShown,
215 base::Unretained(this)));
205 } 216 }
206 217
207 MdHistoryUI::~MdHistoryUI() {} 218 MdHistoryUI::~MdHistoryUI() {}
208 219
209 // static 220 // static
210 bool MdHistoryUI::IsEnabled(Profile* profile) { 221 bool MdHistoryUI::IsEnabled(Profile* profile) {
211 return base::FeatureList::IsEnabled(features::kMaterialDesignHistory) && 222 return base::FeatureList::IsEnabled(features::kMaterialDesignHistory) &&
212 !base::CommandLine::ForCurrentProcess()->HasSwitch( 223 !base::CommandLine::ForCurrentProcess()->HasSwitch(
213 switches::kHistoryEnableGroupByDomain) && 224 switches::kHistoryEnableGroupByDomain) &&
214 !profile->IsSupervised(); 225 !profile->IsSupervised();
215 } 226 }
216 227
217 // static 228 // static
218 void MdHistoryUI::SetEnabledForTesting(bool enabled) { 229 void MdHistoryUI::SetEnabledForTesting(bool enabled) {
219 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); 230 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
220 231
221 const std::string& name = features::kMaterialDesignHistory.name; 232 const std::string& name = features::kMaterialDesignHistory.name;
222 feature_list->InitializeFromCommandLine(enabled ? name : "", 233 feature_list->InitializeFromCommandLine(enabled ? name : "",
223 enabled ? "" : name); 234 enabled ? "" : name);
224 base::FeatureList::ClearInstanceForTesting(); 235 base::FeatureList::ClearInstanceForTesting();
225 base::FeatureList::SetInstance(std::move(feature_list)); 236 base::FeatureList::SetInstance(std::move(feature_list));
226 } 237 }
227 238
228 // static 239 // static
229 base::RefCountedMemory* MdHistoryUI::GetFaviconResourceBytes( 240 base::RefCountedMemory* MdHistoryUI::GetFaviconResourceBytes(
230 ui::ScaleFactor scale_factor) { 241 ui::ScaleFactor scale_factor) {
231 return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( 242 return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
232 IDR_HISTORY_FAVICON, scale_factor); 243 IDR_HISTORY_FAVICON, scale_factor);
233 } 244 }
245
246 void MdHistoryUI::RegisterProfilePrefs(
247 user_prefs::PrefRegistrySyncable* registry) {
248 registry->RegisterBooleanPref(prefs::kMdHistoryMenuPromoShown, false);
tsergeant 2016/09/09 06:09:39 Naive question from someone not very familiar with
Dan Beam 2016/09/16 00:01:24 probably wouldn't have
249 }
250
251 void MdHistoryUI::HandleMenuPromoShown(const base::ListValue* args) {
252 Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean(
253 prefs::kMdHistoryMenuPromoShown, true);
254 data_source_->AddBoolean("showMenuPromo", false);
255 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698