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

fuchsia_web / webengine / common / cast_streaming.cc [blame]

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "fuchsia_web/webengine/common/cast_streaming.h"

#include <string_view>

#include "base/command_line.h"
#include "fuchsia_web/webengine/switches.h"
#include "url/gurl.h"

namespace {

constexpr char kCastStreamingMessagePortOrigin[] = "cast-streaming:receiver";
constexpr char kCastStreamingVideoOnlyMessagePortOrigin[] =
    "cast-streaming:video-only-receiver";

}  // namespace

bool IsCastStreamingEnabled() {
  static bool is_cast_streaming_enabled =
      base::CommandLine::ForCurrentProcess()->HasSwitch(
          switches::kEnableCastStreamingReceiver);
  return is_cast_streaming_enabled;
}

bool IsCastStreamingAppOrigin(std::string_view origin) {
  return origin == kCastStreamingMessagePortOrigin ||
         IsCastStreamingVideoOnlyAppOrigin(origin);
}

bool IsCastStreamingVideoOnlyAppOrigin(std::string_view origin) {
  return origin == kCastStreamingVideoOnlyMessagePortOrigin;
}

bool IsValidCastStreamingMessage(const fuchsia::web::WebMessage& message) {
  // |message| should contain exactly one OutgoingTransferrable, with a single
  // MessagePort.
  return message.has_outgoing_transfer() &&
         message.outgoing_transfer().size() == 1u &&
         message.outgoing_transfer()[0].is_message_port();
}