Skip to content

Commit

Permalink
Bug 1470983 - Remote all LookAndFeel values for the Gtk backend. r=sp…
Browse files Browse the repository at this point in the history
…ohl,jld

This adds a new LookAndFeel implementation, RemoteLookAndFeel, which can
be used in content processes and is supplied with all of its values by the
parent process.

Co-authored-by: Cameron McCormack <[email protected]>

Differential Revision: https://phabricator.services.mozilla.com/D97977
  • Loading branch information
jld committed Dec 16, 2020
1 parent df93a17 commit b311172
Show file tree
Hide file tree
Showing 27 changed files with 482 additions and 51 deletions.
18 changes: 14 additions & 4 deletions dom/ipc/ContentChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
#include "mozilla/net/NeckoChild.h"
#include "mozilla/plugins/PluginInstanceParent.h"
#include "mozilla/plugins/PluginModuleParent.h"
#include "mozilla/widget/RemoteLookAndFeel.h"
#include "mozilla/widget/ScreenManager.h"
#include "mozilla/widget/WidgetMessageUtils.h"
#include "nsBaseDragService.h"
Expand Down Expand Up @@ -602,7 +603,7 @@ NS_INTERFACE_MAP_END

mozilla::ipc::IPCResult ContentChild::RecvSetXPCOMProcessAttributes(
XPCOMInitData&& aXPCOMInit, const StructuredCloneData& aInitialData,
LookAndFeelCache&& aLookAndFeelCache,
LookAndFeelData&& aLookAndFeelData,
nsTArray<SystemFontListEntry>&& aFontList,
const Maybe<SharedMemoryHandle>& aSharedUASheetHandle,
const uintptr_t& aSharedUASheetAddress,
Expand All @@ -611,7 +612,7 @@ mozilla::ipc::IPCResult ContentChild::RecvSetXPCOMProcessAttributes(
return IPC_OK();
}

mLookAndFeelCache = std::move(aLookAndFeelCache);
mLookAndFeelData = std::move(aLookAndFeelData);
mFontList = std::move(aFontList);
mSharedFontListBlocks = std::move(aSharedFontListBlocks);
#ifdef XP_WIN
Expand Down Expand Up @@ -2287,8 +2288,17 @@ mozilla::ipc::IPCResult ContentChild::RecvNotifyVisited(
}

mozilla::ipc::IPCResult ContentChild::RecvThemeChanged(
LookAndFeelCache&& aLookAndFeelCache, widget::ThemeChangeKind aKind) {
LookAndFeel::SetCache(aLookAndFeelCache);
LookAndFeelData&& aLookAndFeelData, widget::ThemeChangeKind aKind) {
switch (aLookAndFeelData.type()) {
case LookAndFeelData::TLookAndFeelCache:
LookAndFeel::SetCache(aLookAndFeelData.get_LookAndFeelCache());
break;
case LookAndFeelData::TFullLookAndFeel:
LookAndFeel::SetData(std::move(aLookAndFeelData.get_FullLookAndFeel()));
break;
default:
MOZ_ASSERT(false, "unreachable");
}
LookAndFeel::NotifyChangedAllWindows(aKind);
return IPC_OK();
}
Expand Down
11 changes: 6 additions & 5 deletions dom/ipc/ContentChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ class ContentChild final : public PContentChild,
const bool& haveBidiKeyboards);

