mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
DevTools: Allow modification of attributes (#32888)
* feat: allow modification of attributes Signed-off-by: eri <eri@inventati.org> * fix: tidiness Signed-off-by: eri <eri@inventati.org> * feat: clean walker name generation Co-authored-by: Martin Robinson <mrobinson@igalia.com> Signed-off-by: eri <eri@inventati.org> * fix: missed out parameter Signed-off-by: eri <eri@inventati.org> --------- Signed-off-by: eri <eri@inventati.org> Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
4d49b04668
commit
babc844c93
5 changed files with 121 additions and 12 deletions
|
@ -16,6 +16,7 @@ use serde::Serialize;
|
|||
use serde_json::{self, Map, Value};
|
||||
|
||||
use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
|
||||
use crate::actors::inspector::walker::WalkerActor;
|
||||
use crate::protocol::JsonPacketStream;
|
||||
use crate::{EmptyReplyMsg, StreamId};
|
||||
|
||||
|
@ -77,6 +78,7 @@ pub struct NodeActor {
|
|||
name: String,
|
||||
script_chan: IpcSender<DevtoolScriptControlMsg>,
|
||||
pipeline: PipelineId,
|
||||
pub walker: String,
|
||||
}
|
||||
|
||||
impl Actor for NodeActor {
|
||||
|
@ -102,12 +104,16 @@ impl Actor for NodeActor {
|
|||
"modifyAttributes" => {
|
||||
let target = msg.get("to").ok_or(())?.as_str().ok_or(())?;
|
||||
let mods = msg.get("modifications").ok_or(())?.as_array().ok_or(())?;
|
||||
let modifications = mods
|
||||
let modifications: Vec<_> = mods
|
||||
.iter()
|
||||
.filter_map(|json_mod| {
|
||||
serde_json::from_str(&serde_json::to_string(json_mod).ok()?).ok()
|
||||
})
|
||||
.collect();
|
||||
|
||||
let walker = registry.find::<WalkerActor>(&self.walker);
|
||||
walker.new_mutations(stream, &self.name, &modifications);
|
||||
|
||||
self.script_chan
|
||||
.send(ModifyAttribute(
|
||||
self.pipeline,
|
||||
|
@ -127,8 +133,13 @@ impl Actor for NodeActor {
|
|||
.send(GetDocumentElement(self.pipeline, tx))
|
||||
.unwrap();
|
||||
let doc_elem_info = rx.recv().map_err(|_| ())?.ok_or(())?;
|
||||
let node =
|
||||
doc_elem_info.encode(registry, true, self.script_chan.clone(), self.pipeline);
|
||||
let node = doc_elem_info.encode(
|
||||
registry,
|
||||
true,
|
||||
self.script_chan.clone(),
|
||||
self.pipeline,
|
||||
self.walker.clone(),
|
||||
);
|
||||
|
||||
let msg = GetUniqueSelectorReply {
|
||||
from: self.name(),
|
||||
|
@ -150,6 +161,7 @@ pub trait NodeInfoToProtocol {
|
|||
display: bool,
|
||||
script_chan: IpcSender<DevtoolScriptControlMsg>,
|
||||
pipeline: PipelineId,
|
||||
walker: String,
|
||||
) -> NodeActorMsg;
|
||||
}
|
||||
|
||||
|
@ -160,6 +172,7 @@ impl NodeInfoToProtocol for NodeInfo {
|
|||
display: bool,
|
||||
script_chan: IpcSender<DevtoolScriptControlMsg>,
|
||||
pipeline: PipelineId,
|
||||
walker: String,
|
||||
) -> NodeActorMsg {
|
||||
let actor = if !actors.script_actor_registered(self.unique_id.clone()) {
|
||||
let name = actors.new_name("node");
|
||||
|
@ -167,6 +180,7 @@ impl NodeInfoToProtocol for NodeInfo {
|
|||
name: name.clone(),
|
||||
script_chan: script_chan.clone(),
|
||||
pipeline,
|
||||
walker: walker.clone(),
|
||||
};
|
||||
actors.register_script_actor(self.unique_id, name.clone());
|
||||
actors.register_later(Box::new(node_actor));
|
||||
|
@ -192,7 +206,7 @@ impl NodeInfoToProtocol for NodeInfo {
|
|||
let mut children = rx.recv().ok()??;
|
||||
|
||||
let child = children.pop()?;
|
||||
let msg = child.encode(actors, true, script_chan.clone(), pipeline);
|
||||
let msg = child.encode(actors, true, script_chan.clone(), pipeline, walker);
|
||||
|
||||
// If the node child is not a text node, do not represent it inline.
|
||||
if msg.node_type != TEXT_NODE {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue