Compare commits

..

6 Commits

Author SHA1 Message Date
Shelley Vohr
c184b93fc5 fix: crash using powerMonitor before ready event (#40888)
* fix: crash using powerMonitor before ready event

* refactor: continue using DBusBluezManagerWrapperLinux
2024-01-09 09:41:42 +01:00
Charles Kerr
7b4d490bfe perf: use fixed-size arrays for the font cache (#40898)
refactor: use fixed-size arrays for the font cache

Since we know at compile time which [family x script] combos we want to
cache, we can hold the cache in fixed std::arrays instead of in nested
std::unordered_maps.
2024-01-08 10:31:02 +01:00
Calvin
37630a6128 fix: wide string concatenation (#40892)
* fix: wide string concatenation

* Use wstring_views to keep length in context

* forgot a space, oopsies
2024-01-07 22:02:20 -08:00
Shelley Vohr
3a22fd3216 docs: add missing vibrancy breaking change (#40893)
docs: add missing vibranch change
2024-01-07 13:56:52 -08:00
Charles Kerr
73e7125041 chore: do not inject DXVA_Decoding trace category (#40891)
This doesn't need to be injected. Looks like it was an accident in
60ca38fb for https://github.com/electron/electron/pull/38465 .
2024-01-05 17:54:41 -06:00
Tamás Zahola
cc1b64e01c fix: macOS maximize button shouldn't be disabled just because the window is non-fullscreenable (#40705)
* fix: macOS maximize button shouldn't be disabled just because the window is non-fullscreenable

* add test

* fix test by enabling maximize button if `resizable && (maximizable || fullscreenable)` instead of `(resizable && maximizable) && fullscreenable`
2024-01-05 12:15:35 -05:00
10 changed files with 128 additions and 70 deletions

View File

@@ -233,6 +233,18 @@ systemPreferences.on('high-contrast-color-scheme-changed', () => { /* ... */ })
nativeTheme.on('updated', () => { /* ... */ })
```
### Removed: Some `window.setVibrancy` options on macOS
The following vibrancy options have been removed:
* 'light'
* 'medium-light'
* 'dark'
* 'ultra-dark'
* 'appearance-based'
These were previously deprecated and have been removed by Apple in 10.15.
### Removed: `webContents.getPrinters`
The `webContents.getPrinters` method has been removed. Use

View File

@@ -8,14 +8,13 @@ categories in use are known / declared. This patch is required for us
to introduce a new Electron category for Electron-specific tracing.
diff --git a/base/trace_event/builtin_categories.h b/base/trace_event/builtin_categories.h
index 0cc26b32992cbbd5f599e0e062dd5b22bbf6d2dc..fd6a0eebd004f9e92ba577d73dfa75f685476288 100644
index 0cc26b32992cbbd5f599e0e062dd5b22bbf6d2dc..2bc3fea0bc469a0cf26fa2a5af9c404294078f4a 100644
--- a/base/trace_event/builtin_categories.h
+++ b/base/trace_event/builtin_categories.h
@@ -82,6 +82,8 @@
@@ -82,6 +82,7 @@
X("drm") \
X("drmcursor") \
X("dwrite") \
+ X("DXVA_Decoding") \
+ X("electron") \
X("evdev") \
X("event") \

View File

@@ -19,8 +19,8 @@
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/strings/strcat_win.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/win/registry.h"
#include "base/win/win_util.h"
@@ -68,13 +68,13 @@ bool GetProtocolLaunchPath(gin::Arguments* args, std::wstring* exe) {
// Read in optional args arg
std::vector<std::wstring> launch_args;
if (args->GetNext(&launch_args) && !launch_args.empty())
*exe = base::UTF8ToWide(
base::StringPrintf("\"%ls\" \"%ls\" \"%%1\"", exe->c_str(),
base::JoinString(launch_args, L"\" \"").c_str()));
else
*exe =
base::UTF8ToWide(base::StringPrintf("\"%ls\" \"%%1\"", exe->c_str()));
if (args->GetNext(&launch_args) && !launch_args.empty()) {
std::wstring joined_args = base::JoinString(launch_args, L"\" \"");
*exe = base::StrCat({L"\"", *exe, L"\" \"", joined_args, L"\" \"%1\""});
} else {
*exe = base::StrCat({L"\"", *exe, L"\" \"%1\""});
}
return true;
}
@@ -142,8 +142,7 @@ bool FormatCommandLineString(std::wstring* exe,
if (!launch_args.empty()) {
std::u16string joined_launch_args = base::JoinString(launch_args, u" ");
*exe = base::UTF8ToWide(base::StringPrintf(
"%ls %ls", exe->c_str(), base::as_wcstr(joined_launch_args)));
*exe = base::StrCat({*exe, L" ", base::AsWStringView(joined_launch_args)});
}
return true;

View File

@@ -81,6 +81,7 @@
#include "base/environment.h"
#include "chrome/browser/ui/views/dark_mode_manager_linux.h"
#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/bluetooth/dbus/bluez_dbus_manager.h"
#include "device/bluetooth/dbus/dbus_bluez_manager_wrapper_linux.h"
#include "electron/electron_gtk_stubs.h"
#include "ui/base/cursor/cursor_factory.h"
@@ -508,7 +509,8 @@ void ElectronBrowserMainParts::PostCreateMainMessageLoop() {
ui::OzonePlatform::GetInstance()->PostCreateMainMessageLoop(
std::move(shutdown_cb),
content::GetUIThreadTaskRunner({content::BrowserTaskType::kUserInput}));
bluez::DBusBluezManagerWrapperLinux::Initialize();
if (!bluez::BluezDBusManager::IsInitialized())
bluez::DBusBluezManagerWrapperLinux::Initialize();
// Set up crypt config. This needs to be done before anything starts the
// network service, as the raw encryption key needs to be shared with the

View File

@@ -4,11 +4,12 @@
#include "shell/browser/font_defaults.h"
#include <array>
#include <string>
#include <unordered_map>
#include <string_view>
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/strcat.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/platform_locale_settings.h"
@@ -106,70 +107,88 @@ const FontDefault kFontDefaults[] = {
// ^^^^^ DO NOT EDIT ^^^^^
std::string GetDefaultFontForPref(const char* pref_name) {
for (auto pref : kFontDefaults) {
if (strcmp(pref.pref_name, pref_name) == 0) {
// Get `kFontDefault`'s default fontname for [font family, script].
// e.g. ("webkit.webprefs.fonts.fixed", "Zyyy") -> "Monospace"
std::string GetDefaultFont(const std::string_view family_name,
const std::string_view script_name) {
const std::string pref_name = base::StrCat({family_name, ".", script_name});
for (const FontDefault& pref : kFontDefaults) {
if (pref_name == pref.pref_name) {
return l10n_util::GetStringUTF8(pref.resource_id);
}
}
return std::string();
return std::string{};
}
// Map from script to font.
// Key comparison uses pointer equality.
using ScriptFontMap = std::unordered_map<const char*, std::u16string>;
// Each font family has kWebKitScriptsForFontFamilyMapsLength scripts.
// This is a lookup array for script_index -> fontname
using PerFamilyFonts =
std::array<std::u16string, prefs::kWebKitScriptsForFontFamilyMapsLength>;
// Map from font family to ScriptFontMap.
// Key comparison uses pointer equality.
using FontFamilyMap = std::unordered_map<const char*, ScriptFontMap>;
// A lookup table mapping (font-family, script) -> font-name
// e.g. ("sans-serif", "Zyyy") -> "Arial"
FontFamilyMap g_font_cache;
std::u16string FetchFont(const char* script, const char* map_name) {
FontFamilyMap::const_iterator it = g_font_cache.find(map_name);
if (it != g_font_cache.end()) {
ScriptFontMap::const_iterator it2 = it->second.find(script);
if (it2 != it->second.end())
return it2->second;
}
std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
std::string font = GetDefaultFontForPref(pref_name.c_str());
std::u16string font16 = base::UTF8ToUTF16(font);
ScriptFontMap& map = g_font_cache[map_name];
map[script] = font16;
return font16;
}
void FillFontFamilyMap(const char* map_name,
blink::web_pref::ScriptFontFamilyMap* map) {
PerFamilyFonts MakeCacheForFamily(const std::string_view family_name) {
PerFamilyFonts ret;
for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
std::u16string result = FetchFont(script, map_name);
if (!result.empty()) {
(*map)[script] = result;
const char* script_name = prefs::kWebKitScriptsForFontFamilyMaps[i];
ret[i] = base::UTF8ToUTF16(GetDefaultFont(family_name, script_name));
}
return ret;
}
void FillFontFamilyMap(const PerFamilyFonts& cache,
blink::web_pref::ScriptFontFamilyMap& font_family_map) {
for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
if (const std::u16string& fontname = cache[i]; !fontname.empty()) {
char const* const script_name = prefs::kWebKitScriptsForFontFamilyMaps[i];
font_family_map[script_name] = fontname;
}
}
}
struct FamilyCache {
std::string_view family_name;
// where to find the font_family_map in a WebPreferences instance
blink::web_pref::ScriptFontFamilyMap blink::web_pref::WebPreferences::*
map_offset;
PerFamilyFonts fonts = {};
};
static auto MakeCache() {
// the font families whose defaults we want to cache
std::array<FamilyCache, 5> cache{{
{prefs::kWebKitStandardFontFamilyMap,
&blink::web_pref::WebPreferences::standard_font_family_map},
{prefs::kWebKitFixedFontFamilyMap,
&blink::web_pref::WebPreferences::fixed_font_family_map},
{prefs::kWebKitSerifFontFamilyMap,
&blink::web_pref::WebPreferences::serif_font_family_map},
{prefs::kWebKitSansSerifFontFamilyMap,
&blink::web_pref::WebPreferences::sans_serif_font_family_map},
{prefs::kWebKitCursiveFontFamilyMap,
&blink::web_pref::WebPreferences::cursive_font_family_map},
}};
// populate the cache
for (FamilyCache& row : cache) {
row.fonts = MakeCacheForFamily(row.family_name);
}
return cache;
}
} // namespace
namespace electron {
void SetFontDefaults(blink::web_pref::WebPreferences* prefs) {
FillFontFamilyMap(prefs::kWebKitStandardFontFamilyMap,
&prefs->standard_font_family_map);
FillFontFamilyMap(prefs::kWebKitFixedFontFamilyMap,
&prefs->fixed_font_family_map);
FillFontFamilyMap(prefs::kWebKitSerifFontFamilyMap,
&prefs->serif_font_family_map);
FillFontFamilyMap(prefs::kWebKitSansSerifFontFamilyMap,
&prefs->sans_serif_font_family_map);
FillFontFamilyMap(prefs::kWebKitCursiveFontFamilyMap,
&prefs->cursive_font_family_map);
static auto const cache = MakeCache();
for (FamilyCache const& row : cache) {
FillFontFamilyMap(row.fonts, prefs->*row.map_offset);
}
}
} // namespace electron

View File

@@ -11,7 +11,9 @@
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "device/bluetooth/dbus/bluez_dbus_manager.h"
#include "device/bluetooth/dbus/bluez_dbus_thread_manager.h"
#include "device/bluetooth/dbus/dbus_bluez_manager_wrapper_linux.h"
namespace {
@@ -34,6 +36,9 @@ PowerObserverLinux::PowerObserverLinux(
base::PowerSuspendObserver* suspend_observer)
: suspend_observer_(suspend_observer),
lock_owner_name_(GetExecutableBaseName()) {
if (!bluez::BluezDBusManager::IsInitialized())
bluez::DBusBluezManagerWrapperLinux::Initialize();
auto* bus = bluez::BluezDBusThreadManager::Get()->GetSystemBus();
if (!bus) {
LOG(WARNING) << "Failed to get system bus connection";

View File

@@ -235,6 +235,8 @@ class NativeWindowMac : public NativeWindow,
void InternalSetParentWindow(NativeWindow* parent, bool attach);
void SetForwardMouseMessages(bool forward);
void UpdateZoomButton();
ElectronNSWindow* window_; // Weak ref, managed by widget_.
ElectronNSWindowDelegate* __strong window_delegate_;

View File

@@ -879,8 +879,7 @@ void NativeWindowMac::SetResizable(bool resizable) {
// the maximize button and ensure fullscreenability matches user setting.
SetCanResize(resizable);
SetFullScreenable(was_fullscreenable);
[[window_ standardWindowButton:NSWindowZoomButton]
setEnabled:resizable ? was_fullscreenable : false];
UpdateZoomButton();
}
bool NativeWindowMac::IsResizable() const {
@@ -908,19 +907,26 @@ bool NativeWindowMac::IsMinimizable() const {
void NativeWindowMac::SetMaximizable(bool maximizable) {
maximizable_ = maximizable;
[[window_ standardWindowButton:NSWindowZoomButton] setEnabled:maximizable];
UpdateZoomButton();
}
bool NativeWindowMac::IsMaximizable() const {
return [[window_ standardWindowButton:NSWindowZoomButton] isEnabled];
}
void NativeWindowMac::UpdateZoomButton() {
[[window_ standardWindowButton:NSWindowZoomButton]
setEnabled:IsResizable() && (CanMaximize() || IsFullScreenable())];
}
void NativeWindowMac::SetFullScreenable(bool fullscreenable) {
SetCollectionBehavior(fullscreenable,
NSWindowCollectionBehaviorFullScreenPrimary);
// On EL Capitan this flag is required to hide fullscreen button.
SetCollectionBehavior(!fullscreenable,
NSWindowCollectionBehaviorFullScreenAuxiliary);
UpdateZoomButton();
}
bool NativeWindowMac::IsFullScreenable() const {

View File

@@ -8,7 +8,8 @@
#include "base/logging.h"
#include "base/process/launch.h"
#include "base/strings/stringprintf.h"
#include "base/strings/strcat_win.h"
#include "base/strings/string_number_conversions_win.h"
#include "base/strings/utf_string_conversions.h"
#include "base/win/scoped_handle.h"
#include "sandbox/win/src/nt_internals.h"
@@ -109,8 +110,8 @@ StringType AddQuoteForArg(const StringType& arg) {
} // namespace
StringType GetWaitEventName(base::ProcessId pid) {
return base::UTF8ToWide(
base::StringPrintf("%ls-%d", kWaitEventName, static_cast<int>(pid)));
return base::StrCat(
{kWaitEventName, L"-", base::NumberToWString(static_cast<int>(pid))});
}
StringType ArgvToCommandLineString(const StringVector& argv) {

View File

@@ -5611,6 +5611,19 @@ describe('BrowserWindow module', () => {
expect(w2.isFullScreenable()).to.be.false('isFullScreenable');
expect(w3.isFullScreenable()).to.be.false('isFullScreenable');
});
it('does not disable maximize button if window is resizable', () => {
const w = new BrowserWindow({
resizable: true,
fullscreenable: false
});
expect(w.isMaximizable()).to.be.true('isMaximizable');
w.setResizable(false);
expect(w.isMaximizable()).to.be.false('isMaximizable');
});
});
ifdescribe(process.platform === 'darwin')('isHiddenInMissionControl state', () => {