mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Auto merge of #23006 - aditj:aditj-patch-7, r=jdm
Added WebDriver DeleteCookies Function <!-- Please describe your changes on the following line: --> This change adds DeleteCookies function of the webdriver crate to the servo webdriver server. See [spec](https://w3c.github.io/webdriver/#delete-all-cookies) --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix part of #8623 (GitHub issue number if applicable) <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23006) <!-- Reviewable:end -->
This commit is contained in:
commit
53b752bab7
8 changed files with 60 additions and 1 deletions
|
@ -143,6 +143,10 @@ impl Cookie {
|
||||||
self.last_access = now();
|
self.last_access = now();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_expiry_time_negative(&mut self) {
|
||||||
|
self.expiry_time = Some(Serde(now() - Duration::seconds(1)));
|
||||||
|
}
|
||||||
|
|
||||||
// http://tools.ietf.org/html/rfc6265#section-5.1.4
|
// http://tools.ietf.org/html/rfc6265#section-5.1.4
|
||||||
pub fn default_path(request_path: &str) -> &str {
|
pub fn default_path(request_path: &str) -> &str {
|
||||||
// Step 2
|
// Step 2
|
||||||
|
|
|
@ -83,6 +83,13 @@ impl CookieStorage {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn clear_storage(&mut self, url: &ServoUrl) {
|
||||||
|
let domain = reg_host(url.host_str().unwrap_or(""));
|
||||||
|
let cookies = self.cookies_map.entry(domain).or_insert(vec![]);
|
||||||
|
for cookie in cookies.iter_mut() {
|
||||||
|
cookie.set_expiry_time_negative();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// http://tools.ietf.org/html/rfc6265#section-5.3
|
// http://tools.ietf.org/html/rfc6265#section-5.3
|
||||||
pub fn push(&mut self, mut cookie: Cookie, url: &ServoUrl, source: CookieSource) {
|
pub fn push(&mut self, mut cookie: Cookie, url: &ServoUrl, source: CookieSource) {
|
||||||
|
|
|
@ -236,6 +236,14 @@ impl ResourceChannelManager {
|
||||||
http_state,
|
http_state,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
CoreResourceMsg::DeleteCookies(request) => {
|
||||||
|
http_state
|
||||||
|
.cookie_jar
|
||||||
|
.write()
|
||||||
|
.unwrap()
|
||||||
|
.clear_storage(&request);
|
||||||
|
return true;
|
||||||
|
},
|
||||||
CoreResourceMsg::FetchRedirect(req_init, res_init, sender, cancel_chan) => self
|
CoreResourceMsg::FetchRedirect(req_init, res_init, sender, cancel_chan) => self
|
||||||
.resource_manager
|
.resource_manager
|
||||||
.fetch(req_init, Some(res_init), sender, http_state, cancel_chan),
|
.fetch(req_init, Some(res_init), sender, http_state, cancel_chan),
|
||||||
|
|
|
@ -397,6 +397,7 @@ pub enum CoreResourceMsg {
|
||||||
IpcSender<Vec<Serde<Cookie<'static>>>>,
|
IpcSender<Vec<Serde<Cookie<'static>>>>,
|
||||||
CookieSource,
|
CookieSource,
|
||||||
),
|
),
|
||||||
|
DeleteCookies(ServoUrl),
|
||||||
/// Get a history state by a given history state id
|
/// Get a history state by a given history state id
|
||||||
GetHistoryState(HistoryStateId, IpcSender<Option<Vec<u8>>>),
|
GetHistoryState(HistoryStateId, IpcSender<Option<Vec<u8>>>),
|
||||||
/// Set a history state for a given history state id
|
/// Set a history state for a given history state id
|
||||||
|
|
|
@ -1844,6 +1844,9 @@ impl ScriptThread {
|
||||||
WebDriverScriptCommand::AddCookie(params, reply) => {
|
WebDriverScriptCommand::AddCookie(params, reply) => {
|
||||||
webdriver_handlers::handle_add_cookie(&*documents, pipeline_id, params, reply)
|
webdriver_handlers::handle_add_cookie(&*documents, pipeline_id, params, reply)
|
||||||
},
|
},
|
||||||
|
WebDriverScriptCommand::DeleteCookies(reply) => {
|
||||||
|
webdriver_handlers::handle_delete_cookies(&*documents, pipeline_id, reply)
|
||||||
|
},
|
||||||
WebDriverScriptCommand::ExecuteScript(script, reply) => {
|
WebDriverScriptCommand::ExecuteScript(script, reply) => {
|
||||||
webdriver_handlers::handle_execute_script(&*documents, pipeline_id, script, reply)
|
webdriver_handlers::handle_execute_script(&*documents, pipeline_id, script, reply)
|
||||||
},
|
},
|
||||||
|
|
|
@ -34,7 +34,7 @@ use js::rust::HandleValue;
|
||||||
use msg::constellation_msg::BrowsingContextId;
|
use msg::constellation_msg::BrowsingContextId;
|
||||||
use msg::constellation_msg::PipelineId;
|
use msg::constellation_msg::PipelineId;
|
||||||
use net_traits::CookieSource::{NonHTTP, HTTP};
|
use net_traits::CookieSource::{NonHTTP, HTTP};
|
||||||
use net_traits::CoreResourceMsg::{GetCookiesDataForUrl, SetCookieForUrl};
|
use net_traits::CoreResourceMsg::{DeleteCookies, GetCookiesDataForUrl, SetCookieForUrl};
|
||||||
use net_traits::IpcSend;
|
use net_traits::IpcSend;
|
||||||
use script_traits::webdriver_msg::WebDriverCookieError;
|
use script_traits::webdriver_msg::WebDriverCookieError;
|
||||||
use script_traits::webdriver_msg::{
|
use script_traits::webdriver_msg::{
|
||||||
|
@ -356,6 +356,27 @@ pub fn handle_add_cookie(
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn handle_delete_cookies(
|
||||||
|
documents: &Documents,
|
||||||
|
pipeline: PipelineId,
|
||||||
|
reply: IpcSender<Result<(), ()>>,
|
||||||
|
) {
|
||||||
|
let document = match documents.find_document(pipeline) {
|
||||||
|
Some(document) => document,
|
||||||
|
None => {
|
||||||
|
return reply.send(Err(())).unwrap();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
let url = document.url();
|
||||||
|
document
|
||||||
|
.window()
|
||||||
|
.upcast::<GlobalScope>()
|
||||||
|
.resource_threads()
|
||||||
|
.send(DeleteCookies(url))
|
||||||
|
.unwrap();
|
||||||
|
let _ = reply.send(Ok(()));
|
||||||
|
}
|
||||||
|
|
||||||
pub fn handle_get_title(documents: &Documents, pipeline: PipelineId, reply: IpcSender<String>) {
|
pub fn handle_get_title(documents: &Documents, pipeline: PipelineId, reply: IpcSender<String>) {
|
||||||
// TODO: Return an error if the pipeline doesn't exist.
|
// TODO: Return an error if the pipeline doesn't exist.
|
||||||
let title = documents
|
let title = documents
|
||||||
|
|
|
@ -21,6 +21,7 @@ pub enum WebDriverScriptCommand {
|
||||||
Cookie<'static>,
|
Cookie<'static>,
|
||||||
IpcSender<Result<(), WebDriverCookieError>>,
|
IpcSender<Result<(), WebDriverCookieError>>,
|
||||||
),
|
),
|
||||||
|
DeleteCookies(IpcSender<Result<(), ()>>),
|
||||||
ExecuteScript(String, IpcSender<WebDriverJSResult>),
|
ExecuteScript(String, IpcSender<WebDriverJSResult>),
|
||||||
ExecuteAsyncScript(String, IpcSender<WebDriverJSResult>),
|
ExecuteAsyncScript(String, IpcSender<WebDriverJSResult>),
|
||||||
FindElementCSS(String, IpcSender<Result<Option<String>, ()>>),
|
FindElementCSS(String, IpcSender<Result<Option<String>, ()>>),
|
||||||
|
|
|
@ -971,6 +971,19 @@ impl Handler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_delete_cookies(&self) -> WebDriverResult<WebDriverResponse> {
|
||||||
|
let (sender, receiver) = ipc::channel().unwrap();
|
||||||
|
let cmd = WebDriverScriptCommand::DeleteCookies(sender);
|
||||||
|
self.browsing_context_script_command(cmd)?;
|
||||||
|
match receiver.recv().unwrap() {
|
||||||
|
Ok(_) => Ok(WebDriverResponse::Void),
|
||||||
|
Err(_) => Err(WebDriverError::new(
|
||||||
|
ErrorStatus::NoSuchWindow,
|
||||||
|
"No such window found.",
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn handle_set_timeouts(
|
fn handle_set_timeouts(
|
||||||
&mut self,
|
&mut self,
|
||||||
parameters: &TimeoutsParameters,
|
parameters: &TimeoutsParameters,
|
||||||
|
@ -1261,6 +1274,7 @@ impl WebDriverHandler<ServoExtensionRoute> for Handler {
|
||||||
WebDriverCommand::ElementSendKeys(ref element, ref keys) => {
|
WebDriverCommand::ElementSendKeys(ref element, ref keys) => {
|
||||||
self.handle_element_send_keys(element, keys)
|
self.handle_element_send_keys(element, keys)
|
||||||
},
|
},
|
||||||
|
WebDriverCommand::DeleteCookies => self.handle_delete_cookies(),
|
||||||
WebDriverCommand::SetTimeouts(ref x) => self.handle_set_timeouts(x),
|
WebDriverCommand::SetTimeouts(ref x) => self.handle_set_timeouts(x),
|
||||||
WebDriverCommand::TakeScreenshot => self.handle_take_screenshot(),
|
WebDriverCommand::TakeScreenshot => self.handle_take_screenshot(),
|
||||||
WebDriverCommand::Extension(ref extension) => match *extension {
|
WebDriverCommand::Extension(ref extension) => match *extension {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue