aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
Diffstat (limited to 'components')
-rw-r--r--components/compositing/windowing.rs5
-rw-r--r--components/config/opts.rs65
-rw-r--r--components/constellation/constellation.rs10
-rw-r--r--components/constellation/pipeline.rs8
-rw-r--r--components/servo/lib.rs70
5 files changed, 88 insertions, 70 deletions
diff --git a/components/compositing/windowing.rs b/components/compositing/windowing.rs
index 1e7a7b30b8d..a9058d419b9 100644
--- a/components/compositing/windowing.rs
+++ b/components/compositing/windowing.rs
@@ -193,6 +193,11 @@ pub trait EmbedderMethods {
_: EmbedderProxy,
) {
}
+
+ /// Returns the user agent string to report in network requests.
+ fn get_user_agent_string(&self) -> Option<String> {
+ None
+ }
}
#[derive(Clone, Copy, Debug)]
diff --git a/components/config/opts.rs b/components/config/opts.rs
index 796bd7d6b96..36a708b2aba 100644
--- a/components/config/opts.rs
+++ b/components/config/opts.rs
@@ -10,7 +10,6 @@ use euclid::Size2D;
use getopts::{Matches, Options};
use servo_geometry::DeviceIndependentPixel;
use servo_url::ServoUrl;
-use std::borrow::Cow;
use std::default::Default;
use std::env;
use std::fs::{self, File};
@@ -130,9 +129,6 @@ pub struct Opts {
/// The initial requested size of the window.
pub initial_window_size: Size2D<u32, DeviceIndependentPixel>,
- /// An optional string allowing the user agent to be set for testing.
- pub user_agent: Cow<'static, str>,
-
/// Whether we're running in multiprocess mode.
pub multiprocess: bool,
@@ -473,51 +469,6 @@ pub fn multiprocess() -> bool {
MULTIPROCESS.load(Ordering::Relaxed)
}
-enum UserAgent {
- Desktop,
- Android,
- #[allow(non_camel_case_types)]
- iOS,
-}
-
-fn default_user_agent_string(agent: UserAgent) -> &'static str {
- #[cfg(all(target_os = "linux", target_arch = "x86_64"))]
- const DESKTOP_UA_STRING: &'static str =
- "Mozilla/5.0 (X11; Linux x86_64; rv:72.0) Servo/1.0 Firefox/72.0";
- #[cfg(all(target_os = "linux", not(target_arch = "x86_64")))]
- const DESKTOP_UA_STRING: &'static str =
- "Mozilla/5.0 (X11; Linux i686; rv:72.0) Servo/1.0 Firefox/72.0";
-
- #[cfg(all(target_os = "windows", target_arch = "x86_64"))]
- const DESKTOP_UA_STRING: &'static str =
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Servo/1.0 Firefox/72.0";
- #[cfg(all(target_os = "windows", not(target_arch = "x86_64")))]
- const DESKTOP_UA_STRING: &'static str =
- "Mozilla/5.0 (Windows NT 10.0; rv:72.0) Servo/1.0 Firefox/72.0";
-
- #[cfg(not(any(target_os = "linux", target_os = "windows")))]
- // Neither Linux nor Windows, so maybe OS X, and if not then OS X is an okay fallback.
- const DESKTOP_UA_STRING: &'static str =
- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:72.0) Servo/1.0 Firefox/72.0";
-
- match agent {
- UserAgent::Desktop => DESKTOP_UA_STRING,
- UserAgent::Android => "Mozilla/5.0 (Android; Mobile; rv:68.0) Servo/1.0 Firefox/68.0",
- UserAgent::iOS => {
- "Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X; rv:72.0) Servo/1.0 Firefox/72.0"
- },
- }
-}
-
-#[cfg(target_os = "android")]
-const DEFAULT_USER_AGENT: UserAgent = UserAgent::Android;
-
-#[cfg(target_os = "ios")]
-const DEFAULT_USER_AGENT: UserAgent = UserAgent::iOS;
-
-#[cfg(not(any(target_os = "android", target_os = "ios")))]
-const DEFAULT_USER_AGENT: UserAgent = UserAgent::Desktop;
-
pub fn default_opts() -> Opts {
Opts {
is_running_problem_test: false,
@@ -546,7 +497,6 @@ pub fn default_opts() -> Opts {
devtools_port: None,
webdriver_port: None,
initial_window_size: Size2D::new(1024, 740),
- user_agent: default_user_agent_string(DEFAULT_USER_AGENT).into(),
multiprocess: false,
background_hang_monitor: false,
random_pipeline_closure_probability: None,
@@ -661,12 +611,6 @@ pub fn from_cmdline_args(mut opts: Options, args: &[String]) -> ArgumentParsingR
"7000",
);
opts.optopt("", "resolution", "Set window resolution.", "1024x740");
- opts.optopt(
- "u",
- "user-agent",
- "Set custom user agent string (or ios / android / desktop for platform default)",
- "NCSA Mosaic/1.0 (X11;SunOS 4.1.4 sun4m)",
- );
opts.optflag("M", "multiprocess", "Run in multiprocess mode");
opts.optflag("B", "bhm", "Background Hang Monitor enabled");
opts.optflag("S", "sandbox", "Run in a sandbox if multiprocess");
@@ -912,14 +856,6 @@ pub fn from_cmdline_args(mut opts: Options, args: &[String]) -> ArgumentParsingR
MULTIPROCESS.store(true, Ordering::SeqCst)
}
- let user_agent = match opt_match.opt_str("u") {
- Some(ref ua) if ua == "ios" => default_user_agent_string(UserAgent::iOS).into(),
- Some(ref ua) if ua == "android" => default_user_agent_string(UserAgent::Android).into(),
- Some(ref ua) if ua == "desktop" => default_user_agent_string(UserAgent::Desktop).into(),
- Some(ua) => ua.into(),
- None => default_user_agent_string(DEFAULT_USER_AGENT).into(),
- };
-
let user_stylesheets = opt_match
.opt_strs("user-stylesheet")
.iter()
@@ -964,7 +900,6 @@ pub fn from_cmdline_args(mut opts: Options, args: &[String]) -> ArgumentParsingR
devtools_port: devtools_port,
webdriver_port: webdriver_port,
initial_window_size: initial_window_size,
- user_agent: user_agent,
multiprocess: opt_match.opt_present("M"),
background_hang_monitor: opt_match.opt_present("B"),
sandbox: opt_match.opt_present("S"),
diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs
index 265db68e7ae..a6cb9df5532 100644
--- a/components/constellation/constellation.rs
+++ b/components/constellation/constellation.rs
@@ -166,7 +166,7 @@ use servo_config::{opts, pref};
use servo_rand::{random, Rng, ServoRng, SliceRandom};
use servo_remutex::ReentrantMutex;
use servo_url::{Host, ImmutableOrigin, ServoUrl};
-use std::borrow::ToOwned;
+use std::borrow::{Cow, ToOwned};
use std::collections::hash_map::Entry;
use std::collections::{HashMap, HashSet, VecDeque};
use std::marker::PhantomData;
@@ -503,6 +503,9 @@ pub struct Constellation<Message, LTF, STF, SWF> {
/// Pipeline ID of the active media session.
active_media_session: Option<PipelineId>,
+
+ /// User agent string to report in network requests.
+ user_agent: Cow<'static, str>,
}
/// State needed to construct a constellation.
@@ -562,6 +565,9 @@ pub struct InitialConstellationState {
/// A flag share with the compositor to indicate that a WR frame is in progress.
pub pending_wr_frame: Arc<AtomicBool>,
+
+ /// User agent string to report in network requests.
+ pub user_agent: Cow<'static, str>,
}
/// Data needed for webdriver
@@ -1021,6 +1027,7 @@ where
player_context: state.player_context,
event_loop_waker: state.event_loop_waker,
active_media_session: None,
+ user_agent: state.user_agent,
};
constellation.run();
@@ -1268,6 +1275,7 @@ where
webxr_registry: self.webxr_registry.clone(),
player_context: self.player_context.clone(),
event_loop_waker: self.event_loop_waker.as_ref().map(|w| (*w).clone_box()),
+ user_agent: self.user_agent.clone(),
});
let pipeline = match result {
diff --git a/components/constellation/pipeline.rs b/components/constellation/pipeline.rs
index 16cb67ab9a2..9739ecf32af 100644
--- a/components/constellation/pipeline.rs
+++ b/components/constellation/pipeline.rs
@@ -41,6 +41,7 @@ use script_traits::{ScriptThreadFactory, TimerSchedulerMsg, WindowSizeData};
use servo_config::opts::{self, Opts};
use servo_config::{prefs, prefs::PrefValue};
use servo_url::ServoUrl;
+use std::borrow::Cow;
use std::collections::{HashMap, HashSet};
use std::rc::Rc;
use std::sync::atomic::AtomicBool;
@@ -201,6 +202,9 @@ pub struct InitialPipelineState {
/// Mechanism to force the compositor to process events.
pub event_loop_waker: Option<Box<dyn EventLoopWaker>>,
+
+ /// User agent string to report in network requests.
+ pub user_agent: Cow<'static, str>,
}
pub struct NewPipeline {
@@ -304,6 +308,7 @@ impl Pipeline {
webvr_chan: state.webvr_chan,
webxr_registry: state.webxr_registry,
player_context: state.player_context,
+ user_agent: state.user_agent,
};
// Spawn the child process.
@@ -520,6 +525,7 @@ pub struct UnprivilegedPipelineContent {
webvr_chan: Option<IpcSender<WebVRMsg>>,
webxr_registry: webxr_api::Registry,
player_context: WindowGLContext,
+ user_agent: Cow<'static, str>,
}
impl UnprivilegedPipelineContent {
@@ -588,7 +594,7 @@ impl UnprivilegedPipelineContent {
self.opts.userscripts,
self.opts.headless,
self.opts.replace_surrogates,
- self.opts.user_agent,
+ self.user_agent,
);
LTF::create(
diff --git a/components/servo/lib.rs b/components/servo/lib.rs
index dff8c842e4f..d5b84bd613d 100644
--- a/components/servo/lib.rs
+++ b/components/servo/lib.rs
@@ -321,7 +321,11 @@ impl<Window> Servo<Window>
where
Window: WindowMethods + 'static + ?Sized,
{
- pub fn new(mut embedder: Box<dyn EmbedderMethods>, window: Rc<Window>) -> Servo<Window> {
+ pub fn new(
+ mut embedder: Box<dyn EmbedderMethods>,
+ window: Rc<Window>,
+ user_agent: Option<String>,
+ ) -> Servo<Window> {
// Global configuration options, parsed from the command line.
let opts = opts::get();
@@ -338,6 +342,21 @@ where
media_platform::init();
}
+ let user_agent = match user_agent {
+ Some(ref ua) if ua == "ios" => default_user_agent_string_for(UserAgent::iOS).into(),
+ Some(ref ua) if ua == "android" => {
+ default_user_agent_string_for(UserAgent::Android).into()
+ },
+ Some(ref ua) if ua == "desktop" => {
+ default_user_agent_string_for(UserAgent::Desktop).into()
+ },
+ Some(ua) => ua.into(),
+ None => embedder
+ .get_user_agent_string()
+ .map(Into::into)
+ .unwrap_or(default_user_agent_string_for(DEFAULT_USER_AGENT).into()),
+ };
+
// Make sure the gl context is made current.
window.make_gl_context_current();
@@ -521,7 +540,7 @@ where
// pipelines, including the script and layout threads, as well
// as the navigation context.
let constellation_chan = create_constellation(
- opts.user_agent.clone(),
+ user_agent,
opts.config_dir.clone(),
embedder_proxy,
compositor_proxy.clone(),
@@ -885,7 +904,7 @@ fn create_constellation(
BluetoothThreadFactory::new(embedder_proxy.clone());
let (public_resource_threads, private_resource_threads) = new_resource_threads(
- user_agent,
+ user_agent.clone(),
devtools_chan.clone(),
time_profiler_chan.clone(),
mem_profiler_chan.clone(),
@@ -918,6 +937,7 @@ fn create_constellation(
player_context,
event_loop_waker,
pending_wr_frame,
+ user_agent,
};
let (canvas_chan, ipc_canvas_chan) = canvas::canvas_paint_thread::CanvasPaintThread::start();
@@ -1146,3 +1166,47 @@ where
Some((webxr_surface_providers, webgl_executor)),
)
}
+
+enum UserAgent {
+ Desktop,
+ Android,
+ #[allow(non_camel_case_types)]
+ iOS,
+}
+
+fn default_user_agent_string_for(agent: UserAgent) -> &'static str {
+ #[cfg(all(target_os = "linux", target_arch = "x86_64"))]
+ const DESKTOP_UA_STRING: &'static str =
+ "Mozilla/5.0 (X11; Linux x86_64; rv:72.0) Servo/1.0 Firefox/72.0";
+ #[cfg(all(target_os = "linux", not(target_arch = "x86_64")))]
+ const DESKTOP_UA_STRING: &'static str =
+ "Mozilla/5.0 (X11; Linux i686; rv:72.0) Servo/1.0 Firefox/72.0";
+
+ #[cfg(all(target_os = "windows", target_arch = "x86_64"))]
+ const DESKTOP_UA_STRING: &'static str =
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Servo/1.0 Firefox/72.0";
+ #[cfg(all(target_os = "windows", not(target_arch = "x86_64")))]
+ const DESKTOP_UA_STRING: &'static str =
+ "Mozilla/5.0 (Windows NT 10.0; rv:72.0) Servo/1.0 Firefox/72.0";
+
+ #[cfg(target_os = "macos")]
+ const DESKTOP_UA_STRING: &'static str =
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:72.0) Servo/1.0 Firefox/72.0";
+
+ match agent {
+ UserAgent::Desktop => DESKTOP_UA_STRING,
+ UserAgent::Android => "Mozilla/5.0 (Android; Mobile; rv:68.0) Servo/1.0 Firefox/68.0",
+ UserAgent::iOS => {
+ "Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X; rv:72.0) Servo/1.0 Firefox/72.0"
+ },
+ }
+}
+
+#[cfg(target_os = "android")]
+const DEFAULT_USER_AGENT: UserAgent = UserAgent::Android;
+
+#[cfg(target_os = "ios")]
+const DEFAULT_USER_AGENT: UserAgent = UserAgent::iOS;
+
+#[cfg(not(any(target_os = "android", target_os = "ios")))]
+const DEFAULT_USER_AGENT: UserAgent = UserAgent::Desktop;