forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcast_streaming.cc
85 lines (67 loc) · 2.9 KB
/
cast_streaming.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "fuchsia_web/runners/cast/cast_streaming.h"
#include <string>
#include "base/fuchsia/file_utils.h"
#include "base/path_service.h"
#include "components/fuchsia_component_support/config_reader.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace {
constexpr char kCastStreamingAppUrl[] = "cast-streaming:receiver";
constexpr char kCastDataDirectory[] = "fuchsia_web/runners/cast/data";
constexpr char kCastStreamingContentDirectoryName[] = "cast-streaming";
constexpr char kCastStreamingMessagePortOrigin[] = "cast-streaming:receiver";
constexpr char kCastStreamingVideoOnlyMessagePortOrigin[] =
"cast-streaming:video-only-receiver";
// Returns the content directories for the Cast Streaming application.
std::vector<fuchsia::web::ContentDirectoryProvider>
GetCastStreamingContentDirectories() {
base::FilePath pkg_path;
bool success = base::PathService::Get(base::DIR_ASSETS, &pkg_path);
DCHECK(success);
fuchsia::web::ContentDirectoryProvider content_directory;
content_directory.set_directory(
base::OpenDirectoryHandle(pkg_path.AppendASCII(kCastDataDirectory)));
content_directory.set_name(kCastStreamingContentDirectoryName);
std::vector<fuchsia::web::ContentDirectoryProvider> content_directories;
content_directories.emplace_back(std::move(content_directory));
return content_directories;
}
} // namespace
const char kCastStreamingWebUrl[] =
"fuchsia-dir://cast-streaming/receiver.html";
const char kCastStreamingMessagePortName[] = "cast.__platform__.cast_transport";
bool IsAppConfigForCastStreaming(
const chromium::cast::ApplicationConfig& application_config) {
return application_config.web_url() == kCastStreamingAppUrl;
}
void ApplyCastStreamingContextParams(
fuchsia::web::CreateContextParams* params) {
*params->mutable_features() |= fuchsia::web::ContextFeatureFlags::NETWORK;
// Set the content directory with the streaming app.
params->set_content_directories(GetCastStreamingContentDirectories());
}
std::string GetMessagePortOriginForAppId(const std::string& app_id) {
const absl::optional<base::Value>& config =
fuchsia_component_support::LoadPackageConfig();
if (!config) {
return kCastStreamingMessagePortOrigin;
}
constexpr char kEnableVideoOnlyReceiverSwitch[] =
"enable-video-only-receiver-for-app-ids";
const base::Value* app_id_list =
config->FindListKey(kEnableVideoOnlyReceiverSwitch);
if (!app_id_list) {
return kCastStreamingMessagePortOrigin;
}
for (const base::Value& app_id_value : app_id_list->GetListDeprecated()) {
if (!app_id_value.is_string()) {
continue;
}
if (app_id == app_id_value.GetString()) {
return kCastStreamingVideoOnlyMessagePortOrigin;
}
}
return kCastStreamingMessagePortOrigin;
}