Skip to content

Commit

Permalink
fix: command-line scheme switch values' spillover (#19912)
Browse files Browse the repository at this point in the history
* fix: command-line scheme switch values' spillover

The value of one of the scheme command-line switches
shouldn't spill over into other switches.

Fixes #19911

* chore: make linter happy
  • Loading branch information
ckerr authored and zcbenz committed Aug 26, 2019
1 parent 181f663 commit 080fdb3
Showing 1 changed file with 24 additions and 29 deletions.
53 changes: 24 additions & 29 deletions shell/app/atom_content_client.cc
Expand Up @@ -5,6 +5,7 @@
#include "shell/app/atom_content_client.h"

#include <string>
#include <utility>
#include <vector>

#include "base/command_line.h"
Expand Down Expand Up @@ -163,14 +164,19 @@ void ComputeBuiltInPlugins(std::vector<content::PepperPluginInfo>* plugins) {
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
}

void ConvertStringWithSeparatorToVector(std::vector<std::string>* vec,
const char* separator,
const char* cmd_switch) {
void AppendDelimitedSwitchToVector(const base::StringPiece cmd_switch,
std::vector<std::string>* append_me) {
auto* command_line = base::CommandLine::ForCurrentProcess();
auto string_with_separator = command_line->GetSwitchValueASCII(cmd_switch);
if (!string_with_separator.empty())
*vec = base::SplitString(string_with_separator, separator,
base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
auto switch_value = command_line->GetSwitchValueASCII(cmd_switch);
if (!switch_value.empty()) {
constexpr base::StringPiece 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
Expand Down Expand Up @@ -202,30 +208,19 @@ base::RefCountedMemory* AtomContentClient::GetDataResourceBytes(
}

void AtomContentClient::AddAdditionalSchemes(Schemes* schemes) {
std::vector<std::string> splited;
ConvertStringWithSeparatorToVector(&splited, ",",
switches::kServiceWorkerSchemes);
for (const std::string& scheme : splited)
schemes->service_worker_schemes.push_back(scheme);
schemes->service_worker_schemes.push_back(url::kFileScheme);
AppendDelimitedSwitchToVector(switches::kServiceWorkerSchemes,
&schemes->service_worker_schemes);
AppendDelimitedSwitchToVector(switches::kStandardSchemes,
&schemes->standard_schemes);
AppendDelimitedSwitchToVector(switches::kSecureSchemes,
&schemes->secure_schemes);
AppendDelimitedSwitchToVector(switches::kBypassCSPSchemes,
&schemes->csp_bypassing_schemes);
AppendDelimitedSwitchToVector(switches::kCORSSchemes,
&schemes->cors_enabled_schemes);

ConvertStringWithSeparatorToVector(&splited, ",", switches::kStandardSchemes);
for (const std::string& scheme : splited)
schemes->standard_schemes.push_back(scheme);
schemes->service_worker_schemes.push_back(url::kFileScheme);
schemes->standard_schemes.push_back("chrome-extension");

ConvertStringWithSeparatorToVector(&splited, ",", switches::kSecureSchemes);
for (const std::string& scheme : splited)
schemes->secure_schemes.push_back(scheme);

ConvertStringWithSeparatorToVector(&splited, ",",
switches::kBypassCSPSchemes);
for (const std::string& scheme : splited)
schemes->csp_bypassing_schemes.push_back(scheme);

ConvertStringWithSeparatorToVector(&splited, ",", switches::kCORSSchemes);
for (const std::string& scheme : splited)
schemes->cors_enabled_schemes.push_back(scheme);
}

void AtomContentClient::AddPepperPlugins(
Expand Down

0 comments on commit 080fdb3

Please sign in to comment.