mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Refactor and simplify 'set cookies' operations on resource thread.
This commit is contained in:
parent
fde9ac1768
commit
77d2f9de36
5 changed files with 35 additions and 44 deletions
|
@ -93,6 +93,8 @@ use euclid::point::Point2D;
|
|||
use gfx_traits::ScrollRootId;
|
||||
use html5ever::tree_builder::{LimitedQuirks, NoQuirks, Quirks, QuirksMode};
|
||||
use html5ever_atoms::{LocalName, QualName};
|
||||
use hyper::header::{Header, SetCookie};
|
||||
use hyper_serde::Serde;
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use js::jsapi::{JSContext, JSObject, JSRuntime};
|
||||
use js::jsapi::JS_GetRuntime;
|
||||
|
@ -2960,11 +2962,15 @@ impl DocumentMethods for Document {
|
|||
return Err(Error::Security);
|
||||
}
|
||||
|
||||
let url = self.url();
|
||||
let _ = self.window
|
||||
.upcast::<GlobalScope>()
|
||||
.resource_threads()
|
||||
.send(SetCookiesForUrl(url, String::from(cookie), NonHTTP));
|
||||
let header = Header::parse_header(&[cookie.into()]);
|
||||
if let Ok(SetCookie(cookies)) = header {
|
||||
let cookies = cookies.into_iter().map(Serde).collect();
|
||||
let _ = self.window
|
||||
.upcast::<GlobalScope>()
|
||||
.resource_threads()
|
||||
.send(SetCookiesForUrl(self.url(), cookies, NonHTTP));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ use dom::eventtarget::EventTarget;
|
|||
use dom::globalscope::GlobalScope;
|
||||
use dom::messageevent::MessageEvent;
|
||||
use dom::urlhelper::UrlHelper;
|
||||
use hyper;
|
||||
use hyper_serde::Serde;
|
||||
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
|
||||
use js::jsapi::{JS_GetArrayBufferData, JS_NewArrayBuffer};
|
||||
use js::jsapi::JSAutoCompartment;
|
||||
|
@ -496,13 +498,10 @@ impl Runnable for ConnectionEstablishedTask {
|
|||
};
|
||||
|
||||
// Step 5: Cookies.
|
||||
if let Some(cookies) = self.headers.get_raw("set-cookie") {
|
||||
for cookie in cookies.iter() {
|
||||
if let Ok(cookie_value) = String::from_utf8(cookie.clone()) {
|
||||
let _ = ws.global().core_resource_thread().send(
|
||||
SetCookiesForUrl(ws.url.clone(), cookie_value, HTTP));
|
||||
}
|
||||
}
|
||||
if let Some(cookies) = self.headers.get::<hyper::header::SetCookie>() {
|
||||
let cookies = cookies.iter().map(|c| Serde(c.clone())).collect();
|
||||
let _ = ws.global().core_resource_thread().send(
|
||||
SetCookiesForUrl(ws.url.clone(), cookies, HTTP));
|
||||
}
|
||||
|
||||
// Step 6.
|
||||
|
|
|
@ -31,7 +31,7 @@ use js::jsapi::{HandleValue, JSContext};
|
|||
use js::jsval::UndefinedValue;
|
||||
use msg::constellation_msg::PipelineId;
|
||||
use net_traits::CookieSource::{HTTP, NonHTTP};
|
||||
use net_traits::CoreResourceMsg::{GetCookiesDataForUrl, SetCookiesForUrlWithData};
|
||||
use net_traits::CoreResourceMsg::{GetCookiesDataForUrl, SetCookieForUrl};
|
||||
use net_traits::IpcSend;
|
||||
use script_thread::Documents;
|
||||
use script_traits::webdriver_msg::{WebDriverFrameId, WebDriverJSError, WebDriverJSResult, WebDriverJSValue};
|
||||
|
@ -243,14 +243,14 @@ pub fn handle_add_cookie(documents: &Documents,
|
|||
(true, _) => Err(WebDriverCookieError::InvalidDomain),
|
||||
(false, Some(ref domain)) if url.host_str().map(|x| { x == &**domain }).unwrap_or(false) => {
|
||||
let _ = document.window().upcast::<GlobalScope>().resource_threads().send(
|
||||
SetCookiesForUrlWithData(url, cookie, method)
|
||||
);
|
||||
SetCookieForUrl(url, cookie, method)
|
||||
);
|
||||
Ok(())
|
||||
},
|
||||
(false, None) => {
|
||||
let _ = document.window().upcast::<GlobalScope>().resource_threads().send(
|
||||
SetCookiesForUrlWithData(url, cookie, method)
|
||||
);
|
||||
SetCookieForUrl(url, cookie, method)
|
||||
);
|
||||
Ok(())
|
||||
},
|
||||
(_, _) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue