This migration has been effected in upstream, but several places in our
codebase got broken by this transition. This change makes several parts
of our codebase more friendly to passing `string_view`.
Chromium changes:
https://chromium.googlesource.com/chromium/src/+/0e1784e3cf990560b173f40338e582f50aba0e85
commit 0e1784e3cf990560b173f40338e582f50aba0e85
Author: Charlie Harrison <csharrison@chromium.org>
Date: Fri Oct 3 11:04:26 2025 -0700
RELAND: Migrate GURL::path() and friends to return string_view
This relands crrev.com/c/7003625. Missing cases were found by staring
at the output of `git grep` for the whole codebase.
Origin description:
Also migrates some last remaining callers of the std::string APIs.
This completes phase 1 of crbug.com/448174617.
Bug: 448174617
Change-Id: I7f24f81d1fbf129d8b0dd94f4cf948626deab933
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7007010
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Charlie Harrison <csharrison@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1524878}
* Add AI Chat build flag to components/ai_chat
* Add AI Chat build flag to browser/ui
* Add AI Chat build flag to browser/resources
* Add AI Chat build flag to chromium overrides
* Add AI Chat build flag to other components
* Add AI Chat build flag to core browser files
* Add AI Chat build flag to app and renderer
* Add AI Chat build flag to remaining files
* Set enable_ai_chat to !is_brave_origin_branded
* Review comments
Including gn_check errors in chromium_src
* Exclude ai_chat Jest tests when not enabled
extends the transpile_web_ui.py to assert that the source roots provided via imports_from are complete.
The purpose of this is to improve the gn analyze functionality to be able to infer which tests need to run based on filechanges alone.
* Gate VPN on !brave_origin_only_mode
* Gate Tor on !brave_origin_only_mode
* Gate speedreader on !brave_origin_only_mode
* Gate Wayback machine on !brave_origin_only_mode
Rename pref/features to try to make them more clear. `Enable` means that the site will open in Speedreader automatically. `Allow` means it may open in Speedreader depending on whether it's a site specific override or allow for all readable urls is true and the url looks readable.
This commit migrates the SplitView implementation from using individual
views for secondary content management to utilizing the centralized
BraveContentsContainerView. This change eliminates code duplication and
improves maintainability by leveraging existing infrastructure.
**Key Changes:**
** SplitView Architecture Refactoring:**
- Replace direct management of secondary_contents_web_view_,
secondary_devtools_web_view_, secondary_reader_mode_toolbar_,
secondary_lens_overlay_view_, and secondary_contents_scrim_view_
- Migrate to using a single BraveContentsContainerView instance that
encapsulates all secondary content management
** View Hierarchy Simplification:**
- secondary_contents_container_ (raw View) → secondary_contents_container_view_
(BraveContentsContainerView)
- All secondary view access now goes through the container view's accessors
- Unified layout management through BraveContentsContainerView
**Benefits:**
- Reduces code duplication between primary and secondary content management
- Leverages existing ContentsContainerView infrastructure for DevTools,
scrim views, lens overlay, and reader mode toolbar
- Simplifies view hierarchy and improves maintainability
- Better separation of concerns with centralized content management
* Make sure SkusJSHandler has correct construtor order to prevent
incorrect GC info index.
Also cppgc::Persistent to prevent immature freeing from GC
* Adding self-referencing to other gin::Wrappable
This class was still using the deprecated version that is set to be
deleted. This change migrates this class to use Oilpan GC for memory
management.
Chromium changes:
https://chromium.googlesource.com/chromium/src/+/61e491610dac67129273aa96549603483c59759f
commit 61e491610dac67129273aa96549603483c59759f
Author: Andreas Haas <ahaas@chromium.org>
Date: Wed Jul 30 03:35:32 2025 -0700
[gin] Delete DeprecatedWrappable
This CL deletes gin::DeprecatedWrappable, and classes and data
structures related to gin::DeprecatedWrappable. Additionally it removes
internal fields of JS wrapper objects that were only used by
gin::DeprecatedWrappable, but are not needed anymore with the new
gin::Wrappable.
Bug: 345640553
Change-Id: Ideb4424048e62fec6c6a7ee5fd60a4635f6ef1e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6799157
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: Camille Lamy <clamy@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1494071}
This change to the ownership model for the delegate passed into
`SetEventDelegate` requires us to separate the controller from the
delegate, and have them share a weak relationship.
Chromium changes:
https://chromium.googlesource.com/chromium/src/+/50d43c7bcf04f5fac7cdc7ad26732f3d94b5bd43
commit 50d43c7bcf04f5fac7cdc7ad26732f3d94b5bd43
Author: Di Wu <diwux@google.com>
Date: Sun Jul 27 20:29:49 2025 -0700
Refactor TtsUtterance to always own its event delegate
This change refactors the ownership model for UtteranceEventDelegate to
establish a single, clear model where TtsUtterance always takes
ownership of its delegate via std::unique_ptr. This simplifies the code,
addresses code review feedback, and fixes underlying memory management
issues that caused test failures.
Problem:
The previous memory management for UtteranceEventDelegate was fragile.
Some delegates used a "delete this" pattern, which is error-prone and
led to memory leaks in browser tests.
An initial refactoring moved to a std::unique_ptr model but introduced a
NonOwnedUtteranceEventDelegate wrapper to handle cases where the
delegate's lifetime was managed externally (e.g., TtsSpeakFunction,
SettingsWithTtsPreviewHandler). Code reviewers pointed out that this
wrapper complicated the ownership model and that a single, consistent
ownership pattern would be preferable.
Solution:
This commit fully adopts the single-ownership model and removes the
NonOwnedUtteranceEventDelegate wrapper.
1. TtsUtterance always owns its delegate: TtsUtterance::SetEventDelegate
now exclusively takes a std::unique_ptr<UtteranceEventDelegate>,
ensuring the delegate is automatically destroyed with the utterance.
2. Refactored externally-managed delegates: The two cases that
previously required a non-owned wrapper have been refactored to use
dedicated, owned delegate classes:
2.1 TtsSpeakFunction: Now uses a new, private TtsExtensionEventHandler
class that implements UtteranceEventDelegate. This handler is owned by
the TtsUtterance and holds the `extension_id` to dispatch events. This
removes the need for a reference back to the `TtsSpeakFunction`,
simplifying lifetime management.
2.2 SettingsWithTtsPreviewHandler: Now uses a new
TtsPreviewEventDelegate class. This handler is owned by the TtsUtterance
and holds a base::WeakPtr to the SettingsWithTtsPreviewHandler to safely
make callbacks.
3. Simplified delegate cleanup: With the removal of the non-owned
wrapper, the GetType() virtual method on UtteranceEventDelegate and the
corresponding logic in TtsControllerImpl are no longer needed and have
been removed.
This refactoring makes the TTS delegate ownership model clear,
consistent, and safe, resolving memory leaks and directly addressing
code review feedback for a simpler design.
Bug: b:281717553, b:251732518, 431531726, 432151731
Test: Run and symbolize the affected two tests with asan and lsan enabled. Then run with MiraclePtr check on the SelectToSpeakTest.FullscreenMagnifierFollowsTextBoundsWhenPrefOn test.
Change-Id: Ia7524c0a859ee2f7c1f208412215c6e6b1b4e512
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6733896
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Di Wu <diwux@google.com>
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1492580}
This class is now called `gin::DeprecatedWrappable`. There seems to be
some work to introduce a new class, but for now it is reverted.
Chromium changes:
https://chromium.googlesource.com/chromium/src/+/3c15226886207c98dffc33a20b6a3dfd7df7a21c
commit 3c15226886207c98dffc33a20b6a3dfd7df7a21c
Author: Andreas Haas <ahaas@chromium.org>
Date: Wed Jul 2 05:57:48 2025 -0700
[gin] Rename gin::Wrappable to gin::DeprecatedWrappable
This is the first CL of a sequence of CLs to refactor gin::Wrappable
such that it is based on cppgc. In a follow-up CL we will re-introduce
`gin::Wrappable` again, and then port all uses from
`gin::DeprecatedWrappable` to `gin::Wrappable`.
BYPASS_LARGE_CHANGE_WARNING
Bug: 345640553
Change-Id: Iad028a1cec93aa8ade3b35c8099f8de5081f88fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6513641
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Owners-Override: Rick Byers <rbyers@chromium.org>
Reviewed-by: Rick Byers <rbyers@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1481539}
Chromium changes:
https://chromium.googlesource.com/chromium/src/+/f99163fe2d3428680834db3f141a6d83590561f0
commit f99163fe2d3428680834db3f141a6d83590561f0
Author: Nina Satragno <nsatragno@chromium.org>
Date: Wed Jul 2 08:36:22 2025 -0700
Revert "[gin] Introduce gin::Wrappable based on cppgc"
This reverts commit dfbe3b4a57ddbfbfc74ab261b51db2ed87f754c2.
Reason for revert: WrappableTest.WrapAndUnwrap failing on Linux
UBSan tests
https://ci.chromium.org/ui/p/chromium/builders/ci/Linux%20UBSan%20Tests/7971/overview
Bug: 345640553
Original change's description:
> [gin] Introduce gin::Wrappable based on cppgc
>
> This CL implements the new `gin::Wrappable` based on cppgc, and ports
> the tests in `wrappable_unittest` from `gin::DeprecatedWrappable` to
> `gin::Wrappable`.
>
> The new implementation of `gin::Wrappable` has sightly different
> semantics than the old one. In the old one it was possible to call
> `Converter<WrappableSubClass>::FromV8()` with any JSObject, and the
> JSObject would either get unwrapped if it wrapped an object of type
> `WrappableSubClass`, or it would return nullptr. The new implementation
> would either return nullptr or crash in a DCHECK if the JSObject wrapped
> an object which is not of type `WrappableSubClass`.
>
> Bug: 345640553
> Change-Id: Ia32e2d82f0383afb56382e9fe78fd94677b00fe8
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6519611
> Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
> Commit-Queue: Andreas Haas <ahaas@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1481565}
Bug: 345640553
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Change-Id: I6499b57f278ce600d03e2d3bbeaee1df04ba3512
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6701047
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Auto-Submit: Nina Satragno <nsatragno@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Owners-Override: Nina Satragno <nsatragno@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1481635}
- BraveSpeedReaderDisabled is now called BraveSpeedReaderEnabled
- Replace kSpeedreaderDisabledByPolicy with kSpeedreaderPrefFeatureEnabled which already existed
- Invert Disabled policy name to Enabled to match the pref that already existed.
- Invert logic at various places to be for enabled checks instead of disabled.
- Update tests and policy definitions accordingly.
- We now show opt-ins for Recommended policy enforcement (things set via `defaults write` on macOS, it should show an indicator if you match the recommended setting or not)
- We now hide opt-ins for Mandatory enforcements (things set via `sudo /usr/libexec/PlistBuddy`)
* Add top level toggle to enable/disable Speedreader
This migrates away an old bad named feature for automatically using
speedreader for all sites. The pref was wrongly named `enabled`.
This also adds a new preference for actually enabling/disabling the
feature.
* Fixes Android presubmit
---------
Co-authored-by: Serg <serg.zhukovsky@gmail.com>
This PR is the run of `gn format` on all `gn` files. This is a
mechanical change done with:
```sh
git ls-files -- "*.gn" | xargs gn format
git ls-files -- "*.gni" | xargs gn format
```
This change has been motivated primarily by an improvement to the
formatters privided by `gn` correcting cases of redundant target naming,
i.e cases where `//foo:foo` is used, and should just be `//foo`.
For this particular `gn` change, see:
https://chromium.googlesource.com/chromium/src/+/c822490a82cdb6ad479159683a92858f7c6f0a58
Resolves https://github.com/brave/brave-browser/issues/48161
Files that use functions from `string_util.h` should include that header
directly instead of relying on transient inclusions.
This is a mechanical change using this script:
```sh
remove_header_if_unused() {
files=$(git grep -l "base/strings/string_util.h")
for file in $files; do
if ! git grep -qE "base::MakeStringPiece|base::MakeWStringView|base::ToLowerASCII|base::ToUpperASCII|base::CompareCaseInsensitiveASCII|base::EqualsCaseInsensitiveASCII|base::EmptyString|base::RemoveChars|base::ReplaceChars|base::TrimPositions|base::TrimString|base::TruncateUTF8ToByteSize|base::TrimWhitespace|base::CollapseWhitespace|base::ContainsOnlyChars|base::IsStringUTF8|base::IsStringASCII|base::EqualsASCII|base::CompareCase|base::StartsWith|base::EndsWith|base::RemovePrefix|base::RemoveSuffix|base::IsAscii|base::IsUnicodeControl|base::IsHexDigit|base::IsUnicodeWhitespace|base::FormatBytesUnlocalized|base::ReplaceFirstSubstringAfterOffset|base::ReplaceSubstringsAfterOffset|base::WriteInto|base::JoinString|base::ReplaceStringPlaceholders|base::MakeStringViewWithNulChars" "$file"; then
sed -i '/base\/strings\/string_util.h/d' "$file"
echo "Removed 'base/strings/string_util.h' from $file"
fi
done
}
add_header_if_needed() {
files=$(git grep -lE "base::MakeStringPiece|base::MakeWStringView|base::ToLowerASCII|base::ToUpperASCII|base::CompareCaseInsensitiveASCII|base::EqualsCaseInsensitiveASCII|base::EmptyString|base::RemoveChars|base::ReplaceChars|base::TrimPositions|base::TrimString|base::TruncateUTF8ToByteSize|base::TrimWhitespace|base::CollapseWhitespace|base::ContainsOnlyChars|base::IsStringUTF8|base::IsStringASCII|base::EqualsASCII|base::CompareCase|base::StartsWith|base::EndsWith|base::RemovePrefix|base::RemoveSuffix|base::IsAscii|base::IsUnicodeControl|base::IsHexDigit|base::IsUnicodeWhitespace|base::FormatBytesUnlocalized|base::ReplaceFirstSubstringAfterOffset|base::ReplaceSubstringsAfterOffset|base::WriteInto|base::JoinString|base::ReplaceStringPlaceholders|base::MakeStringViewWithNulChars")
for file in $files; do
../tools/add_header.py --header '"base/strings/string_util.h"' "$file"
done
}
remove_header_if_unused
add_header_if_needed
```
Resolves https://github.com/brave/brave-browser/issues/46559
Removing some of this unnecessary inclusions can help with build times.
This is a mechanical change, with the following script:
```sh
remove_header_if_unused() {
files=$(git grep -l "url/gurl.h")
for file in $files; do
if ! git grep -qE "\bGURL\b" "$file"; then
sed -i '/url\/gurl.h/d' "$file"
echo "Removed 'url/gurl.h' from $file"
fi
done
}
remove_header_if_unused
```
* Fix includes for `base::StringPrintf`
Upstream is doing a couple of IWYU fixes for `base::StringPrintf`, and
this will have an effect on our own uses of this function. This change
corrects all the includes we have.
This is a mechanical change, done with the following script.
```sh
remove_header_if_unused() {
files=$(git grep -l "base/strings/stringprintf.h")
for file in $files; do
if ! git grep -qE "base::StringPrintf|base::StringAppend" "$file"; then
sed -i '/base\/strings\/stringprintf.h/d' "$file"
echo "Removed 'base/strings/stringprintf.h' from $file"
fi
done
}
add_header_if_needed() {
files=$(git grep -lE "base::StringPrintf|base::StringAppend")
for file in $files; do
../tools/add_header.py --header '"base/strings/stringprintf.h"' "$file"
done
}
remove_header_if_unused
add_header_if_needed
```
* IWYU fix for `ostream` operators
This header was being pulled transiently. This caused build failures
once https://github.com/brave/brave-core/pull/29156 was merged.
Upstream is doing a couple of IWYU fixes for `base::StringPrintf`, and
this will have an effect on our own uses of this function. This change
corrects all the includes we have.
This is a mechanical change, done with the following script.
```sh
remove_header_if_unused() {
files=$(git grep -l "base/strings/stringprintf.h")
for file in $files; do
if ! git grep -qE "base::StringPrintf|base::StringAppend" "$file"; then
sed -i '/base\/strings\/stringprintf.h/d' "$file"
echo "Removed 'base/strings/stringprintf.h' from $file"
fi
done
}
add_header_if_needed() {
files=$(git grep -lE "base::StringPrintf|base::StringAppend")
for file in $files; do
../tools/add_header.py --header '"base/strings/stringprintf.h"' "$file"
done
}
remove_header_if_unused
add_header_if_needed
```
There's no need to patch off the crate `test_only` value anymore as the
crate is now gone from the upstream tree.
Chromium change:
https://chromium.googlesource.com/chromium/src/+/3eac73aa297e57a1d6e17bec25973848d16e91a4
commit 3eac73aa297e57a1d6e17bec25973848d16e91a4
Author: Lukasz Anforowicz <lukasza@chromium.org>
Date: Mon Mar 24 15:12:42 2025 -0700
[rust] Remove unneeded, grandparented-in, direct Rust crate deps.
This CL removes dependencies from
`third_party/rust/chromium_crates_io/Cargo.toml` that have been
grand-parented-in in https://crrev.com/c/5019147, but that do not seem
to have any direct dependencies from Chromium targets.
The CL has been created by:
* Manually editing `third_party/rust/chromium_crates_io/Cargo.toml`
and `third_party/rust/chromium_crates_io/gnrt_config.toml`
* Running:
- `tools/crates/run_gnrt.py vendor`
- `tools/crates/run_gnrt.py gen`
Bug: 405468274
Chromium is now migrating to `std::variant`, and this change does the
same in Brave.
This change was done with a script:
```sh
function delete_line_with {
echo "Deleting lines with $1"
git grep -l "$1" \
| grep -E "\.(h|cc|mm|py)$" \
| sort \
| uniq \
| xargs sed -e "/$(echo "$1" | sed -e 's/[\/&]/\\&/g')/d"
}
function add_header {
echo "Adding header $1"
git diff --name-only \
| xargs ../tools/add_header.py --header "$1"
git grep -l "std::variant" \
| xargs ../tools/add_header.py --header "$1"
}
delete_line_with "\"third_party/abseil-cpp/absl/types/variant.h\""
add_header "<variant>"
git cl format
```
Chromium change:
https://chromium.googlesource.com/chromium/src/+/c01ae649582b75bce39769132a5a41bec8e2d3e4
commit c01ae649582b75bce39769132a5a41bec8e2d3e4
Author: Victor Hugo Vianna Silva <victorvianna@google.com>
Date: Mon Mar 10 19:15:52 2025 -0700
Make absl::variant a typedef for std::variant
This is a re-upload of https://crrev.com/c/5469234, see original
description below. Differences from the original CL:
- Windows symbol definition files were regenerated with
generate_def_files.py.
- New build fixes in password_store_consumer.h,
plus_address_jit_allocator_unittest.cc and mojo_proxy_test.cc.
- Revert change in enclave_protocol_utils.cc, it doesn't seem needed
anymore.
We estimate that ~75% of the regression shown by the
android-binary-size bot will recover after PGO profiles are updated.
See comments 34 to 42 in the linked bug for some numbers.
Original CL description:
"
Discussion thread: https://groups.google.com/u/1/a/chromium.org/g/cxx/c/0EhbuwD-Dpw/m/lbGjN1sxAgAJ
This commit is an updated/tuned version of
David Benjamin's patches (5313884, 5314107).
This only changes the types around. It doesn't rewrite the existing
uses, which we can do incrementally.
"
Binary-Size: See commit description.
Bug: 40242126