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

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: damn it Created 4 years, 2 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
« no previous file with comments | « chrome/browser/ui/webui/md_history_ui.h ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
48 source->AddLocalizedString("closeMenuPromo", IDS_MD_HISTORY_CLOSE_MENU_PROMO);
47 source->AddLocalizedString("collapseSessionButton", 49 source->AddLocalizedString("collapseSessionButton",
48 IDS_HISTORY_OTHER_SESSIONS_COLLAPSE_SESSION); 50 IDS_HISTORY_OTHER_SESSIONS_COLLAPSE_SESSION);
49 source->AddLocalizedString("delete", IDS_MD_HISTORY_DELETE); 51 source->AddLocalizedString("delete", IDS_MD_HISTORY_DELETE);
50 source->AddLocalizedString("deleteConfirm", 52 source->AddLocalizedString("deleteConfirm",
51 IDS_HISTORY_DELETE_PRIOR_VISITS_CONFIRM_BUTTON); 53 IDS_HISTORY_DELETE_PRIOR_VISITS_CONFIRM_BUTTON);
52 source->AddLocalizedString("deleteSession", 54 source->AddLocalizedString("deleteSession",
53 IDS_HISTORY_OTHER_SESSIONS_HIDE_FOR_NOW); 55 IDS_HISTORY_OTHER_SESSIONS_HIDE_FOR_NOW);
54 source->AddLocalizedString( 56 source->AddLocalizedString(
55 "deleteWarning", IDS_HISTORY_DELETE_PRIOR_VISITS_WARNING_NO_INCOGNITO); 57 "deleteWarning", IDS_HISTORY_DELETE_PRIOR_VISITS_WARNING_NO_INCOGNITO);
56 source->AddLocalizedString("entrySummary", IDS_HISTORY_ENTRY_SUMMARY); 58 source->AddLocalizedString("entrySummary", IDS_HISTORY_ENTRY_SUMMARY);
57 source->AddLocalizedString("expandSessionButton", 59 source->AddLocalizedString("expandSessionButton",
58 IDS_HISTORY_OTHER_SESSIONS_EXPAND_SESSION); 60 IDS_HISTORY_OTHER_SESSIONS_EXPAND_SESSION);
59 source->AddLocalizedString("foundSearchResults", 61 source->AddLocalizedString("foundSearchResults",
60 IDS_HISTORY_FOUND_SEARCH_RESULTS); 62 IDS_HISTORY_FOUND_SEARCH_RESULTS);
61 source->AddLocalizedString("hasSyncedResults", 63 source->AddLocalizedString("hasSyncedResults",
62 IDS_MD_HISTORY_HAS_SYNCED_RESULTS); 64 IDS_MD_HISTORY_HAS_SYNCED_RESULTS);
63 source->AddLocalizedString("hasSyncedResultsDescription", 65 source->AddLocalizedString("hasSyncedResultsDescription",
64 IDS_MD_HISTORY_HAS_SYNCED_RESULTS_DESCRIPTION); 66 IDS_MD_HISTORY_HAS_SYNCED_RESULTS_DESCRIPTION);
65 source->AddLocalizedString("historyInterval", IDS_HISTORY_INTERVAL); 67 source->AddLocalizedString("historyInterval", IDS_HISTORY_INTERVAL);
66 source->AddLocalizedString("historyMenuButton", 68 source->AddLocalizedString("historyMenuButton",
67 IDS_MD_HISTORY_HISTORY_MENU_DESCRIPTION); 69 IDS_MD_HISTORY_HISTORY_MENU_DESCRIPTION);
68 source->AddLocalizedString("historyMenuItem", 70 source->AddLocalizedString("historyMenuItem",
69 IDS_MD_HISTORY_HISTORY_MENU_ITEM); 71 IDS_MD_HISTORY_HISTORY_MENU_ITEM);
70 source->AddLocalizedString("itemsSelected", IDS_MD_HISTORY_ITEMS_SELECTED); 72 source->AddLocalizedString("itemsSelected", IDS_MD_HISTORY_ITEMS_SELECTED);
71 source->AddLocalizedString("loading", IDS_HISTORY_LOADING); 73 source->AddLocalizedString("loading", IDS_HISTORY_LOADING);
74 source->AddLocalizedString("menuPromo", IDS_MD_HISTORY_MENU_PROMO);
72 source->AddLocalizedString("moreActionsButton", 75 source->AddLocalizedString("moreActionsButton",
73 IDS_HISTORY_ACTION_MENU_DESCRIPTION); 76 IDS_HISTORY_ACTION_MENU_DESCRIPTION);
74 source->AddLocalizedString("moreFromSite", IDS_HISTORY_MORE_FROM_SITE); 77 source->AddLocalizedString("moreFromSite", IDS_HISTORY_MORE_FROM_SITE);
75 source->AddLocalizedString("openAll", IDS_HISTORY_OTHER_SESSIONS_OPEN_ALL); 78 source->AddLocalizedString("openAll", IDS_HISTORY_OTHER_SESSIONS_OPEN_ALL);
76 source->AddLocalizedString("openTabsMenuItem", 79 source->AddLocalizedString("openTabsMenuItem",
77 IDS_MD_HISTORY_OPEN_TABS_MENU_ITEM); 80 IDS_MD_HISTORY_OPEN_TABS_MENU_ITEM);
78 source->AddLocalizedString("noResults", IDS_HISTORY_NO_RESULTS); 81 source->AddLocalizedString("noResults", IDS_HISTORY_NO_RESULTS);
79 source->AddLocalizedString("noSearchResults", IDS_HISTORY_NO_SEARCH_RESULTS); 82 source->AddLocalizedString("noSearchResults", IDS_HISTORY_NO_SEARCH_RESULTS);
80 source->AddLocalizedString("noSyncedResults", 83 source->AddLocalizedString("noSyncedResults",
81 IDS_MD_HISTORY_NO_SYNCED_RESULTS); 84 IDS_MD_HISTORY_NO_SYNCED_RESULTS);
(...skipping 16 matching lines...) Expand all
98 IDS_MD_HISTORY_SIGN_IN_PROMO_DESC); 101 IDS_MD_HISTORY_SIGN_IN_PROMO_DESC);
99 source->AddLocalizedString("title", IDS_HISTORY_TITLE); 102 source->AddLocalizedString("title", IDS_HISTORY_TITLE);
100 103
101 source->AddString( 104 source->AddString(
102 "sidebarFooter", 105 "sidebarFooter",
103 l10n_util::GetStringFUTF16( 106 l10n_util::GetStringFUTF16(
104 IDS_HISTORY_OTHER_FORMS_OF_HISTORY, 107 IDS_HISTORY_OTHER_FORMS_OF_HISTORY,
105 l10n_util::GetStringUTF16( 108 l10n_util::GetStringUTF16(
106 IDS_SETTINGS_CLEAR_DATA_WEB_HISTORY_URL_IN_HISTORY))); 109 IDS_SETTINGS_CLEAR_DATA_WEB_HISTORY_URL_IN_HISTORY)));
107 110
111 PrefService* prefs = profile->GetPrefs();
108 bool allow_deleting_history = 112 bool allow_deleting_history =
109 prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory); 113 prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory);
110 source->AddBoolean("allowDeletingHistory", allow_deleting_history); 114 source->AddBoolean("allowDeletingHistory", allow_deleting_history);
111 115
116 source->AddBoolean("showMenuPromo",
117 !prefs->GetBoolean(prefs::kMdHistoryMenuPromoShown));
118
112 bool group_by_domain = base::CommandLine::ForCurrentProcess()->HasSwitch( 119 bool group_by_domain = base::CommandLine::ForCurrentProcess()->HasSwitch(
113 switches::kHistoryEnableGroupByDomain) || profile->IsSupervised(); 120 switches::kHistoryEnableGroupByDomain) || profile->IsSupervised();
114 source->AddBoolean("groupByDomain", group_by_domain); 121 source->AddBoolean("groupByDomain", group_by_domain);
115 122
116 source->AddBoolean("isGuestSession", profile->IsGuestSession()); 123 source->AddBoolean("isGuestSession", profile->IsGuestSession());
117 124
118 SigninManagerBase* signin_manager = 125 SigninManagerBase* signin_manager =
119 SigninManagerFactory::GetForProfile(profile); 126 SigninManagerFactory::GetForProfile(profile);
120 bool is_authenticated = signin_manager != nullptr && 127 bool is_authenticated = signin_manager != nullptr &&
121 signin_manager->IsAuthenticated(); 128 signin_manager->IsAuthenticated();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 MdHistoryUI::MdHistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { 201 MdHistoryUI::MdHistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) {
195 Profile* profile = Profile::FromWebUI(web_ui); 202 Profile* profile = Profile::FromWebUI(web_ui);
196 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); 203 web_ui->AddMessageHandler(new BrowsingHistoryHandler());
197 web_ui->AddMessageHandler(new MetricsHandler()); 204 web_ui->AddMessageHandler(new MetricsHandler());
198 205
199 if (search::IsInstantExtendedAPIEnabled()) { 206 if (search::IsInstantExtendedAPIEnabled()) {
200 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); 207 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler());
201 web_ui->AddMessageHandler(new HistoryLoginHandler()); 208 web_ui->AddMessageHandler(new HistoryLoginHandler());
202 } 209 }
203 210
204 content::WebUIDataSource::Add(profile, CreateMdHistoryUIHTMLSource(profile)); 211 data_source_ = CreateMdHistoryUIHTMLSource(profile);
212 content::WebUIDataSource::Add(profile, data_source_);
213
214 web_ui->RegisterMessageCallback("menuPromoShown",
215 base::Bind(&MdHistoryUI::HandleMenuPromoShown, 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,
249 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
250 }
251
252 void MdHistoryUI::HandleMenuPromoShown(const base::ListValue* args) {
253 Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean(
254 prefs::kMdHistoryMenuPromoShown, true);
255 data_source_->AddBoolean("showMenuPromo", false);
256 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/md_history_ui.h ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698