mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
libservo: Combine LoadStart,
HeadParsed, and
LoadComplete` messages (#35260)
These will be a single method in the upcoming `WebView` delegate, so it makes sense to also combine the internal message to match this. In addition, since `LoadStatus` is now exposed to the API if there is ever the need to add more statuses or to move to an event-based version, the API is already set up for this. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
b8ab820e3c
commit
fdfaf7b15c
11 changed files with 97 additions and 92 deletions
|
@ -15,7 +15,7 @@ use jni::objects::{GlobalRef, JClass, JObject, JString, JValue, JValueOwned};
|
|||
use jni::sys::{jboolean, jfloat, jint, jobject};
|
||||
use jni::{JNIEnv, JavaVM};
|
||||
use log::{debug, error, info, warn};
|
||||
use servo::MediaSessionActionType;
|
||||
use servo::{LoadStatus, MediaSessionActionType};
|
||||
use simpleservo::{
|
||||
DeviceIntRect, EventLoopWaker, InitOptions, InputMethodType, MediaSessionPlaybackState,
|
||||
PromptResult, SERVO,
|
||||
|
@ -496,18 +496,20 @@ impl HostTrait for HostCallbacks {
|
|||
Some(default)
|
||||
}
|
||||
|
||||
fn on_load_started(&self) {
|
||||
debug!("on_load_started");
|
||||
fn notify_load_status_changed(&self, load_status: LoadStatus) {
|
||||
debug!("notify_load_status_changed: {load_status:?}");
|
||||
let mut env = self.jvm.get_env().unwrap();
|
||||
env.call_method(self.callbacks.as_obj(), "onLoadStarted", "()V", &[])
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn on_load_ended(&self) {
|
||||
debug!("on_load_ended");
|
||||
let mut env = self.jvm.get_env().unwrap();
|
||||
env.call_method(self.callbacks.as_obj(), "onLoadEnded", "()V", &[])
|
||||
.unwrap();
|
||||
match load_status {
|
||||
LoadStatus::Started => {
|
||||
env.call_method(self.callbacks.as_obj(), "onLoadStarted", "()V", &[])
|
||||
.unwrap();
|
||||
},
|
||||
LoadStatus::HeadParsed => {},
|
||||
LoadStatus::Complete => {
|
||||
env.call_method(self.callbacks.as_obj(), "onLoadEnded", "()V", &[])
|
||||
.unwrap();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
fn on_shutdown_complete(&self) {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use servo::webrender_api::units::DeviceIntRect;
|
||||
use servo::{InputMethodType, MediaSessionPlaybackState, PromptResult};
|
||||
use servo::{InputMethodType, LoadStatus, MediaSessionPlaybackState, PromptResult};
|
||||
|
||||
/// Callbacks. Implemented by embedder. Called by Servo.
|
||||
pub trait HostTrait {
|
||||
|
@ -17,16 +17,16 @@ pub trait HostTrait {
|
|||
fn prompt_input(&self, msg: String, default: String, trusted: bool) -> Option<String>;
|
||||
/// Show context menu
|
||||
fn show_context_menu(&self, title: Option<String>, items: Vec<String>);
|
||||
/// Page starts loading.
|
||||
/// "Reload button" should be disabled.
|
||||
/// "Stop button" should be enabled.
|
||||
/// Throbber starts spinning.
|
||||
fn on_load_started(&self);
|
||||
/// Page has loaded.
|
||||
/// "Reload button" should be enabled.
|
||||
/// "Stop button" should be disabled.
|
||||
/// Throbber stops spinning.
|
||||
fn on_load_ended(&self);
|
||||
/// Notify that the load status of the page has changed.
|
||||
/// Started:
|
||||
/// - "Reload button" should be disabled.
|
||||
/// - "Stop button" should be enabled.
|
||||
/// - Throbber starts spinning.
|
||||
/// Complete:
|
||||
/// - "Reload button" should be enabled.
|
||||
/// - "Stop button" should be disabled.
|
||||
/// - Throbber stops spinning.
|
||||
fn notify_load_status_changed(&self, load_status: LoadStatus);
|
||||
/// Page title has changed.
|
||||
fn on_title_changed(&self, title: Option<String>);
|
||||
/// Allow Navigation.
|
||||
|
|
|
@ -21,7 +21,7 @@ use napi_ohos::{Env, JsObject, JsString, NapiRaw};
|
|||
use ohos_ime::{AttachOptions, Ime, ImeProxy, RawTextEditorProxy};
|
||||
use ohos_ime_sys::types::InputMethod_EnterKeyType;
|
||||
use servo::style::Zero;
|
||||
use servo::{InputMethodType, MediaSessionPlaybackState, PromptResult};
|
||||
use servo::{InputMethodType, LoadStatus, MediaSessionPlaybackState, PromptResult};
|
||||
use simpleservo::EventLoopWaker;
|
||||
use xcomponent_sys::{
|
||||
OH_NativeXComponent, OH_NativeXComponent_Callback, OH_NativeXComponent_GetKeyEvent,
|
||||
|
@ -733,19 +733,17 @@ impl HostTrait for HostCallbacks {
|
|||
warn!("show_context_menu not implemented")
|
||||
}
|
||||
|
||||
fn on_load_started(&self) {
|
||||
warn!("on_load_started not implemented")
|
||||
}
|
||||
|
||||
fn on_load_ended(&self) {
|
||||
// Note: It seems that we don't necessarily get 1 `on_load_ended` for each
|
||||
// each time `on_loaded_started` is called. Presumably this requires some API changes,
|
||||
fn notify_load_status_changed(&self, load_status: LoadStatus) {
|
||||
// Note: It seems that we don't necessarily get 1 `LoadStatus::Complete` for each
|
||||
// each time `LoadStatus::Started` is called. Presumably this requires some API changes,
|
||||
// e.g. including webview id, perhaps URL and some additional investigation effort.
|
||||
// For now we just add a trace event here, so that we can see in the trace if we
|
||||
// successfully loaded **a** page.
|
||||
#[cfg(feature = "tracing-hitrace")]
|
||||
let _scope = hitrace::ScopedTrace::start_trace(&c"PageLoadEndedPrompt");
|
||||
self.prompt_alert("Page finished loading!".to_string(), true);
|
||||
if load_status == LoadStatus::Complete {
|
||||
#[cfg(feature = "tracing-hitrace")]
|
||||
let _scope = hitrace::ScopedTrace::start_trace(&c"PageLoadEndedPrompt");
|
||||
self.prompt_alert("Page finished loading!".to_string(), true);
|
||||
}
|
||||
}
|
||||
|
||||
fn on_title_changed(&self, title: Option<String>) {
|
||||
|
|
|
@ -479,11 +479,10 @@ impl ServoGlue {
|
|||
.host_callbacks
|
||||
.on_url_changed(entries[current].clone().to_string());
|
||||
},
|
||||
EmbedderMsg::LoadStart(_) => {
|
||||
self.callbacks.host_callbacks.on_load_started();
|
||||
},
|
||||
EmbedderMsg::LoadComplete(_) => {
|
||||
self.callbacks.host_callbacks.on_load_ended();
|
||||
EmbedderMsg::NotifyLoadStatusChanged(_, load_status) => {
|
||||
self.callbacks
|
||||
.host_callbacks
|
||||
.notify_load_status_changed(load_status);
|
||||
},
|
||||
EmbedderMsg::GetSelectedBluetoothDevice(_, _, sender) => {
|
||||
let _ = sender.send(None);
|
||||
|
@ -653,7 +652,6 @@ impl ServoGlue {
|
|||
EmbedderMsg::MoveTo(..) |
|
||||
EmbedderMsg::SetCursor(..) |
|
||||
EmbedderMsg::NewFavicon(..) |
|
||||
EmbedderMsg::HeadParsed(..) |
|
||||
EmbedderMsg::SetFullscreenState(..) |
|
||||
EmbedderMsg::ReportProfile(..) |
|
||||
EmbedderMsg::EventDelivered(..) |
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue