aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorUsman Yahaya Baba <91813795+uthmaniv@users.noreply.github.com>2025-04-06 15:19:42 +0100
committerGitHub <noreply@github.com>2025-04-06 14:19:42 +0000
commitfab5e029726a85c179b57b834eae547abf006256 (patch)
tree6c8b79440f743b94d6735b23ab99e1c438ead455 /components
parent9d074161638829deb0f0b1adacb8ff270abd1978 (diff)
downloadservo-fab5e029726a85c179b57b834eae547abf006256.tar.gz
servo-fab5e029726a85c179b57b834eae547abf006256.zip
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>
Diffstat (limited to 'components')
-rw-r--r--components/devtools/actors/browsing_context.rs11
-rw-r--r--components/devtools/actors/watcher/target_configuration.rs38
-rw-r--r--components/shared/embedder/lib.rs2
3 files changed, 44 insertions, 7 deletions
diff --git a/components/devtools/actors/browsing_context.rs b/components/devtools/actors/browsing_context.rs
index 261eb4112bf..9a037c11428 100644
--- a/components/devtools/actors/browsing_context.rs
+++ b/components/devtools/actors/browsing_context.rs
@@ -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(|_| ())
+ }
}
diff --git a/components/devtools/actors/watcher/target_configuration.rs b/components/devtools/actors/watcher/target_configuration.rs
index 7b83cdde698..0d366e81475 100644
--- a/components/devtools/actors/watcher/target_configuration.rs
+++ b/components/devtools/actors/watcher/target_configuration.rs
@@ -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),
diff --git a/components/shared/embedder/lib.rs b/components/shared/embedder/lib.rs
index 85dd4bf3af9..529ae465567 100644
--- a/components/shared/embedder/lib.rs
+++ b/components/shared/embedder/lib.rs
@@ -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,