fix: use ScreenCaptureKit exclusively on macOS 14.4 and higher (#41404)

This fixes a nasty warning / permission dialog that pops up to end-users
when consuming legacy APIs.  Chrome has flipped these flags via field trials
as have other Electron apps. It should just be the default.

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Samuel Attard <marshallofsound@electronjs.org>
This commit is contained in:
trop[bot] 2024-02-22 14:32:32 +01:00 committed by GitHub
parent 310598c43d
commit 25b0212fe6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 43 additions and 0 deletions

View file

@ -383,6 +383,7 @@ filenames = {
"shell/browser/extended_web_contents_observer.h", "shell/browser/extended_web_contents_observer.h",
"shell/browser/feature_list.cc", "shell/browser/feature_list.cc",
"shell/browser/feature_list.h", "shell/browser/feature_list.h",
"shell/browser/feature_list_mac.mm",
"shell/browser/file_select_helper.cc", "shell/browser/file_select_helper.cc",
"shell/browser/file_select_helper.h", "shell/browser/file_select_helper.h",
"shell/browser/file_select_helper_mac.mm", "shell/browser/file_select_helper_mac.mm",

View file

@ -49,6 +49,11 @@ void InitializeFeatureList() {
// 'custom dictionary word list API' spec to crash. // 'custom dictionary word list API' spec to crash.
std::string(",") + spellcheck::kWinDelaySpellcheckServiceInit.name; std::string(",") + spellcheck::kWinDelaySpellcheckServiceInit.name;
#endif #endif
std::string platform_specific_enable_features =
EnablePlatformSpecificFeatures();
if (platform_specific_enable_features.size() > 0) {
enable_features += std::string(",") + platform_specific_enable_features;
}
base::FeatureList::InitInstance(enable_features, disable_features); base::FeatureList::InitInstance(enable_features, disable_features);
} }
@ -60,4 +65,10 @@ void InitializeFieldTrials() {
base::FieldTrialList::CreateTrialsFromString(force_fieldtrials); base::FieldTrialList::CreateTrialsFromString(force_fieldtrials);
} }
#if !BUILDFLAG(IS_MAC)
std::string EnablePlatformSpecificFeatures() {
return "";
}
#endif
} // namespace electron } // namespace electron

View file

@ -5,9 +5,12 @@
#ifndef ELECTRON_SHELL_BROWSER_FEATURE_LIST_H_ #ifndef ELECTRON_SHELL_BROWSER_FEATURE_LIST_H_
#define ELECTRON_SHELL_BROWSER_FEATURE_LIST_H_ #define ELECTRON_SHELL_BROWSER_FEATURE_LIST_H_
#include <string>
namespace electron { namespace electron {
void InitializeFeatureList(); void InitializeFeatureList();
void InitializeFieldTrials(); void InitializeFieldTrials();
std::string EnablePlatformSpecificFeatures();
} // namespace electron } // namespace electron
#endif // ELECTRON_SHELL_BROWSER_FEATURE_LIST_H_ #endif // ELECTRON_SHELL_BROWSER_FEATURE_LIST_H_

View file

@ -0,0 +1,28 @@
// Copyright (c) 2024 Salesforce, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "electron/shell/browser/feature_list.h"
#include <string>
namespace electron {
std::string EnablePlatformSpecificFeatures() {
if (@available(macOS 14.4, *)) {
// These flags aren't exported so reference them by name directly, they are
// used to ensure that screen and window capture exclusive use
// ScreenCaptureKit APIs to avoid warning dialogs on macOS 14.4 and higher.
// kScreenCaptureKitPickerScreen,
// chrome/browser/media/webrtc/thumbnail_capturer_mac.mm
// kScreenCaptureKitStreamPickerSonoma,
// chrome/browser/media/webrtc/thumbnail_capturer_mac.mm
// kThumbnailCapturerMac,
// chrome/browser/media/webrtc/thumbnail_capturer_mac.mm
return "ScreenCaptureKitPickerScreen,ScreenCaptureKitStreamPickerSonoma,"
"ThumbnailCapturerMac:capture_mode/sc_screenshot_manager";
}
return "";
}
} // namespace electron