fix: check screen capture permissions in desktopCapturer (#43080)

fix: check screen capture permissions in desktopCapturer
This commit is contained in:
Shelley Vohr 2024-08-09 10:08:49 +02:00 committed by GitHub
parent 0718c2b9ee
commit f49f6ff68b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 8 deletions

View file

@ -42,6 +42,10 @@
#include "ui/gfx/x/randr.h"
#endif
#if BUILDFLAG(IS_MAC)
#include "ui/base/cocoa/permissions_utils.h"
#endif
#if BUILDFLAG(IS_LINUX)
// Private function in ui/base/x/x11_display_util.cc
base::flat_map<x11::RandR::Output, int> GetMonitors(
@ -305,6 +309,13 @@ void DesktopCapturer::StartHandling(bool capture_window,
capture_window_ = capture_window;
capture_screen_ = capture_screen;
#if BUILDFLAG(IS_MAC)
if (!ui::TryPromptUserForScreenCapture()) {
HandleFailure();
return;
}
#endif
{
// Initialize the source list.
// Apply the new thumbnail size and restart capture.
@ -456,21 +467,25 @@ void DesktopCapturer::UpdateSourcesList(DesktopMediaList* list) {
std::back_inserter(captured_sources_));
}
if (!capture_window_ && !capture_screen_) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::HandleScope scope(isolate);
gin_helper::CallMethod(this, "_onfinished", captured_sources_);
if (!capture_window_ && !capture_screen_)
HandleSuccess();
}
screen_capturer_.reset();
window_capturer_.reset();
void DesktopCapturer::HandleSuccess() {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::HandleScope scope(isolate);
gin_helper::CallMethod(this, "_onfinished", captured_sources_);
Unpin();
}
screen_capturer_.reset();
window_capturer_.reset();
Unpin();
}
void DesktopCapturer::HandleFailure() {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::HandleScope scope(isolate);
gin_helper::CallMethod(this, "_onerror", "Failed to get sources.");
screen_capturer_.reset();

View file

@ -94,6 +94,7 @@ class DesktopCapturer : public gin::Wrappable<DesktopCapturer>,
void UpdateSourcesList(DesktopMediaList* list);
void HandleFailure();
void HandleSuccess();
std::unique_ptr<DesktopListListener> window_listener_;
std::unique_ptr<DesktopListListener> screen_listener_;