/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::NavigatorBinding; use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::Fallible; use dom::window::Window; use servo_util::str::DOMString; #[deriving(Encodable)] pub struct Navigator { pub reflector_: Reflector //XXXjdm cycle: window->navigator->window } impl Navigator { pub fn new_inherited() -> Navigator { Navigator { reflector_: Reflector::new() } } pub fn new(window: &JSRef) -> Temporary { reflect_dom_object(~Navigator::new_inherited(), window, NavigatorBinding::Wrap) } } pub trait NavigatorMethods { fn DoNotTrack(&self) -> DOMString; fn Vendor(&self) -> DOMString; fn VendorSub(&self) -> DOMString; fn Product(&self) -> DOMString; fn ProductSub(&self) -> DOMString; fn CookieEnabled(&self) -> bool; fn GetBuildID(&self) -> Fallible; fn JavaEnabled(&self) -> Fallible; fn TaintEnabled(&self) -> bool; fn AppName(&self) -> DOMString; fn GetAppCodeName(&self) -> Fallible; fn GetAppVersion(&self) -> Fallible; fn GetPlatform(&self) -> Fallible; fn GetUserAgent(&self) -> Fallible; fn GetLanguage(&self) -> Option; fn OnLine(&self) -> bool; } impl<'a> NavigatorMethods for JSRef<'a, Navigator> { fn DoNotTrack(&self) -> DOMString { ~"unspecified" } fn Vendor(&self) -> DOMString { ~"" // Like Gecko } fn VendorSub(&self) -> DOMString { ~"" // Like Gecko } fn Product(&self) -> DOMString { ~"Gecko" } fn ProductSub(&self) -> DOMString { ~"" } fn CookieEnabled(&self) -> bool { false } fn GetBuildID(&self) -> Fallible { Ok(~"") } fn JavaEnabled(&self) -> Fallible { Ok(false) } fn TaintEnabled(&self) -> bool { false } fn AppName(&self) -> DOMString { ~"Netscape" // Like Gecko/Webkit } fn GetAppCodeName(&self) -> Fallible { Ok(~"Mozilla") // Like Gecko/Webkit } fn GetAppVersion(&self) -> Fallible { Ok(~"") } fn GetPlatform(&self) -> Fallible { Ok(~"") } fn GetUserAgent(&self) -> Fallible { Ok(~"") } fn GetLanguage(&self) -> Option { None } fn OnLine(&self) -> bool { true } } impl Reflectable for Navigator { fn reflector<'a>(&'a self) -> &'a Reflector { &self.reflector_ } fn mut_reflector<'a>(&'a mut self) -> &'a mut Reflector { &mut self.reflector_ } }