refactor: use base::Extend in AddAdditionalSchemes() (#44864)

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
trop[bot] 2024-11-27 12:30:32 -06:00 committed by GitHub
parent cd6e3d720f
commit f22baeb670
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,6 +10,7 @@
#include <vector> #include <vector>
#include "base/command_line.h" #include "base/command_line.h"
#include "base/containers/extend.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "content/public/common/content_constants.h" #include "content/public/common/content_constants.h"
@ -98,21 +99,6 @@ bool IsWidevineAvailable(
} }
#endif // BUILDFLAG(ENABLE_WIDEVINE) #endif // BUILDFLAG(ENABLE_WIDEVINE)
void AppendDelimitedSwitchToVector(const std::string_view cmd_switch,
std::vector<std::string>* append_me) {
auto* command_line = base::CommandLine::ForCurrentProcess();
auto switch_value = command_line->GetSwitchValueASCII(cmd_switch);
if (!switch_value.empty()) {
constexpr std::string_view delimiter{",", 1};
auto tokens =
base::SplitString(switch_value, delimiter, base::TRIM_WHITESPACE,
base::SPLIT_WANT_NONEMPTY);
append_me->reserve(append_me->size() + tokens.size());
std::move(std::begin(tokens), std::end(tokens),
std::back_inserter(*append_me));
}
}
} // namespace } // namespace
ElectronContentClient::ElectronContentClient() = default; ElectronContentClient::ElectronContentClient() = default;
@ -149,16 +135,19 @@ void ElectronContentClient::AddAdditionalSchemes(Schemes* schemes) {
// //
// We use this for registration to network utility process // We use this for registration to network utility process
if (IsUtilityProcess()) { if (IsUtilityProcess()) {
AppendDelimitedSwitchToVector(switches::kServiceWorkerSchemes, const auto& cmd = *base::CommandLine::ForCurrentProcess();
&schemes->service_worker_schemes); auto append_cli_schemes = [&cmd](auto& appendme, const auto key) {
AppendDelimitedSwitchToVector(switches::kStandardSchemes, base::Extend(appendme, base::SplitString(cmd.GetSwitchValueASCII(key),
&schemes->standard_schemes); ",", base::TRIM_WHITESPACE,
AppendDelimitedSwitchToVector(switches::kSecureSchemes, base::SPLIT_WANT_NONEMPTY));
&schemes->secure_schemes); };
AppendDelimitedSwitchToVector(switches::kBypassCSPSchemes,
&schemes->csp_bypassing_schemes); using namespace switches;
AppendDelimitedSwitchToVector(switches::kCORSSchemes, append_cli_schemes(schemes->cors_enabled_schemes, kCORSSchemes);
&schemes->cors_enabled_schemes); append_cli_schemes(schemes->csp_bypassing_schemes, kBypassCSPSchemes);
append_cli_schemes(schemes->secure_schemes, kSecureSchemes);
append_cli_schemes(schemes->service_worker_schemes, kServiceWorkerSchemes);
append_cli_schemes(schemes->standard_schemes, kStandardSchemes);
} }
if (electron::fuses::IsGrantFileProtocolExtraPrivilegesEnabled()) { if (electron::fuses::IsGrantFileProtocolExtraPrivilegesEnabled()) {