Webdriver delete cookie (#36306)

1. Implement `WebDriverCommand::DeleteCookie`
2. Remove unnecessary clone for `WebDriverCommand::GetNamedCookie`

Fixes: #36287

---------

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
This commit is contained in:
Euclid Ye 2025-04-04 13:24:47 +08:00 committed by GitHub
parent e1de46c691
commit 4bad7c0a5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 65 additions and 4 deletions

View file

@ -23,7 +23,9 @@ use js::jsval::UndefinedValue;
use js::rust::wrappers::{JS_CallFunctionName, JS_GetProperty, JS_HasOwnProperty, JS_TypeOfValue};
use js::rust::{HandleObject, HandleValue, IdVector, ToString};
use net_traits::CookieSource::{HTTP, NonHTTP};
use net_traits::CoreResourceMsg::{DeleteCookies, GetCookiesDataForUrl, SetCookieForUrl};
use net_traits::CoreResourceMsg::{
DeleteCookie, DeleteCookies, GetCookiesDataForUrl, SetCookieForUrl,
};
use net_traits::IpcSend;
use servo_url::ServoUrl;
use webdriver::common::{WebElement, WebFrame, WebWindow};
@ -929,6 +931,7 @@ pub(crate) fn handle_add_cookie(
.unwrap();
}
// https://w3c.github.io/webdriver/#delete-all-cookies
pub(crate) fn handle_delete_cookies(
documents: &DocumentCollection,
pipeline: PipelineId,
@ -950,6 +953,29 @@ pub(crate) fn handle_delete_cookies(
reply.send(Ok(())).unwrap();
}
// https://w3c.github.io/webdriver/#delete-cookie
pub(crate) fn handle_delete_cookie(
documents: &DocumentCollection,
pipeline: PipelineId,
name: String,
reply: IpcSender<Result<(), ErrorStatus>>,
) {
let document = match documents.find_document(pipeline) {
Some(document) => document,
None => {
return reply.send(Err(ErrorStatus::UnknownError)).unwrap();
},
};
let url = document.url();
document
.window()
.as_global_scope()
.resource_threads()
.send(DeleteCookie(url, name))
.unwrap();
reply.send(Ok(())).unwrap();
}
pub(crate) fn handle_get_title(
documents: &DocumentCollection,
pipeline: PipelineId,