aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/script/dom/navigator.rs4
-rw-r--r--components/script/dom/navigatorinfo.rs8
-rw-r--r--components/script/dom/webidls/Navigator.webidl2
-rw-r--r--components/script/dom/workernavigator.rs4
-rw-r--r--components/util/opts.rs23
-rw-r--r--tests/wpt/metadata/html/dom/interfaces.html.ini9
6 files changed, 38 insertions, 12 deletions
diff --git a/components/script/dom/navigator.rs b/components/script/dom/navigator.rs
index 9810c67a877..957abd558ec 100644
--- a/components/script/dom/navigator.rs
+++ b/components/script/dom/navigator.rs
@@ -51,6 +51,10 @@ impl<'a> NavigatorMethods for JSRef<'a, Navigator> {
fn Platform(self) -> DOMString {
NavigatorInfo::Platform()
}
+
+ fn UserAgent(self) -> DOMString {
+ NavigatorInfo::UserAgent()
+ }
}
impl Reflectable for Navigator {
diff --git a/components/script/dom/navigatorinfo.rs b/components/script/dom/navigatorinfo.rs
index 8832aca8697..d8081ef134a 100644
--- a/components/script/dom/navigatorinfo.rs
+++ b/components/script/dom/navigatorinfo.rs
@@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use servo_util::str::DOMString;
+use servo_util::opts;
pub struct NavigatorInfo;
@@ -26,4 +27,11 @@ impl NavigatorInfo {
pub fn Platform() -> DOMString {
"".to_string()
}
+
+ pub fn UserAgent() -> DOMString {
+ match opts::get().user_agent {
+ Some(ref user_agent) => user_agent.clone(),
+ None => "".to_string(),
+ }
+ }
}
diff --git a/components/script/dom/webidls/Navigator.webidl b/components/script/dom/webidls/Navigator.webidl
index 16d96d53470..0ce509f4c04 100644
--- a/components/script/dom/webidls/Navigator.webidl
+++ b/components/script/dom/webidls/Navigator.webidl
@@ -23,5 +23,5 @@ interface NavigatorID {
readonly attribute DOMString platform;
readonly attribute DOMString product; // constant "Gecko"
boolean taintEnabled(); // constant false
- //readonly attribute DOMString userAgent;
+ readonly attribute DOMString userAgent;
};
diff --git a/components/script/dom/workernavigator.rs b/components/script/dom/workernavigator.rs
index 2265b23c6bc..2d3c496048c 100644
--- a/components/script/dom/workernavigator.rs
+++ b/components/script/dom/workernavigator.rs
@@ -51,6 +51,10 @@ impl<'a> WorkerNavigatorMethods for JSRef<'a, WorkerNavigator> {
fn Platform(self) -> DOMString {
NavigatorInfo::Platform()
}
+
+ fn UserAgent(self) -> DOMString {
+ NavigatorInfo::UserAgent()
+ }
}
impl Reflectable for WorkerNavigator {
diff --git a/components/util/opts.rs b/components/util/opts.rs
index de8b295d1eb..b5970a1f5c1 100644
--- a/components/util/opts.rs
+++ b/components/util/opts.rs
@@ -15,6 +15,7 @@ use layers::geometry::DevicePixel;
use getopts;
use std::cmp;
use std::io;
+use std::mem;
use std::os;
use std::rt;
@@ -230,7 +231,7 @@ pub fn from_cmdline_args(args: &[String]) -> Option<Opts> {
}
};
- Some(Opts {
+ let opts = Opts {
urls: urls,
render_backend: render_backend,
n_render_threads: n_render_threads,
@@ -253,7 +254,14 @@ pub fn from_cmdline_args(args: &[String]) -> Option<Opts> {
initial_window_size: initial_window_size,
user_agent: opt_match.opt_str("u"),
dump_flow_tree: opt_match.opt_present("dump-flow-tree"),
- })
+ };
+
+ unsafe {
+ let box_opts = box opts.clone();
+ OPTIONS = mem::transmute(box_opts);
+ }
+
+ Some(opts)
}
static mut EXPERIMENTAL_ENABLED: bool = false;
@@ -269,3 +277,14 @@ pub fn experimental_enabled() -> bool {
EXPERIMENTAL_ENABLED
}
}
+
+// Make Opts available globally. This saves having to clone and pass
+// opts everywhere it is used, which gets particularly cumbersome
+// when passing through the DOM structures.
+// GWTODO: Change existing code that takes copies of opts to instead
+// make use of the global copy.
+static mut OPTIONS: *mut Opts = 0 as *mut Opts;
+
+pub fn get() -> &'static Opts {
+ unsafe { mem::transmute(OPTIONS) }
+}
diff --git a/tests/wpt/metadata/html/dom/interfaces.html.ini b/tests/wpt/metadata/html/dom/interfaces.html.ini
index 2c8e63fc1b0..2b46a216624 100644
--- a/tests/wpt/metadata/html/dom/interfaces.html.ini
+++ b/tests/wpt/metadata/html/dom/interfaces.html.ini
@@ -8802,9 +8802,6 @@
[Navigator interface: attribute appVersion]
expected: FAIL
- [Navigator interface: attribute userAgent]
- expected: FAIL
-
[Navigator interface: attribute language]
expected: FAIL
@@ -8850,9 +8847,6 @@
[Navigator interface: window.navigator must inherit property "appVersion" with the proper type (2)]
expected: FAIL
- [Navigator interface: window.navigator must inherit property "userAgent" with the proper type (6)]
- expected: FAIL
-
[Navigator interface: window.navigator must inherit property "language" with the proper type (7)]
expected: FAIL
@@ -9405,9 +9399,6 @@
[WorkerNavigator interface: attribute appVersion]
expected: FAIL
- [WorkerNavigator interface: attribute userAgent]
- expected: FAIL
-
[WorkerNavigator interface: attribute language]
expected: FAIL