Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow embedders to provide user agent string #25672

Closed
wants to merge 8 commits into from

Add default implementation of EmbedderMethods::default_user_agent_string

  • Loading branch information
mediremi committed Feb 1, 2020
commit 632964984d0b5585b498b3185a8401e1fde81799
@@ -184,7 +184,46 @@ pub trait EmbedderMethods {
fn register_webxr(&mut self, _: &mut webxr::MainThreadRegistry) {}

/// Returns the default user agent string
fn default_user_agent_string(&self) -> &'static str;
fn default_user_agent_string(&self) -> &'static str {
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
const UA_STRING: &'static str =
"Mozilla/5.0 (X11; Linux x86_64; rv:63.0) Servo/1.0 Firefox/63.0";
#[cfg(all(target_os = "linux", not(target_arch = "x86_64")))]
const UA_STRING: &'static str =
"Mozilla/5.0 (X11; Linux i686; rv:63.0) Servo/1.0 Firefox/63.0";

#[cfg(all(target_os = "windows", target_arch = "x86_64"))]
const UA_STRING: &'static str =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Servo/1.0 Firefox/63.0";
#[cfg(all(target_os = "windows", not(target_arch = "x86_64")))]
const UA_STRING: &'static str =
"Mozilla/5.0 (Windows NT 10.0; rv:63.0) Servo/1.0 Firefox/63.0";

#[cfg(all(target_os = "macos"))]

This comment has been minimized.

@paulrouget

paulrouget Feb 7, 2020

Contributor

I don’t think the all is necessary here.

const UA_STRING: &'static str =
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:63.0) Servo/1.0 Firefox/63.0";

#[cfg(target_os = "android")]
const UA_STRING: &'static str =
"Mozilla/5.0 (Android; Mobile; rv:63.0) Servo/1.0 Firefox/63.0";

#[cfg(target_os = "ios")]
const UA_STRING: &'static str =
"Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X; rv:63.0) Servo/1.0 Firefox/63.0";

#[cfg(not(any(
target_os = "linux",
target_os = "windows",
target_os = "macos",
target_os = "android",
target_os = "ios"
)))]
// Use OS X user agent as fallback
const UA_STRING: &'static str =
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:63.0) Servo/1.0 Firefox/63.0";

UA_STRING
}
}

#[derive(Clone, Copy, Debug)]
@@ -687,47 +687,6 @@ impl EmbedderMethods for ServoEmbedderCallbacks {
debug!("EmbedderMethods::create_event_loop_waker");
self.waker.clone()
}

fn default_user_agent_string(&self) -> &'static str {
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
const UA_STRING: &'static str =
"Mozilla/5.0 (X11; Linux x86_64; rv:63.0) Servo/1.0 Firefox/63.0";
#[cfg(all(target_os = "linux", not(target_arch = "x86_64")))]
const UA_STRING: &'static str =
"Mozilla/5.0 (X11; Linux i686; rv:63.0) Servo/1.0 Firefox/63.0";

#[cfg(all(target_os = "windows", target_arch = "x86_64"))]
const UA_STRING: &'static str =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Servo/1.0 Firefox/63.0";
#[cfg(all(target_os = "windows", not(target_arch = "x86_64")))]
const UA_STRING: &'static str =
"Mozilla/5.0 (Windows NT 10.0; rv:63.0) Servo/1.0 Firefox/63.0";

#[cfg(all(target_os = "macos"))]
const UA_STRING: &'static str =
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:63.0) Servo/1.0 Firefox/63.0";

#[cfg(target_os = "android")]
const UA_STRING: &'static str =
"Mozilla/5.0 (Android; Mobile; rv:63.0) Servo/1.0 Firefox/63.0";

#[cfg(target_os = "ios")]
const UA_STRING: &'static str =
"Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X; rv:63.0) Servo/1.0 Firefox/63.0";

#[cfg(not(any(
target_os = "linux",
target_os = "windows",
target_os = "macos",
target_os = "android",
target_os = "ios"
)))]
// Use OS X user agent as fallback
const UA_STRING: &'static str =
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:63.0) Servo/1.0 Firefox/63.0";

UA_STRING
}
}

impl WindowMethods for ServoWindowCallbacks {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.