mirror of
https://github.com/servo/servo.git
synced 2025-09-23 05:10:09 +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
|
@ -160,6 +160,7 @@ use script_traits::{
|
|||
ScriptThreadMessage, UpdatePipelineIdReason,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use servo_config::prefs::{self, PrefValue};
|
||||
use servo_config::{opts, pref};
|
||||
use servo_rand::{Rng, ServoRng, SliceRandom, random};
|
||||
use servo_url::{Host, ImmutableOrigin, ServoUrl};
|
||||
|
@ -254,6 +255,18 @@ struct BrowsingContextGroup {
|
|||
webgpus: HashMap<Host, WebGPU>,
|
||||
}
|
||||
|
||||
struct PreferenceForwarder(Sender<EmbedderToConstellationMessage>);
|
||||
|
||||
impl prefs::Observer for PreferenceForwarder {
|
||||
fn prefs_changed(&self, changes: &[(&'static str, PrefValue)]) {
|
||||
let _ = self
|
||||
.0
|
||||
.send(EmbedderToConstellationMessage::PreferencesUpdated(
|
||||
changes.to_owned(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// The `Constellation` itself. In the servo browser, there is one
|
||||
/// constellation, which maintains all of the browser global data.
|
||||
/// In embedded applications, there may be more than one constellation,
|
||||
|
@ -583,6 +596,7 @@ where
|
|||
hard_fail: bool,
|
||||
) -> Sender<EmbedderToConstellationMessage> {
|
||||
let (compositor_sender, compositor_receiver) = unbounded();
|
||||
let compositor_sender_self = compositor_sender.clone();
|
||||
|
||||
// service worker manager to communicate with constellation
|
||||
let (swmanager_ipc_sender, swmanager_ipc_receiver) =
|
||||
|
@ -654,6 +668,10 @@ where
|
|||
|
||||
let rippy_data = resources::read_bytes(Resource::RippyPNG);
|
||||
|
||||
if opts::get().multiprocess {
|
||||
prefs::add_observer(Box::new(PreferenceForwarder(compositor_sender_self)));
|
||||
}
|
||||
|
||||
let mut constellation: Constellation<STF, SWF> = Constellation {
|
||||
namespace_receiver,
|
||||
namespace_ipc_sender,
|
||||
|
@ -1507,6 +1525,20 @@ where
|
|||
EmbedderToConstellationMessage::SetWebDriverResponseSender(sender) => {
|
||||
self.webdriver_input_command_reponse_sender = Some(sender);
|
||||
},
|
||||
EmbedderToConstellationMessage::PreferencesUpdated(updates) => {
|
||||
let event_loops = self
|
||||
.pipelines
|
||||
.values()
|
||||
.map(|pipeline| pipeline.event_loop.clone());
|
||||
for event_loop in event_loops {
|
||||
let _ = event_loop.send(ScriptThreadMessage::PreferencesUpdated(
|
||||
updates
|
||||
.iter()
|
||||
.map(|(name, value)| (String::from(*name), value.clone()))
|
||||
.collect(),
|
||||
));
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -78,6 +78,7 @@ mod from_compositor {
|
|||
Self::CreateMemoryReport(..) => target!("CreateMemoryReport"),
|
||||
Self::SendImageKeysForPipeline(..) => target!("SendImageKeysForPipeline"),
|
||||
Self::SetWebDriverResponseSender(..) => target!("SetWebDriverResponseSender"),
|
||||
Self::PreferencesUpdated(..) => target!("PreferencesUpdated"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue