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:
Delan Azabani 2025-01-30 19:15:35 +08:00 committed by GitHub
parent 9eeb602f7a
commit 5e9de2cb61
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
70 changed files with 809 additions and 753 deletions

View file

@ -15,6 +15,7 @@ use std::sync::{LazyLock, Mutex};
use std::time::{Duration, Instant};
use base::cross_process_instant::CrossProcessInstant;
use base::id::WebViewId;
use canvas_traits::webgl::{self, WebGLContextId, WebGLMsg};
use chrono::Local;
use content_security_policy::{self as csp, CspList};
@ -648,6 +649,10 @@ impl Document {
}
}
pub(crate) fn webview_id(&self) -> WebViewId {
self.window.webview_id()
}
#[inline]
pub(crate) fn window(&self) -> &Window {
&self.window
@ -1027,13 +1032,13 @@ impl Document {
match state {
DocumentReadyState::Loading => {
if self.window().is_top_level() {
self.send_to_embedder(EmbedderMsg::LoadStart);
self.send_to_embedder(EmbedderMsg::Status(None));
self.send_to_embedder(EmbedderMsg::LoadStart(self.webview_id()));
self.send_to_embedder(EmbedderMsg::Status(self.webview_id(), None));
}
},
DocumentReadyState::Complete => {
if self.window().is_top_level() {
self.send_to_embedder(EmbedderMsg::LoadComplete);
self.send_to_embedder(EmbedderMsg::LoadComplete(self.webview_id()));
}
update_with_current_instant(&self.dom_complete);
},
@ -1121,7 +1126,7 @@ impl Document {
// Notify the embedder to hide the input method.
if elem.input_method_type().is_some() {
self.send_to_embedder(EmbedderMsg::HideIME);
self.send_to_embedder(EmbedderMsg::HideIME(self.webview_id()));
}
}
@ -1165,6 +1170,7 @@ impl Document {
(None, false)
};
self.send_to_embedder(EmbedderMsg::ShowIME(
self.webview_id(),
kind,
text,
multiline,
@ -1225,7 +1231,7 @@ impl Document {
let window = self.window();
if window.is_top_level() {
let title = self.title().map(String::from);
self.send_to_embedder(EmbedderMsg::ChangePageTitle(title));
self.send_to_embedder(EmbedderMsg::ChangePageTitle(self.webview_id(), title));
}
}
@ -1621,7 +1627,7 @@ impl Document {
// Step 1
if drag_data_store.list_len() > 0 {
// Step 1.1 Clear the clipboard.
self.send_to_embedder(EmbedderMsg::ClearClipboardContents);
self.send_to_embedder(EmbedderMsg::ClearClipboardContents(self.webview_id()));
// Step 1.2
for item in drag_data_store.iter_item_list() {
match item {
@ -1629,7 +1635,10 @@ impl Document {
// Step 1.2.1.1 Ensure encoding is correct per OS and locale conventions
// Step 1.2.1.2 Normalize line endings according to platform conventions
// Step 1.2.1.3
self.send_to_embedder(EmbedderMsg::SetClipboardContents(string.data()));
self.send_to_embedder(EmbedderMsg::SetClipboardContents(
self.webview_id(),
string.data(),
));
},
Kind::File(_) => {
// Step 1.2.2 If data is of a type listed in the mandatory data types list, then
@ -1642,7 +1651,7 @@ impl Document {
// Step 2.1
if drag_data_store.clear_was_called {
// Step 2.1.1 If types-to-clear list is empty, clear the clipboard
self.send_to_embedder(EmbedderMsg::ClearClipboardContents);
self.send_to_embedder(EmbedderMsg::ClearClipboardContents(self.webview_id()));
// Step 2.1.2 Else remove the types in the list from the clipboard
// As of now this can't be done with Arboard, and it's possible that will be removed from the spec
}
@ -2049,7 +2058,7 @@ impl Document {
}
if cancel_state == EventDefault::Allowed {
let msg = EmbedderMsg::Keyboard(keyboard_event.clone());
let msg = EmbedderMsg::Keyboard(self.webview_id(), keyboard_event.clone());
self.send_to_embedder(msg);
// This behavior is unspecced
@ -2455,7 +2464,7 @@ impl Document {
.is_empty();
if default_prevented || return_value_not_empty {
let (chan, port) = ipc::channel().expect("Failed to create IPC channel!");
let msg = EmbedderMsg::AllowUnload(chan);
let msg = EmbedderMsg::AllowUnload(self.webview_id(), chan);
self.send_to_embedder(msg);
can_unload = port.recv().unwrap();
}
@ -4049,7 +4058,7 @@ impl Document {
let window = self.window();
// Step 6
if !error {
let event = EmbedderMsg::SetFullscreenState(true);
let event = EmbedderMsg::SetFullscreenState(self.webview_id(), true);
self.send_to_embedder(event);
}
@ -4091,7 +4100,7 @@ impl Document {
let window = self.window();
// Step 8
let event = EmbedderMsg::SetFullscreenState(false);
let event = EmbedderMsg::SetFullscreenState(self.webview_id(), false);
self.send_to_embedder(event);
// Step 9