Chromium Code Reviews| Index: chrome/browser/ui/webui/md_history_ui.cc |
| diff --git a/chrome/browser/ui/webui/md_history_ui.cc b/chrome/browser/ui/webui/md_history_ui.cc |
| index 49ae383b54b02cc0f74db484d3b45afaadb31b0e..b8274ba19eb87c5700aea45d370ce46a16968114 100644 |
| --- a/chrome/browser/ui/webui/md_history_ui.cc |
| +++ b/chrome/browser/ui/webui/md_history_ui.cc |
| @@ -5,6 +5,7 @@ |
| #include "chrome/browser/ui/webui/md_history_ui.h" |
| #include "build/build_config.h" |
| +#include "chrome/browser/browser_process.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/ui/webui/browsing_history_handler.h" |
| #include "chrome/browser/ui/webui/metrics_handler.h" |
| @@ -17,7 +18,10 @@ |
| #include "grit/components_strings.h" |
| #include "grit/generated_resources.h" |
| #include "grit/theme_resources.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| #include "ui/base/resource/resource_bundle.h" |
| +#include "ui/base/template_expressions.h" |
| +#include "ui/base/webui/web_ui_util.h" |
| #if !defined(OS_ANDROID) |
| #include "chrome/browser/ui/webui/foreign_session_handler.h" |
| @@ -26,36 +30,63 @@ |
| namespace { |
| +bool HandleDataRequest( |
| + const std::string& path, |
| + const content::WebUIDataSource::GotDataCallback& callback) { |
| + std::map<const std::string, std::string> substitutions; |
| + // Localized strings (alphabetical order). |
| + substitutions["clearSearch"] = |
| + l10n_util::GetStringUTF8(IDS_MD_HISTORY_CLEAR_SEARCH); |
| + substitutions["language"] = |
| + l10n_util::GetLanguage(g_browser_process->GetApplicationLocale()); |
| + substitutions["moreFromSite"] = |
| + l10n_util::GetStringUTF8(IDS_HISTORY_MORE_FROM_SITE); |
| + substitutions["removeFromHistory"] = |
| + l10n_util::GetStringUTF8(IDS_HISTORY_REMOVE_PAGE); |
| + substitutions["search"] = l10n_util::GetStringUTF8(IDS_MD_HISTORY_SEARCH); |
| + substitutions["title"] = l10n_util::GetStringUTF8(IDS_HISTORY_TITLE); |
| + substitutions["textdirection"] = webui::GetTextDirection(); |
| + |
| + std::map<std::string, int> router; |
|
calamity
2016/02/01 23:45:33
Can we make this a const static local?
tsergeant
2016/02/02 01:33:10
Yes, we can.
|
| + // Localized resources (alphabetical order). |
| + router[""] = IDR_MD_HISTORY_HISTORY_HTML; |
| + router["history_card.html"] = IDR_MD_HISTORY_HISTORY_CARD_HTML; |
| + router["history_card_manager.html"] = |
| + IDR_MD_HISTORY_HISTORY_CARD_MANAGER_HTML; |
| + router["history_item.html"] = IDR_MD_HISTORY_HISTORY_ITEM_HTML; |
| + router["history_toolbar.html"] = IDR_MD_HISTORY_HISTORY_TOOLBAR_HTML; |
| + |
| + auto path_resource = router.find(path); |
| + if (path_resource != router.end()) { |
| + base::StringPiece resource_full_text( |
| + ResourceBundle::GetSharedInstance().GetRawDataResource( |
| + (*path_resource).second)); |
| + |
| + std::string localized_text = |
| + ui::ReplaceTemplateExpressions(resource_full_text, substitutions); |
| + callback.Run(base::RefCountedString::TakeString(&localized_text)); |
| + |
| + return true; |
| + } |
| + |
| + return false; |
| +} |
| + |
| content::WebUIDataSource* CreateMdHistoryUIHTMLSource() { |
| content::WebUIDataSource* source = |
| content::WebUIDataSource::Create(chrome::kChromeUIHistoryHost); |
| - // Localized strings (alphabetical order). |
| - source->AddLocalizedString("clearSearch", IDS_MD_HISTORY_CLEAR_SEARCH); |
| - source->AddLocalizedString("moreFromSite", IDS_HISTORY_MORE_FROM_SITE); |
| - source->AddLocalizedString("removeFromHistory", IDS_HISTORY_REMOVE_PAGE); |
| - source->AddLocalizedString("search", IDS_MD_HISTORY_SEARCH); |
| - source->AddLocalizedString("title", IDS_HISTORY_TITLE); |
| - |
| - source->AddResourcePath("history_card.html", |
| - IDR_MD_HISTORY_HISTORY_CARD_HTML); |
| + // Resources which do not need localization. |
| source->AddResourcePath("history_card.js", IDR_MD_HISTORY_HISTORY_CARD_JS); |
| - source->AddResourcePath("history_card_manager.html", |
| - IDR_MD_HISTORY_HISTORY_CARD_MANAGER_HTML); |
| source->AddResourcePath("history_card_manager.js", |
| IDR_MD_HISTORY_HISTORY_CARD_MANAGER_JS); |
| - source->AddResourcePath("history_item.html", |
| - IDR_MD_HISTORY_HISTORY_ITEM_HTML); |
| source->AddResourcePath("history_item.js", IDR_MD_HISTORY_HISTORY_ITEM_JS); |
| - source->AddResourcePath("history_toolbar.html", |
| - IDR_MD_HISTORY_HISTORY_TOOLBAR_HTML); |
| source->AddResourcePath("history_toolbar.js", |
| IDR_MD_HISTORY_HISTORY_TOOLBAR_JS); |
| source->AddResourcePath("history.js", IDR_MD_HISTORY_HISTORY_JS); |
| - source->SetDefaultResource(IDR_MD_HISTORY_HISTORY_HTML); |
| source->SetJsonPath("strings.js"); |
| - |
| + source->SetRequestFilter(base::Bind(&HandleDataRequest)); |
| return source; |
| } |