chore: migrate base::StringPiece to std::string_view (#40915)
* chore: migrate from base::StringPiece to std::string_view in keyboard_util.cc
* chore: migrate from base::StringPiece to std::string_view in error_thrower.cc
* chore: migrate from base::StringPiece to std::string_view in electron_api_web_contents.cc
* chore: migrate from base::StringPiece to std::string_view in gin_helper/dictionary.h
* chore: migrate from base::StringPiece to std::string_view in electron_api_url_loader.cc
* chore: phase out internal use of base:::StringPiece
`base::StringPiece` is being phased out upstream. Its code has been
removed upstream and it's just a typedef for `std::string_view`.
They haven't removed the typedef yet, so this PR tries to get ahead
of future breakage by migrating "internal" use (i.e. leaving alone the
places where the `base::StringPiece` name is coming from an upstream
method that we override).
Xref: https://bugs.chromium.org/p/chromium/issues/detail?id=691162
Xref: 4294483
Xref: https://docs.google.com/document/d/1d4RnD1uAE2t4iANR0nXy82ASIPGsPuw2mpO6v6T7JKs
This commit is contained in:
parent
892c9d78a3
commit
f36ceae024
45 changed files with 223 additions and 174 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/fixed_flat_map.h"
|
||||
|
@ -135,7 +136,7 @@ struct Converter<blink::WebMouseEvent::Button> {
|
|||
blink::WebMouseEvent::Button* out) {
|
||||
using Val = blink::WebMouseEvent::Button;
|
||||
static constexpr auto Lookup =
|
||||
base::MakeFixedFlatMap<base::StringPiece, Val>({
|
||||
base::MakeFixedFlatMap<std::string_view, Val>({
|
||||
{"left", Val::kLeft},
|
||||
{"middle", Val::kMiddle},
|
||||
{"right", Val::kRight},
|
||||
|
@ -148,7 +149,7 @@ struct Converter<blink::WebMouseEvent::Button> {
|
|||
|
||||
// these are the modifier names we both accept and return
|
||||
static constexpr auto Modifiers =
|
||||
base::MakeFixedFlatMap<base::StringPiece, blink::WebInputEvent::Modifiers>({
|
||||
base::MakeFixedFlatMap<std::string_view, blink::WebInputEvent::Modifiers>({
|
||||
{"alt", blink::WebInputEvent::Modifiers::kAltKey},
|
||||
{"capslock", blink::WebInputEvent::Modifiers::kCapsLockOn},
|
||||
{"control", blink::WebInputEvent::Modifiers::kControlKey},
|
||||
|
@ -167,14 +168,14 @@ static constexpr auto Modifiers =
|
|||
|
||||
// these are the modifier names we accept but do not return
|
||||
static constexpr auto ModifierAliases =
|
||||
base::MakeFixedFlatMap<base::StringPiece, blink::WebInputEvent::Modifiers>({
|
||||
base::MakeFixedFlatMap<std::string_view, blink::WebInputEvent::Modifiers>({
|
||||
{"cmd", blink::WebInputEvent::Modifiers::kMetaKey},
|
||||
{"command", blink::WebInputEvent::Modifiers::kMetaKey},
|
||||
{"ctrl", blink::WebInputEvent::Modifiers::kControlKey},
|
||||
});
|
||||
|
||||
static constexpr auto ReferrerPolicies =
|
||||
base::MakeFixedFlatMap<base::StringPiece, network::mojom::ReferrerPolicy>({
|
||||
base::MakeFixedFlatMap<std::string_view, network::mojom::ReferrerPolicy>({
|
||||
{"default", network::mojom::ReferrerPolicy::kDefault},
|
||||
{"no-referrer", network::mojom::ReferrerPolicy::kNever},
|
||||
{"no-referrer-when-downgrade", network::mojom::ReferrerPolicy::kNoReferrerWhenDowngrade},
|
||||
|
@ -197,8 +198,8 @@ struct Converter<blink::WebInputEvent::Modifiers> {
|
|||
}
|
||||
};
|
||||
|
||||
std::vector<base::StringPiece> ModifiersToArray(int modifiers) {
|
||||
std::vector<base::StringPiece> modifier_strings;
|
||||
std::vector<std::string_view> ModifiersToArray(int modifiers) {
|
||||
std::vector<std::string_view> modifier_strings;
|
||||
|
||||
for (const auto& [name, mask] : Modifiers)
|
||||
if (mask & modifiers)
|
||||
|
@ -463,7 +464,7 @@ v8::Local<v8::Value>
|
|||
Converter<std::optional<blink::mojom::FormControlType>>::ToV8(
|
||||
v8::Isolate* isolate,
|
||||
const std::optional<blink::mojom::FormControlType>& in) {
|
||||
base::StringPiece str{"none"};
|
||||
std::string_view str{"none"};
|
||||
if (in.has_value()) {
|
||||
switch (*in) {
|
||||
case blink::mojom::FormControlType::kButtonButton:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue