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

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

Issue 2352553002: [MD History] Run MD History on chrome://chrome/history. (Closed)
Patch Set: 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
« no previous file with comments | « chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc ('k') | no next file » | 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/command_line.h" 7 #include "base/command_line.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/signin/signin_manager_factory.h" 10 #include "chrome/browser/signin/signin_manager_factory.h"
(...skipping 18 matching lines...) Expand all
29 #include "content/public/browser/web_ui_data_source.h" 29 #include "content/public/browser/web_ui_data_source.h"
30 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
31 #include "ui/base/resource/resource_bundle.h" 31 #include "ui/base/resource/resource_bundle.h"
32 32
33 namespace { 33 namespace {
34 34
35 content::WebUIDataSource* CreateMdHistoryUIHTMLSource(Profile* profile) { 35 content::WebUIDataSource* CreateMdHistoryUIHTMLSource(Profile* profile) {
36 PrefService* prefs = profile->GetPrefs(); 36 PrefService* prefs = profile->GetPrefs();
37 37
38 content::WebUIDataSource* source = 38 content::WebUIDataSource* source =
39 content::WebUIDataSource::Create(chrome::kChromeUIHistoryHost); 39 content::WebUIDataSource::Create(chrome::kChromeUIUberHost);
40 40
41 // Localized strings (alphabetical order). 41 // Localized strings (alphabetical order).
42 source->AddLocalizedString("bookmarked", IDS_HISTORY_ENTRY_BOOKMARKED); 42 source->AddLocalizedString("bookmarked", IDS_HISTORY_ENTRY_BOOKMARKED);
43 source->AddLocalizedString("cancel", IDS_CANCEL); 43 source->AddLocalizedString("cancel", IDS_CANCEL);
44 source->AddLocalizedString("clearBrowsingData", 44 source->AddLocalizedString("clearBrowsingData",
45 IDS_CLEAR_BROWSING_DATA_TITLE); 45 IDS_CLEAR_BROWSING_DATA_TITLE);
46 source->AddLocalizedString("clearSearch", IDS_MD_HISTORY_CLEAR_SEARCH); 46 source->AddLocalizedString("clearSearch", IDS_MD_HISTORY_CLEAR_SEARCH);
47 source->AddLocalizedString("collapseSessionButton", 47 source->AddLocalizedString("collapseSessionButton",
48 IDS_HISTORY_OTHER_SESSIONS_COLLAPSE_SESSION); 48 IDS_HISTORY_OTHER_SESSIONS_COLLAPSE_SESSION);
49 source->AddLocalizedString("delete", IDS_MD_HISTORY_DELETE); 49 source->AddLocalizedString("delete", IDS_MD_HISTORY_DELETE);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 l10n_util::GetStringFUTF16( 103 l10n_util::GetStringFUTF16(
104 IDS_HISTORY_OTHER_FORMS_OF_HISTORY, 104 IDS_HISTORY_OTHER_FORMS_OF_HISTORY,
105 l10n_util::GetStringUTF16( 105 l10n_util::GetStringUTF16(
106 IDS_SETTINGS_CLEAR_DATA_WEB_HISTORY_URL_IN_HISTORY))); 106 IDS_SETTINGS_CLEAR_DATA_WEB_HISTORY_URL_IN_HISTORY)));
107 107
108 bool allow_deleting_history = 108 bool allow_deleting_history =
109 prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory); 109 prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory);
110 source->AddBoolean("allowDeletingHistory", allow_deleting_history); 110 source->AddBoolean("allowDeletingHistory", allow_deleting_history);
111 111
112 bool group_by_domain = base::CommandLine::ForCurrentProcess()->HasSwitch( 112 bool group_by_domain = base::CommandLine::ForCurrentProcess()->HasSwitch(
113 switches::kHistoryEnableGroupByDomain) || profile->IsSupervised(); 113 switches::kHistoryEnableGroupByDomain) ||
114 profile->IsSupervised();
114 source->AddBoolean("groupByDomain", group_by_domain); 115 source->AddBoolean("groupByDomain", group_by_domain);
115 116
116 source->AddBoolean("isGuestSession", profile->IsGuestSession()); 117 source->AddBoolean("isGuestSession", profile->IsGuestSession());
117 118
118 SigninManagerBase* signin_manager = 119 SigninManagerBase* signin_manager =
119 SigninManagerFactory::GetForProfile(profile); 120 SigninManagerFactory::GetForProfile(profile);
120 bool is_authenticated = signin_manager != nullptr && 121 bool is_authenticated =
121 signin_manager->IsAuthenticated(); 122 signin_manager != nullptr && signin_manager->IsAuthenticated();
122 source->AddBoolean("isUserSignedIn", is_authenticated); 123 source->AddBoolean("isUserSignedIn", is_authenticated);
123 124
124 source->AddResourcePath("constants.html", IDR_MD_HISTORY_CONSTANTS_HTML); 125 source->AddResourcePath("history/constants.html",
125 source->AddResourcePath("constants.js", IDR_MD_HISTORY_CONSTANTS_JS); 126 IDR_MD_HISTORY_CONSTANTS_HTML);
126 source->AddResourcePath("images/100/sign_in_promo.png", 127 source->AddResourcePath("history/constants.js", IDR_MD_HISTORY_CONSTANTS_JS);
128 source->AddResourcePath("history/images/100/sign_in_promo.png",
127 IDR_MD_HISTORY_IMAGES_100_SIGN_IN_PROMO_PNG); 129 IDR_MD_HISTORY_IMAGES_100_SIGN_IN_PROMO_PNG);
128 source->AddResourcePath("images/200/sign_in_promo.png", 130 source->AddResourcePath("history/images/200/sign_in_promo.png",
129 IDR_MD_HISTORY_IMAGES_200_SIGN_IN_PROMO_PNG); 131 IDR_MD_HISTORY_IMAGES_200_SIGN_IN_PROMO_PNG);
130 source->AddResourcePath("history.js", IDR_MD_HISTORY_HISTORY_JS); 132 source->AddResourcePath("history/history.js", IDR_MD_HISTORY_HISTORY_JS);
131 133
132 #if BUILDFLAG(USE_VULCANIZE) 134 #if BUILDFLAG(USE_VULCANIZE)
133 source->AddResourcePath("app.html", 135 source->AddResourcePath("history/app.html",
134 IDR_MD_HISTORY_APP_VULCANIZED_HTML); 136 IDR_MD_HISTORY_APP_VULCANIZED_HTML);
135 source->AddResourcePath("app.crisper.js", 137 source->AddResourcePath("history/app.crisper.js",
136 IDR_MD_HISTORY_APP_CRISPER_JS); 138 IDR_MD_HISTORY_APP_CRISPER_JS);
137 #else 139 #else
138 source->AddResourcePath("app.html", IDR_MD_HISTORY_APP_HTML); 140 source->AddResourcePath("history/app.html", IDR_MD_HISTORY_APP_HTML);
139 source->AddResourcePath("app.js", IDR_MD_HISTORY_APP_JS); 141 source->AddResourcePath("history/app.js", IDR_MD_HISTORY_APP_JS);
140 source->AddResourcePath("browser_service.html", 142 source->AddResourcePath("history/browser_service.html",
141 IDR_MD_HISTORY_BROWSER_SERVICE_HTML); 143 IDR_MD_HISTORY_BROWSER_SERVICE_HTML);
142 source->AddResourcePath("browser_service.js", 144 source->AddResourcePath("history/browser_service.js",
143 IDR_MD_HISTORY_BROWSER_SERVICE_JS); 145 IDR_MD_HISTORY_BROWSER_SERVICE_JS);
144 source->AddResourcePath("grouped_list.html", 146 source->AddResourcePath("history/grouped_list.html",
145 IDR_MD_HISTORY_GROUPED_LIST_HTML); 147 IDR_MD_HISTORY_GROUPED_LIST_HTML);
146 source->AddResourcePath("grouped_list.js", IDR_MD_HISTORY_GROUPED_LIST_JS); 148 source->AddResourcePath("history/grouped_list.js",
147 source->AddResourcePath("history_item.html", 149 IDR_MD_HISTORY_GROUPED_LIST_JS);
150 source->AddResourcePath("history/history_item.html",
148 IDR_MD_HISTORY_HISTORY_ITEM_HTML); 151 IDR_MD_HISTORY_HISTORY_ITEM_HTML);
149 source->AddResourcePath("history_item.js", IDR_MD_HISTORY_HISTORY_ITEM_JS); 152 source->AddResourcePath("history/history_item.js",
150 source->AddResourcePath("history_list.html", 153 IDR_MD_HISTORY_HISTORY_ITEM_JS);
154 source->AddResourcePath("history/history_list.html",
151 IDR_MD_HISTORY_HISTORY_LIST_HTML); 155 IDR_MD_HISTORY_HISTORY_LIST_HTML);
152 source->AddResourcePath("history_list.js", IDR_MD_HISTORY_HISTORY_LIST_JS); 156 source->AddResourcePath("history/history_list.js",
153 source->AddResourcePath("history_list_behavior.html", 157 IDR_MD_HISTORY_HISTORY_LIST_JS);
158 source->AddResourcePath("history/history_list_behavior.html",
154 IDR_MD_HISTORY_HISTORY_LIST_BEHAVIOR_HTML); 159 IDR_MD_HISTORY_HISTORY_LIST_BEHAVIOR_HTML);
155 source->AddResourcePath("history_list_behavior.js", 160 source->AddResourcePath("history/history_list_behavior.js",
156 IDR_MD_HISTORY_HISTORY_LIST_BEHAVIOR_JS); 161 IDR_MD_HISTORY_HISTORY_LIST_BEHAVIOR_JS);
157 source->AddResourcePath("history_toolbar.html", 162 source->AddResourcePath("history/history_toolbar.html",
158 IDR_MD_HISTORY_HISTORY_TOOLBAR_HTML); 163 IDR_MD_HISTORY_HISTORY_TOOLBAR_HTML);
159 source->AddResourcePath("history_toolbar.js", 164 source->AddResourcePath("history/history_toolbar.js",
160 IDR_MD_HISTORY_HISTORY_TOOLBAR_JS); 165 IDR_MD_HISTORY_HISTORY_TOOLBAR_JS);
161 source->AddResourcePath("icons.html", IDR_MD_HISTORY_ICONS_HTML); 166 source->AddResourcePath("history/icons.html", IDR_MD_HISTORY_ICONS_HTML);
162 source->AddResourcePath("lazy_render.html", 167 source->AddResourcePath("history/lazy_render.html",
163 IDR_MD_HISTORY_LAZY_RENDER_HTML); 168 IDR_MD_HISTORY_LAZY_RENDER_HTML);
164 source->AddResourcePath("lazy_render.js", 169 source->AddResourcePath("history/lazy_render.js",
165 IDR_MD_HISTORY_LAZY_RENDER_JS); 170 IDR_MD_HISTORY_LAZY_RENDER_JS);
166 source->AddResourcePath("list_container.html", 171 source->AddResourcePath("history/list_container.html",
167 IDR_MD_HISTORY_LIST_CONTAINER_HTML); 172 IDR_MD_HISTORY_LIST_CONTAINER_HTML);
168 source->AddResourcePath("list_container.js", 173 source->AddResourcePath("history/list_container.js",
169 IDR_MD_HISTORY_LIST_CONTAINER_JS); 174 IDR_MD_HISTORY_LIST_CONTAINER_JS);
170 source->AddResourcePath("searched_label.html", 175 source->AddResourcePath("history/searched_label.html",
171 IDR_MD_HISTORY_SEARCHED_LABEL_HTML); 176 IDR_MD_HISTORY_SEARCHED_LABEL_HTML);
172 source->AddResourcePath("searched_label.js", 177 source->AddResourcePath("history/searched_label.js",
173 IDR_MD_HISTORY_SEARCHED_LABEL_JS); 178 IDR_MD_HISTORY_SEARCHED_LABEL_JS);
174 source->AddResourcePath("shared_style.html", 179 source->AddResourcePath("history/shared_style.html",
175 IDR_MD_HISTORY_SHARED_STYLE_HTML); 180 IDR_MD_HISTORY_SHARED_STYLE_HTML);
176 source->AddResourcePath("shared_vars.html", 181 source->AddResourcePath("history/shared_vars.html",
177 IDR_MD_HISTORY_SHARED_VARS_HTML); 182 IDR_MD_HISTORY_SHARED_VARS_HTML);
178 source->AddResourcePath("side_bar.html", IDR_MD_HISTORY_SIDE_BAR_HTML); 183 source->AddResourcePath("history/side_bar.html",
179 source->AddResourcePath("side_bar.js", IDR_MD_HISTORY_SIDE_BAR_JS); 184 IDR_MD_HISTORY_SIDE_BAR_HTML);
180 source->AddResourcePath("synced_device_card.html", 185 source->AddResourcePath("history/side_bar.js", IDR_MD_HISTORY_SIDE_BAR_JS);
186 source->AddResourcePath("history/synced_device_card.html",
181 IDR_MD_HISTORY_SYNCED_DEVICE_CARD_HTML); 187 IDR_MD_HISTORY_SYNCED_DEVICE_CARD_HTML);
182 source->AddResourcePath("synced_device_card.js", 188 source->AddResourcePath("history/synced_device_card.js",
183 IDR_MD_HISTORY_SYNCED_DEVICE_CARD_JS); 189 IDR_MD_HISTORY_SYNCED_DEVICE_CARD_JS);
184 source->AddResourcePath("synced_device_manager.html", 190 source->AddResourcePath("history/synced_device_manager.html",
185 IDR_MD_HISTORY_SYNCED_DEVICE_MANAGER_HTML); 191 IDR_MD_HISTORY_SYNCED_DEVICE_MANAGER_HTML);
186 source->AddResourcePath("synced_device_manager.js", 192 source->AddResourcePath("history/synced_device_manager.js",
187 IDR_MD_HISTORY_SYNCED_DEVICE_MANAGER_JS); 193 IDR_MD_HISTORY_SYNCED_DEVICE_MANAGER_JS);
188 #endif // BUILDFLAG(USE_VULCANIZE) 194 #endif // BUILDFLAG(USE_VULCANIZE)
189 195
190 source->SetDefaultResource(IDR_MD_HISTORY_HISTORY_HTML); 196 source->SetDefaultResource(IDR_MD_HISTORY_HISTORY_HTML);
191 source->SetJsonPath("strings.js"); 197 source->SetJsonPath("strings.js");
192 198
193 return source; 199 return source;
194 } 200 }
195 201
196 } // namespace 202 } // namespace
197 203
198 MdHistoryUI::MdHistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { 204 MdHistoryUI::MdHistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) {
199 Profile* profile = Profile::FromWebUI(web_ui); 205 Profile* profile = Profile::FromWebUI(web_ui);
200 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); 206 web_ui->AddMessageHandler(new BrowsingHistoryHandler());
201 web_ui->AddMessageHandler(new MetricsHandler()); 207 web_ui->AddMessageHandler(new MetricsHandler());
202 208
203 if (search::IsInstantExtendedAPIEnabled()) { 209 if (search::IsInstantExtendedAPIEnabled()) {
204 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); 210 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler());
205 web_ui->AddMessageHandler(new HistoryLoginHandler()); 211 web_ui->AddMessageHandler(new HistoryLoginHandler());
206 } 212 }
207 213
208 content::WebUIDataSource::Add(profile, CreateMdHistoryUIHTMLSource(profile)); 214 content::WebUIDataSource::Add(profile, CreateMdHistoryUIHTMLSource(profile));
209 } 215 }
210 216
211 MdHistoryUI::~MdHistoryUI() {} 217 MdHistoryUI::~MdHistoryUI() {}
212 218
213 // static 219 // static
214 bool MdHistoryUI::IsEnabled(Profile* profile) { 220 bool MdHistoryUI::IsEnabled(Profile* profile) {
221 if (profile && profile->IsSupervised())
222 return false;
223
215 return base::FeatureList::IsEnabled(features::kMaterialDesignHistory) && 224 return base::FeatureList::IsEnabled(features::kMaterialDesignHistory) &&
216 !base::CommandLine::ForCurrentProcess()->HasSwitch( 225 !base::CommandLine::ForCurrentProcess()->HasSwitch(
217 switches::kHistoryEnableGroupByDomain) && 226 switches::kHistoryEnableGroupByDomain);
218 !profile->IsSupervised();
219 } 227 }
220 228
221 // static 229 // static
222 void MdHistoryUI::SetEnabledForTesting(bool enabled) { 230 void MdHistoryUI::SetEnabledForTesting(bool enabled) {
223 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); 231 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
224 232
225 const std::string& name = features::kMaterialDesignHistory.name; 233 const std::string& name = features::kMaterialDesignHistory.name;
226 feature_list->InitializeFromCommandLine(enabled ? name : "", 234 feature_list->InitializeFromCommandLine(enabled ? name : "",
227 enabled ? "" : name); 235 enabled ? "" : name);
228 base::FeatureList::ClearInstanceForTesting(); 236 base::FeatureList::ClearInstanceForTesting();
229 base::FeatureList::SetInstance(std::move(feature_list)); 237 base::FeatureList::SetInstance(std::move(feature_list));
230 } 238 }
231 239
232 // static 240 // static
233 base::RefCountedMemory* MdHistoryUI::GetFaviconResourceBytes( 241 base::RefCountedMemory* MdHistoryUI::GetFaviconResourceBytes(
234 ui::ScaleFactor scale_factor) { 242 ui::ScaleFactor scale_factor) {
235 return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( 243 return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
236 IDR_HISTORY_FAVICON, scale_factor); 244 IDR_HISTORY_FAVICON, scale_factor);
237 } 245 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698