devtools/actors/
stylesheets.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use serde::Serialize;
6use serde_json::{Map, Value};
7
8use crate::StreamId;
9use crate::actor::{Actor, ActorError, ActorRegistry};
10use crate::protocol::ClientRequest;
11
12#[derive(Serialize)]
13#[serde(rename_all = "camelCase")]
14struct GetStyleSheetsReply {
15    from: String,
16    style_sheets: Vec<u32>, // TODO: real JSON structure.
17}
18
19pub struct StyleSheetsActor {
20    pub name: String,
21}
22
23impl Actor for StyleSheetsActor {
24    fn name(&self) -> String {
25        self.name.clone()
26    }
27    fn handle_message(
28        &self,
29        request: ClientRequest,
30        _registry: &ActorRegistry,
31        msg_type: &str,
32        _msg: &Map<String, Value>,
33        _id: StreamId,
34    ) -> Result<(), ActorError> {
35        match msg_type {
36            "getStyleSheets" => {
37                let msg = GetStyleSheetsReply {
38                    from: self.name(),
39                    style_sheets: vec![],
40                };
41                request.reply_final(&msg)?
42            },
43
44            _ => return Err(ActorError::UnrecognizedPacketType),
45        };
46        Ok(())
47    }
48}
49
50impl StyleSheetsActor {
51    pub fn new(name: String) -> StyleSheetsActor {
52        StyleSheetsActor { name }
53    }
54}