diff options
Diffstat (limited to 'components')
-rw-r--r-- | components/net/Cargo.toml | 2 | ||||
-rw-r--r-- | components/net/cookie.rs | 65 | ||||
-rw-r--r-- | components/net/cookie_storage.rs | 2 | ||||
-rw-r--r-- | components/net/resource_thread.rs | 43 | ||||
-rw-r--r-- | components/net/storage_thread.rs | 6 | ||||
-rw-r--r-- | components/servo/Cargo.lock | 9 |
6 files changed, 52 insertions, 75 deletions
diff --git a/components/net/Cargo.toml b/components/net/Cargo.toml index 927ecf67fd2..5fb3978a9c1 100644 --- a/components/net/Cargo.toml +++ b/components/net/Cargo.toml @@ -33,7 +33,7 @@ git = "https://github.com/servo/ipc-channel" git = "https://github.com/servo/webrender_traits" [dependencies] -cookie = "0.2" +cookie = { version = "0.2.4", features = [ "serialize-rustc" ] } flate2 = "0.2.0" hyper = { version = "0.9", features = [ "serde-serialization" ] } immeta = "0.3.1" diff --git a/components/net/cookie.rs b/components/net/cookie.rs index 0d82c196cca..e85f0b41397 100644 --- a/components/net/cookie.rs +++ b/components/net/cookie.rs @@ -8,7 +8,6 @@ use cookie_rs; use net_traits::CookieSource; use pub_domains::PUB_DOMAINS; -use rustc_serialize::{Encodable, Encoder}; use std::borrow::ToOwned; use std::net::{Ipv4Addr, Ipv6Addr}; use time::{Tm, now, at, Duration}; @@ -17,7 +16,7 @@ use url::Url; /// A stored cookie that wraps the definition in cookie-rs. This is used to implement /// various behaviours defined in the spec that rely on an associated request URL, /// which cookie-rs and hyper's header parsing do not support. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, RustcDecodable, RustcEncodable)] pub struct Cookie { pub cookie: cookie_rs::Cookie, pub host_only: bool, @@ -174,65 +173,3 @@ impl Cookie { true } } - -impl Encodable for Cookie { - fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> { - s.emit_struct("Cookie", 6, |e| { - try!(e.emit_struct_field("cookie", 0, |e| RsCookie(self.cookie.clone()).encode(e))); - try!(e.emit_struct_field("host_only", 1, |e| self.host_only.encode(e))); - try!(e.emit_struct_field("persistent", 2, |e| self.persistent.encode(e))); - try!(e.emit_struct_field("creation_time", 3, |e| Time(self.creation_time).encode(e))); - try!(e.emit_struct_field("last_access", 4, |e| Time(self.last_access).encode(e))); - match self.expiry_time { - Some(time) => try!(e.emit_struct_field("expiry_time", 5, |e| Time(time).encode(e))), - None => {}, - } - Ok(()) - }) - } -} - -struct Time(Tm); - -impl Encodable for Time { - fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> { - let Time(time) = *self; - s.emit_struct("Time", 11, |e| { - try!(e.emit_struct_field("tm_sec", 0, |e| time.tm_sec.encode(e))); - try!(e.emit_struct_field("tm_min", 1, |e| time.tm_min.encode(e))); - try!(e.emit_struct_field("tm_hour", 2, |e| time.tm_hour.encode(e))); - try!(e.emit_struct_field("tm_mday", 3, |e| time.tm_mday.encode(e))); - try!(e.emit_struct_field("tm_mon", 4, |e| time.tm_mon.encode(e))); - try!(e.emit_struct_field("tm_year", 5, |e| time.tm_year.encode(e))); - try!(e.emit_struct_field("tm_wday", 6, |e| time.tm_wday.encode(e))); - try!(e.emit_struct_field("tm_yday", 7, |e| time.tm_yday.encode(e))); - try!(e.emit_struct_field("tm_isdst", 8, |e| time.tm_isdst.encode(e))); - try!(e.emit_struct_field("tm_utcoff", 9, |e| time.tm_utcoff.encode(e))); - try!(e.emit_struct_field("tm_nsec", 10, |e| time.tm_nsec.encode(e))); - Ok(()) - }) - } -} - -struct RsCookie(cookie_rs::Cookie); - -impl Encodable for RsCookie { - fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> { - let RsCookie(ref rs_cookie) = *self; - s.emit_struct("RsCookie", 9, |e| { - try!(e.emit_struct_field("name", 0, |e| rs_cookie.name.encode(e))); - try!(e.emit_struct_field("value", 1, |e| rs_cookie.value.encode(e))); - match rs_cookie.expires { - Some(time) => try!(e.emit_struct_field("expires", 2, |e| Time(time).encode(e))), - None => {}, - } - try!(e.emit_struct_field("max_age", 3, |e| rs_cookie.max_age.encode(e))); - try!(e.emit_struct_field("domain", 4, |e| rs_cookie.domain.encode(e))); - try!(e.emit_struct_field("path", 5, |e| rs_cookie.path.encode(e))); - try!(e.emit_struct_field("secure", 6, |e| rs_cookie.secure.encode(e))); - try!(e.emit_struct_field("httponly", 7, |e| rs_cookie.httponly.encode(e))); - try!(e.emit_struct_field("custom", 8, |e| rs_cookie.custom.encode(e))); - Ok(()) - }) - } -} diff --git a/components/net/cookie_storage.rs b/components/net/cookie_storage.rs index e71664f9611..092cdd4882f 100644 --- a/components/net/cookie_storage.rs +++ b/components/net/cookie_storage.rs @@ -11,7 +11,7 @@ use rustc_serialize::{Encodable, Encoder}; use std::cmp::Ordering; use url::Url; -#[derive(RustcEncodable, Clone)] +#[derive(Clone, RustcDecodable, RustcEncodable)] pub struct CookieStorage { version: u32, cookies: Vec<Cookie> diff --git a/components/net/resource_thread.rs b/components/net/resource_thread.rs index 77891931120..622ac054085 100644 --- a/components/net/resource_thread.rs +++ b/components/net/resource_thread.rs @@ -22,8 +22,8 @@ use net_traits::ProgressMsg::Done; use net_traits::{AsyncResponseTarget, Metadata, ProgressMsg, ResourceThread, ResponseAction}; use net_traits::{ControlMsg, CookieSource, LoadConsumer, LoadData, LoadResponse, ResourceId}; use net_traits::{NetworkError, WebSocketCommunicate, WebSocketConnectData}; -use rustc_serialize::Encodable; use rustc_serialize::json; +use rustc_serialize::{Decodable, Encodable}; use std::borrow::ToOwned; use std::boxed::FnBox; use std::cell::Cell; @@ -219,6 +219,34 @@ impl ResourceChannelManager { } } +pub fn read_json_from_file<T: Decodable>(data: &mut T, profile_dir: &str, filename: &str) { + + let path = Path::new(profile_dir).join(filename); + let display = path.display(); + + let mut file = match File::open(&path) { + Err(why) => { + warn!("couldn't open {}: {}", display, Error::description(&why)); + return; + }, + Ok(file) => file, + }; + + let mut string_buffer: String = String::new(); + match file.read_to_string(&mut string_buffer) { + Err(why) => { + panic!("couldn't read from {}: {}", display, + Error::description(&why)) + }, + Ok(_) => println!("successfully read from {}", display), + } + + match json::decode(&string_buffer) { + Ok(decoded_buffer) => *data = decoded_buffer, + Err(why) => warn!("Could not decode buffer{}", why), + } +} + pub fn write_json_to_file<T: Encodable>(data: &T, profile_dir: &str, filename: &str) { let json_encoded: String; match json::encode(&data) { @@ -343,12 +371,19 @@ pub struct ResourceManager { impl ResourceManager { pub fn new(user_agent: String, - hsts_list: HstsList, + mut hsts_list: HstsList, devtools_channel: Option<Sender<DevtoolsControlMsg>>) -> ResourceManager { + let mut auth_cache = AuthCache::new(); + let mut cookie_jar = CookieStorage::new(); + if let Some(ref profile_dir) = opts::get().profile_dir { + read_json_from_file(&mut auth_cache, profile_dir, "auth_cache.json"); + read_json_from_file(&mut hsts_list, profile_dir, "hsts_list.json"); + read_json_from_file(&mut cookie_jar, profile_dir, "cookie_jar.json"); + } ResourceManager { user_agent: user_agent, - cookie_jar: Arc::new(RwLock::new(CookieStorage::new())), - auth_cache: Arc::new(RwLock::new(AuthCache::new())), + cookie_jar: Arc::new(RwLock::new(cookie_jar)), + auth_cache: Arc::new(RwLock::new(auth_cache)), mime_classifier: Arc::new(MIMEClassifier::new()), devtools_chan: devtools_channel, hsts_list: Arc::new(RwLock::new(hsts_list)), diff --git a/components/net/storage_thread.rs b/components/net/storage_thread.rs index 4a018e6ead8..49c65c96e19 100644 --- a/components/net/storage_thread.rs +++ b/components/net/storage_thread.rs @@ -37,10 +37,14 @@ struct StorageManager { impl StorageManager { fn new(port: IpcReceiver<StorageThreadMsg>) -> StorageManager { + let mut local_data = HashMap::new(); + if let Some(ref profile_dir) = opts::get().profile_dir { + resource_thread::read_json_from_file(&mut local_data, profile_dir, "local_data.json"); + } StorageManager { port: port, session_data: HashMap::new(), - local_data: HashMap::new(), + local_data: local_data, } } } diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 07db2a42b0d..620ec07eb28 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -316,7 +316,7 @@ dependencies = [ [[package]] name = "cookie" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "openssl 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -886,7 +886,7 @@ name = "hyper" version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cookie 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cookie 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "httparse 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "language-tags 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1270,7 +1270,7 @@ name = "net" version = "0.0.1" dependencies = [ "brotli 0.3.20 (git+https://github.com/ende76/brotli-rs)", - "cookie 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cookie 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "devtools_traits 0.0.1", "flate2 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1312,7 +1312,7 @@ dependencies = [ name = "net_tests" version = "0.0.1" dependencies = [ - "cookie 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cookie 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "devtools_traits 0.0.1", "flate2 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2153,6 +2153,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", ] |