Align Servo version between user agent string and servoshell about dialog (#33398)

* Align Servo version between Agen and About screen for consistency

Signed-off-by: Taym <haddadi.taym@gmail.com>

* Improve passing servo_version to desktop_ua_string

Signed-off-by: Taym <haddadi.taym@gmail.com>

---------

Signed-off-by: Taym <haddadi.taym@gmail.com>
This commit is contained in:
Taym Haddadi 2024-09-10 18:06:56 +02:00 committed by GitHub
parent 1b27a911af
commit 9346d9cc8d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1293,39 +1293,51 @@ enum UserAgent {
iOS,
}
fn default_user_agent_string_for(agent: UserAgent) -> &'static str {
fn get_servo_version() -> &'static str {
env!("CARGO_PKG_VERSION")
}
fn default_user_agent_string_for(agent: UserAgent) -> String {
let servo_version = get_servo_version();
#[cfg(all(target_os = "linux", target_arch = "x86_64", not(target_env = "ohos")))]
const DESKTOP_UA_STRING: &str =
"Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Servo/1.0 Firefox/111.0";
let desktop_ua_string =
format!("Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Servo/{servo_version} Firefox/111.0");
#[cfg(all(
target_os = "linux",
not(target_arch = "x86_64"),
not(target_env = "ohos")
))]
const DESKTOP_UA_STRING: &str =
"Mozilla/5.0 (X11; Linux i686; rv:109.0) Servo/1.0 Firefox/111.0";
let desktop_ua_string =
format!("Mozilla/5.0 (X11; Linux i686; rv:109.0) Servo/{servo_version} Firefox/111.0");
#[cfg(all(target_os = "windows", target_arch = "x86_64"))]
const DESKTOP_UA_STRING: &str =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Servo/1.0 Firefox/111.0";
let desktop_ua_string = format!(
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Servo/{servo_version} Firefox/111.0"
);
#[cfg(all(target_os = "windows", not(target_arch = "x86_64")))]
const DESKTOP_UA_STRING: &str =
"Mozilla/5.0 (Windows NT 10.0; rv:109.0) Servo/1.0 Firefox/111.0";
let desktop_ua_string =
format!("Mozilla/5.0 (Windows NT 10.0; rv:109.0) Servo/{servo_version} Firefox/111.0");
#[cfg(target_os = "macos")]
const DESKTOP_UA_STRING: &str =
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Servo/1.0 Firefox/111.0";
let desktop_ua_string = format!(
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Servo/{servo_version} Firefox/111.0"
);
#[cfg(any(target_os = "android", target_env = "ohos"))]
const DESKTOP_UA_STRING: &str = "";
let desktop_ua_string = "".to_string();
match agent {
UserAgent::Desktop => DESKTOP_UA_STRING,
UserAgent::Android => "Mozilla/5.0 (Android; Mobile; rv:109.0) Servo/1.0 Firefox/111.0",
UserAgent::OpenHarmony => "Mozilla/5.0 (OpenHarmony; Mobile; rv:109.0) Servo/1.0 Firefox/111.0",
UserAgent::iOS => {
"Mozilla/5.0 (iPhone; CPU iPhone OS 16_4 like Mac OS X; rv:109.0) Servo/1.0 Firefox/111.0"
},
UserAgent::Desktop => desktop_ua_string,
UserAgent::Android => format!(
"Mozilla/5.0 (Android; Mobile; rv:109.0) Servo/{servo_version} Firefox/111.0"
),
UserAgent::OpenHarmony => format!(
"Mozilla/5.0 (OpenHarmony; Mobile; rv:109.0) Servo/{servo_version} Firefox/111.0"
),
UserAgent::iOS => format!(
"Mozilla/5.0 (iPhone; CPU iPhone OS 16_4 like Mac OS X; rv:109.0) Servo/{servo_version} Firefox/111.0"
),
}
}