feat: use upstream MacOS SCContentSharingPicker implementation pt. 1

This commit is contained in:
Keeley Hammond 2024-08-21 19:00:33 -07:00
Родитель 9ba1cf2644
Коммит af809d0419
Не найден ключ, соответствующий данной подписи
4 изменённых файлов: 108 добавлений и 3 удалений

Просмотреть файл

@ -130,3 +130,4 @@ chore_remove_reference_to_chrome_browser_themes.patch
feat_enable_customizing_symbol_color_in_framecaptionbutton.patch
build_expose_webplugininfo_interface_to_electron.patch
osr_shared_texture_remove_keyed_mutex_on_win_dxgi.patch
feat_make_macos_sccontentsharingpicker_work_in_electron.patch

Просмотреть файл

@ -0,0 +1,79 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Keeley Hammond <khammond@slack-corp.com>
Date: Wed, 21 Aug 2024 19:00:00 -0700
Subject: feat: make MacOS SCContentSharingPicker work in Electron
This patch is a work in progress that contains assorted changes to make the MacOS SCContentSharingPicker upstream implementation work within Electron. If this comment is still in this patch during PR review, it is not ready for prime time
This patch can be removed after our desktopCapturer is refactored.
diff --git a/chrome/browser/media/webrtc/desktop_media_list_base.cc b/chrome/browser/media/webrtc/desktop_media_list_base.cc
index 6599311831b638f49658e768fe35e19e9961ef1d..f49519a6cc52d6e90ff07b64e5a71010094f9c5d 100644
--- a/chrome/browser/media/webrtc/desktop_media_list_base.cc
+++ b/chrome/browser/media/webrtc/desktop_media_list_base.cc
@@ -77,7 +77,7 @@ void DesktopMediaListBase::StartUpdating(DesktopMediaListObserver* observer) {
void DesktopMediaListBase::Update(UpdateCallback callback, bool refresh_thumbnails) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(sources_.empty());
- DCHECK(!refresh_callback_);
+ // DCHECK(!refresh_callback_);
refresh_callback_ = std::move(callback);
Refresh(refresh_thumbnails);
}
diff --git a/chrome/browser/media/webrtc/thumbnail_capturer_mac.mm b/chrome/browser/media/webrtc/thumbnail_capturer_mac.mm
index 2215bf4589342fa4619fb58ec3e21ff5ef3ed3b4..2bbe253afd5895adc79fb6ddffff3bce5155a42f 100644
--- a/chrome/browser/media/webrtc/thumbnail_capturer_mac.mm
+++ b/chrome/browser/media/webrtc/thumbnail_capturer_mac.mm
@@ -40,14 +40,14 @@
// is required to avoid recurring permission dialogs.
BASE_FEATURE(kUseSCContentSharingPicker,
"UseSCContentSharingPicker",
- base::FEATURE_DISABLED_BY_DEFAULT);
+ base::FEATURE_ENABLED_BY_DEFAULT);
// Use the built-in MacOS screen-sharing picker (SCContentSharingPicker) on
// MacOS 14 Sonoma and later. This flag will use the built-in picker for all
// MacOS versions where it is supported.
BASE_FEATURE(kUseSCContentSharingPickerSonoma,
"UseSCContentSharingPickerSonoma",
- base::FEATURE_DISABLED_BY_DEFAULT);
+ base::FEATURE_ENABLED_BY_DEFAULT);
#endif
using SampleCallback =
diff --git a/content/browser/media/capture/native_screen_capture_picker_mac.mm b/content/browser/media/capture/native_screen_capture_picker_mac.mm
index b5a776f37b4bb667bc1aa62a08102b67a12f5b64..298c95601dd605c5db3792f7213b6e87f1a400dc 100644
--- a/content/browser/media/capture/native_screen_capture_picker_mac.mm
+++ b/content/browser/media/capture/native_screen_capture_picker_mac.mm
@@ -117,8 +117,11 @@ void Open(DesktopMediaID::Type type,
base::OnceCallback<void()> cancel_callback,
base::OnceCallback<void()> error_callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
+ // TODO: Handle for either screens or windows here, since
+ // Chrome doesn't mesh the two types together in their picker
CHECK(type == DesktopMediaID::Type::TYPE_SCREEN ||
- type == DesktopMediaID::Type::TYPE_WINDOW);
+ type == DesktopMediaID::Type::TYPE_WINDOW ||
+ type == DesktopMediaID::Type::TYPE_NONE);
if (@available(macOS 14.0, *)) {
NSNumber* source_id = @(next_id_);
auto picker_observer = [[PickerObserver alloc]
@@ -143,11 +146,17 @@ void Open(DesktopMediaID::Type type,
picker.defaultConfiguration = config;
picker.maximumStreamCount = max_stream_count;
[picker presentPickerUsingContentStyle:SCShareableContentStyleDisplay];
- } else {
+ } else if (type == DesktopMediaID::Type::TYPE_WINDOW) {
config.allowedPickerModes = SCContentSharingPickerModeSingleWindow;
picker.defaultConfiguration = config;
picker.maximumStreamCount = max_stream_count;
[picker presentPickerUsingContentStyle:SCShareableContentStyleWindow];
+ } else {
+ // TODO: Which config to handle here?
+ config.allowedPickerModes = SCContentSharingPickerModeSingleDisplay;
+ picker.defaultConfiguration = config;
+ picker.maximumStreamCount = max_stream_count;
+ [picker presentPickerUsingContentStyle:SCShareableContentStyleWindow];
}
} else {
NOTREACHED();

Просмотреть файл

@ -9,6 +9,7 @@
#include <vector>
#include "base/containers/flat_map.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h"
@ -238,6 +239,12 @@ void DesktopCapturer::DesktopListListener::OnDelegatedSourceListSelection() {
}
}
void DesktopCapturer::DesktopListListener::OnSourceAdded(int index) {
// TODO: Implement the wrapped DesktopCapturer::RequestUpdate callback
// here for native pickers, instead of in the screen/window implementation
// below
}
void DesktopCapturer::DesktopListListener::OnSourceThumbnailChanged(int index) {
if (have_selection_) {
// This is called every time a thumbnail is refreshed. Reset variable to
@ -334,11 +341,16 @@ void DesktopCapturer::StartHandling(bool capture_window,
&DesktopCapturer::UpdateSourcesList, weak_ptr_factory_.GetWeakPtr(),
window_capturer_.get());
// Needed to force a refresh for the native MacOS Picker
OnceCallback wrapped_update_callback = base::BindOnce(
&DesktopCapturer::RequestUpdate, weak_ptr_factory_.GetWeakPtr(),
screen_capturer_.get(), std::move(update_callback));
if (window_capturer_->IsSourceListDelegated()) {
OnceCallback failure_callback = base::BindOnce(
&DesktopCapturer::HandleFailure, weak_ptr_factory_.GetWeakPtr());
window_listener_ = std::make_unique<DesktopListListener>(
std::move(update_callback), std::move(failure_callback),
std::move(wrapped_update_callback), std::move(failure_callback),
thumbnail_size.IsEmpty());
window_capturer_->StartUpdating(window_listener_.get());
} else {
@ -354,6 +366,7 @@ void DesktopCapturer::StartHandling(bool capture_window,
screen_capturer_ = std::make_unique<NativeDesktopMediaList>(
DesktopMediaList::Type::kScreen, std::move(capturer));
screen_capturer_->SetThumbnailSize(thumbnail_size);
screen_capturer_->ShowDelegatedList();
#if BUILDFLAG(IS_MAC)
screen_capturer_->skip_next_refresh_ =
ShouldUseThumbnailCapturerMac(DesktopMediaList::Type::kScreen) ? 2
@ -364,11 +377,16 @@ void DesktopCapturer::StartHandling(bool capture_window,
&DesktopCapturer::UpdateSourcesList, weak_ptr_factory_.GetWeakPtr(),
screen_capturer_.get());
// Needed to force a refresh for the native MacOS Picker
OnceCallback wrapped_update_callback = base::BindOnce(
&DesktopCapturer::RequestUpdate, weak_ptr_factory_.GetWeakPtr(),
screen_capturer_.get(), std::move(update_callback));
if (screen_capturer_->IsSourceListDelegated()) {
OnceCallback failure_callback = base::BindOnce(
&DesktopCapturer::HandleFailure, weak_ptr_factory_.GetWeakPtr());
screen_listener_ = std::make_unique<DesktopListListener>(
std::move(update_callback), std::move(failure_callback),
std::move(wrapped_update_callback), std::move(failure_callback),
thumbnail_size.IsEmpty());
screen_capturer_->StartUpdating(screen_listener_.get());
} else {
@ -380,6 +398,11 @@ void DesktopCapturer::StartHandling(bool capture_window,
}
}
void DesktopCapturer::RequestUpdate(DesktopMediaList* list,
OnceCallback update_callback) {
list->Update(std::move(update_callback));
}
void DesktopCapturer::UpdateSourcesList(DesktopMediaList* list) {
if (capture_window_ &&
list->GetMediaListType() == DesktopMediaList::Type::kWindow) {
@ -397,6 +420,7 @@ void DesktopCapturer::UpdateSourcesList(DesktopMediaList* list) {
if (capture_screen_ &&
list->GetMediaListType() == DesktopMediaList::Type::kScreen) {
capture_screen_ = false;
LOG(ERROR) << "GetSourceCount" << list->GetSourceCount();
std::vector<DesktopCapturer::Source> screen_sources;
screen_sources.reserve(list->GetSourceCount());
for (int i = 0; i < list->GetSourceCount(); i++) {

Просмотреть файл

@ -78,7 +78,7 @@ class DesktopCapturer final : public gin::Wrappable<DesktopCapturer>,
~DesktopListListener() override;
protected:
void OnSourceAdded(int index) override {}
void OnSourceAdded(int index) override;
void OnSourceRemoved(int index) override {}
void OnSourceMoved(int old_index, int new_index) override {}
void OnSourceNameChanged(int index) override {}
@ -94,6 +94,7 @@ class DesktopCapturer final : public gin::Wrappable<DesktopCapturer>,
bool have_thumbnail_ = false;
};
void RequestUpdate(DesktopMediaList* list, OnceCallback update_callback);
void UpdateSourcesList(DesktopMediaList* list);
void HandleFailure();
void HandleSuccess();