xjz | f6f63a8 | 2016-05-11 18:35:29 | [diff] [blame] | 1 | // 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 Rummell | 51634e6 | 2020-01-30 22:11:55 | [diff] [blame] | 10 | #include "base/macros.h" |
xjz | f6f63a8 | 2016-05-11 18:35:29 | [diff] [blame] | 11 | #include "chrome/browser/media/media_access_handler.h" |
John Rummell | 51634e6 | 2020-01-30 22:11:55 | [diff] [blame] | 12 | #include "content/public/browser/desktop_media_id.h" |
xjz | f6f63a8 | 2016-05-11 18:35:29 | [diff] [blame] | 13 | #include "content/public/browser/media_request_state.h" |
Guido Urdaneta | 73fa663 | 2019-01-14 18:46:26 | [diff] [blame] | 14 | #include "third_party/blink/public/common/mediastream/media_stream_request.h" |
John Rummell | 51634e6 | 2020-01-30 22:11:55 | [diff] [blame] | 15 | #include "third_party/blink/public/mojom/mediastream/media_stream.mojom.h" |
| 16 | |
| 17 | namespace extensions { |
| 18 | class Extension; |
| 19 | } |
xjz | f6f63a8 | 2016-05-11 18:35:29 | [diff] [blame] | 20 | |
| 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. |
| 24 | class 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 Gomes | c8b734b | 2019-06-05 18:22:16 | [diff] [blame] | 33 | blink::mojom::MediaStreamType stream_type, |
xjz | f6f63a8 | 2016-05-11 18:35:29 | [diff] [blame] | 34 | content::MediaRequestState state) override; |
| 35 | |
John Rummell | 51634e6 | 2020-01-30 22:11:55 | [diff] [blame] | 36 | // 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 Wang | 4e3fdc9 | 2019-01-16 04:58:08 | [diff] [blame] | 38 | // 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. |
xjz | f6f63a8 | 2016-05-11 18:35:29 | [diff] [blame] | 42 | bool IsInsecureCapturingInProgress(int render_process_id, |
Emircan Uysaler | 0dd972a | 2018-08-14 05:15:37 | [diff] [blame] | 43 | int render_frame_id) override; |
xjz | f6f63a8 | 2016-05-11 18:35:29 | [diff] [blame] | 44 | |
Xiaohan Wang | 4e3fdc9 | 2019-01-16 04:58:08 | [diff] [blame] | 45 | // 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; |
xjz | f6f63a8 | 2016-05-11 18:35:29 | [diff] [blame] | 50 | |
| 51 | protected: |
mark a. foltz | 5bbecfa | 2020-08-04 17:07:44 | [diff] [blame^] | 52 | static bool IsExtensionAllowedForScreenCapture( |
xjz | f6f63a8 | 2016-05-11 18:35:29 | [diff] [blame] | 53 | 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 Uysaler | 0dd972a | 2018-08-14 05:15:37 | [diff] [blame] | 60 | void UpdateTrusted(const content::MediaStreamRequest& request, |
| 61 | bool is_trusted); |
| 62 | |
John Rummell | 51634e6 | 2020-01-30 22:11:55 | [diff] [blame] | 63 | void UpdateTarget(const content::MediaStreamRequest& request, |
| 64 | const content::DesktopMediaID& target); |
| 65 | |
xjz | f6f63a8 | 2016-05-11 18:35:29 | [diff] [blame] | 66 | private: |
| 67 | struct Session; |
| 68 | |
| 69 | void AddCaptureSession(int render_process_id, |
| 70 | int render_frame_id, |
| 71 | int page_request_id, |
Emircan Uysaler | 0dd972a | 2018-08-14 05:15:37 | [diff] [blame] | 72 | bool is_trusted); |
xjz | f6f63a8 | 2016-05-11 18:35:29 | [diff] [blame] | 73 | |
| 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 Rummell | 51634e6 | 2020-01-30 22:11:55 | [diff] [blame] | 82 | // 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 | |
xjz | f6f63a8 | 2016-05-11 18:35:29 | [diff] [blame] | 88 | std::list<Session> sessions_; |
| 89 | |
| 90 | DISALLOW_COPY_AND_ASSIGN(CaptureAccessHandlerBase); |
| 91 | }; |
| 92 | |
| 93 | #endif // CHROME_BROWSER_MEDIA_CAPTURE_ACCESS_HANDLER_BASE_H_ |