Rewild Your Web
web
browser
dweb
1--- original
2+++ modified
3@@ -259,6 +259,20 @@
4 pub fn root_scroll_id(&self) -> webrender_api::ExternalScrollId {
5 ExternalScrollId(0, self.into())
6 }
7+
8+ pub fn from_string(str: &str) -> Option<PipelineId> {
9+ let re = Regex::new(r"^Pipeline\((\d+),(\d+)\)$").ok()?;
10+ let caps = re.captures(str)?;
11+ let namespace_id = caps.get(1)?.as_str().parse::<u32>().ok()?;
12+ let index = caps.get(2)?.as_str().parse::<u32>().ok()?;
13+
14+ let result = PipelineId {
15+ namespace_id: PipelineNamespaceId(namespace_id),
16+ index: Index::new(index).ok()?,
17+ };
18+ assert_eq!(result.to_string(), str.to_string());
19+ Some(result)
20+ }
21 }
22
23 impl From<WebRenderPipelineId> for PipelineId {
24@@ -345,6 +359,24 @@
25 pub fn mock_for_testing(browsing_context_id: BrowsingContextId) -> WebViewId {
26 WebViewId(TEST_PAINTER_ID, browsing_context_id)
27 }
28+
29+ /// Parse a WebViewId from its string representation.
30+ /// Format: "PainterId: {id}, TopLevel({namespace},{index})"
31+ pub fn from_string(str: &str) -> Option<WebViewId> {
32+ let re = Regex::new(r"^PainterId: (\d+), TopLevelBrowsingContext\((\d+),(\d+)\)$").ok()?;
33+ let caps = re.captures(str)?;
34+ let painter_id = caps.get(1)?.as_str().parse::<u32>().ok()?;
35+ let namespace_id = caps.get(2)?.as_str().parse::<u32>().ok()?;
36+ let index = caps.get(3)?.as_str().parse::<u32>().ok()?;
37+
38+ let browsing_context_id = BrowsingContextId {
39+ namespace_id: PipelineNamespaceId(namespace_id),
40+ index: Index::new(index).ok()?,
41+ };
42+ let result = WebViewId(PainterId(painter_id), browsing_context_id);
43+ assert_eq!(result.to_string(), str.to_string());
44+ Some(result)
45+ }
46 }
47
48 impl From<WebViewId> for BrowsingContextId {