Process colorSchemeSimulation in TargetConfigurationActor (#36297)

Implements Steps 1,4&6 of https://github.com/servo/servo/issues/35867:
- Adds `pub simulate_color_scheme` to `BrowsingContextActor` using
`script_chan`.
- Processes `colorSchemeSimulation` flag in `TargetConfigurationActor`’s
`updateConfiguration`.
- Routes `colorSchemeSimulation` from `RootActor` via
`TabDescriptorActor` to `BrowsingContextActor`.

Testing: Compiles and lints clean.
Fixes: https://github.com/servo/servo/issues/35867

---------

Signed-off-by: Uthman Yahaya Baba <uthmanyahayababa@gmail.com>
This commit is contained in:
Usman Yahaya Baba 2025-04-06 15:19:42 +01:00 committed by GitHub
parent 9d07416163
commit fab5e02972
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 44 additions and 7 deletions

View file

@ -11,8 +11,11 @@ use std::collections::HashMap;
use std::net::TcpStream;
use base::id::PipelineId;
use devtools_traits::DevtoolScriptControlMsg::{self, GetCssDatabase, WantsLiveNotifications};
use devtools_traits::DevtoolScriptControlMsg::{
self, GetCssDatabase, SimulateColorScheme, WantsLiveNotifications,
};
use devtools_traits::{DevtoolsPageInfo, NavigationState};
use embedder_traits::Theme;
use ipc_channel::ipc::{self, IpcSender};
use serde::Serialize;
use serde_json::{Map, Value};
@ -352,4 +355,10 @@ impl BrowsingContextActor {
let _ = stream.write_json_packet(&msg);
}
}
pub fn simulate_color_scheme(&self, theme: Theme) -> Result<(), ()> {
self.script_chan
.send(SimulateColorScheme(self.active_pipeline_id.get(), theme))
.map_err(|_| ())
}
}

View file

@ -8,12 +8,16 @@
use std::collections::HashMap;
use std::net::TcpStream;
use embedder_traits::Theme;
use log::warn;
use serde::Serialize;
use serde_json::{Map, Value};
use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
use crate::actors::browsing_context::BrowsingContextActor;
use crate::actors::tab::TabDescriptorActor;
use crate::protocol::JsonPacketStream;
use crate::{EmptyReplyMsg, StreamId};
use crate::{EmptyReplyMsg, RootActor, StreamId};
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
@ -44,15 +48,39 @@ impl Actor for TargetConfigurationActor {
/// - `updateConfiguration`: Receives new configuration flags from the devtools host.
fn handle_message(
&self,
_registry: &ActorRegistry,
registry: &ActorRegistry,
msg_type: &str,
_msg: &Map<String, Value>,
msg: &Map<String, Value>,
stream: &mut TcpStream,
_id: StreamId,
) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"updateConfiguration" => {
// TODO: Actually update configuration
let config = match msg.get("configuration").and_then(|v| v.as_object()) {
Some(config) => config,
None => {
let msg = EmptyReplyMsg { from: self.name() };
let _ = stream.write_json_packet(&msg);
return Ok(ActorMessageStatus::Processed);
},
};
if let Some(scheme) = config.get("colorSchemeSimulation").and_then(|v| v.as_str()) {
let theme = match scheme {
"dark" => Theme::Dark,
"light" => Theme::Light,
_ => Theme::Light,
};
let root_actor = registry.find::<RootActor>("root");
if let Some(tab_name) = root_actor.active_tab() {
let tab_actor = registry.find::<TabDescriptorActor>(&tab_name);
let browsing_context_name = tab_actor.browsing_context();
let browsing_context_actor =
registry.find::<BrowsingContextActor>(&browsing_context_name);
browsing_context_actor.simulate_color_scheme(theme)?;
} else {
warn!("No active tab for updateConfiguration");
}
}
let msg = EmptyReplyMsg { from: self.name() };
let _ = stream.write_json_packet(&msg);
ActorMessageStatus::Processed
@ -69,7 +97,7 @@ impl TargetConfigurationActor {
configuration: HashMap::new(),
supported_options: HashMap::from([
("cacheDisabled", false),
("colorSchemeSimulation", false),
("colorSchemeSimulation", true),
("customFormatters", false),
("customUserAgent", false),
("javascriptEnabled", false),

View file

@ -293,7 +293,7 @@ pub enum EmbedderMsg {
AllowOpeningWebView(WebViewId, IpcSender<Option<(WebViewId, ViewportDetails)>>),
/// A webview was destroyed.
WebViewClosed(WebViewId),
/// A webview gained focus for keyboard events.
/// A webview gained focus for keyboard events
WebViewFocused(WebViewId),
/// All webviews lost focus for keyboard events.
WebViewBlurred,