summaryrefslogtreecommitdiffstats
path: root/content/public/browser/web_contents_media_capture_id.h
blob: 84d91dbe7da4595ef63eed60a67af8bf504e93e2 (plain)
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
// Copyright 2016 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.

#ifndef CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_MEDIA_CAPTURE_ID_H_
#define CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_MEDIA_CAPTURE_ID_H_

#include <string>

#include "content/common/content_export.h"
#include "ipc/ipc_message.h"

namespace content {

struct CONTENT_EXPORT WebContentsMediaCaptureId {
 public:
  WebContentsMediaCaptureId() = default;
  WebContentsMediaCaptureId(int render_process_id, int main_render_frame_id)
      : render_process_id(render_process_id),
        main_render_frame_id(main_render_frame_id) {}

  WebContentsMediaCaptureId(int render_process_id,
                            int main_render_frame_id,
                            bool enable_auto_throttling)
      : render_process_id(render_process_id),
        main_render_frame_id(main_render_frame_id),
        enable_auto_throttling(enable_auto_throttling) {}

  bool operator<(const WebContentsMediaCaptureId& other) const;
  bool operator==(const WebContentsMediaCaptureId& other) const;

  // Return true if render_process_id or main_render_frame_id is invalid.
  bool is_null() const;

  std::string ToString() const;

  // Tab video and audio capture need render process id and render frame id.
  int render_process_id = MSG_ROUTING_NONE;
  int main_render_frame_id = MSG_ROUTING_NONE;

  bool enable_auto_throttling = false;

  // Create WebContentsMediaCaptureId based on a string.
  static WebContentsMediaCaptureId Parse(const std::string& str);

  // Check whether the device id indicates that this is a web contents stream.
  static bool IsWebContentsDeviceId(const std::string& device_id);

  // Function to extract the target render frame id's from a media stream
  // request's device id.
  static bool ExtractTabCaptureTarget(const std::string& device_id,
                                      int* render_process_id,
                                      int* main_render_frame_id);

  // Parses the media stream request |device_id| and returns true if both 1) the
  // format is valid, and 2) the throttling option is set to auto.
  static bool IsAutoThrottlingOptionSet(const std::string& device_id);
};

}  // namespace content

#endif  // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_MEDIA_CAPTURE_ID_H_