aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/window.rs
diff options
context:
space:
mode:
authorDelan Azabani <dazabani@igalia.com>2025-01-30 19:15:35 +0800
committerGitHub <noreply@github.com>2025-01-30 11:15:35 +0000
commit5e9de2cb61fbfd82b27343bf03439838458b9848 (patch)
tree64574624cda94237bbfc443a29b792229fde0ee2 /components/script/dom/window.rs
parent9eeb602f7afca502753bb8211ab646c952951761 (diff)
downloadservo-5e9de2cb61fbfd82b27343bf03439838458b9848.tar.gz
servo-5e9de2cb61fbfd82b27343bf03439838458b9848.zip
Include `WebViewId` into EmbedderMsg variants where possible (#35211)
`EmbedderMsg` was previously paired with an implicit `Option<WebViewId>`, even though almost all variants were either always `Some` or always `None`, depending on whether there was a `WebView involved. This patch adds the `WebViewId` to as many `EmbedderMsg` variants as possible, so we can call their associated `WebView` delegate methods without needing to check and unwrap the `Option`. In many cases, this required more changes to plumb through the `WebViewId`. Notably, all `Request`s now explicitly need a `WebView` or not, in order to ensure that it is passed when appropriate. Signed-off-by: Delan Azabani <dazabani@igalia.com> Co-authored-by: Martin Robinson <mrobinson@igalia.com>
Diffstat (limited to 'components/script/dom/window.rs')
-rw-r--r--components/script/dom/window.rs23
1 files changed, 17 insertions, 6 deletions
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index e8487f24b95..73ce02a40ab 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -17,7 +17,7 @@ use std::time::{Duration, Instant};
use app_units::Au;
use backtrace::Backtrace;
use base::cross_process_instant::CrossProcessInstant;
-use base::id::{BrowsingContextId, PipelineId};
+use base::id::{BrowsingContextId, PipelineId, WebViewId};
use base64::Engine;
use bluetooth_traits::BluetoothRequest;
use canvas_traits::webgl::WebGLChan;
@@ -209,6 +209,11 @@ impl LayoutBlocker {
#[dom_struct]
pub(crate) struct Window {
globalscope: GlobalScope,
+ /// The webview that contains this [`Window`].
+ ///
+ /// This may not be the top-level [`Window`], in the case of frames.
+ #[no_trace]
+ webview_id: WebViewId,
script_chan: Sender<MainThreadScriptMsg>,
#[no_trace]
#[ignore_malloc_size_of = "TODO: Add MallocSizeOf support to layout"]
@@ -391,6 +396,10 @@ pub(crate) struct Window {
}
impl Window {
+ pub(crate) fn webview_id(&self) -> WebViewId {
+ self.webview_id
+ }
+
pub(crate) fn as_global_scope(&self) -> &GlobalScope {
self.upcast::<GlobalScope>()
}
@@ -726,7 +735,7 @@ impl WindowMethods<crate::DomTypeHolder> for Window {
let (sender, receiver) =
ProfiledIpc::channel(self.global().time_profiler_chan().clone()).unwrap();
let prompt = PromptDefinition::Alert(s.to_string(), sender);
- let msg = EmbedderMsg::Prompt(prompt, PromptOrigin::Untrusted);
+ let msg = EmbedderMsg::Prompt(self.webview_id(), prompt, PromptOrigin::Untrusted);
self.send_to_embedder(msg);
receiver.recv().unwrap();
}
@@ -736,7 +745,7 @@ impl WindowMethods<crate::DomTypeHolder> for Window {
let (sender, receiver) =
ProfiledIpc::channel(self.global().time_profiler_chan().clone()).unwrap();
let prompt = PromptDefinition::OkCancel(s.to_string(), sender);
- let msg = EmbedderMsg::Prompt(prompt, PromptOrigin::Untrusted);
+ let msg = EmbedderMsg::Prompt(self.webview_id(), prompt, PromptOrigin::Untrusted);
self.send_to_embedder(msg);
receiver.recv().unwrap() == PromptResult::Primary
}
@@ -746,7 +755,7 @@ impl WindowMethods<crate::DomTypeHolder> for Window {
let (sender, receiver) =
ProfiledIpc::channel(self.global().time_profiler_chan().clone()).unwrap();
let prompt = PromptDefinition::Input(message.to_string(), default.to_string(), sender);
- let msg = EmbedderMsg::Prompt(prompt, PromptOrigin::Untrusted);
+ let msg = EmbedderMsg::Prompt(self.webview_id(), prompt, PromptOrigin::Untrusted);
self.send_to_embedder(msg);
receiver.recv().unwrap().map(|s| s.into())
}
@@ -1322,7 +1331,7 @@ impl WindowMethods<crate::DomTypeHolder> for Window {
//TODO determine if this operation is allowed
let dpr = self.device_pixel_ratio();
let size = Size2D::new(width, height).to_f32() * dpr;
- self.send_to_embedder(EmbedderMsg::ResizeTo(size.to_i32()));
+ self.send_to_embedder(EmbedderMsg::ResizeTo(self.webview_id(), size.to_i32()));
}
// https://drafts.csswg.org/cssom-view/#dom-window-resizeby
@@ -1341,7 +1350,7 @@ impl WindowMethods<crate::DomTypeHolder> for Window {
//TODO determine if this operation is allowed
let dpr = self.device_pixel_ratio();
let point = Point2D::new(x, y).to_f32() * dpr;
- let msg = EmbedderMsg::MoveTo(point.to_i32());
+ let msg = EmbedderMsg::MoveTo(self.webview_id(), point.to_i32());
self.send_to_embedder(msg);
}
@@ -2738,6 +2747,7 @@ impl Window {
#[allow(unsafe_code)]
#[allow(clippy::too_many_arguments)]
pub(crate) fn new(
+ webview_id: WebViewId,
runtime: Rc<Runtime>,
script_chan: Sender<MainThreadScriptMsg>,
layout: Box<dyn Layout>,
@@ -2786,6 +2796,7 @@ impl Window {
));
let win = Box::new(Self {
+ webview_id,
globalscope: GlobalScope::new_inherited(
pipeline_id,
devtools_chan,