Add strings for NavigationBar on relevant WebUI data sources directly.

This fixes a layer-violation for dependencies where we were using a convenience function in the base //ui project in order to set the strings on all WebUI data sources. With this refactor, the dependencies are already in place from the chromium ui project (containing the webui data sources) to the brave webui project (containing the new navigation bar data provider).

This new NavigationBarDataProvider is not much of a class, in that it only contains a single static function, but it follows the chromium practice of splitting data in to functional classes, and leaving it up to the provider as to whether it adds strings, functions or observers to the WebUI.
This commit is contained in:
petemill
2019-05-08 21:49:04 -07:00
parent 1f733143f8
commit f37ff3f025
14 changed files with 140 additions and 37 deletions
+2
View File
@@ -46,6 +46,8 @@ source_set("ui") {
"toolbar/brave_app_menu_model.h",
"webui/brave_md_settings_ui.cc",
"webui/brave_md_settings_ui.h",
"webui/navigation_bar_data_provider.cc",
"webui/navigation_bar_data_provider.h",
"webui/settings/brave_privacy_handler.cc",
"webui/settings/brave_privacy_handler.h",
"webui/settings/brave_relaunch_handler_mac.mm",
+2
View File
@@ -13,6 +13,7 @@
#include "brave/browser/ui/webui/settings/brave_default_extensions_handler.h"
#include "brave/browser/ui/webui/settings/brave_privacy_handler.h"
#include "brave/browser/ui/webui/settings/default_brave_shields_handler.h"
#include "brave/browser/ui/webui/navigation_bar_data_provider.h"
#include "brave/browser/version_info.h"
#include "brave/common/brave_switches.h"
#include "chrome/browser/profiles/profile.h"
@@ -56,4 +57,5 @@ void BraveMdSettingsUI::AddResources(content::WebUIDataSource* html_source,
command_line.HasSwitch(switches::kDisableBraveSync));
html_source->AddString("braveProductVersion",
version_info::GetBraveVersionWithoutChromiumMajorVersion());
NavigationBarDataProvider::Initialize(html_source);
}
+6
View File
@@ -14,6 +14,7 @@
#include "content/public/browser/web_ui_data_source.h"
#if !defined(OS_ANDROID)
#include "brave/browser/ui/webui/navigation_bar_data_provider.h"
#include "brave/components/brave_rewards/resources/grit/brave_rewards_resources.h"
#endif
@@ -44,6 +45,11 @@ void AddResourcePaths(content::WebUIDataSource* html_source,
void CustomizeWebUIHTMLSource(const std::string &name,
content::WebUIDataSource* source) {
#if !defined(OS_ANDROID)
if (name == "rewards") {
NavigationBarDataProvider::Initialize(source);
}
#endif
static std::map<std::string, std::vector<WebUISimpleItem> > resources = {
{
std::string("newtab"), {
@@ -0,0 +1,22 @@
// Copyright (c) 2019 The Brave Authors
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// you can obtain one at http://mozilla.org/MPL/2.0/.
#include "brave/browser/ui/webui/navigation_bar_data_provider.h"
#include "chrome/grit/generated_resources.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/web_ui_data_source.h"
// static
void NavigationBarDataProvider::Initialize(content::WebUIDataSource* source) {
source->AddLocalizedString(
"brToolbarSettingsTitle", IDS_SETTINGS_SETTINGS);
source->AddLocalizedString(
"brToolbarBookmarksTitle", IDS_BOOKMARK_MANAGER_TITLE);
source->AddLocalizedString(
"brToolbarDownloadsTitle", IDS_DOWNLOAD_TITLE);
source->AddLocalizedString(
"brToolbarHistoryTitle", IDS_HISTORY_TITLE);
}
@@ -0,0 +1,20 @@
// Copyright (c) 2019 The Brave Authors
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// you can obtain one at http://mozilla.org/MPL/2.0/.
#ifndef BRAVE_BROWSER_UI_WEBUI_NAVIGATION_BAR_DATA_PROVIDER_H
#define BRAVE_BROWSER_UI_WEBUI_NAVIGATION_BAR_DATA_PROVIDER_H
namespace content {
class WebUIDataSource;
}
class NavigationBarDataProvider {
public:
// Sets load-time constants on |source|. This handles a flicker-free initial
// page load (i.e. loadTimeData.getString('brToolbarSettingsTitle')).
static void Initialize(content::WebUIDataSource* source);
};
#endif
@@ -0,0 +1,16 @@
// Copyright (c) 2019 The Brave Authors
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// you can obtain one at http://mozilla.org/MPL/2.0/.
#include "brave/browser/ui/webui/navigation_bar_data_provider.h"
namespace {
void BraveCustomizeBookmarksDataSource(content::WebUIDataSource* source) {
NavigationBarDataProvider::Initialize(source);
}
} // namespace
#include "../../../../../../chrome/browser/ui/webui/bookmarks/bookmarks_ui.cc"
@@ -0,0 +1,16 @@
// Copyright (c) 2019 The Brave Authors
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// you can obtain one at http://mozilla.org/MPL/2.0/.
#include "brave/browser/ui/webui/navigation_bar_data_provider.h"
namespace {
void BraveCustomizeDownloadsDataSource(content::WebUIDataSource* source) {
NavigationBarDataProvider::Initialize(source);
}
} // namespace
#include "../../../../../../chrome/browser/ui/webui/downloads/downloads_ui.cc" // NOLINT
@@ -5,6 +5,7 @@
#include "brave/browser/resources/md_extensions/grit/brave_extensions_resources.h"
#include "brave/browser/resources/md_extensions/grit/brave_extensions_resources_map.h"
#include "brave/browser/ui/webui/navigation_bar_data_provider.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/common/buildflags.h"
#include "chrome/grit/generated_resources.h"
@@ -23,6 +24,7 @@ void BraveAddExtensionsResources(content::WebUIDataSource* source) {
kBraveExtensionsResources[i].value);
}
#endif
NavigationBarDataProvider::Initialize(source);
}
} // namespace
@@ -0,0 +1,16 @@
// Copyright (c) 2019 The Brave Authors
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// you can obtain one at http://mozilla.org/MPL/2.0/.
#include "brave/browser/ui/webui/navigation_bar_data_provider.h"
namespace {
void BraveCustomizeHistoryDataSource(content::WebUIDataSource* source) {
NavigationBarDataProvider::Initialize(source);
}
} // namespace
#include "../../../../../chrome/browser/ui/webui/history_ui.cc"
+2 -36
View File
@@ -3,48 +3,14 @@
#include "brave/ui/webui/resources/grit/brave_webui_resources.h"
#include "ui/resources/grit/webui_resources.h"
#define SetLoadTimeDataDefaults SetLoadTimeDataDefaults_ChromiumImpl
// Replace text_defaults.css with brave's text_defaults.css
// which is defined in brave_webui_resources.grd.
#define IDR_WEBUI_CSS_TEXT_DEFAULTS_MD_PREVIOUS IDR_WEBUI_CSS_TEXT_DEFAULTS_MD
#undef IDR_WEBUI_CSS_TEXT_DEFAULTS_MD
#define IDR_WEBUI_CSS_TEXT_DEFAULTS_MD IDR_BRAVE_WEBUI_CSS_TEXT_DEFAULTS
#include "../../../../../ui/base/webui/web_ui_util.cc"
#undef SetLoadTimeDataDefaults
#undef IDR_WEBUI_CSS_TEXT_DEFAULTS_MD
#define IDR_WEBUI_CSS_TEXT_DEFAULTS_MD IDR_WEBUI_CSS_TEXT_DEFAULTS_MD_PREVIOUS
#include "chrome/grit/generated_resources.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"
namespace webui {
void SetLoadTimeDataDefaults(const std::string& app_locale,
base::DictionaryValue* localized_strings) {
SetLoadTimeDataDefaults_ChromiumImpl(app_locale, localized_strings);
#if !defined(OS_ANDROID)
localized_strings->SetString(
"brToolbarSettingsTitle",
l10n_util::GetStringUTF16(IDS_SETTINGS_SETTINGS)
);
#endif
localized_strings->SetString(
"brToolbarBookmarksTitle",
l10n_util::GetStringUTF16(IDS_BOOKMARK_MANAGER_TITLE)
);
localized_strings->SetString(
"brToolbarDownloadsTitle",
l10n_util::GetStringUTF16(IDS_DOWNLOAD_TITLE)
);
localized_strings->SetString(
"brToolbarHistoryTitle",
l10n_util::GetStringUTF16(IDS_HISTORY_TITLE)
);
}
void SetLoadTimeDataDefaults(const std::string& app_locale,
ui::TemplateReplacements* replacements) {
SetLoadTimeDataDefaults_ChromiumImpl(app_locale, replacements);
}
}
@@ -0,0 +1,12 @@
diff --git a/chrome/browser/ui/webui/bookmarks/bookmarks_ui.cc b/chrome/browser/ui/webui/bookmarks/bookmarks_ui.cc
index 0542e022aeaedc240cf0bc79b9acebfe121fcc4d..ac9fe90cb2d96fa9850c066ae33630a60bf4ba22 100644
--- a/chrome/browser/ui/webui/bookmarks/bookmarks_ui.cc
+++ b/chrome/browser/ui/webui/bookmarks/bookmarks_ui.cc
@@ -45,6 +45,7 @@ content::WebUIDataSource* CreateBookmarksUIHTMLSource(Profile* profile) {
content::WebUIDataSource* source =
content::WebUIDataSource::Create(chrome::kChromeUIBookmarksHost);
+ BraveCustomizeBookmarksDataSource(source);
// Build an Accelerator to describe undo shortcut
// NOTE: the undo shortcut is also defined in bookmarks/command_manager.js
// TODO(b/893033): de-duplicate shortcut by moving all shortcut definitions
@@ -0,0 +1,12 @@
diff --git a/chrome/browser/ui/webui/downloads/downloads_ui.cc b/chrome/browser/ui/webui/downloads/downloads_ui.cc
index 9f595a7bbb7adc1e42fd7eac31d0b8819deda532..41bfbeddcc010e8c76cf198c64d428d274b44137 100644
--- a/chrome/browser/ui/webui/downloads/downloads_ui.cc
+++ b/chrome/browser/ui/webui/downloads/downloads_ui.cc
@@ -47,6 +47,7 @@ content::WebUIDataSource* CreateDownloadsUIHTMLSource(Profile* profile) {
content::WebUIDataSource* source =
content::WebUIDataSource::Create(chrome::kChromeUIDownloadsHost);
+ BraveCustomizeDownloadsDataSource(source);
source->AddLocalizedString("title", IDS_DOWNLOAD_TITLE);
source->AddLocalizedString("searchResultsPlural", IDS_SEARCH_RESULTS_PLURAL);
source->AddLocalizedString("searchResultsSingular",
@@ -0,0 +1,12 @@
diff --git a/chrome/browser/ui/webui/history_ui.cc b/chrome/browser/ui/webui/history_ui.cc
index b6b6f4f7aa79a1c3a44a187c1f618e10194442bd..09a0d991a87ff90c84678ac0f6325a8e5076560a 100644
--- a/chrome/browser/ui/webui/history_ui.cc
+++ b/chrome/browser/ui/webui/history_ui.cc
@@ -56,6 +56,7 @@ content::WebUIDataSource* CreateHistoryUIHTMLSource(Profile* profile) {
content::WebUIDataSource* source =
content::WebUIDataSource::Create(chrome::kChromeUIHistoryHost);
+ BraveCustomizeHistoryDataSource(source);
// Localized strings (alphabetical order).
source->AddLocalizedString("actionMenuDescription",
IDS_HISTORY_ACTION_MENU_DESCRIPTION);
-1
View File
@@ -1,6 +1,5 @@
group("chromium_deps") {
deps = [
"//brave/ui/webui/resources",
"//brave/app:brave_generated_resources_grit",
]
}