mirror of
https://github.com/servo/servo.git
synced 2025-09-29 16:19:14 +01:00
constellation: Broadcast preference changes to all content processes (#38716)
Building on the preference observer work from #38649, we now automatically install an observer when multiprocess mode is enabled. This observer notifies the constellation of updated preferences, which in turn notifies each content process so the changes will be reflected into script/layout as expected. There's a unit test that verifies this works correctly by checking a preference-gated WebIDL property before and after the preference is toggled. Testing: New unit test added. Fixes: #35966 Depends on #38649. --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
61692b26c2
commit
ed6bf196c9
16 changed files with 191 additions and 60 deletions
|
@ -12,10 +12,10 @@ pub use crate::pref_util::PrefValue;
|
|||
static PREFERENCES: RwLock<Preferences> = RwLock::new(Preferences::const_default());
|
||||
|
||||
pub trait Observer: Send + Sync {
|
||||
fn prefs_changed(&self, _changes: Vec<(&'static str, PrefValue)>) {}
|
||||
fn prefs_changed(&self, _changes: &[(&'static str, PrefValue)]) {}
|
||||
}
|
||||
|
||||
static OBSERVER: RwLock<Option<Box<dyn Observer>>> = RwLock::new(None);
|
||||
static OBSERVERS: RwLock<Vec<Box<dyn Observer>>> = RwLock::new(Vec::new());
|
||||
|
||||
#[inline]
|
||||
/// Get the current set of global preferences for Servo.
|
||||
|
@ -23,8 +23,8 @@ pub fn get() -> RwLockReadGuard<'static, Preferences> {
|
|||
PREFERENCES.read().unwrap()
|
||||
}
|
||||
|
||||
pub fn set_observer(observer: Box<dyn Observer>) {
|
||||
*OBSERVER.write().unwrap() = Some(observer);
|
||||
pub fn add_observer(observer: Box<dyn Observer>) {
|
||||
OBSERVERS.write().unwrap().push(observer);
|
||||
}
|
||||
|
||||
pub fn set(preferences: Preferences) {
|
||||
|
@ -57,8 +57,8 @@ pub fn set(preferences: Preferences) {
|
|||
|
||||
*PREFERENCES.write().unwrap() = preferences;
|
||||
|
||||
if let Some(observer) = OBSERVER.read().unwrap().as_deref() {
|
||||
observer.prefs_changed(changed);
|
||||
for observer in &*OBSERVERS.read().unwrap() {
|
||||
observer.prefs_changed(&changed);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue