Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/history_ui.h" | 5 #include "chrome/browser/ui/webui/history_ui.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ref_counted_memory.h" | 10 #include "base/memory/ref_counted_memory.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 const char kIncognitoModeShortcut[] = "(" | 53 const char kIncognitoModeShortcut[] = "(" |
| 54 "\xE2\x87\xA7" // Shift symbol (U+21E7 'UPWARDS WHITE ARROW'). | 54 "\xE2\x87\xA7" // Shift symbol (U+21E7 'UPWARDS WHITE ARROW'). |
| 55 "\xE2\x8C\x98" // Command symbol (U+2318 'PLACE OF INTEREST SIGN'). | 55 "\xE2\x8C\x98" // Command symbol (U+2318 'PLACE OF INTEREST SIGN'). |
| 56 "N)"; | 56 "N)"; |
| 57 #elif defined(OS_WIN) | 57 #elif defined(OS_WIN) |
| 58 const char kIncognitoModeShortcut[] = "(Ctrl+Shift+N)"; | 58 const char kIncognitoModeShortcut[] = "(Ctrl+Shift+N)"; |
| 59 #else | 59 #else |
| 60 const char kIncognitoModeShortcut[] = "(Shift+Ctrl+N)"; | 60 const char kIncognitoModeShortcut[] = "(Shift+Ctrl+N)"; |
| 61 #endif | 61 #endif |
| 62 | 62 |
| 63 content::WebUIDataSource* CreateHistoryUIHTMLSource(Profile* profile) { | 63 content::WebUIDataSource* CreateHistoryUIHTMLSource(Profile* profile) { |
|
Dan Beam
2016/09/30 00:47:43
is there a reason why this is an anonymous method
lshang
2016/09/30 01:31:08
Probably in order to enclose this function inside
| |
| 64 PrefService* prefs = profile->GetPrefs(); | 64 PrefService* prefs = profile->GetPrefs(); |
| 65 | 65 |
| 66 // Check if the profile is authenticated. Guest profiles or incognito | 66 // Check if the profile is authenticated. Guest profiles or incognito |
| 67 // windows may not have a sign in manager, and are considered not | 67 // windows may not have a sign in manager, and are considered not |
| 68 // authenticated. | 68 // authenticated. |
| 69 SigninManagerBase* signin_manager = | 69 SigninManagerBase* signin_manager = |
| 70 SigninManagerFactory::GetForProfile(profile); | 70 SigninManagerFactory::GetForProfile(profile); |
| 71 bool is_authenticated = signin_manager != nullptr && | 71 bool is_authenticated = signin_manager != nullptr && |
| 72 signin_manager->IsAuthenticated(); | 72 signin_manager->IsAuthenticated(); |
| 73 | 73 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 | 169 |
| 170 return source; | 170 return source; |
| 171 } | 171 } |
| 172 | 172 |
| 173 } // namespace | 173 } // namespace |
| 174 | 174 |
| 175 HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 175 HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
| 176 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); | 176 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); |
| 177 web_ui->AddMessageHandler(new MetricsHandler()); | 177 web_ui->AddMessageHandler(new MetricsHandler()); |
| 178 | 178 |
| 179 // Set up the chrome://history-frame/ source. | |
| 180 CreateAndGetDataSource(); | |
| 181 | |
| 179 // On mobile we deal with foreign sessions differently. | 182 // On mobile we deal with foreign sessions differently. |
| 180 #if !defined(OS_ANDROID) | 183 #if !defined(OS_ANDROID) |
| 181 if (search::IsInstantExtendedAPIEnabled()) { | 184 if (search::IsInstantExtendedAPIEnabled()) { |
| 182 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); | 185 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); |
| 183 web_ui->AddMessageHandler(new HistoryLoginHandler()); | 186 web_ui->AddMessageHandler(new HistoryLoginHandler( |
| 187 base::Bind(&HistoryUI::SignInChanged, base::Unretained(this)))); | |
| 184 } | 188 } |
| 185 #endif | 189 #endif |
| 186 | 190 |
| 187 // TODO(crbug.com/595332): Since the API to query other forms of browsing | 191 // TODO(crbug.com/595332): Since the API to query other forms of browsing |
| 188 // history is not ready yet, make it possible to test the history UI as if | 192 // history is not ready yet, make it possible to test the history UI as if |
| 189 // it were. If the user opens chrome://history/?reset_ofbh, we will assume | 193 // it were. If the user opens chrome://history/?reset_ofbh, we will assume |
| 190 // that other forms of browsing history exist (for all accounts), and we will | 194 // that other forms of browsing history exist (for all accounts), and we will |
| 191 // also reset the one-time notice shown in the Clear Browsing Data dialog. | 195 // also reset the one-time notice shown in the Clear Browsing Data dialog. |
| 192 // This code should be removed as soon as the API is ready. | 196 // This code should be removed as soon as the API is ready. |
| 193 GURL url = web_ui->GetWebContents()->GetVisibleURL(); | 197 GURL url = web_ui->GetWebContents()->GetVisibleURL(); |
| 194 if (url.has_query() && url.query() == "reset_ofbh") { | 198 if (url.has_query() && url.query() == "reset_ofbh") { |
| 195 Profile::FromWebUI(web_ui)->GetPrefs()->SetInteger( | 199 Profile::FromWebUI(web_ui)->GetPrefs()->SetInteger( |
| 196 browsing_data::prefs::kClearBrowsingDataHistoryNoticeShownTimes, 0); | 200 browsing_data::prefs::kClearBrowsingDataHistoryNoticeShownTimes, 0); |
| 197 browsing_data::testing:: | 201 browsing_data::testing:: |
| 198 g_override_other_forms_of_browsing_history_query = true; | 202 g_override_other_forms_of_browsing_history_query = true; |
| 199 } | 203 } |
| 200 | |
| 201 // Set up the chrome://history-frame/ source. | |
| 202 Profile* profile = Profile::FromWebUI(web_ui); | |
| 203 content::WebUIDataSource::Add(profile, CreateHistoryUIHTMLSource(profile)); | |
| 204 } | 204 } |
| 205 | 205 |
| 206 HistoryUI::~HistoryUI() {} | 206 HistoryUI::~HistoryUI() {} |
| 207 | 207 |
| 208 // static | 208 // static |
| 209 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( | 209 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( |
| 210 ui::ScaleFactor scale_factor) { | 210 ui::ScaleFactor scale_factor) { |
| 211 return ResourceBundle::GetSharedInstance(). | 211 return ResourceBundle::GetSharedInstance(). |
| 212 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); | 212 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); |
| 213 } | 213 } |
| 214 | |
| 215 content::WebUIDataSource* HistoryUI::CreateAndGetDataSource() { | |
| 216 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 217 content::WebUIDataSource* data_source = CreateHistoryUIHTMLSource(profile); | |
| 218 content::WebUIDataSource::Add(profile, data_source); | |
| 219 return data_source; | |
|
Dan Beam
2016/09/30 00:47:43
so, groby@ is going to make this API take a std::u
lshang
2016/09/30 01:31:08
Changed to just create it. groby@'s change would b
Dan Beam
2016/09/30 02:55:40
let's just re-create every time with a TODO for no
lshang
2016/09/30 03:21:13
Done.
| |
| 220 } | |
| 221 | |
| 222 void HistoryUI::SignInChanged(bool signed_in) { | |
| 223 // Recreate the data source so sign in state get updated in there. | |
| 224 CreateAndGetDataSource(); | |
| 225 } | |
| OLD | NEW |