Skip to content

Commit

Permalink
Use RefCountedString to return modifed flags.js resources
Browse files Browse the repository at this point in the history
new flags.js includes original flags.js and our flags.js file.
  • Loading branch information
simonhong committed May 13, 2020
1 parent a60358f commit f7b1bc2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ source_set("common") {
"//components/resources",
"//content/public/common",
"//extensions/buildflags",
"//ui/base",
]

if (is_mac) {
Expand Down
20 changes: 10 additions & 10 deletions common/brave_content_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}

Expand All @@ -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);
}
Expand Down

0 comments on commit f7b1bc2

Please sign in to comment.