Rework “visible” to “throttled” in embedder-to-constellation + jniapi (#31815)

This commit is contained in:
Delan Azabani 2024-03-22 02:48:17 +08:00 committed by GitHub
parent 49c6f9e463
commit 0b863de846
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 16 additions and 16 deletions

View file

@ -103,8 +103,8 @@ pub enum EmbedderEvent {
/// Sent when the user triggers a media action through the UA exposed media UI /// Sent when the user triggers a media action through the UA exposed media UI
/// (play, pause, seek, etc.). /// (play, pause, seek, etc.).
MediaSessionAction(MediaSessionActionType), MediaSessionAction(MediaSessionActionType),
/// The visibility of the webview has changed. /// Set whether to use less resources, by stopping animations and running timers at a heavily limited rate.
WebViewVisibilityChanged(TopLevelBrowsingContextId, bool), SetWebViewThrottled(TopLevelBrowsingContextId, bool),
/// Virtual keyboard was dismissed /// Virtual keyboard was dismissed
IMEDismissed, IMEDismissed,
/// Sent on platforms like Android where the native widget surface can be /// Sent on platforms like Android where the native widget surface can be
@ -148,7 +148,7 @@ impl Debug for EmbedderEvent {
EmbedderEvent::ToggleSamplingProfiler(..) => write!(f, "ToggleSamplingProfiler"), EmbedderEvent::ToggleSamplingProfiler(..) => write!(f, "ToggleSamplingProfiler"),
EmbedderEvent::ExitFullScreen(..) => write!(f, "ExitFullScreen"), EmbedderEvent::ExitFullScreen(..) => write!(f, "ExitFullScreen"),
EmbedderEvent::MediaSessionAction(..) => write!(f, "MediaSessionAction"), EmbedderEvent::MediaSessionAction(..) => write!(f, "MediaSessionAction"),
EmbedderEvent::WebViewVisibilityChanged(..) => write!(f, "WebViewVisibilityChanged"), EmbedderEvent::SetWebViewThrottled(..) => write!(f, "SetWebViewThrottled"),
EmbedderEvent::IMEDismissed => write!(f, "IMEDismissed"), EmbedderEvent::IMEDismissed => write!(f, "IMEDismissed"),
EmbedderEvent::ClearCache => write!(f, "ClearCache"), EmbedderEvent::ClearCache => write!(f, "ClearCache"),
EmbedderEvent::InvalidateNativeSurface => write!(f, "InvalidateNativeSurface"), EmbedderEvent::InvalidateNativeSurface => write!(f, "InvalidateNativeSurface"),

View file

@ -1535,8 +1535,8 @@ where
FromCompositorMsg::MediaSessionAction(action) => { FromCompositorMsg::MediaSessionAction(action) => {
self.handle_media_session_action_msg(action); self.handle_media_session_action_msg(action);
}, },
FromCompositorMsg::WebViewVisibilityChanged(webview_id, visible) => { FromCompositorMsg::SetWebViewThrottled(webview_id, throttled) => {
self.notify_webview_visibility(webview_id, visible); self.notify_webview_visibility(webview_id, !throttled);
}, },
FromCompositorMsg::ReadyToPresent(top_level_browsing_context_id) => { FromCompositorMsg::ReadyToPresent(top_level_browsing_context_id) => {
self.embedder_proxy.send(( self.embedder_proxy.send((

View file

@ -86,7 +86,7 @@ mod from_compositor {
Self::DisableProfiler => target!("DisableProfiler"), Self::DisableProfiler => target!("DisableProfiler"),
Self::ExitFullScreen(_) => target!("ExitFullScreen"), Self::ExitFullScreen(_) => target!("ExitFullScreen"),
Self::MediaSessionAction(_) => target!("MediaSessionAction"), Self::MediaSessionAction(_) => target!("MediaSessionAction"),
Self::WebViewVisibilityChanged(_, _) => target!("WebViewVisibilityChanged"), Self::SetWebViewThrottled(_, _) => target!("SetWebViewThrottled"),
Self::IMEDismissed => target!("IMEDismissed"), Self::IMEDismissed => target!("IMEDismissed"),
Self::ReadyToPresent(_) => target!("ReadyToPresent"), Self::ReadyToPresent(_) => target!("ReadyToPresent"),
Self::Gamepad(_) => target!("Gamepad"), Self::Gamepad(_) => target!("Gamepad"),

View file

@ -783,11 +783,11 @@ where
} }
}, },
EmbedderEvent::WebViewVisibilityChanged(webview_id, visible) => { EmbedderEvent::SetWebViewThrottled(webview_id, throttled) => {
let msg = ConstellationMsg::WebViewVisibilityChanged(webview_id, visible); let msg = ConstellationMsg::SetWebViewThrottled(webview_id, throttled);
if let Err(e) = self.constellation_chan.send(msg) { if let Err(e) = self.constellation_chan.send(msg) {
warn!( warn!(
"Sending WebViewVisibilityChanged to constellation failed ({:?}).", "Sending SetWebViewThrottled to constellation failed ({:?}).",
e e
); );
} }

View file

@ -76,8 +76,8 @@ pub enum ConstellationMsg {
ExitFullScreen(TopLevelBrowsingContextId), ExitFullScreen(TopLevelBrowsingContextId),
/// Media session action. /// Media session action.
MediaSessionAction(MediaSessionActionType), MediaSessionAction(MediaSessionActionType),
/// The visibility of the webview has changed. /// Set whether to use less resources, by stopping animations and running timers at a heavily limited rate.
WebViewVisibilityChanged(TopLevelBrowsingContextId, bool), SetWebViewThrottled(TopLevelBrowsingContextId, bool),
/// Virtual keyboard was dismissed /// Virtual keyboard was dismissed
IMEDismissed, IMEDismissed,
/// Compositing done, but external code needs to present. /// Compositing done, but external code needs to present.
@ -115,7 +115,7 @@ impl fmt::Debug for ConstellationMsg {
DisableProfiler => "DisableProfiler", DisableProfiler => "DisableProfiler",
ExitFullScreen(..) => "ExitFullScreen", ExitFullScreen(..) => "ExitFullScreen",
MediaSessionAction(..) => "MediaSessionAction", MediaSessionAction(..) => "MediaSessionAction",
WebViewVisibilityChanged(..) => "WebViewVisibilityChanged", SetWebViewThrottled(..) => "SetWebViewThrottled",
IMEDismissed => "IMEDismissed", IMEDismissed => "IMEDismissed",
ClearCache => "ClearCache", ClearCache => "ClearCache",
ReadyToPresent(..) => "ReadyToPresent", ReadyToPresent(..) => "ReadyToPresent",

View file

@ -601,10 +601,10 @@ impl ServoGlue {
self.process_event(EmbedderEvent::MediaSessionAction(action)) self.process_event(EmbedderEvent::MediaSessionAction(action))
} }
pub fn change_visibility(&mut self, visible: bool) -> Result<(), &'static str> { pub fn set_throttled(&mut self, throttled: bool) -> Result<(), &'static str> {
info!("change_visibility"); info!("set_throttled");
if let Ok(id) = self.get_browser_id() { if let Ok(id) = self.get_browser_id() {
let event = EmbedderEvent::WebViewVisibilityChanged(id, visible); let event = EmbedderEvent::SetWebViewThrottled(id, throttled);
self.process_event(event) self.process_event(event)
} else { } else {
// Ignore visibility change if no browser has been created yet. // Ignore visibility change if no browser has been created yet.

View file

@ -218,7 +218,7 @@ mod to_servo {
Self::ClearCache => target!("ClearCache"), Self::ClearCache => target!("ClearCache"),
Self::ToggleSamplingProfiler(_, _) => target!("ToggleSamplingProfiler"), Self::ToggleSamplingProfiler(_, _) => target!("ToggleSamplingProfiler"),
Self::MediaSessionAction(_) => target!("MediaSessionAction"), Self::MediaSessionAction(_) => target!("MediaSessionAction"),
Self::WebViewVisibilityChanged(_, _) => target!("WebViewVisibilityChanged"), Self::SetWebViewThrottled(_, _) => target!("SetWebViewThrottled"),
Self::IMEDismissed => target!("IMEDismissed"), Self::IMEDismissed => target!("IMEDismissed"),
Self::InvalidateNativeSurface => target!("InvalidateNativeSurface"), Self::InvalidateNativeSurface => target!("InvalidateNativeSurface"),
Self::ReplaceNativeSurface(_, _) => target!("ReplaceNativeSurface"), Self::ReplaceNativeSurface(_, _) => target!("ReplaceNativeSurface"),