File: capture_access_handler_base.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 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 (124 lines) | stat: -rw-r--r-- 5,081 bytes parent folder | download | duplicates (6)
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
124
// Copyright 2016 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_MEDIA_CAPTURE_ACCESS_HANDLER_BASE_H_
#define CHROME_BROWSER_MEDIA_CAPTURE_ACCESS_HANDLER_BASE_H_

#include <list>
#include <string>

#include "chrome/browser/media/media_access_handler.h"
#include "chrome/browser/media/webrtc/desktop_media_picker.h"
#include "content/public/browser/desktop_media_id.h"
#include "content/public/browser/media_request_state.h"
#include "extensions/buildflags/buildflags.h"
#include "third_party/blink/public/common/mediastream/media_stream_request.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom.h"

namespace extensions {
class Extension;
}

// Base class for DesktopCaptureAccessHandler and TabCaptureAccessHandler. This
// class tracks active capturing sessions, and provides API to check if there is
// ongoing insecure video capturing.
class CaptureAccessHandlerBase : public MediaAccessHandler {
 public:
  CaptureAccessHandlerBase();

  CaptureAccessHandlerBase(const CaptureAccessHandlerBase&) = delete;
  CaptureAccessHandlerBase& operator=(const CaptureAccessHandlerBase&) = delete;

  ~CaptureAccessHandlerBase() override;

  // MediaAccessHandler implementation.
  void UpdateMediaRequestState(int render_process_id,
                               int render_frame_id,
                               int page_request_id,
                               blink::mojom::MediaStreamType stream_type,
                               content::MediaRequestState state) override;

  // Returns true if there is any ongoing insecured capturing of the frame
  // specified by |render_process_id| and |render_frame_id|. Returns false
  // otherwise, e.g. there is no capturing, or all capturing are secure. A
  // capturing is deemed secure if all connected video sinks are reported secure
  // and the connections to the sinks are also secure, e.g. being managed by a
  // trusted extension.
  bool IsInsecureCapturingInProgress(int render_process_id,
                                     int render_frame_id) override;

  // Updates video screen capture status with whether it |is_secure| or not.
  void UpdateVideoScreenCaptureStatus(int render_process_id,
                                      int render_frame_id,
                                      int page_request_id,
                                      bool is_secure) override;

 protected:
  // Holds pending request information.
  struct PendingAccessRequest {
    PendingAccessRequest(std::unique_ptr<DesktopMediaPicker> picker,
                         const content::MediaStreamRequest& request,
                         content::MediaResponseCallback callback,
                         std::u16string application_title,
                         bool should_display_notification,
                         bool is_allowlisted_extension);
    PendingAccessRequest(const PendingAccessRequest& other) = delete;
    PendingAccessRequest& operator=(const PendingAccessRequest& other) = delete;
    ~PendingAccessRequest();

    std::unique_ptr<DesktopMediaPicker> picker;
    content::MediaStreamRequest request;
    content::MediaResponseCallback callback;
    std::u16string application_title;
    const bool should_display_notification;
    const bool is_allowlisted_extension;
  };

  using RequestsQueue =
      base::circular_deque<std::unique_ptr<PendingAccessRequest>>;

  using RequestsQueues = base::flat_map<content::WebContents*, RequestsQueue>;

#if BUILDFLAG(ENABLE_EXTENSIONS)
  static bool IsExtensionAllowedForScreenCapture(
      const extensions::Extension* extension);
#endif  // BUILDFLAG(ENABLE_EXTENSIONS)

  static bool IsBuiltInFeedbackUI(const GURL& origin);

  void UpdateExtensionTrusted(const content::MediaStreamRequest& request,
                              bool is_allowlisted_extension);

  void UpdateTrusted(const content::MediaStreamRequest& request,
                     bool is_trusted);

  void UpdateTarget(const content::MediaStreamRequest& request,
                    const content::DesktopMediaID& target);

 private:
  struct Session;

  void AddCaptureSession(int render_process_id,
                         int render_frame_id,
                         int page_request_id,
                         bool is_trusted);

  void RemoveCaptureSession(int render_process_id,
                            int render_frame_id,
                            int page_request_id);

  std::list<Session>::iterator FindSession(int render_process_id,
                                           int render_frame_id,
                                           int page_request_id);

  // Returns true if the frame specified by |target_process_id| and
  // |target_frame_id| matches the target in |session|.
  static bool MatchesSession(const Session& session,
                             int target_process_id,
                             int target_frame_id);

  std::list<Session> sessions_;
};

#endif  // CHROME_BROWSER_MEDIA_CAPTURE_ACCESS_HANDLER_BASE_H_