Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add strings for NavigationBar on relevant WebUI data sources directly #2384

Merged
merged 1 commit into from
May 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions browser/ui/webui/brave_md_settings_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 changes: 6 additions & 0 deletions browser/ui/webui/brave_webui_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"), {
Expand Down
22 changes: 22 additions & 0 deletions browser/ui/webui/navigation_bar_data_provider.cc
Original file line number Diff line number Diff line change
@@ -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);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lint?

20 changes: 20 additions & 0 deletions browser/ui/webui/navigation_bar_data_provider.h
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions chromium_src/chrome/browser/ui/webui/bookmarks/bookmarks_ui.cc
Original file line number Diff line number Diff line change
@@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lint

16 changes: 16 additions & 0 deletions chromium_src/chrome/browser/ui/webui/downloads/downloads_ui.cc
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lint fail by no last empty line?

Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -23,6 +24,7 @@ void BraveAddExtensionsResources(content::WebUIDataSource* source) {
kBraveExtensionsResources[i].value);
}
#endif
NavigationBarDataProvider::Initialize(source);
}

} // namespace
Expand Down
16 changes: 16 additions & 0 deletions chromium_src/chrome/browser/ui/webui/history_ui.cc
Original file line number Diff line number Diff line change
@@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lint?

38 changes: 2 additions & 36 deletions chromium_src/ui/base/webui/web_ui_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This define pair can be removed

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);
}

}
12 changes: 12 additions & 0 deletions patches/chrome-browser-ui-webui-bookmarks-bookmarks_ui.cc.patch
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions patches/chrome-browser-ui-webui-downloads-downloads_ui.cc.patch
Original file line number Diff line number Diff line change
@@ -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",
12 changes: 12 additions & 0 deletions patches/chrome-browser-ui-webui-history_ui.cc.patch
Original file line number Diff line number Diff line change
@@ -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 change: 0 additions & 1 deletion ui/base/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
group("chromium_deps") {
deps = [
"//brave/ui/webui/resources",
"//brave/app:brave_generated_resources_grit",
]
}