Skip to content

Commit

Permalink
fix: re-enable WindowCaptureMacV2
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Jun 5, 2023
1 parent 905aad9 commit 4c6abd3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 25 deletions.
12 changes: 1 addition & 11 deletions patches/chromium/desktop_media_list.patch
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Date: Thu, 18 Oct 2018 17:07:01 -0700
Subject: desktop_media_list.patch

* Use our grit resources instead of the chrome ones.
* Disabled WindowCaptureMacV2 feature for https://github.com/electron/electron/pull/30507
* Ensure "OnRefreshComplete()" even if there are no items in the list

diff --git a/chrome/browser/media/webrtc/desktop_media_list.h b/chrome/browser/media/webrtc/desktop_media_list.h
Expand Down Expand Up @@ -85,16 +84,7 @@ diff --git a/chrome/browser/media/webrtc/native_desktop_media_list.cc b/chrome/b
index b548c9fbd3c0bf425447b29dcd866cd27e96b14c..f994ac6086c7b4cd3e8534f34691189d78a21601 100644
--- a/chrome/browser/media/webrtc/native_desktop_media_list.cc
+++ b/chrome/browser/media/webrtc/native_desktop_media_list.cc
@@ -147,7 +147,7 @@ BOOL CALLBACK AllHwndCollector(HWND hwnd, LPARAM param) {
#if BUILDFLAG(IS_MAC)
BASE_FEATURE(kWindowCaptureMacV2,
"WindowCaptureMacV2",
- base::FEATURE_ENABLED_BY_DEFAULT);
+ base::FEATURE_DISABLED_BY_DEFAULT);
#endif

} // namespace
@@ -457,6 +457,9 @@ void NativeDesktopMediaList::Worker::RefreshNextThumbnail() {
@@ -451,6 +451,9 @@ void NativeDesktopMediaList::Worker::RefreshNextThumbnail() {
FROM_HERE,
base::BindOnce(&NativeDesktopMediaList::UpdateNativeThumbnailsFinished,
media_list_));
Expand Down
4 changes: 3 additions & 1 deletion shell/browser/api/electron_api_desktop_capturer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@ struct Converter<electron::api::DesktopCapturer::Source> {
v8::Isolate* isolate,
const electron::api::DesktopCapturer::Source& source) {
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
content::DesktopMediaID id = source.media_list_source.id;
dict.Set("name", base::UTF16ToUTF8(source.media_list_source.name));
content::DesktopMediaID id = source.media_list_source.id;
if (id.window_id == id.id)
id.window_id = content::DesktopMediaID::kNullId;
dict.Set("id", id.ToString());
dict.Set("thumbnail",
electron::api::NativeImage::Create(
Expand Down
14 changes: 2 additions & 12 deletions shell/browser/native_window_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1240,18 +1240,8 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
}

content::DesktopMediaID NativeWindowMac::GetDesktopMediaID() const {
auto desktop_media_id = content::DesktopMediaID(
content::DesktopMediaID::TYPE_WINDOW, GetAcceleratedWidget());
// c.f.
// https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/media/webrtc/native_desktop_media_list.cc;l=775-780;drc=79502ab47f61bff351426f57f576daef02b1a8dc
// Refs https://github.com/electron/electron/pull/30507
// TODO(deepak1556): Match upstream for `kWindowCaptureMacV2`
#if 0
if (remote_cocoa::ScopedCGWindowID::Get(desktop_media_id.id)) {
desktop_media_id.window_id = desktop_media_id.id;
}
#endif
return desktop_media_id;
return content::DesktopMediaID(content::DesktopMediaID::TYPE_WINDOW,
GetAcceleratedWidget());
}

NativeWindowHandle NativeWindowMac::GetNativeWindowHandle() const {
Expand Down
7 changes: 6 additions & 1 deletion spec/api-desktop-capturer-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ ifdescribe(!process.arch.includes('arm') && process.platform !== 'win32')('deskt
});

it('getSources should not incorrectly duplicate window_id', async () => {
const w = new BrowserWindow({ show: false, width: 100, height: 100, webPreferences: { contextIsolation: false } });
const w = new BrowserWindow({
show: false,
width: 100,
height: 100,
webPreferences: { contextIsolation: false }
});
const wShown = once(w, 'show');
const wFocused = once(w, 'focus');
w.show();
Expand Down

0 comments on commit 4c6abd3

Please sign in to comment.