mirror of
https://github.com/servo/servo
synced 2026-05-09 16:42:16 +02:00
Fix caching before the console is opened and stop sending messages prematurely. Fix line numbers not showing in console messages because of a missing `rename_all`. Remove `getCachedMessages` in favour of sending a list of messages as a reply to the `watchResources` for `console-message`/`error-message` in the watcher. Remove `startListeners` and `stopListeners`. These are legacy methods of watching properties before the watcher actor. It is preferred to enable properties in `supported_resources` in the watcher than to use these messages. Remove `clearMessagesCache`, only `clearMessagesCacheAsync` seems to be used now. Add a reply to `clearMessagesCacheAsync`. Simplify a bit the structs for console messages and prefer serde's annotations to manual serialization. Merge `handle_console_message` and `handle_page_error`, and improve the usability of `ConsoleResource`. Fix some fields in console messages. We are missing `source_id` for now. This will be easier to add after better support for source actors. We are also missing stack traces. | Before | After | | --- | --- | |  |  | Testing: Manual testing Fixes: #26666 --------- Signed-off-by: eri <eri@igalia.com> Co-authored-by: Martin Robinson <mrobinson@igalia.com>
58 lines
1.5 KiB
Rust
58 lines
1.5 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
use serde::Serialize;
|
|
|
|
use crate::protocol::JsonPacketStream;
|
|
|
|
pub enum ResourceArrayType {
|
|
Available,
|
|
Updated,
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
pub(crate) struct ResourceAvailableReply<T: Serialize> {
|
|
from: String,
|
|
#[serde(rename = "type")]
|
|
type_: String,
|
|
array: Vec<(String, Vec<T>)>,
|
|
}
|
|
|
|
pub(crate) trait ResourceAvailable {
|
|
fn actor_name(&self) -> String;
|
|
|
|
fn resource_array<T: Serialize, S: JsonPacketStream>(
|
|
&self,
|
|
resource: T,
|
|
resource_type: String,
|
|
array_type: ResourceArrayType,
|
|
stream: &mut S,
|
|
) {
|
|
self.resources_array(vec![resource], resource_type, array_type, stream);
|
|
}
|
|
|
|
fn resources_array<T: Serialize, S: JsonPacketStream>(
|
|
&self,
|
|
resources: Vec<T>,
|
|
resource_type: String,
|
|
array_type: ResourceArrayType,
|
|
stream: &mut S,
|
|
) {
|
|
if resources.is_empty() {
|
|
return;
|
|
}
|
|
|
|
let msg = ResourceAvailableReply::<T> {
|
|
from: self.actor_name(),
|
|
type_: match array_type {
|
|
ResourceArrayType::Available => "resources-available-array".to_string(),
|
|
ResourceArrayType::Updated => "resources-updated-array".to_string(),
|
|
},
|
|
array: vec![(resource_type, resources)],
|
|
};
|
|
|
|
let _ = stream.write_json_packet(&msg);
|
|
}
|
|
}
|