From a60358fd0395b46e77e744c4f967fa6e53d5a5f4 Mon Sep 17 00:00:00 2001 From: Simon Hong Date: Tue, 12 May 2020 16:45:41 +0900 Subject: [PATCH 1/2] Revert "Revert "Use brave download link and Brave brand in brave://flags for download"" This reverts commit 3e277d12959f6814cfc1b7022bd61b72837acccc. --- common/BUILD.gn | 3 +++ common/brave_content_client.cc | 22 +++++++++++++++++++ common/brave_content_client.h | 3 +++ .../resources/brave_flags_overrides.js | 15 +++++++++++++ .../resources/brave_components_resources.grd | 1 + .../resources/brave_flags_ui_resources.grdp | 4 ++++ 6 files changed, 48 insertions(+) create mode 100644 components/flags_ui/resources/brave_flags_overrides.js create mode 100644 components/resources/brave_flags_ui_resources.grdp diff --git a/common/BUILD.gn b/common/BUILD.gn index 724893bf0485..ffb9ec4bb112 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -92,11 +92,14 @@ source_set("common") { } deps = [ + "//base", ":network_constants", ":pref_names", ":shield_exceptions", ":switches", "//brave/chromium_src:common", + "//brave/components/resources", + "//components/resources", "//content/public/common", "//extensions/buildflags", ] diff --git a/common/brave_content_client.cc b/common/brave_content_client.cc index ddea34c74ee0..4063df722be3 100644 --- a/common/brave_content_client.cc +++ b/common/brave_content_client.cc @@ -5,12 +5,34 @@ #include "brave/common/brave_content_client.h" +#include + +#include "base/memory/ref_counted_memory.h" +#include "components/grit/brave_components_resources.h" +#include "components/grit/components_resources.h" #include "content/public/common/url_constants.h" BraveContentClient::BraveContentClient() {} BraveContentClient::~BraveContentClient() {} +base::RefCountedMemory* BraveContentClient::GetDataResourceBytes( + int resource_id) { + if (resource_id == IDR_FLAGS_UI_FLAGS_JS) { + auto* chromium_flags_ui_data = + ChromeContentClient::GetDataResourceBytes(resource_id); + auto* brave_flags_ui_data = ChromeContentClient::GetDataResourceBytes( + IDR_FLAGS_UI_BRAVE_FLAGS_OVERRIDES_JS); + std::string new_flags_js(chromium_flags_ui_data->front_as(), + chromium_flags_ui_data->size()); + new_flags_js.append(brave_flags_ui_data->front_as(), + brave_flags_ui_data->size()); + return new base::RefCountedStaticMemory(new_flags_js.c_str(), + new_flags_js.length()); + } + return ChromeContentClient::GetDataResourceBytes(resource_id); +} + void BraveContentClient::AddAdditionalSchemes(Schemes* schemes) { ChromeContentClient::AddAdditionalSchemes(schemes); schemes->standard_schemes.push_back(content::kBraveUIScheme); diff --git a/common/brave_content_client.h b/common/brave_content_client.h index 3b5c44c9be26..dd8a6282ccf2 100644 --- a/common/brave_content_client.h +++ b/common/brave_content_client.h @@ -13,6 +13,9 @@ class BraveContentClient : public ChromeContentClient { BraveContentClient(); ~BraveContentClient() override; + private: + // ChromeContentClinet overrides: + base::RefCountedMemory* GetDataResourceBytes(int resource_id) override; void AddAdditionalSchemes(Schemes* schemes) override; }; diff --git a/components/flags_ui/resources/brave_flags_overrides.js b/components/flags_ui/resources/brave_flags_overrides.js new file mode 100644 index 000000000000..f3e6c46d6d4a --- /dev/null +++ b/components/flags_ui/resources/brave_flags_overrides.js @@ -0,0 +1,15 @@ +/* Copyright (c) 2020 The Brave Authors. All rights reserved. + * 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/. */ + +document.addEventListener('DOMContentLoaded', function() { + $('channel-promo-beta').innerHTML = ` + Interested in cool new Brave features? Try our + beta channel. + ` + $('channel-promo-dev').innerHTML = ` + Interested in cool new Brave features? Try our + dev channel. + ` +}); diff --git a/components/resources/brave_components_resources.grd b/components/resources/brave_components_resources.grd index db11289b5fa0..64f4bf6f3e21 100644 --- a/components/resources/brave_components_resources.grd +++ b/components/resources/brave_components_resources.grd @@ -62,6 +62,7 @@ + diff --git a/components/resources/brave_flags_ui_resources.grdp b/components/resources/brave_flags_ui_resources.grdp new file mode 100644 index 000000000000..5258d20be499 --- /dev/null +++ b/components/resources/brave_flags_ui_resources.grdp @@ -0,0 +1,4 @@ + + + + From f7b1bc2d71e456a89a51810492c8b662be1dabc1 Mon Sep 17 00:00:00 2001 From: Simon Hong Date: Tue, 12 May 2020 20:16:45 +0900 Subject: [PATCH 2/2] Use RefCountedString to return modifed flags.js resources new flags.js includes original flags.js and our flags.js file. --- common/BUILD.gn | 1 + common/brave_content_client.cc | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/common/BUILD.gn b/common/BUILD.gn index ffb9ec4bb112..3810314432b5 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -102,6 +102,7 @@ source_set("common") { "//components/resources", "//content/public/common", "//extensions/buildflags", + "//ui/base", ] if (is_mac) { diff --git a/common/brave_content_client.cc b/common/brave_content_client.cc index 4063df722be3..74fc87a7893b 100644 --- a/common/brave_content_client.cc +++ b/common/brave_content_client.cc @@ -11,6 +11,7 @@ #include "components/grit/brave_components_resources.h" #include "components/grit/components_resources.h" #include "content/public/common/url_constants.h" +#include "ui/base/resource/resource_bundle.h" BraveContentClient::BraveContentClient() {} @@ -19,16 +20,15 @@ BraveContentClient::~BraveContentClient() {} base::RefCountedMemory* BraveContentClient::GetDataResourceBytes( int resource_id) { if (resource_id == IDR_FLAGS_UI_FLAGS_JS) { - auto* chromium_flags_ui_data = - ChromeContentClient::GetDataResourceBytes(resource_id); - auto* brave_flags_ui_data = ChromeContentClient::GetDataResourceBytes( - IDR_FLAGS_UI_BRAVE_FLAGS_OVERRIDES_JS); - std::string new_flags_js(chromium_flags_ui_data->front_as(), - chromium_flags_ui_data->size()); - new_flags_js.append(brave_flags_ui_data->front_as(), - brave_flags_ui_data->size()); - return new base::RefCountedStaticMemory(new_flags_js.c_str(), - new_flags_js.length()); + const ui::ResourceBundle& resource_bundle = + ui::ResourceBundle::GetSharedInstance(); + const std::string flags_js = + resource_bundle.LoadDataResourceString(resource_id) + + resource_bundle.LoadDataResourceString( + IDR_FLAGS_UI_BRAVE_FLAGS_OVERRIDES_JS); + base::RefCountedString* bytes = new base::RefCountedString(); + bytes->data().assign(flags_js.data(), flags_js.length()); + return bytes; } return ChromeContentClient::GetDataResourceBytes(resource_id); }