Bug 1775320 - WinContentSystemParameters is not needed. r=cmartin

It was needed before we had remote lookandfeel and non-native theme, but now we
no longer call any of the APIs in child processes.

Differential Revision: https://phabricator.services.mozilla.com/D149907
This commit is contained in:
Emilio Cobos Álvarez 2022-06-22 18:03:01 +00:00
parent a3b48ab633
commit fc56cb5d2d
10 changed files with 1 additions and 341 deletions

View File

@ -226,7 +226,6 @@
# include <process.h>
# define getpid _getpid
# include "mozilla/WinDllServices.h"
# include "mozilla/widget/WinContentSystemParameters.h"
#endif
#if defined(XP_MACOSX)
@ -677,10 +676,6 @@ mozilla::ipc::IPCResult ContentChild::RecvSetXPCOMProcessAttributes(
mLookAndFeelData = std::move(aLookAndFeelData);
mFontList = std::move(aFontList);
mSharedFontListBlocks = std::move(aSharedFontListBlocks);
#ifdef XP_WIN
widget::WinContentSystemParameters::GetSingleton()->SetContentValues(
aXPCOMInit.systemParameters());
#endif
gfx::gfxVars::SetValuesForInitialize(aXPCOMInit.gfxNonDefaultVarUpdates());
InitSharedUASheets(std::move(aSharedUASheetHandle), aSharedUASheetAddress);
@ -2321,16 +2316,6 @@ mozilla::ipc::IPCResult ContentChild::RecvThemeChanged(
return IPC_OK();
}
mozilla::ipc::IPCResult ContentChild::RecvUpdateSystemParameters(
nsTArray<SystemParameterKVPair>&& aUpdates) {
#ifdef XP_WIN
widget::WinContentSystemParameters::GetSingleton()->SetContentValues(
aUpdates);
#endif
return IPC_OK();
}
mozilla::ipc::IPCResult ContentChild::RecvLoadProcessScript(
const nsString& aURL) {
auto* global = ContentProcessMessageManager::Get();

View File

@ -273,9 +273,6 @@ class ContentChild final : public PContentChild,
mozilla::ipc::IPCResult RecvThemeChanged(FullLookAndFeel&&,
widget::ThemeChangeKind);
mozilla::ipc::IPCResult RecvUpdateSystemParameters(
nsTArray<SystemParameterKVPair>&& aUpdates);
// auto remove when alertfinished is received.
nsresult AddRemoteAlertObserver(const nsString& aData,
nsIObserver* aObserver);

View File

@ -309,7 +309,6 @@
#ifdef XP_WIN
# include "mozilla/widget/AudioSession.h"
# include "mozilla/widget/WinContentSystemParameters.h"
# include "mozilla/WinDllServices.h"
#endif
@ -3016,11 +3015,6 @@ bool ContentParent::InitInternal(ProcessPriority aInitialPriority) {
xpcomInit.gfxFeatureStatus() = gfxInfoRaw->GetAllFeatures();
}
#ifdef XP_WIN
xpcomInit.systemParameters() =
widget::WinContentSystemParameters::GetSingleton()->GetParentValues();
#endif
// Send the dynamic scalar definitions to the new process.
TelemetryIPC::GetDynamicScalarDefinitions(xpcomInit.dynamicScalarDefs());

View File

@ -220,11 +220,6 @@ union SystemParameterValue {
float;
};
struct SystemParameterKVPair {
uint8_t id;
SystemParameterValue value;
};
struct ClipboardCapabilities {
bool supportsSelectionClipboard;
bool supportsFindClipboard;
@ -366,7 +361,6 @@ struct XPCOMInitData
nsCString[] requestedLocales;
L10nFileSourceDescriptor[] l10nFileSources;
DynamicScalarDefinition[] dynamicScalarDefs;
SystemParameterKVPair[] systemParameters;
};
struct VisitedQueryResult
@ -658,8 +652,6 @@ child:
*/
async ThemeChanged(FullLookAndFeel lookAndFeelData, ThemeChangeKind aKind);
async UpdateSystemParameters(SystemParameterKVPair[] aUpdates);
async PreferenceUpdate(Pref pref);
async VarUpdate(GfxVarUpdate var);

View File

@ -1,213 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "WinContentSystemParameters.h"
#include "WinUtils.h"
#include "nsUXThemeData.h"
#include "mozilla/Mutex.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/ContentParent.h"
namespace mozilla {
namespace widget {
using dom::SystemParameterKVPair;
static_assert(uint8_t(SystemParameterId::Count) < 32,
"Too many SystemParameterId for "
"WinContentSystemParameters::Detail::validCachedValueBitfield");
struct WinContentSystemParameters::Detail {
OffTheBooksMutex mutex{"WinContentSystemParameters::Detail::mutex"};
// A bitfield indicating which cached ids are valid
uint32_t validCachedValueBitfield{0};
bool cachedIsPerMonitorDPIAware{false};
float cachedSystemDPI{0.0f};
bool cachedFlatMenusEnabled{false};
// Almost-always true in Windows 7, always true starting in Windows 8
bool cachedIsAppThemed{true};
};
// static
WinContentSystemParameters* WinContentSystemParameters::GetSingleton() {
static WinContentSystemParameters sInstance{};
return &sInstance;
}
WinContentSystemParameters::WinContentSystemParameters()
: mDetail(std::make_unique<Detail>()) {}
WinContentSystemParameters::~WinContentSystemParameters() {}
bool WinContentSystemParameters::IsPerMonitorDPIAware() {
MOZ_ASSERT(XRE_IsContentProcess());
OffTheBooksMutexAutoLock lock(mDetail->mutex);
MOZ_RELEASE_ASSERT(
IsCachedValueValid(SystemParameterId::IsPerMonitorDPIAware));
return mDetail->cachedIsPerMonitorDPIAware;
}
float WinContentSystemParameters::SystemDPI() {
MOZ_ASSERT(XRE_IsContentProcess());
OffTheBooksMutexAutoLock lock(mDetail->mutex);
MOZ_RELEASE_ASSERT(IsCachedValueValid(SystemParameterId::SystemDPI));
return mDetail->cachedSystemDPI;
}
bool WinContentSystemParameters::AreFlatMenusEnabled() {
MOZ_ASSERT(XRE_IsContentProcess());
OffTheBooksMutexAutoLock lock(mDetail->mutex);
MOZ_RELEASE_ASSERT(IsCachedValueValid(SystemParameterId::FlatMenusEnabled));
return mDetail->cachedFlatMenusEnabled;
}
bool WinContentSystemParameters::IsAppThemed() {
MOZ_ASSERT(XRE_IsContentProcess());
OffTheBooksMutexAutoLock lock(mDetail->mutex);
MOZ_RELEASE_ASSERT(IsCachedValueValid(SystemParameterId::IsAppThemed));
return mDetail->cachedIsAppThemed;
}
void WinContentSystemParameters::SetContentValueInternal(
const SystemParameterKVPair& aKVPair) {
MOZ_ASSERT(XRE_IsContentProcess());
MOZ_ASSERT(NS_IsMainThread());
MOZ_RELEASE_ASSERT(aKVPair.id() < uint8_t(SystemParameterId::Count));
SetCachedValueValid(SystemParameterId(aKVPair.id()), true);
mDetail->mutex.AssertCurrentThreadOwns();
switch (SystemParameterId(aKVPair.id())) {
case SystemParameterId::IsPerMonitorDPIAware:
mDetail->cachedIsPerMonitorDPIAware = aKVPair.value();
return;
case SystemParameterId::SystemDPI:
mDetail->cachedSystemDPI = aKVPair.value();
return;
case SystemParameterId::FlatMenusEnabled:
mDetail->cachedFlatMenusEnabled = aKVPair.value();
return;
case SystemParameterId::IsAppThemed:
mDetail->cachedIsAppThemed = aKVPair.value();
return;
case SystemParameterId::Count:
MOZ_CRASH("Invalid SystemParameterId");
}
MOZ_CRASH("Unhandled SystemParameterId");
}
void WinContentSystemParameters::SetContentValues(
const nsTArray<dom::SystemParameterKVPair>& values) {
MOZ_ASSERT(XRE_IsContentProcess());
MOZ_ASSERT(NS_IsMainThread());
OffTheBooksMutexAutoLock lock(mDetail->mutex);
for (auto& kvPair : values) {
SetContentValueInternal(kvPair);
}
}
bool WinContentSystemParameters::GetParentValueInternal(
SystemParameterId aId, SystemParameterKVPair* aKVPair) {
MOZ_ASSERT(XRE_IsParentProcess());
MOZ_ASSERT(aKVPair);
aKVPair->id() = uint8_t(aId);
switch (aId) {
case SystemParameterId::IsPerMonitorDPIAware:
aKVPair->value() = WinUtils::IsPerMonitorDPIAware();
return true;
case SystemParameterId::SystemDPI:
aKVPair->value() = WinUtils::SystemDPI();
return true;
case SystemParameterId::FlatMenusEnabled:
aKVPair->value() = nsUXThemeData::AreFlatMenusEnabled();
return true;
case SystemParameterId::IsAppThemed:
aKVPair->value() = nsUXThemeData::IsAppThemed();
return true;
case SystemParameterId::Count:
MOZ_CRASH("Invalid SystemParameterId");
}
MOZ_CRASH("Unhandled SystemParameterId");
}
nsTArray<dom::SystemParameterKVPair>
WinContentSystemParameters::GetParentValues() {
MOZ_ASSERT(XRE_IsParentProcess());
nsTArray<dom::SystemParameterKVPair> results;
for (uint8_t i = 0; i < uint8_t(SystemParameterId::Count); ++i) {
dom::SystemParameterKVPair kvPair{};
GetParentValueInternal(SystemParameterId(i), &kvPair);
results.AppendElement(std::move(kvPair));
}
return results;
}
void WinContentSystemParameters::OnThemeChanged() {
MOZ_ASSERT(XRE_IsParentProcess());
nsTArray<dom::SystemParameterKVPair> updates;
{
dom::SystemParameterKVPair kvPair{};
GetParentValueInternal(SystemParameterId::FlatMenusEnabled, &kvPair);
updates.AppendElement(std::move(kvPair));
}
{
dom::SystemParameterKVPair kvPair{};
GetParentValueInternal(SystemParameterId::IsAppThemed, &kvPair);
updates.AppendElement(std::move(kvPair));
}
nsTArray<dom::ContentParent*> contentProcesses{};
dom::ContentParent::GetAll(contentProcesses);
for (auto contentProcess : contentProcesses) {
Unused << contentProcess->SendUpdateSystemParameters(updates);
}
}
bool WinContentSystemParameters::IsCachedValueValid(SystemParameterId aId) {
MOZ_ASSERT(XRE_IsContentProcess());
MOZ_ASSERT(uint8_t(aId) < uint8_t(SystemParameterId::Count));
mDetail->mutex.AssertCurrentThreadOwns();
uint32_t mask = uint32_t(1) << uint8_t(aId);
return (mDetail->validCachedValueBitfield & mask) != 0;
}
void WinContentSystemParameters::SetCachedValueValid(SystemParameterId aId,
bool aIsValid) {
MOZ_ASSERT(XRE_IsContentProcess());
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(uint8_t(aId) < uint8_t(SystemParameterId::Count));
mDetail->mutex.AssertCurrentThreadOwns();
uint32_t mask = uint32_t(1) << uint8_t(aId);
if (aIsValid) {
mDetail->validCachedValueBitfield |= mask;
} else {
mDetail->validCachedValueBitfield &= ~mask;
}
}
} // namespace widget
} // namespace mozilla

View File

@ -1,72 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_widget_WinContentSystemParameters_h
#define mozilla_widget_WinContentSystemParameters_h
#include <memory>
#include <cinttypes>
#include "nsTArray.h"
namespace mozilla {
namespace dom {
class SystemParameterKVPair;
}
namespace widget {
enum class SystemParameterId : uint8_t {
IsPerMonitorDPIAware = 0,
SystemDPI,
FlatMenusEnabled,
IsAppThemed,
Count,
};
class WinContentSystemParameters {
public:
static WinContentSystemParameters* GetSingleton();
bool IsPerMonitorDPIAware();
float SystemDPI();
bool AreFlatMenusEnabled();
bool IsAppThemed();
void SetContentValues(const nsTArray<dom::SystemParameterKVPair>& values);
nsTArray<dom::SystemParameterKVPair> GetParentValues();
void OnThemeChanged();
WinContentSystemParameters(const WinContentSystemParameters&) = delete;
WinContentSystemParameters(WinContentSystemParameters&&) = delete;
WinContentSystemParameters& operator=(const WinContentSystemParameters&) =
delete;
WinContentSystemParameters& operator=(WinContentSystemParameters&&) = delete;
private:
WinContentSystemParameters();
~WinContentSystemParameters();
void SetContentValueInternal(const dom::SystemParameterKVPair& aKVPair);
bool GetParentValueInternal(SystemParameterId aId,
dom::SystemParameterKVPair* aKVPair);
bool IsCachedValueValid(SystemParameterId aId);
void SetCachedValueValid(SystemParameterId aId, bool aIsValid);
struct Detail;
std::unique_ptr<Detail> mDetail;
};
} // namespace widget
} // namespace mozilla
#endif // mozilla_widget_WinContentSystemParameters_h

View File

@ -53,7 +53,6 @@
#include "nsLookAndFeel.h"
#include "nsUnicharUtils.h"
#include "nsWindowsHelpers.h"
#include "WinContentSystemParameters.h"
#include "WinWindowOcclusionTracker.h"
#include <textstor.h>
@ -563,9 +562,6 @@ void WinUtils::Log(const char* fmt, ...) {
// static
float WinUtils::SystemDPI() {
if (XRE_IsContentProcess()) {
return WinContentSystemParameters::GetSingleton()->SystemDPI();
}
// The result of GetDeviceCaps won't change dynamically, as it predates
// per-monitor DPI and support for on-the-fly resolution changes.
// Therefore, we only need to look it up once.
@ -628,9 +624,6 @@ static bool SlowIsPerMonitorDPIAware() {
/* static */
bool WinUtils::IsPerMonitorDPIAware() {
if (XRE_IsContentProcess()) {
return WinContentSystemParameters::GetSingleton()->IsPerMonitorDPIAware();
}
static bool perMonitorDPIAware = SlowIsPerMonitorDPIAware();
return perMonitorDPIAware;
}

View File

@ -48,7 +48,6 @@ EXPORTS.mozilla.widget += [
"InProcessWinCompositorWidget.h",
"WinCompositorWidget.h",
"WinCompositorWindowThread.h",
"WinContentSystemParameters.h",
"WindowsEMF.h",
"WindowsSMTCProvider.h",
"WinEventObserver.h",
@ -121,7 +120,6 @@ SOURCES += [
"nsWidgetFactory.cpp",
"OSKInputPaneManager.cpp",
"WinCompositorWidget.cpp",
"WinContentSystemParameters.cpp",
"WindowsSMTCProvider.cpp",
"WindowsUIUtils.cpp",
"WinMouseScrollHandler.cpp",

View File

@ -12,7 +12,6 @@
#include "nsDebug.h"
#include "nsToolkit.h"
#include "nsUXThemeConstants.h"
#include "WinContentSystemParameters.h"
#include "gfxWindowsPlatform.h"
using namespace mozilla;
@ -350,19 +349,10 @@ void nsUXThemeData::UpdateNativeThemeInfo() {
// static
bool nsUXThemeData::AreFlatMenusEnabled() {
if (XRE_IsContentProcess()) {
return WinContentSystemParameters::GetSingleton()->AreFlatMenusEnabled();
}
BOOL useFlat = FALSE;
return !!::SystemParametersInfo(SPI_GETFLATMENU, 0, &useFlat, 0) ? useFlat
: false;
}
// static
bool nsUXThemeData::IsAppThemed() {
if (XRE_IsContentProcess()) {
return WinContentSystemParameters::GetSingleton()->IsAppThemed();
}
return !!::IsAppThemed();
}
bool nsUXThemeData::IsAppThemed() { return !!::IsAppThemed(); }

View File

@ -133,7 +133,6 @@
#include "SystemTimeConverter.h"
#include "WinTaskbar.h"
#include "WidgetUtils.h"
#include "WinContentSystemParameters.h"
#include "WinWindowOcclusionTracker.h"
#include "nsIWidgetListener.h"
#include "mozilla/dom/Document.h"
@ -5150,9 +5149,6 @@ bool nsWindow::ProcessMessageInternal(UINT msg, WPARAM& wParam, LPARAM& lParam,
break;
case WM_THEMECHANGED: {
// Before anything else, push updates to child processes
WinContentSystemParameters::GetSingleton()->OnThemeChanged();
// Update non-client margin offsets
UpdateNonClientMargins();
nsUXThemeData::UpdateNativeThemeInfo();