From c8d911817fff69f86a55a16a767a62e583ed738e Mon Sep 17 00:00:00 2001 From: Sudarsan Date: Sat, 12 Sep 2020 18:55:11 +0800 Subject: [PATCH 1/2] preferences actor now returns real values. The preferences actor was previously returning mock values. This changes picks up the pref_values from the pref_map which is global preferences state and returns values from there. --- components/devtools/actors/preference.rs | 52 +++++++++++++++--------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/components/devtools/actors/preference.rs b/components/devtools/actors/preference.rs index a690148342f..ce3123ce5dd 100644 --- a/components/devtools/actors/preference.rs +++ b/components/devtools/actors/preference.rs @@ -6,6 +6,8 @@ use crate::actor::{Actor, ActorMessageStatus, ActorRegistry}; use crate::protocol::JsonPacketStream; use crate::StreamId; use serde_json::{Map, Value}; +use servo_config::pref_util::PrefValue; +use servo_config::prefs::pref_map; use std::net::TcpStream; pub struct PreferenceActor { @@ -31,35 +33,41 @@ impl Actor for PreferenceActor { stream: &mut TcpStream, _id: StreamId, ) -> Result { - Ok(match msg_type { - "getBoolPref" => { - let reply = BoolReply { + let pref_value = pref_map().get(msg_type); + Ok(match pref_value { + PrefValue::Float(value) => { + let reply = FloatReply { from: self.name(), - value: false, + value: value, }; let _ = stream.write_json_packet(&reply); ActorMessageStatus::Processed }, - - "getCharPref" => { - let reply = CharReply { - from: self.name(), - value: "".to_owned(), - }; - let _ = stream.write_json_packet(&reply); - ActorMessageStatus::Processed - }, - - "getIntPref" => { + PrefValue::Int(value) => { let reply = IntReply { from: self.name(), - value: 0, + value: value, }; let _ = stream.write_json_packet(&reply); ActorMessageStatus::Processed }, - - _ => ActorMessageStatus::Ignored, + PrefValue::Str(value) => { + let reply = CharReply { + from: self.name(), + value: value, + }; + let _ = stream.write_json_packet(&reply); + ActorMessageStatus::Processed + }, + PrefValue::Bool(value) => { + let reply = BoolReply { + from: self.name(), + value: value, + }; + let _ = stream.write_json_packet(&reply); + ActorMessageStatus::Processed + }, + PrefValue::Missing => ActorMessageStatus::Ignored, }) } } @@ -79,5 +87,11 @@ struct CharReply { #[derive(Serialize)] struct IntReply { from: String, - value: i32, + value: i64, +} + +#[derive(Serialize)] +struct FloatReply { + from: String, + value: f64, } From 9048185a10104380ff6e2052d3183c1849eb5d77 Mon Sep 17 00:00:00 2001 From: Sudarsan Date: Sat, 12 Sep 2020 21:57:08 +0800 Subject: [PATCH 2/2] Returns fake preferences if PrefValue::Missing. If the pref_map().get() enum returns PrefValue::Missing, then fake values are returned just like before. --- components/devtools/actors/preference.rs | 41 +++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/components/devtools/actors/preference.rs b/components/devtools/actors/preference.rs index ce3123ce5dd..1c8e9129787 100644 --- a/components/devtools/actors/preference.rs +++ b/components/devtools/actors/preference.rs @@ -67,11 +67,50 @@ impl Actor for PreferenceActor { let _ = stream.write_json_packet(&reply); ActorMessageStatus::Processed }, - PrefValue::Missing => ActorMessageStatus::Ignored, + PrefValue::Missing => handle_missing_preference(self.name(), msg_type, stream), }) } } +// if the preferences are missing from pref_map then we return a +// fake preference response based on msg_type. +fn handle_missing_preference( + name: String, + msg_type: &str, + stream: &mut TcpStream, +) -> ActorMessageStatus { + match msg_type { + "getBoolPref" => { + let reply = BoolReply { + from: name, + value: false, + }; + let _ = stream.write_json_packet(&reply); + ActorMessageStatus::Processed + }, + + "getCharPref" => { + let reply = CharReply { + from: name, + value: "".to_owned(), + }; + let _ = stream.write_json_packet(&reply); + ActorMessageStatus::Processed + }, + + "getIntPref" => { + let reply = IntReply { + from: name, + value: 0, + }; + let _ = stream.write_json_packet(&reply); + ActorMessageStatus::Processed + }, + + _ => ActorMessageStatus::Ignored, + } +} + #[derive(Serialize)] struct BoolReply { from: String,