mirror of
https://github.com/servo/servo.git
synced 2025-06-28 19:13:41 +01:00
Currently Source related code exists in watcher.rs and thread.rs. This change moves source-related code to a dedicated source.rs file. This is in preparation for adding support for showing source code in the Debugger > Source panel. - [x] Testing: These changes should not affect current functionality as it only moves the existing code - [x] Fixes: part of https://github.com/servo/servo/issues/36027 --------- Signed-off-by: atbrakhi <atbrakhi@igalia.com>
50 lines
1.3 KiB
Rust
50 lines
1.3 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 std::cell::{Ref, RefCell};
|
|
use std::collections::BTreeSet;
|
|
|
|
use serde::Serialize;
|
|
use servo_url::ServoUrl;
|
|
|
|
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Serialize)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub(crate) struct SourceData {
|
|
pub actor: String,
|
|
/// URL of the script, or URL of the page for inline scripts.
|
|
pub url: String,
|
|
pub is_black_boxed: bool,
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
pub(crate) struct SourcesReply {
|
|
pub from: String,
|
|
pub sources: Vec<SourceData>,
|
|
}
|
|
|
|
pub(crate) struct Source {
|
|
actor_name: String,
|
|
source_urls: RefCell<BTreeSet<SourceData>>,
|
|
}
|
|
|
|
impl Source {
|
|
pub fn new(actor_name: String) -> Self {
|
|
Self {
|
|
actor_name,
|
|
source_urls: RefCell::new(BTreeSet::default()),
|
|
}
|
|
}
|
|
|
|
pub fn add_source(&self, url: ServoUrl) {
|
|
self.source_urls.borrow_mut().insert(SourceData {
|
|
actor: self.actor_name.clone(),
|
|
url: url.to_string(),
|
|
is_black_boxed: false,
|
|
});
|
|
}
|
|
|
|
pub fn sources(&self) -> Ref<BTreeSet<SourceData>> {
|
|
self.source_urls.borrow()
|
|
}
|
|
}
|