Use RefCountedString to return modifed flags.js resources

new flags.js includes original flags.js and our flags.js file.
This commit is contained in:
Simon Hong
2020-05-13 11:47:21 +09:00
parent a60358fd03
commit f7b1bc2d71
2 changed files with 11 additions and 10 deletions
+1
View File
@@ -102,6 +102,7 @@ source_set("common") {
"//components/resources",
"//content/public/common",
"//extensions/buildflags",
"//ui/base",
]
if (is_mac) {
+10 -10
View File
@@ -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<const char>(),
chromium_flags_ui_data->size());
new_flags_js.append(brave_flags_ui_data->front_as<const char>(),
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);
}