feat: add {stream} opt to custom protocol registry to configure media player (#22955)

This commit is contained in:
Paul Frazee 2020-06-08 11:49:36 -05:00 committed by GitHub
parent 261f385b5e
commit c6c022dc46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 719 additions and 4 deletions

View file

@ -28,6 +28,9 @@ namespace {
// List of registered custom standard schemes.
std::vector<std::string> g_standard_schemes;
// List of registered custom streaming schemes.
std::vector<std::string> g_streaming_schemes;
struct SchemeOptions {
bool standard = false;
bool secure = false;
@ -35,6 +38,7 @@ struct SchemeOptions {
bool allowServiceWorkers = false;
bool supportFetchAPI = false;
bool corsEnabled = false;
bool stream = false;
};
struct CustomScheme {
@ -66,6 +70,7 @@ struct Converter<CustomScheme> {
opt.Get("allowServiceWorkers", &(out->options.allowServiceWorkers));
opt.Get("supportFetchAPI", &(out->options.supportFetchAPI));
opt.Get("corsEnabled", &(out->options.corsEnabled));
opt.Get("stream", &(out->options.stream));
}
return true;
}
@ -119,6 +124,9 @@ void RegisterSchemesAsPrivileged(gin_helper::ErrorThrower thrower,
if (custom_scheme.options.allowServiceWorkers) {
service_worker_schemes.push_back(custom_scheme.scheme);
}
if (custom_scheme.options.stream) {
g_streaming_schemes.push_back(custom_scheme.scheme);
}
}
const auto AppendSchemesToCmdLine = [](const char* switch_name,
@ -138,6 +146,8 @@ void RegisterSchemesAsPrivileged(gin_helper::ErrorThrower thrower,
service_worker_schemes);
AppendSchemesToCmdLine(electron::switches::kStandardSchemes,
g_standard_schemes);
AppendSchemesToCmdLine(electron::switches::kStreamingSchemes,
g_streaming_schemes);
}
namespace {

View file

@ -744,7 +744,8 @@ void ElectronBrowserClient::AppendExtraCommandLineSwitches(
switches::kStandardSchemes, switches::kEnableSandbox,
switches::kSecureSchemes, switches::kBypassCSPSchemes,
switches::kCORSSchemes, switches::kFetchSchemes,
switches::kServiceWorkerSchemes, switches::kEnableApiFilteringLogging};
switches::kServiceWorkerSchemes, switches::kEnableApiFilteringLogging,
switches::kStreamingSchemes};
command_line->CopySwitchesFrom(*base::CommandLine::ForCurrentProcess(),
kCommonSwitchNames,
base::size(kCommonSwitchNames));

View file

@ -221,6 +221,9 @@ const char kFetchSchemes[] = "fetch-schemes";
// Register schemes as CORS enabled.
const char kCORSSchemes[] = "cors-schemes";
// Register schemes as streaming responses.
const char kStreamingSchemes[] = "streaming-schemes";
// The browser process app model ID
const char kAppUserModelId[] = "app-user-model-id";

View file

@ -111,6 +111,7 @@ extern const char kSecureSchemes[];
extern const char kBypassCSPSchemes[];
extern const char kFetchSchemes[];
extern const char kCORSSchemes[];
extern const char kStreamingSchemes[];
extern const char kAppUserModelId[];
extern const char kAppPath[];
extern const char kEnableApiFilteringLogging[];

View file

@ -20,6 +20,7 @@
#include "content/public/renderer/render_thread.h"
#include "content/public/renderer/render_view.h"
#include "electron/buildflags/buildflags.h"
#include "media/blink/multibuffer_data_source.h"
#include "printing/buildflags/buildflags.h"
#include "shell/common/color_util.h"
#include "shell/common/gin_helper/dictionary.h"
@ -107,6 +108,11 @@ RendererClientBase::RendererClientBase() {
ParseSchemesCLISwitch(command_line, switches::kCORSSchemes);
for (const std::string& scheme : cors_schemes_list)
url::AddCorsEnabledScheme(scheme.c_str());
// Parse --streaming-schemes=scheme1,scheme2
std::vector<std::string> streaming_schemes_list =
ParseSchemesCLISwitch(command_line, switches::kStreamingSchemes);
for (const std::string& scheme : streaming_schemes_list)
media::AddStreamingScheme(scheme.c_str());
isolated_world_ = base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kContextIsolation);
// We rely on the unique process host id which is notified to the