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

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

Issue 2077473002: MD History: add sign in promo in synced tabs when user isn't logged in (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: first acceptable version Created 4 years, 6 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/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/ui/webui/browsing_history_handler.h" 11 #include "chrome/browser/ui/webui/browsing_history_handler.h"
11 #include "chrome/browser/ui/webui/foreign_session_handler.h" 12 #include "chrome/browser/ui/webui/foreign_session_handler.h"
12 #include "chrome/browser/ui/webui/history_login_handler.h" 13 #include "chrome/browser/ui/webui/history_login_handler.h"
13 #include "chrome/browser/ui/webui/metrics_handler.h" 14 #include "chrome/browser/ui/webui/metrics_handler.h"
15 #include "chrome/browser/ui/webui/settings/people_handler.h"
14 #include "chrome/common/chrome_features.h" 16 #include "chrome/common/chrome_features.h"
15 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
17 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
18 #include "components/prefs/pref_service.h" 20 #include "components/prefs/pref_service.h"
19 #include "components/search/search.h" 21 #include "components/search/search.h"
22 #include "components/signin/core/browser/signin_manager.h"
20 #include "content/public/browser/web_ui.h" 23 #include "content/public/browser/web_ui.h"
21 #include "content/public/browser/web_ui_data_source.h" 24 #include "content/public/browser/web_ui_data_source.h"
22 #include "grit/browser_resources.h" 25 #include "grit/browser_resources.h"
23 #include "grit/components_scaled_resources.h" 26 #include "grit/components_scaled_resources.h"
24 #include "grit/components_strings.h" 27 #include "grit/components_strings.h"
25 #include "grit/generated_resources.h" 28 #include "grit/generated_resources.h"
26 #include "grit/theme_resources.h" 29 #include "grit/theme_resources.h"
27 #include "ui/base/resource/resource_bundle.h" 30 #include "ui/base/resource/resource_bundle.h"
28 31
29 namespace { 32 namespace {
(...skipping 16 matching lines...) Expand all
46 source->AddLocalizedString("historyMenuItem", 49 source->AddLocalizedString("historyMenuItem",
47 IDS_MD_HISTORY_HISTORY_MENU_ITEM); 50 IDS_MD_HISTORY_HISTORY_MENU_ITEM);
48 source->AddLocalizedString("itemsSelected", IDS_MD_HISTORY_ITEMS_SELECTED); 51 source->AddLocalizedString("itemsSelected", IDS_MD_HISTORY_ITEMS_SELECTED);
49 source->AddLocalizedString("loading", IDS_HISTORY_LOADING); 52 source->AddLocalizedString("loading", IDS_HISTORY_LOADING);
50 source->AddLocalizedString("moreFromSite", IDS_HISTORY_MORE_FROM_SITE); 53 source->AddLocalizedString("moreFromSite", IDS_HISTORY_MORE_FROM_SITE);
51 source->AddLocalizedString("openAll", IDS_HISTORY_OTHER_SESSIONS_OPEN_ALL); 54 source->AddLocalizedString("openAll", IDS_HISTORY_OTHER_SESSIONS_OPEN_ALL);
52 source->AddLocalizedString("openTabsMenuItem", 55 source->AddLocalizedString("openTabsMenuItem",
53 IDS_MD_HISTORY_OPEN_TABS_MENU_ITEM); 56 IDS_MD_HISTORY_OPEN_TABS_MENU_ITEM);
54 source->AddLocalizedString("noResults", IDS_HISTORY_NO_RESULTS); 57 source->AddLocalizedString("noResults", IDS_HISTORY_NO_RESULTS);
55 source->AddLocalizedString("noSearchResults", IDS_HISTORY_NO_SEARCH_RESULTS); 58 source->AddLocalizedString("noSearchResults", IDS_HISTORY_NO_SEARCH_RESULTS);
59 source->AddLocalizedString("noSyncedResults",
60 IDS_MD_HISTORY_NO_SYNCED_RESULTS);
56 source->AddLocalizedString("rangeAllTime", IDS_HISTORY_RANGE_ALL_TIME); 61 source->AddLocalizedString("rangeAllTime", IDS_HISTORY_RANGE_ALL_TIME);
57 source->AddLocalizedString("rangeWeek", IDS_HISTORY_RANGE_WEEK); 62 source->AddLocalizedString("rangeWeek", IDS_HISTORY_RANGE_WEEK);
58 source->AddLocalizedString("rangeMonth", IDS_HISTORY_RANGE_MONTH); 63 source->AddLocalizedString("rangeMonth", IDS_HISTORY_RANGE_MONTH);
59 source->AddLocalizedString("rangeToday", IDS_HISTORY_RANGE_TODAY); 64 source->AddLocalizedString("rangeToday", IDS_HISTORY_RANGE_TODAY);
60 source->AddLocalizedString("rangeNext", IDS_HISTORY_RANGE_NEXT); 65 source->AddLocalizedString("rangeNext", IDS_HISTORY_RANGE_NEXT);
61 source->AddLocalizedString("rangePrevious", IDS_HISTORY_RANGE_PREVIOUS); 66 source->AddLocalizedString("rangePrevious", IDS_HISTORY_RANGE_PREVIOUS);
62 source->AddLocalizedString("removeFromHistory", IDS_HISTORY_REMOVE_PAGE); 67 source->AddLocalizedString("removeFromHistory", IDS_HISTORY_REMOVE_PAGE);
63 source->AddLocalizedString("searchPrompt", IDS_MD_HISTORY_SEARCH_PROMPT); 68 source->AddLocalizedString("searchPrompt", IDS_MD_HISTORY_SEARCH_PROMPT);
64 source->AddLocalizedString("searchResult", IDS_HISTORY_SEARCH_RESULT); 69 source->AddLocalizedString("searchResult", IDS_HISTORY_SEARCH_RESULT);
65 source->AddLocalizedString("searchResults", IDS_HISTORY_SEARCH_RESULTS); 70 source->AddLocalizedString("searchResults", IDS_HISTORY_SEARCH_RESULTS);
71 source->AddLocalizedString("signInButton", IDS_MD_HISTORY_SIGN_IN_BUTTON);
72 source->AddLocalizedString("signInPromo", IDS_MD_HISTORY_SIGN_IN_PROMO);
73 source->AddLocalizedString("signInPromoDesc",
74 IDS_MD_HISTORY_SIGN_IN_PROMO_DESC);
66 source->AddLocalizedString("title", IDS_HISTORY_TITLE); 75 source->AddLocalizedString("title", IDS_HISTORY_TITLE);
67 76
68 bool allow_deleting_history = 77 bool allow_deleting_history =
69 prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory); 78 prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory);
70 source->AddBoolean("allowDeletingHistory", allow_deleting_history); 79 source->AddBoolean("allowDeletingHistory", allow_deleting_history);
71 80
72 bool group_by_domain = base::CommandLine::ForCurrentProcess()->HasSwitch( 81 bool group_by_domain = base::CommandLine::ForCurrentProcess()->HasSwitch(
73 switches::kHistoryEnableGroupByDomain) || profile->IsSupervised(); 82 switches::kHistoryEnableGroupByDomain) || profile->IsSupervised();
74 source->AddBoolean("groupByDomain", group_by_domain); 83 source->AddBoolean("groupByDomain", group_by_domain);
75 84
85 SigninManagerBase* signin_manager =
86 SigninManagerFactory::GetForProfile(profile);
87 bool is_authenticated = signin_manager != nullptr &&
88 signin_manager->IsAuthenticated();
89 source->AddBoolean("isUserSignedIn", is_authenticated);
90
91 source->AddResourcePath("images/100/no_synced_tab.png",
tsergeant 2016/06/17 06:22:03 Nit: Grouped these with the rest of the AddResourc
lshang 2016/06/21 03:00:26 Done.
92 IDR_MD_HISTORY_100_NO_SYNCED_TAB_PNG);
93 source->AddResourcePath("images/200/no_synced_tab.png",
94 IDR_MD_HISTORY_200_NO_SYNCED_TAB_PNG);
95
76 source->AddResourcePath("app.html", IDR_MD_HISTORY_APP_HTML); 96 source->AddResourcePath("app.html", IDR_MD_HISTORY_APP_HTML);
77 source->AddResourcePath("app.js", IDR_MD_HISTORY_APP_JS); 97 source->AddResourcePath("app.js", IDR_MD_HISTORY_APP_JS);
78 source->AddResourcePath("browser_service.html", 98 source->AddResourcePath("browser_service.html",
79 IDR_MD_HISTORY_BROWSER_SERVICE_HTML); 99 IDR_MD_HISTORY_BROWSER_SERVICE_HTML);
80 source->AddResourcePath("browser_service.js", 100 source->AddResourcePath("browser_service.js",
81 IDR_MD_HISTORY_BROWSER_SERVICE_JS); 101 IDR_MD_HISTORY_BROWSER_SERVICE_JS);
82 source->AddResourcePath("constants.html", IDR_MD_HISTORY_CONSTANTS_HTML); 102 source->AddResourcePath("constants.html", IDR_MD_HISTORY_CONSTANTS_HTML);
83 source->AddResourcePath("constants.js", IDR_MD_HISTORY_CONSTANTS_JS); 103 source->AddResourcePath("constants.js", IDR_MD_HISTORY_CONSTANTS_JS);
84 source->AddResourcePath("grouped_list.html", 104 source->AddResourcePath("grouped_list.html",
85 IDR_MD_HISTORY_GROUPED_LIST_HTML); 105 IDR_MD_HISTORY_GROUPED_LIST_HTML);
(...skipping 25 matching lines...) Expand all
111 131
112 source->SetDefaultResource(IDR_MD_HISTORY_HISTORY_HTML); 132 source->SetDefaultResource(IDR_MD_HISTORY_HISTORY_HTML);
113 source->SetJsonPath("strings.js"); 133 source->SetJsonPath("strings.js");
114 134
115 return source; 135 return source;
116 } 136 }
117 137
118 } // namespace 138 } // namespace
119 139
120 MdHistoryUI::MdHistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { 140 MdHistoryUI::MdHistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) {
141 Profile* profile = Profile::FromWebUI(web_ui);
121 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); 142 web_ui->AddMessageHandler(new BrowsingHistoryHandler());
122 web_ui->AddMessageHandler(new MetricsHandler()); 143 web_ui->AddMessageHandler(new MetricsHandler());
144 web_ui->AddMessageHandler(new settings::PeopleHandler(profile));
tsergeant 2016/06/17 06:22:03 Perhaps add a comment here explaining what this is
lshang 2016/06/21 03:00:26 Done.
123 145
124 if (search::IsInstantExtendedAPIEnabled()) { 146 if (search::IsInstantExtendedAPIEnabled()) {
125 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); 147 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler());
126 web_ui->AddMessageHandler(new HistoryLoginHandler()); 148 web_ui->AddMessageHandler(new HistoryLoginHandler());
127 } 149 }
128 150
129 Profile* profile = Profile::FromWebUI(web_ui);
130 content::WebUIDataSource::Add(profile, CreateMdHistoryUIHTMLSource(profile)); 151 content::WebUIDataSource::Add(profile, CreateMdHistoryUIHTMLSource(profile));
131 } 152 }
132 153
133 MdHistoryUI::~MdHistoryUI() {} 154 MdHistoryUI::~MdHistoryUI() {}
134 155
135 // static 156 // static
136 bool MdHistoryUI::IsEnabled(Profile* profile) { 157 bool MdHistoryUI::IsEnabled(Profile* profile) {
137 return base::FeatureList::IsEnabled( 158 return base::FeatureList::IsEnabled(
138 features::kMaterialDesignHistoryFeature) && 159 features::kMaterialDesignHistoryFeature) &&
139 !base::CommandLine::ForCurrentProcess()->HasSwitch( 160 !base::CommandLine::ForCurrentProcess()->HasSwitch(
140 switches::kHistoryEnableGroupByDomain) && 161 switches::kHistoryEnableGroupByDomain) &&
141 !profile->IsSupervised(); 162 !profile->IsSupervised();
142 } 163 }
143 164
144 // static 165 // static
145 base::RefCountedMemory* MdHistoryUI::GetFaviconResourceBytes( 166 base::RefCountedMemory* MdHistoryUI::GetFaviconResourceBytes(
146 ui::ScaleFactor scale_factor) { 167 ui::ScaleFactor scale_factor) {
147 return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( 168 return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
148 IDR_HISTORY_FAVICON, scale_factor); 169 IDR_HISTORY_FAVICON, scale_factor);
149 } 170 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698