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

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

Issue 2355233002: Revert "MD History: promote menu button to show clear browsing data in narrow mode" (Closed)
Patch Set: 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"
9 #include "base/command_line.h" 7 #include "base/command_line.h"
10 #include "build/build_config.h" 8 #include "build/build_config.h"
11 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/signin/signin_manager_factory.h" 10 #include "chrome/browser/signin/signin_manager_factory.h"
13 #include "chrome/browser/ui/webui/browsing_history_handler.h" 11 #include "chrome/browser/ui/webui/browsing_history_handler.h"
14 #include "chrome/browser/ui/webui/foreign_session_handler.h" 12 #include "chrome/browser/ui/webui/foreign_session_handler.h"
15 #include "chrome/browser/ui/webui/history_login_handler.h" 13 #include "chrome/browser/ui/webui/history_login_handler.h"
16 #include "chrome/browser/ui/webui/metrics_handler.h" 14 #include "chrome/browser/ui/webui/metrics_handler.h"
17 #include "chrome/common/chrome_features.h" 15 #include "chrome/common/chrome_features.h"
18 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
20 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
21 #include "chrome/grit/browser_resources.h" 19 #include "chrome/grit/browser_resources.h"
22 #include "chrome/grit/generated_resources.h" 20 #include "chrome/grit/generated_resources.h"
23 #include "chrome/grit/locale_settings.h" 21 #include "chrome/grit/locale_settings.h"
24 #include "chrome/grit/theme_resources.h" 22 #include "chrome/grit/theme_resources.h"
25 #include "components/grit/components_scaled_resources.h" 23 #include "components/grit/components_scaled_resources.h"
26 #include "components/pref_registry/pref_registry_syncable.h"
27 #include "components/prefs/pref_service.h" 24 #include "components/prefs/pref_service.h"
28 #include "components/search/search.h" 25 #include "components/search/search.h"
29 #include "components/signin/core/browser/signin_manager.h" 26 #include "components/signin/core/browser/signin_manager.h"
30 #include "components/strings/grit/components_strings.h" 27 #include "components/strings/grit/components_strings.h"
31 #include "content/public/browser/web_ui.h" 28 #include "content/public/browser/web_ui.h"
32 #include "content/public/browser/web_ui_data_source.h" 29 #include "content/public/browser/web_ui_data_source.h"
33 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
34 #include "ui/base/resource/resource_bundle.h" 31 #include "ui/base/resource/resource_bundle.h"
35 32
36 namespace { 33 namespace {
37 34
38 content::WebUIDataSource* CreateMdHistoryUIHTMLSource(Profile* profile) { 35 content::WebUIDataSource* CreateMdHistoryUIHTMLSource(Profile* profile) {
36 PrefService* prefs = profile->GetPrefs();
37
39 content::WebUIDataSource* source = 38 content::WebUIDataSource* source =
40 content::WebUIDataSource::Create(chrome::kChromeUIHistoryHost); 39 content::WebUIDataSource::Create(chrome::kChromeUIHistoryHost);
41 40
42 // Localized strings (alphabetical order). 41 // Localized strings (alphabetical order).
43 source->AddLocalizedString("bookmarked", IDS_HISTORY_ENTRY_BOOKMARKED); 42 source->AddLocalizedString("bookmarked", IDS_HISTORY_ENTRY_BOOKMARKED);
44 source->AddLocalizedString("cancel", IDS_CANCEL); 43 source->AddLocalizedString("cancel", IDS_CANCEL);
45 source->AddLocalizedString("clearBrowsingData", 44 source->AddLocalizedString("clearBrowsingData",
46 IDS_CLEAR_BROWSING_DATA_TITLE); 45 IDS_CLEAR_BROWSING_DATA_TITLE);
47 source->AddLocalizedString("clearSearch", IDS_MD_HISTORY_CLEAR_SEARCH); 46 source->AddLocalizedString("clearSearch", IDS_MD_HISTORY_CLEAR_SEARCH);
48 source->AddLocalizedString("closeMenuPromo", IDS_MD_HISTORY_CLOSE_MENU_PROMO);
49 source->AddLocalizedString("collapseSessionButton", 47 source->AddLocalizedString("collapseSessionButton",
50 IDS_HISTORY_OTHER_SESSIONS_COLLAPSE_SESSION); 48 IDS_HISTORY_OTHER_SESSIONS_COLLAPSE_SESSION);
51 source->AddLocalizedString("delete", IDS_MD_HISTORY_DELETE); 49 source->AddLocalizedString("delete", IDS_MD_HISTORY_DELETE);
52 source->AddLocalizedString("deleteConfirm", 50 source->AddLocalizedString("deleteConfirm",
53 IDS_HISTORY_DELETE_PRIOR_VISITS_CONFIRM_BUTTON); 51 IDS_HISTORY_DELETE_PRIOR_VISITS_CONFIRM_BUTTON);
54 source->AddLocalizedString("deleteSession", 52 source->AddLocalizedString("deleteSession",
55 IDS_HISTORY_OTHER_SESSIONS_HIDE_FOR_NOW); 53 IDS_HISTORY_OTHER_SESSIONS_HIDE_FOR_NOW);
56 source->AddLocalizedString( 54 source->AddLocalizedString(
57 "deleteWarning", IDS_HISTORY_DELETE_PRIOR_VISITS_WARNING_NO_INCOGNITO); 55 "deleteWarning", IDS_HISTORY_DELETE_PRIOR_VISITS_WARNING_NO_INCOGNITO);
58 source->AddLocalizedString("entrySummary", IDS_HISTORY_ENTRY_SUMMARY); 56 source->AddLocalizedString("entrySummary", IDS_HISTORY_ENTRY_SUMMARY);
59 source->AddLocalizedString("expandSessionButton", 57 source->AddLocalizedString("expandSessionButton",
60 IDS_HISTORY_OTHER_SESSIONS_EXPAND_SESSION); 58 IDS_HISTORY_OTHER_SESSIONS_EXPAND_SESSION);
61 source->AddLocalizedString("foundSearchResults", 59 source->AddLocalizedString("foundSearchResults",
62 IDS_HISTORY_FOUND_SEARCH_RESULTS); 60 IDS_HISTORY_FOUND_SEARCH_RESULTS);
63 source->AddLocalizedString("hasSyncedResults", 61 source->AddLocalizedString("hasSyncedResults",
64 IDS_MD_HISTORY_HAS_SYNCED_RESULTS); 62 IDS_MD_HISTORY_HAS_SYNCED_RESULTS);
65 source->AddLocalizedString("hasSyncedResultsDescription", 63 source->AddLocalizedString("hasSyncedResultsDescription",
66 IDS_MD_HISTORY_HAS_SYNCED_RESULTS_DESCRIPTION); 64 IDS_MD_HISTORY_HAS_SYNCED_RESULTS_DESCRIPTION);
67 source->AddLocalizedString("historyInterval", IDS_HISTORY_INTERVAL); 65 source->AddLocalizedString("historyInterval", IDS_HISTORY_INTERVAL);
68 source->AddLocalizedString("historyMenuButton", 66 source->AddLocalizedString("historyMenuButton",
69 IDS_MD_HISTORY_HISTORY_MENU_DESCRIPTION); 67 IDS_MD_HISTORY_HISTORY_MENU_DESCRIPTION);
70 source->AddLocalizedString("historyMenuItem", 68 source->AddLocalizedString("historyMenuItem",
71 IDS_MD_HISTORY_HISTORY_MENU_ITEM); 69 IDS_MD_HISTORY_HISTORY_MENU_ITEM);
72 source->AddLocalizedString("itemsSelected", IDS_MD_HISTORY_ITEMS_SELECTED); 70 source->AddLocalizedString("itemsSelected", IDS_MD_HISTORY_ITEMS_SELECTED);
73 source->AddLocalizedString("loading", IDS_HISTORY_LOADING); 71 source->AddLocalizedString("loading", IDS_HISTORY_LOADING);
74 source->AddLocalizedString("menuPromo", IDS_MD_HISTORY_MENU_PROMO);
75 source->AddLocalizedString("moreActionsButton", 72 source->AddLocalizedString("moreActionsButton",
76 IDS_HISTORY_ACTION_MENU_DESCRIPTION); 73 IDS_HISTORY_ACTION_MENU_DESCRIPTION);
77 source->AddLocalizedString("moreFromSite", IDS_HISTORY_MORE_FROM_SITE); 74 source->AddLocalizedString("moreFromSite", IDS_HISTORY_MORE_FROM_SITE);
78 source->AddLocalizedString("openAll", IDS_HISTORY_OTHER_SESSIONS_OPEN_ALL); 75 source->AddLocalizedString("openAll", IDS_HISTORY_OTHER_SESSIONS_OPEN_ALL);
79 source->AddLocalizedString("openTabsMenuItem", 76 source->AddLocalizedString("openTabsMenuItem",
80 IDS_MD_HISTORY_OPEN_TABS_MENU_ITEM); 77 IDS_MD_HISTORY_OPEN_TABS_MENU_ITEM);
81 source->AddLocalizedString("noResults", IDS_HISTORY_NO_RESULTS); 78 source->AddLocalizedString("noResults", IDS_HISTORY_NO_RESULTS);
82 source->AddLocalizedString("noSearchResults", IDS_HISTORY_NO_SEARCH_RESULTS); 79 source->AddLocalizedString("noSearchResults", IDS_HISTORY_NO_SEARCH_RESULTS);
83 source->AddLocalizedString("noSyncedResults", 80 source->AddLocalizedString("noSyncedResults",
84 IDS_MD_HISTORY_NO_SYNCED_RESULTS); 81 IDS_MD_HISTORY_NO_SYNCED_RESULTS);
(...skipping 16 matching lines...) Expand all
101 IDS_MD_HISTORY_SIGN_IN_PROMO_DESC); 98 IDS_MD_HISTORY_SIGN_IN_PROMO_DESC);
102 source->AddLocalizedString("title", IDS_HISTORY_TITLE); 99 source->AddLocalizedString("title", IDS_HISTORY_TITLE);
103 100
104 source->AddString( 101 source->AddString(
105 "sidebarFooter", 102 "sidebarFooter",
106 l10n_util::GetStringFUTF16( 103 l10n_util::GetStringFUTF16(
107 IDS_HISTORY_OTHER_FORMS_OF_HISTORY, 104 IDS_HISTORY_OTHER_FORMS_OF_HISTORY,
108 l10n_util::GetStringUTF16( 105 l10n_util::GetStringUTF16(
109 IDS_SETTINGS_CLEAR_DATA_WEB_HISTORY_URL_IN_HISTORY))); 106 IDS_SETTINGS_CLEAR_DATA_WEB_HISTORY_URL_IN_HISTORY)));
110 107
111 PrefService* prefs = profile->GetPrefs();
112 bool allow_deleting_history = 108 bool allow_deleting_history =
113 prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory); 109 prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory);
114 source->AddBoolean("allowDeletingHistory", allow_deleting_history); 110 source->AddBoolean("allowDeletingHistory", allow_deleting_history);
115 111
116 source->AddBoolean("showMenuPromo",
117 !prefs->GetBoolean(prefs::kMdHistoryMenuPromoShown));
118
119 bool group_by_domain = base::CommandLine::ForCurrentProcess()->HasSwitch( 112 bool group_by_domain = base::CommandLine::ForCurrentProcess()->HasSwitch(
120 switches::kHistoryEnableGroupByDomain) || profile->IsSupervised(); 113 switches::kHistoryEnableGroupByDomain) || profile->IsSupervised();
121 source->AddBoolean("groupByDomain", group_by_domain); 114 source->AddBoolean("groupByDomain", group_by_domain);
122 115
123 source->AddBoolean("isGuestSession", profile->IsGuestSession()); 116 source->AddBoolean("isGuestSession", profile->IsGuestSession());
124 117
125 SigninManagerBase* signin_manager = 118 SigninManagerBase* signin_manager =
126 SigninManagerFactory::GetForProfile(profile); 119 SigninManagerFactory::GetForProfile(profile);
127 bool is_authenticated = signin_manager != nullptr && 120 bool is_authenticated = signin_manager != nullptr &&
128 signin_manager->IsAuthenticated(); 121 signin_manager->IsAuthenticated();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 MdHistoryUI::MdHistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { 194 MdHistoryUI::MdHistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) {
202 Profile* profile = Profile::FromWebUI(web_ui); 195 Profile* profile = Profile::FromWebUI(web_ui);
203 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); 196 web_ui->AddMessageHandler(new BrowsingHistoryHandler());
204 web_ui->AddMessageHandler(new MetricsHandler()); 197 web_ui->AddMessageHandler(new MetricsHandler());
205 198
206 if (search::IsInstantExtendedAPIEnabled()) { 199 if (search::IsInstantExtendedAPIEnabled()) {
207 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); 200 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler());
208 web_ui->AddMessageHandler(new HistoryLoginHandler()); 201 web_ui->AddMessageHandler(new HistoryLoginHandler());
209 } 202 }
210 203
211 data_source_ = CreateMdHistoryUIHTMLSource(profile); 204 content::WebUIDataSource::Add(profile, CreateMdHistoryUIHTMLSource(profile));
212 content::WebUIDataSource::Add(profile, data_source_);
213
214 web_ui->RegisterMessageCallback("menuPromoShown",
215 base::Bind(&MdHistoryUI::HandleMenuPromoShown, base::Unretained(this)));
216 } 205 }
217 206
218 MdHistoryUI::~MdHistoryUI() {} 207 MdHistoryUI::~MdHistoryUI() {}
219 208
220 // static 209 // static
221 bool MdHistoryUI::IsEnabled(Profile* profile) { 210 bool MdHistoryUI::IsEnabled(Profile* profile) {
222 return base::FeatureList::IsEnabled(features::kMaterialDesignHistory) && 211 return base::FeatureList::IsEnabled(features::kMaterialDesignHistory) &&
223 !base::CommandLine::ForCurrentProcess()->HasSwitch( 212 !base::CommandLine::ForCurrentProcess()->HasSwitch(
224 switches::kHistoryEnableGroupByDomain) && 213 switches::kHistoryEnableGroupByDomain) &&
225 !profile->IsSupervised(); 214 !profile->IsSupervised();
226 } 215 }
227 216
228 // static 217 // static
229 void MdHistoryUI::SetEnabledForTesting(bool enabled) { 218 void MdHistoryUI::SetEnabledForTesting(bool enabled) {
230 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); 219 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
231 220
232 const std::string& name = features::kMaterialDesignHistory.name; 221 const std::string& name = features::kMaterialDesignHistory.name;
233 feature_list->InitializeFromCommandLine(enabled ? name : "", 222 feature_list->InitializeFromCommandLine(enabled ? name : "",
234 enabled ? "" : name); 223 enabled ? "" : name);
235 base::FeatureList::ClearInstanceForTesting(); 224 base::FeatureList::ClearInstanceForTesting();
236 base::FeatureList::SetInstance(std::move(feature_list)); 225 base::FeatureList::SetInstance(std::move(feature_list));
237 } 226 }
238 227
239 // static 228 // static
240 base::RefCountedMemory* MdHistoryUI::GetFaviconResourceBytes( 229 base::RefCountedMemory* MdHistoryUI::GetFaviconResourceBytes(
241 ui::ScaleFactor scale_factor) { 230 ui::ScaleFactor scale_factor) {
242 return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( 231 return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
243 IDR_HISTORY_FAVICON, scale_factor); 232 IDR_HISTORY_FAVICON, scale_factor);
244 } 233 }
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