File: media_router_ui_helper.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (123 lines) | stat: -rw-r--r-- 4,066 bytes parent folder | download | duplicates (7)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_MEDIA_ROUTER_MEDIA_ROUTER_UI_HELPER_H_
#define CHROME_BROWSER_UI_MEDIA_ROUTER_MEDIA_ROUTER_UI_HELPER_H_

#include <string>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/ui/media_router/media_cast_mode.h"
#include "components/media_router/browser/media_router.h"
#include "components/media_router/common/media_sink.h"
#include "components/media_router/common/media_source.h"
#include "media/base/audio_codecs.h"
#include "media/base/video_codecs.h"
#include "url/origin.h"

namespace extensions {
class ExtensionRegistry;
}

class GURL;

namespace media_router {

class StartPresentationContext;

// Returns the extension name for |url|, so that it can be displayed for
// extension-initiated presentations.
std::string GetExtensionName(const GURL& url,
                             extensions::ExtensionRegistry* registry);

std::string GetHostFromURL(const GURL& gurl);

// Returns the duration to wait for route creation result before we time out.
base::TimeDelta GetRouteRequestTimeout(MediaCastMode cast_mode);

// Determines if the specified cast mode requires permission from the user
// in order to proceed.
bool RequiresScreenCapturePermission(MediaCastMode cast_mode);

// Requests permission for screen capturing.
bool GetScreenCapturePermission();

void set_screen_capture_allowed_for_testing(bool allowed);
void clear_screen_capture_allowed_for_testing();

// A variation of MediaRouteResponseCallback that doesn't require the
// PresentationConnection objects.
using MediaRouteResultCallback =
    base::OnceCallback<void(const RouteRequestResult&)>;

struct RouteRequest {
 public:
  explicit RouteRequest(const MediaSink::Id& sink_id);
  ~RouteRequest();

  int id;
  MediaSink::Id sink_id;
};

// Contains parameters passed to MediaRouterUI's constructor.
struct MediaRouterUIParameters {
  MediaRouterUIParameters(
      CastModeSet initial_modes,
      content::WebContents* initiator,
      std::unique_ptr<StartPresentationContext> start_presentation_context =
          nullptr,
      media::VideoCodec video_codec = media::VideoCodec::kUnknown,
      media::AudioCodec audio_codec = media::AudioCodec::kUnknown);

  MediaRouterUIParameters(const MediaRouterUIParameters& other) = delete;
  MediaRouterUIParameters(MediaRouterUIParameters&& other);
  ~MediaRouterUIParameters();
  MediaRouterUIParameters& operator=(MediaRouterUIParameters&) = delete;
  MediaRouterUIParameters& operator=(MediaRouterUIParameters&&) = default;

  CastModeSet initial_modes;
  raw_ptr<content::WebContents> initiator;
  // Used to initialize MediaRouterUI with a PresentationRequest.
  std::unique_ptr<StartPresentationContext> start_presentation_context;
  // Used to initialize MediaRouterUI with RemotePlayback Media Source.
  media::VideoCodec video_codec;
  media::AudioCodec audio_codec;
};

// Contains common parameters for route requests to MediaRouter.
struct RouteParameters {
 public:
  RouteParameters();
  RouteParameters(RouteParameters&& other);
  ~RouteParameters();

  RouteParameters& operator=(RouteParameters&& other);

  MediaCastMode cast_mode;

  // A string identifying the media source, which should be the source for this
  // route (e.g. a presentation url, tab mirroring id, etc.).
  MediaSource::Id source_id;

  // Unique id identifying the attempt to connect to a specific sink
  std::unique_ptr<RouteRequest> request;

  // The origin of the page requesting the route.
  url::Origin origin;

  // Callbacks which should be invoked on both success and failure of the route
  // creation.
  std::vector<MediaRouteResultCallback> route_result_callbacks;

  // A timeout value, after which the request should be considered to have
  // failed.
  base::TimeDelta timeout;
};

}  // namespace media_router

#endif  // CHROME_BROWSER_UI_MEDIA_ROUTER_MEDIA_ROUTER_UI_HELPER_H_