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

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: address review comments 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
76 source->AddResourcePath("app.html", IDR_MD_HISTORY_APP_HTML); 91 source->AddResourcePath("app.html", IDR_MD_HISTORY_APP_HTML);
77 source->AddResourcePath("app.js", IDR_MD_HISTORY_APP_JS); 92 source->AddResourcePath("app.js", IDR_MD_HISTORY_APP_JS);
78 source->AddResourcePath("browser_service.html", 93 source->AddResourcePath("browser_service.html",
79 IDR_MD_HISTORY_BROWSER_SERVICE_HTML); 94 IDR_MD_HISTORY_BROWSER_SERVICE_HTML);
80 source->AddResourcePath("browser_service.js", 95 source->AddResourcePath("browser_service.js",
81 IDR_MD_HISTORY_BROWSER_SERVICE_JS); 96 IDR_MD_HISTORY_BROWSER_SERVICE_JS);
82 source->AddResourcePath("constants.html", IDR_MD_HISTORY_CONSTANTS_HTML); 97 source->AddResourcePath("constants.html", IDR_MD_HISTORY_CONSTANTS_HTML);
83 source->AddResourcePath("constants.js", IDR_MD_HISTORY_CONSTANTS_JS); 98 source->AddResourcePath("constants.js", IDR_MD_HISTORY_CONSTANTS_JS);
84 source->AddResourcePath("grouped_list.html", 99 source->AddResourcePath("grouped_list.html",
85 IDR_MD_HISTORY_GROUPED_LIST_HTML); 100 IDR_MD_HISTORY_GROUPED_LIST_HTML);
86 source->AddResourcePath("grouped_list.js", IDR_MD_HISTORY_GROUPED_LIST_JS); 101 source->AddResourcePath("grouped_list.js", IDR_MD_HISTORY_GROUPED_LIST_JS);
87 source->AddResourcePath("history_item.html", 102 source->AddResourcePath("history_item.html",
88 IDR_MD_HISTORY_HISTORY_ITEM_HTML); 103 IDR_MD_HISTORY_HISTORY_ITEM_HTML);
89 source->AddResourcePath("history_item.js", IDR_MD_HISTORY_HISTORY_ITEM_JS); 104 source->AddResourcePath("history_item.js", IDR_MD_HISTORY_HISTORY_ITEM_JS);
90 source->AddResourcePath("history_list.html", 105 source->AddResourcePath("history_list.html",
91 IDR_MD_HISTORY_HISTORY_LIST_HTML); 106 IDR_MD_HISTORY_HISTORY_LIST_HTML);
92 source->AddResourcePath("history_list.js", IDR_MD_HISTORY_HISTORY_LIST_JS); 107 source->AddResourcePath("history_list.js", IDR_MD_HISTORY_HISTORY_LIST_JS);
93 source->AddResourcePath("history_toolbar.html", 108 source->AddResourcePath("history_toolbar.html",
94 IDR_MD_HISTORY_HISTORY_TOOLBAR_HTML); 109 IDR_MD_HISTORY_HISTORY_TOOLBAR_HTML);
95 source->AddResourcePath("history_toolbar.js", 110 source->AddResourcePath("history_toolbar.js",
96 IDR_MD_HISTORY_HISTORY_TOOLBAR_JS); 111 IDR_MD_HISTORY_HISTORY_TOOLBAR_JS);
97 source->AddResourcePath("history.js", IDR_MD_HISTORY_HISTORY_JS); 112 source->AddResourcePath("history.js", IDR_MD_HISTORY_HISTORY_JS);
98 source->AddResourcePath("icons.html", IDR_MD_HISTORY_ICONS_HTML); 113 source->AddResourcePath("icons.html", IDR_MD_HISTORY_ICONS_HTML);
114 source->AddResourcePath("images/100/sign_in_promo.png",
115 IDR_MD_HISTORY_IMAGES_100_SIGN_IN_PROMO_PNG);
116 source->AddResourcePath("images/200/sign_in_promo.png",
117 IDR_MD_HISTORY_IMAGES_200_SIGN_IN_PROMO_PNG);
99 source->AddResourcePath("searched_label.html", 118 source->AddResourcePath("searched_label.html",
100 IDR_MD_HISTORY_SEARCHED_LABEL_HTML); 119 IDR_MD_HISTORY_SEARCHED_LABEL_HTML);
101 source->AddResourcePath("searched_label.js", 120 source->AddResourcePath("searched_label.js",
102 IDR_MD_HISTORY_SEARCHED_LABEL_JS); 121 IDR_MD_HISTORY_SEARCHED_LABEL_JS);
103 source->AddResourcePath("shared_style.html", 122 source->AddResourcePath("shared_style.html",
104 IDR_MD_HISTORY_SHARED_STYLE_HTML); 123 IDR_MD_HISTORY_SHARED_STYLE_HTML);
105 source->AddResourcePath("side_bar.html", IDR_MD_HISTORY_SIDE_BAR_HTML); 124 source->AddResourcePath("side_bar.html", IDR_MD_HISTORY_SIDE_BAR_HTML);
106 source->AddResourcePath("side_bar.js", IDR_MD_HISTORY_SIDE_BAR_JS); 125 source->AddResourcePath("side_bar.js", IDR_MD_HISTORY_SIDE_BAR_JS);
107 source->AddResourcePath("synced_device_card.html", 126 source->AddResourcePath("synced_device_card.html",
108 IDR_MD_HISTORY_SYNCED_DEVICE_CARD_HTML); 127 IDR_MD_HISTORY_SYNCED_DEVICE_CARD_HTML);
109 source->AddResourcePath("synced_device_card.js", 128 source->AddResourcePath("synced_device_card.js",
110 IDR_MD_HISTORY_SYNCED_DEVICE_CARD_JS); 129 IDR_MD_HISTORY_SYNCED_DEVICE_CARD_JS);
111 source->AddResourcePath("synced_device_manager.html", 130 source->AddResourcePath("synced_device_manager.html",
112 IDR_MD_HISTORY_SYNCED_DEVICE_MANAGER_HTML); 131 IDR_MD_HISTORY_SYNCED_DEVICE_MANAGER_HTML);
113 source->AddResourcePath("synced_device_manager.js", 132 source->AddResourcePath("synced_device_manager.js",
114 IDR_MD_HISTORY_SYNCED_DEVICE_MANAGER_JS); 133 IDR_MD_HISTORY_SYNCED_DEVICE_MANAGER_JS);
115 134
116 source->SetDefaultResource(IDR_MD_HISTORY_HISTORY_HTML); 135 source->SetDefaultResource(IDR_MD_HISTORY_HISTORY_HTML);
117 source->SetJsonPath("strings.js"); 136 source->SetJsonPath("strings.js");
118 137
119 return source; 138 return source;
120 } 139 }
121 140
122 } // namespace 141 } // namespace
123 142
124 MdHistoryUI::MdHistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { 143 MdHistoryUI::MdHistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) {
144 Profile* profile = Profile::FromWebUI(web_ui);
125 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); 145 web_ui->AddMessageHandler(new BrowsingHistoryHandler());
126 web_ui->AddMessageHandler(new MetricsHandler()); 146 web_ui->AddMessageHandler(new MetricsHandler());
147 // Add handler for showing Chrome log in overlay.
calamity 2016/06/22 02:20:48 nit: s/log in/sign in/
lshang 2016/06/22 04:51:40 Done.
148 web_ui->AddMessageHandler(new settings::PeopleHandler(profile));
127 149
128 if (search::IsInstantExtendedAPIEnabled()) { 150 if (search::IsInstantExtendedAPIEnabled()) {
129 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); 151 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler());
130 web_ui->AddMessageHandler(new HistoryLoginHandler()); 152 web_ui->AddMessageHandler(new HistoryLoginHandler());
131 } 153 }
132 154
133 Profile* profile = Profile::FromWebUI(web_ui);
134 content::WebUIDataSource::Add(profile, CreateMdHistoryUIHTMLSource(profile)); 155 content::WebUIDataSource::Add(profile, CreateMdHistoryUIHTMLSource(profile));
135 } 156 }
136 157
137 MdHistoryUI::~MdHistoryUI() {} 158 MdHistoryUI::~MdHistoryUI() {}
138 159
139 // static 160 // static
140 bool MdHistoryUI::IsEnabled(Profile* profile) { 161 bool MdHistoryUI::IsEnabled(Profile* profile) {
141 return base::FeatureList::IsEnabled( 162 return base::FeatureList::IsEnabled(
142 features::kMaterialDesignHistoryFeature) && 163 features::kMaterialDesignHistoryFeature) &&
143 !base::CommandLine::ForCurrentProcess()->HasSwitch( 164 !base::CommandLine::ForCurrentProcess()->HasSwitch(
144 switches::kHistoryEnableGroupByDomain) && 165 switches::kHistoryEnableGroupByDomain) &&
145 !profile->IsSupervised(); 166 !profile->IsSupervised();
146 } 167 }
147 168
148 // static 169 // static
149 void MdHistoryUI::DisableForTesting() { 170 void MdHistoryUI::DisableForTesting() {
150 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); 171 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
151 feature_list->InitializeFromCommandLine( 172 feature_list->InitializeFromCommandLine(
152 std::string(), features::kMaterialDesignHistoryFeature.name); 173 std::string(), features::kMaterialDesignHistoryFeature.name);
153 base::FeatureList::ClearInstanceForTesting(); 174 base::FeatureList::ClearInstanceForTesting();
154 base::FeatureList::SetInstance(std::move(feature_list)); 175 base::FeatureList::SetInstance(std::move(feature_list));
155 } 176 }
156 177
157 // static 178 // static
158 base::RefCountedMemory* MdHistoryUI::GetFaviconResourceBytes( 179 base::RefCountedMemory* MdHistoryUI::GetFaviconResourceBytes(
159 ui::ScaleFactor scale_factor) { 180 ui::ScaleFactor scale_factor) {
160 return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( 181 return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
161 IDR_HISTORY_FAVICON, scale_factor); 182 IDR_HISTORY_FAVICON, scale_factor);
162 } 183 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698