From f7b1bc2d71e456a89a51810492c8b662be1dabc1 Mon Sep 17 00:00:00 2001 From: Simon Hong Date: Tue, 12 May 2020 20:16:45 +0900 Subject: [PATCH] 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); }