mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
[WebDriver] Unify Cookie related Error types (#37339)
Remove `embedder/webdriver.rs::WebDriverCookieError` and use universal `ErrorStatus` from webdriver crate. This is needed as we might need to send back more universal error such as `NoSuchWindow`. Testing: No behaviour change. Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
This commit is contained in:
parent
96b0973037
commit
4e9993128b
3 changed files with 30 additions and 40 deletions
|
@ -9,9 +9,7 @@ use std::ptr::NonNull;
|
||||||
|
|
||||||
use base::id::{BrowsingContextId, PipelineId};
|
use base::id::{BrowsingContextId, PipelineId};
|
||||||
use cookie::Cookie;
|
use cookie::Cookie;
|
||||||
use embedder_traits::{
|
use embedder_traits::{WebDriverFrameId, WebDriverJSError, WebDriverJSResult, WebDriverJSValue};
|
||||||
WebDriverCookieError, WebDriverFrameId, WebDriverJSError, WebDriverJSResult, WebDriverJSValue,
|
|
||||||
};
|
|
||||||
use euclid::default::{Point2D, Rect, Size2D};
|
use euclid::default::{Point2D, Rect, Size2D};
|
||||||
use hyper_serde::Serde;
|
use hyper_serde::Serde;
|
||||||
use ipc_channel::ipc::{self, IpcSender};
|
use ipc_channel::ipc::{self, IpcSender};
|
||||||
|
@ -994,7 +992,7 @@ pub(crate) fn handle_get_page_source(
|
||||||
pub(crate) fn handle_get_cookies(
|
pub(crate) fn handle_get_cookies(
|
||||||
documents: &DocumentCollection,
|
documents: &DocumentCollection,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
reply: IpcSender<Vec<Serde<Cookie<'static>>>>,
|
reply: IpcSender<Result<Vec<Serde<Cookie<'static>>>, ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
reply
|
reply
|
||||||
.send(
|
.send(
|
||||||
|
@ -1008,9 +1006,9 @@ pub(crate) fn handle_get_cookies(
|
||||||
.as_global_scope()
|
.as_global_scope()
|
||||||
.resource_threads()
|
.resource_threads()
|
||||||
.send(GetCookiesDataForUrl(url, sender, NonHTTP));
|
.send(GetCookiesDataForUrl(url, sender, NonHTTP));
|
||||||
receiver.recv().unwrap()
|
Ok(receiver.recv().unwrap())
|
||||||
},
|
},
|
||||||
None => Vec::new(),
|
None => Ok(Vec::new()),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -1021,7 +1019,7 @@ pub(crate) fn handle_get_cookie(
|
||||||
documents: &DocumentCollection,
|
documents: &DocumentCollection,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
name: String,
|
name: String,
|
||||||
reply: IpcSender<Vec<Serde<Cookie<'static>>>>,
|
reply: IpcSender<Result<Vec<Serde<Cookie<'static>>>, ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
reply
|
reply
|
||||||
.send(
|
.send(
|
||||||
|
@ -1036,12 +1034,12 @@ pub(crate) fn handle_get_cookie(
|
||||||
.resource_threads()
|
.resource_threads()
|
||||||
.send(GetCookiesDataForUrl(url, sender, NonHTTP));
|
.send(GetCookiesDataForUrl(url, sender, NonHTTP));
|
||||||
let cookies = receiver.recv().unwrap();
|
let cookies = receiver.recv().unwrap();
|
||||||
cookies
|
Ok(cookies
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|cookie| cookie.name() == &*name)
|
.filter(|cookie| cookie.name() == &*name)
|
||||||
.collect()
|
.collect())
|
||||||
},
|
},
|
||||||
None => Vec::new(),
|
None => Ok(Vec::new()),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -1052,15 +1050,13 @@ pub(crate) fn handle_add_cookie(
|
||||||
documents: &DocumentCollection,
|
documents: &DocumentCollection,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
cookie: Cookie<'static>,
|
cookie: Cookie<'static>,
|
||||||
reply: IpcSender<Result<(), WebDriverCookieError>>,
|
reply: IpcSender<Result<(), ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
// TODO: Return a different error if the pipeline doesn't exist
|
// TODO: Return a different error if the pipeline doesn't exist
|
||||||
let document = match documents.find_document(pipeline) {
|
let document = match documents.find_document(pipeline) {
|
||||||
Some(document) => document,
|
Some(document) => document,
|
||||||
None => {
|
None => {
|
||||||
return reply
|
return reply.send(Err(ErrorStatus::UnableToSetCookie)).unwrap();
|
||||||
.send(Err(WebDriverCookieError::UnableToSetCookie))
|
|
||||||
.unwrap();
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let url = document.url();
|
let url = document.url();
|
||||||
|
@ -1073,7 +1069,7 @@ pub(crate) fn handle_add_cookie(
|
||||||
let domain = cookie.domain().map(ToOwned::to_owned);
|
let domain = cookie.domain().map(ToOwned::to_owned);
|
||||||
reply
|
reply
|
||||||
.send(match (document.is_cookie_averse(), domain) {
|
.send(match (document.is_cookie_averse(), domain) {
|
||||||
(true, _) => Err(WebDriverCookieError::InvalidDomain),
|
(true, _) => Err(ErrorStatus::InvalidCookieDomain),
|
||||||
(false, Some(ref domain)) if url.host_str().map(|x| x == domain).unwrap_or(false) => {
|
(false, Some(ref domain)) if url.host_str().map(|x| x == domain).unwrap_or(false) => {
|
||||||
let _ = document
|
let _ = document
|
||||||
.window()
|
.window()
|
||||||
|
@ -1090,7 +1086,7 @@ pub(crate) fn handle_add_cookie(
|
||||||
.send(SetCookieForUrl(url, Serde(cookie), method));
|
.send(SetCookieForUrl(url, Serde(cookie), method));
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
(_, _) => Err(WebDriverCookieError::UnableToSetCookie),
|
(_, _) => Err(ErrorStatus::UnableToSetCookie),
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,7 @@ pub enum WebDriverScriptCommand {
|
||||||
serialize_with = "::hyper_serde::serialize"
|
serialize_with = "::hyper_serde::serialize"
|
||||||
)]
|
)]
|
||||||
Cookie<'static>,
|
Cookie<'static>,
|
||||||
IpcSender<Result<(), WebDriverCookieError>>,
|
IpcSender<Result<(), ErrorStatus>>,
|
||||||
),
|
),
|
||||||
DeleteCookies(IpcSender<Result<(), ErrorStatus>>),
|
DeleteCookies(IpcSender<Result<(), ErrorStatus>>),
|
||||||
DeleteCookie(String, IpcSender<Result<(), ErrorStatus>>),
|
DeleteCookie(String, IpcSender<Result<(), ErrorStatus>>),
|
||||||
|
@ -134,8 +134,11 @@ pub enum WebDriverScriptCommand {
|
||||||
ElementClick(String, IpcSender<Result<Option<String>, ErrorStatus>>),
|
ElementClick(String, IpcSender<Result<Option<String>, ErrorStatus>>),
|
||||||
GetActiveElement(IpcSender<Option<String>>),
|
GetActiveElement(IpcSender<Option<String>>),
|
||||||
GetComputedRole(String, IpcSender<Result<Option<String>, ErrorStatus>>),
|
GetComputedRole(String, IpcSender<Result<Option<String>, ErrorStatus>>),
|
||||||
GetCookie(String, IpcSender<Vec<Serde<Cookie<'static>>>>),
|
GetCookie(
|
||||||
GetCookies(IpcSender<Vec<Serde<Cookie<'static>>>>),
|
String,
|
||||||
|
IpcSender<Result<Vec<Serde<Cookie<'static>>>, ErrorStatus>>,
|
||||||
|
),
|
||||||
|
GetCookies(IpcSender<Result<Vec<Serde<Cookie<'static>>>, ErrorStatus>>),
|
||||||
GetElementAttribute(
|
GetElementAttribute(
|
||||||
String,
|
String,
|
||||||
String,
|
String,
|
||||||
|
@ -165,12 +168,6 @@ pub enum WebDriverScriptCommand {
|
||||||
WillSendKeys(String, String, bool, IpcSender<Result<bool, ErrorStatus>>),
|
WillSendKeys(String, String, bool, IpcSender<Result<bool, ErrorStatus>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
|
||||||
pub enum WebDriverCookieError {
|
|
||||||
InvalidDomain,
|
|
||||||
UnableToSetCookie,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub enum WebDriverJSValue {
|
pub enum WebDriverJSValue {
|
||||||
Undefined,
|
Undefined,
|
||||||
|
|
|
@ -24,9 +24,9 @@ use constellation_traits::{EmbedderToConstellationMessage, TraversalDirection};
|
||||||
use cookie::{CookieBuilder, Expiration};
|
use cookie::{CookieBuilder, Expiration};
|
||||||
use crossbeam_channel::{Receiver, Sender, after, select, unbounded};
|
use crossbeam_channel::{Receiver, Sender, after, select, unbounded};
|
||||||
use embedder_traits::{
|
use embedder_traits::{
|
||||||
MouseButton, WebDriverCommandMsg, WebDriverCommandResponse, WebDriverCookieError,
|
MouseButton, WebDriverCommandMsg, WebDriverCommandResponse, WebDriverFrameId, WebDriverJSError,
|
||||||
WebDriverFrameId, WebDriverJSError, WebDriverJSResult, WebDriverJSValue, WebDriverLoadStatus,
|
WebDriverJSResult, WebDriverJSValue, WebDriverLoadStatus, WebDriverMessageId,
|
||||||
WebDriverMessageId, WebDriverScriptCommand,
|
WebDriverScriptCommand,
|
||||||
};
|
};
|
||||||
use euclid::{Rect, Size2D};
|
use euclid::{Rect, Size2D};
|
||||||
use http::method::Method;
|
use http::method::Method;
|
||||||
|
@ -1365,7 +1365,10 @@ impl Handler {
|
||||||
let (sender, receiver) = ipc::channel().unwrap();
|
let (sender, receiver) = ipc::channel().unwrap();
|
||||||
let cmd = WebDriverScriptCommand::GetCookies(sender);
|
let cmd = WebDriverScriptCommand::GetCookies(sender);
|
||||||
self.browsing_context_script_command(cmd)?;
|
self.browsing_context_script_command(cmd)?;
|
||||||
let cookies = wait_for_script_response(receiver)?;
|
let cookies = match wait_for_script_response(receiver)? {
|
||||||
|
Ok(cookies) => cookies,
|
||||||
|
Err(error) => return Err(WebDriverError::new(error, "")),
|
||||||
|
};
|
||||||
let response = cookies
|
let response = cookies
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|cookie| cookie_msg_to_cookie(cookie.into_inner()))
|
.map(|cookie| cookie_msg_to_cookie(cookie.into_inner()))
|
||||||
|
@ -1377,7 +1380,10 @@ impl Handler {
|
||||||
let (sender, receiver) = ipc::channel().unwrap();
|
let (sender, receiver) = ipc::channel().unwrap();
|
||||||
let cmd = WebDriverScriptCommand::GetCookie(name, sender);
|
let cmd = WebDriverScriptCommand::GetCookie(name, sender);
|
||||||
self.browsing_context_script_command(cmd)?;
|
self.browsing_context_script_command(cmd)?;
|
||||||
let cookies = wait_for_script_response(receiver)?;
|
let cookies = match wait_for_script_response(receiver)? {
|
||||||
|
Ok(cookies) => cookies,
|
||||||
|
Err(error) => return Err(WebDriverError::new(error, "")),
|
||||||
|
};
|
||||||
let Some(response) = cookies
|
let Some(response) = cookies
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|cookie| cookie_msg_to_cookie(cookie.into_inner()))
|
.map(|cookie| cookie_msg_to_cookie(cookie.into_inner()))
|
||||||
|
@ -1410,16 +1416,7 @@ impl Handler {
|
||||||
self.browsing_context_script_command(cmd)?;
|
self.browsing_context_script_command(cmd)?;
|
||||||
match wait_for_script_response(receiver)? {
|
match wait_for_script_response(receiver)? {
|
||||||
Ok(_) => Ok(WebDriverResponse::Void),
|
Ok(_) => Ok(WebDriverResponse::Void),
|
||||||
Err(response) => match response {
|
Err(error) => Err(WebDriverError::new(error, "")),
|
||||||
WebDriverCookieError::InvalidDomain => Err(WebDriverError::new(
|
|
||||||
ErrorStatus::InvalidCookieDomain,
|
|
||||||
"Invalid cookie domain",
|
|
||||||
)),
|
|
||||||
WebDriverCookieError::UnableToSetCookie => Err(WebDriverError::new(
|
|
||||||
ErrorStatus::UnableToSetCookie,
|
|
||||||
"Unable to set cookie",
|
|
||||||
)),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue