blob: 9efe561f5efe6455ec7b9a182f4555d6429fe92f [file] [log] [blame]
xjzf6f63a82016-05-11 18:35:291// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_MEDIA_CAPTURE_ACCESS_HANDLER_BASE_H_
6#define CHROME_BROWSER_MEDIA_CAPTURE_ACCESS_HANDLER_BASE_H_
7
8#include <list>
9
John Rummell51634e62020-01-30 22:11:5510#include "base/macros.h"
xjzf6f63a82016-05-11 18:35:2911#include "chrome/browser/media/media_access_handler.h"
John Rummell51634e62020-01-30 22:11:5512#include "content/public/browser/desktop_media_id.h"
xjzf6f63a82016-05-11 18:35:2913#include "content/public/browser/media_request_state.h"
Guido Urdaneta73fa6632019-01-14 18:46:2614#include "third_party/blink/public/common/mediastream/media_stream_request.h"
John Rummell51634e62020-01-30 22:11:5515#include "third_party/blink/public/mojom/mediastream/media_stream.mojom.h"
16
17namespace extensions {
18class Extension;
19}
xjzf6f63a82016-05-11 18:35:2920
21// Base class for DesktopCaptureAccessHandler and TabCaptureAccessHandler. This
22// class tracks active capturing sessions, and provides API to check if there is
23// ongoing insecure video capturing.
24class CaptureAccessHandlerBase : public MediaAccessHandler {
25 public:
26 CaptureAccessHandlerBase();
27 ~CaptureAccessHandlerBase() override;
28
29 // MediaAccessHandler implementation.
30 void UpdateMediaRequestState(int render_process_id,
31 int render_frame_id,
32 int page_request_id,
Antonio Gomesc8b734b2019-06-05 18:22:1633 blink::mojom::MediaStreamType stream_type,
xjzf6f63a82016-05-11 18:35:2934 content::MediaRequestState state) override;
35
John Rummell51634e62020-01-30 22:11:5536 // Returns true if there is any ongoing insecured capturing of the frame
37 // specified by |render_process_id| and |render_frame_id|. Returns false
Xiaohan Wang4e3fdc92019-01-16 04:58:0838 // otherwise, e.g. there is no capturing, or all capturing are secure. A
39 // capturing is deemed secure if all connected video sinks are reported secure
40 // and the connections to the sinks are also secure, e.g. being managed by a
41 // trusted extension.
xjzf6f63a82016-05-11 18:35:2942 bool IsInsecureCapturingInProgress(int render_process_id,
Emircan Uysaler0dd972a2018-08-14 05:15:3743 int render_frame_id) override;
xjzf6f63a82016-05-11 18:35:2944
Xiaohan Wang4e3fdc92019-01-16 04:58:0845 // Updates video screen capture status with whether it |is_secure| or not.
46 void UpdateVideoScreenCaptureStatus(int render_process_id,
47 int render_frame_id,
48 int page_request_id,
49 bool is_secure) override;
xjzf6f63a82016-05-11 18:35:2950
51 protected:
mark a. foltz5bbecfa2020-08-04 17:07:4452 static bool IsExtensionAllowedForScreenCapture(
xjzf6f63a82016-05-11 18:35:2953 const extensions::Extension* extension);
54
55 static bool IsBuiltInExtension(const GURL& origin);
56
57 void UpdateExtensionTrusted(const content::MediaStreamRequest& request,
58 const extensions::Extension* extension);
59
Emircan Uysaler0dd972a2018-08-14 05:15:3760 void UpdateTrusted(const content::MediaStreamRequest& request,
61 bool is_trusted);
62
John Rummell51634e62020-01-30 22:11:5563 void UpdateTarget(const content::MediaStreamRequest& request,
64 const content::DesktopMediaID& target);
65
xjzf6f63a82016-05-11 18:35:2966 private:
67 struct Session;
68
69 void AddCaptureSession(int render_process_id,
70 int render_frame_id,
71 int page_request_id,
Emircan Uysaler0dd972a2018-08-14 05:15:3772 bool is_trusted);
xjzf6f63a82016-05-11 18:35:2973
74 void RemoveCaptureSession(int render_process_id,
75 int render_frame_id,
76 int page_request_id);
77
78 std::list<Session>::iterator FindSession(int render_process_id,
79 int render_frame_id,
80 int page_request_id);
81
John Rummell51634e62020-01-30 22:11:5582 // Returns true if the frame specified by |target_process_id| and
83 // |target_frame_id| matches the target in |session|.
84 static bool MatchesSession(const Session& session,
85 int target_process_id,
86 int target_frame_id);
87
xjzf6f63a82016-05-11 18:35:2988 std::list<Session> sessions_;
89
90 DISALLOW_COPY_AND_ASSIGN(CaptureAccessHandlerBase);
91};
92
93#endif // CHROME_BROWSER_MEDIA_CAPTURE_ACCESS_HANDLER_BASE_H_