mozilla::ipc::IPCResult RecvNotifyVisited(nsTArray<VisitedQueryResult>&&);
mozilla::ipc::IPCResult RecvThemeChanged(LookAndFeelCache&& aLookAndFeelCache,

mozilla::ipc::IPCResult RecvThemeChanged(LookAndFeelData&& aLookAndFeelData,
widget::ThemeChangeKind);

mozilla::ipc::IPCResult RecvUpdateSystemParameters(
Expand Down Expand Up @@ -546,7 +547,7 @@ class ContentChild final : public PContentChild,

mozilla::ipc::IPCResult RecvSetXPCOMProcessAttributes(
XPCOMInitData&& aXPCOMInit, const StructuredCloneData& aInitialData,
LookAndFeelCache&& aLookAndFeelCache,
LookAndFeelData&& aLookAndFeelData,
nsTArray<SystemFontListEntry>&& aFontList,
const Maybe<base::SharedMemoryHandle>& aSharedUASheetHandle,
const uintptr_t& aSharedUASheetAddress,
Expand Down Expand Up @@ -611,7 +612,7 @@ class ContentChild final : public PContentChild,
bool DeallocPSessionStorageObserverChild(
PSessionStorageObserverChild* aActor);

LookAndFeelCache& BorrowLookAndFeelCache() { return mLookAndFeelCache; }
LookAndFeelData& BorrowLookAndFeelData() { return mLookAndFeelData; }

/**
* Helper function for protocols that use the GPU process when available.
Expand Down Expand Up @@ -856,8 +857,8 @@ class ContentChild final : public PContentChild,
// parent process and used to initialize gfx in the child. Currently used
// only on MacOSX and Linux.
nsTArray<mozilla::dom::SystemFontListEntry> mFontList;
// Temporary storage for nsXPLookAndFeel cache info.
LookAndFeelCache mLookAndFeelCache;
// Temporary storage for look and feel data.
LookAndFeelData mLookAndFeelData;
// Temporary storage for list of shared-fontlist memory blocks.
nsTArray<base::SharedMemoryHandle> mSharedFontListBlocks;

Expand Down
21 changes: 19 additions & 2 deletions dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
#include "mozilla/Sprintf.h"
#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/StaticPrefs_media.h"
#include "mozilla/StaticPrefs_widget.h"
#include "mozilla/StyleSheet.h"
#include "mozilla/StyleSheetInlines.h"
#include "mozilla/Telemetry.h"
Expand Down Expand Up @@ -158,6 +159,7 @@
#include "mozilla/net/PCookieServiceParent.h"
#include "mozilla/plugins/PluginBridge.h"
#include "mozilla/RemoteLazyInputStreamParent.h"
#include "mozilla/widget/RemoteLookAndFeel.h"
#include "mozilla/widget/ScreenManager.h"
#include "nsAnonymousTemporaryFile.h"
#include "nsAppRunner.h"
Expand Down Expand Up @@ -1484,6 +1486,21 @@ void ContentParent::BroadcastFontListChanged() {
}
}

static LookAndFeelData GetLookAndFeelData() {
if (StaticPrefs::widget_remote_look_and_feel_AtStartup()) {
return RemoteLookAndFeel::ExtractData();
}
return LookAndFeel::GetCache();
}

void ContentParent::BroadcastThemeUpdate(widget::ThemeChangeKind aKind) {
LookAndFeelData lnfData = GetLookAndFeelData();

for (auto* cp : AllProcesses(eLive)) {
Unused << cp->SendThemeChanged(lnfData, aKind);
}
}

const nsACString& ContentParent::GetRemoteType() const { return mRemoteType; }

void ContentParent::Init() {
Expand Down Expand Up @@ -2730,7 +2747,7 @@ bool ContentParent::InitInternal(ProcessPriority aInitialPriority) {
nsTArray<SystemFontListEntry> fontList;
gfxPlatform::GetPlatform()->ReadSystemFontList(&fontList);

LookAndFeelCache lnfCache = LookAndFeel::GetCache();
LookAndFeelData lnfData = GetLookAndFeelData();

// If the shared fontlist is in use, collect its shmem block handles to pass
// to the child.
Expand Down Expand Up @@ -2791,7 +2808,7 @@ bool ContentParent::InitInternal(ProcessPriority aInitialPriority) {
}

Unused << SendSetXPCOMProcessAttributes(
xpcomInit, initialData, lnfCache, fontList, sharedUASheetHandle,
xpcomInit, initialData, lnfData, fontList, sharedUASheetHandle,
sharedUASheetAddress, sharedFontListBlocks);

ipc::WritableSharedMap* sharedData =
Expand Down
2 changes: 2 additions & 0 deletions dom/ipc/ContentParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ class ContentParent final

static void BroadcastFontListChanged();

static void BroadcastThemeUpdate(widget::ThemeChangeKind);

const nsACString& GetRemoteType() const override;

virtual void DoGetRemoteType(nsACString& aRemoteType,
Expand Down
4 changes: 2 additions & 2 deletions dom/ipc/PContent.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ child:
* Tell the child that the system theme has changed, and that a repaint is
* necessary.
*/
async ThemeChanged(LookAndFeelCache aCache, ThemeChangeKind aKind);
async ThemeChanged(LookAndFeelData lookAndFeelData, ThemeChangeKind aKind);

async UpdateSystemParameters(SystemParameterKVPair[] aUpdates);

Expand Down Expand Up @@ -688,7 +688,7 @@ child:

async SetXPCOMProcessAttributes(XPCOMInitData xpcomInit,
StructuredCloneData initialData,
LookAndFeelCache lookAndFeelCache,
LookAndFeelData lookAndFeeldata,
/* used on MacOSX/Linux/Android only: */
SystemFontListEntry[] systemFontList,
SharedMemoryHandle? sharedUASheetHandle,
Expand Down
7 changes: 1 addition & 6 deletions layout/base/nsPresContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1398,12 +1398,7 @@ void nsPresContext::ThemeChangedInternal() {
image::SurfaceCacheUtils::DiscardAll();

if (XRE_IsParentProcess()) {
nsTArray<ContentParent*> cp;
ContentParent::GetAll(cp);
widget::LookAndFeelCache lnfCache = LookAndFeel::GetCache();
for (ContentParent* c : cp) {
Unused << c->SendThemeChanged(lnfCache, kind);
}
ContentParent::BroadcastThemeUpdate(kind);
}
}

Expand Down
19 changes: 16 additions & 3 deletions modules/libpref/init/StaticPrefList.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9579,9 +9579,9 @@
#if defined(XP_LINUX) && defined(MOZ_SANDBOX)
# Run content processes in headless mode and disallow connections to
# the X server. Experimental; breaks WebGL and Flash, and requires
# `widget.disable-native-theme-for-content`. Changing it requires a
# restart because sandbox policy information dependent on it is cached.
# See bug 1640345 for details.
# `widget.disable-native-theme-for-content` and `widget.remote-look-and-feel`.
# Changing it requires a restart because sandbox policy information dependent
# on it is cached. See bug 1640345 for details.
- name: security.sandbox.content.headless
type: bool
value: false
Expand Down Expand Up @@ -10417,6 +10417,19 @@
mirror: always
#endif

# Enable the RemoteLookAndFeel in content processes, which will cause all
# LookAndFeel values to be queried in the parent process and sent to content
# processes using IPC. This is required for widgets to paint and behave
# correctly when `security.sandbox.content.headless` is enabled.
- name: widget.remote-look-and-feel
type: bool
#ifdef MOZ_WIDGET_GTK
value: true
#else
value: false
#endif
mirror: once

#---------------------------------------------------------------------------
# Prefs starting with "xul."
#---------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions widget/LookAndFeel.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct gfxFontStyle;
namespace mozilla {

namespace widget {
class FullLookAndFeel;
class LookAndFeelCache;
} // namespace widget

Expand Down Expand Up @@ -400,6 +401,9 @@ class LookAndFeel {
// The width/height ratio of the cursor. If used, the CaretWidth int metric
// should be added to the calculated caret width.
CaretAspectRatio,

// Not an ID; used to define the range of valid IDs. Must be last.
End,
};

// These constants must be kept in 1:1 correspondence with the
Expand Down Expand Up @@ -555,6 +559,7 @@ class LookAndFeel {
*/
static widget::LookAndFeelCache GetCache();
static void SetCache(const widget::LookAndFeelCache& aCache);
static void SetData(widget::FullLookAndFeel&& aTables);
static void NotifyChangedAllWindows(widget::ThemeChangeKind);
};

Expand Down
42 changes: 41 additions & 1 deletion widget/LookAndFeelTypes.ipdlh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct LookAndFeelInt {
int32_t value;
};

struct LookAndFeelFont {
comparable struct LookAndFeelFont {
bool haveFont;
nsString name;
float size;
Expand All @@ -35,5 +35,45 @@ struct LookAndFeelCache {
LookAndFeelColor[] mColors;
};

/**
* Stores the entirety of a LookAndFeel's data.
*
* The format allows for some compression compared with having fixed
* length arrays for each value type and some indication of whether
* a value is present. This is because not all values are present on
* a given platform, and because there is also substantial repetition
* of specific values.
*
* Each of ints, floats, colors, and fonts is an array that stores the
* unique values that occur in the LookAndFeel. intMap, floatMap,
* colorMap, and fontMap map from value IDs (LookAndFeel::IntID, etc.)
* to indexes into the value arrays. The map arrays are of fixed
* length, determined by the maximum ID value. If a value for a
* particular ID is not present, the entry in the map is set to -1.
*
* (Note that fontMap is different from the others since it maps from a
* LookAndFeel::FontID value minus 1, as 1 is the minimum value of that
* enum.)
*/
struct FullLookAndFeel {
int32_t[] ints;
float[] floats;
nscolor[] colors;
LookAndFeelFont[] fonts;

uint8_t[] intMap;
uint8_t[] floatMap;
uint8_t[] colorMap;
uint8_t[] fontMap;

uint16_t passwordChar;
bool passwordEcho;
};

union LookAndFeelData {
LookAndFeelCache;
FullLookAndFeel;
};

} // namespace widget
} // namespace mozilla
Loading

0 comments on commit b311172

Please sign in to comment.