mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
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>
This commit is contained in:
parent
9eeb602f7a
commit
5e9de2cb61
70 changed files with 809 additions and 753 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue