| OLD | NEW |
| 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" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "chrome/grit/locale_settings.h" | 23 #include "chrome/grit/locale_settings.h" |
| 24 #include "chrome/grit/theme_resources.h" | 24 #include "chrome/grit/theme_resources.h" |
| 25 #include "components/grit/components_scaled_resources.h" | 25 #include "components/grit/components_scaled_resources.h" |
| 26 #include "components/pref_registry/pref_registry_syncable.h" | 26 #include "components/pref_registry/pref_registry_syncable.h" |
| 27 #include "components/prefs/pref_service.h" | 27 #include "components/prefs/pref_service.h" |
| 28 #include "components/search/search.h" | 28 #include "components/search/search.h" |
| 29 #include "components/signin/core/browser/signin_manager.h" | 29 #include "components/signin/core/browser/signin_manager.h" |
| 30 #include "components/strings/grit/components_strings.h" | 30 #include "components/strings/grit/components_strings.h" |
| 31 #include "content/public/browser/web_ui.h" | 31 #include "content/public/browser/web_ui.h" |
| 32 #include "content/public/browser/web_ui_data_source.h" | 32 #include "content/public/browser/web_ui_data_source.h" |
| 33 #include "content/public/common/url_constants.h" | |
| 34 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 35 #include "ui/base/resource/resource_bundle.h" | 34 #include "ui/base/resource/resource_bundle.h" |
| 36 | 35 |
| 37 namespace { | 36 namespace { |
| 38 | 37 |
| 39 constexpr char kIsUserSignedInKey[] = "isUserSignedIn"; | 38 constexpr char kIsUserSignedInKey[] = "isUserSignedIn"; |
| 40 constexpr char kShowMenuPromoKey[] = "showMenuPromo"; | 39 constexpr char kShowMenuPromoKey[] = "showMenuPromo"; |
| 41 | 40 |
| 42 bool IsUserSignedIn(Profile* profile) { | 41 bool IsUserSignedIn(Profile* profile) { |
| 43 SigninManagerBase* signin_manager = | 42 SigninManagerBase* signin_manager = |
| 44 SigninManagerFactory::GetForProfile(profile); | 43 SigninManagerFactory::GetForProfile(profile); |
| 45 return signin_manager && signin_manager->IsAuthenticated(); | 44 return signin_manager && signin_manager->IsAuthenticated(); |
| 46 } | 45 } |
| 47 | 46 |
| 48 bool MenuPromoShown(Profile* profile) { | 47 bool MenuPromoShown(Profile* profile) { |
| 49 return profile->GetPrefs()->GetBoolean(prefs::kMdHistoryMenuPromoShown); | 48 return profile->GetPrefs()->GetBoolean(prefs::kMdHistoryMenuPromoShown); |
| 50 } | 49 } |
| 51 | 50 |
| 52 content::WebUIDataSource* CreateMdHistoryUIHTMLSource(Profile* profile, | 51 content::WebUIDataSource* CreateMdHistoryUIHTMLSource(Profile* profile, |
| 53 bool use_test_title) { | 52 bool use_test_title) { |
| 54 content::WebUIDataSource* source = | 53 content::WebUIDataSource* source = |
| 55 content::WebUIDataSource::Create(content::kChromeUIHistoryHost); | 54 content::WebUIDataSource::Create(chrome::kChromeUIHistoryHost); |
| 56 | 55 |
| 57 // Localized strings (alphabetical order). | 56 // Localized strings (alphabetical order). |
| 58 source->AddLocalizedString("bookmarked", IDS_HISTORY_ENTRY_BOOKMARKED); | 57 source->AddLocalizedString("bookmarked", IDS_HISTORY_ENTRY_BOOKMARKED); |
| 59 source->AddLocalizedString("cancel", IDS_CANCEL); | 58 source->AddLocalizedString("cancel", IDS_CANCEL); |
| 60 source->AddLocalizedString("clearBrowsingData", | 59 source->AddLocalizedString("clearBrowsingData", |
| 61 IDS_CLEAR_BROWSING_DATA_TITLE); | 60 IDS_CLEAR_BROWSING_DATA_TITLE); |
| 62 source->AddLocalizedString("clearSearch", IDS_MD_HISTORY_CLEAR_SEARCH); | 61 source->AddLocalizedString("clearSearch", IDS_MD_HISTORY_CLEAR_SEARCH); |
| 63 source->AddLocalizedString("closeMenuPromo", IDS_MD_HISTORY_CLOSE_MENU_PROMO); | 62 source->AddLocalizedString("closeMenuPromo", IDS_MD_HISTORY_CLOSE_MENU_PROMO); |
| 64 source->AddLocalizedString("collapseSessionButton", | 63 source->AddLocalizedString("collapseSessionButton", |
| 65 IDS_HISTORY_OTHER_SESSIONS_COLLAPSE_SESSION); | 64 IDS_HISTORY_OTHER_SESSIONS_COLLAPSE_SESSION); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 | 242 |
| 244 void MdHistoryUI::UpdateDataSource() { | 243 void MdHistoryUI::UpdateDataSource() { |
| 245 CHECK(web_ui()); | 244 CHECK(web_ui()); |
| 246 | 245 |
| 247 Profile* profile = Profile::FromWebUI(web_ui()); | 246 Profile* profile = Profile::FromWebUI(web_ui()); |
| 248 | 247 |
| 249 std::unique_ptr<base::DictionaryValue> update(new base::DictionaryValue); | 248 std::unique_ptr<base::DictionaryValue> update(new base::DictionaryValue); |
| 250 update->SetBoolean(kIsUserSignedInKey, IsUserSignedIn(profile)); | 249 update->SetBoolean(kIsUserSignedInKey, IsUserSignedIn(profile)); |
| 251 update->SetBoolean(kShowMenuPromoKey, !MenuPromoShown(profile)); | 250 update->SetBoolean(kShowMenuPromoKey, !MenuPromoShown(profile)); |
| 252 | 251 |
| 253 content::WebUIDataSource::Update(profile, content::kChromeUIHistoryHost, | 252 content::WebUIDataSource::Update(profile, chrome::kChromeUIHistoryHost, |
| 254 std::move(update)); | 253 std::move(update)); |
| 255 } | 254 } |
| 256 | 255 |
| 257 void MdHistoryUI::HandleMenuPromoShown(const base::ListValue* args) { | 256 void MdHistoryUI::HandleMenuPromoShown(const base::ListValue* args) { |
| 258 Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean( | 257 Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean( |
| 259 prefs::kMdHistoryMenuPromoShown, true); | 258 prefs::kMdHistoryMenuPromoShown, true); |
| 260 UpdateDataSource(); | 259 UpdateDataSource(); |
| 261 } | 260 } |
| OLD | NEW |