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

Replace chrome link with brave link from "chrome://flags #5526

Merged
merged 2 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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());
Copy link
Member Author

@simonhong simonhong May 13, 2020

Choose a reason for hiding this comment

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

This fixes previous bug - RefCountedString owns string data(flags_js).
RefCountedStaticMemory just store data address (only useful for static data).
I think it was luck to load properly on macOS with RefCountedStaticMemory.

return bytes;
}
return ChromeContentClient::GetDataResourceBytes(resource_id);
}
Expand Down