libservo: Add a delegate method for HTTP authentication (#35400)

Add a delegate method for HTTP authentication and a related
`AuthenticationRequest` object that carries with it the URL as well as
whether or not the authentication request is for a proxy or not.

This is now separate from the prompt API because requesting
authentication doesn't necessarily involve prompting -- this is an
implementation detail of the embedder. In addition, the internal bits
are cleaned up slightly.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-02-11 00:39:24 +01:00 committed by GitHub
parent 118a813dba
commit 8486e585f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 149 additions and 103 deletions

View file

@ -17,9 +17,9 @@ use servo::ipc_channel::ipc::IpcSender;
use servo::webrender_api::units::{DeviceIntPoint, DeviceIntSize};
use servo::webrender_api::ScrollLocation;
use servo::{
AllowOrDenyRequest, CompositorEventVariant, FilterPattern, GamepadHapticEffectType, LoadStatus,
PermissionRequest, PromptCredentialsInput, PromptDefinition, PromptOrigin, PromptResult, Servo,
ServoDelegate, ServoError, TouchEventType, WebView, WebViewDelegate,
AllowOrDenyRequest, AuthenticationRequest, CompositorEventVariant, FilterPattern,
GamepadHapticEffectType, LoadStatus, PermissionRequest, PromptDefinition, PromptOrigin,
PromptResult, Servo, ServoDelegate, ServoError, TouchEventType, WebView, WebViewDelegate,
};
use tinyfiledialogs::{self, MessageBoxIcon, OkCancel};
use url::Url;
@ -354,10 +354,6 @@ impl WebViewDelegate for RunningAppState {
PromptDefinition::Input(_message, default, sender) => {
sender.send(Some(default.to_owned()))
},
PromptDefinition::Credentials(sender) => sender.send(PromptCredentialsInput {
username: None,
password: None,
}),
}
} else {
thread::Builder::new()
@ -397,12 +393,6 @@ impl WebViewDelegate for RunningAppState {
let result = tinyfiledialogs::input_box("", &message, &default);
sender.send(result)
},
PromptDefinition::Credentials(sender) => {
// TODO: figure out how to make the message a localized string
let username = tinyfiledialogs::input_box("", "username", "");
let password = tinyfiledialogs::input_box("", "password", "");
sender.send(PromptCredentialsInput { username, password })
},
})
.unwrap()
.join()
@ -414,6 +404,23 @@ impl WebViewDelegate for RunningAppState {
}
}
fn request_authentication(
&self,
_webview: WebView,
authentication_request: AuthenticationRequest,
) {
if self.inner().headless {
return;
}
if let (Some(username), Some(password)) = (
tinyfiledialogs::input_box("", "username", ""),
tinyfiledialogs::input_box("", "password", ""),
) {
authentication_request.authenticate(username, password);
}
}
fn request_open_auxiliary_webview(
&self,
parent_webview: servo::WebView,

View file

@ -255,10 +255,6 @@ impl WebViewDelegate for RunningAppState {
PromptDefinition::Input(message, default, response_sender) => {
response_sender.send(cb.prompt_input(message, default, trusted))
},
PromptDefinition::Credentials(response_sender) => {
warn!("implement credentials prompt for OpenHarmony OS and Android");
response_sender.send(Default::default())
},
};
}