leyline/profile/
browser.rs1use crate::profile::{BrowserProfile, ChromiumBrand, Platform, PlatformIdentity, resolve_identity};
2
3include!(concat!(env!("OUT_DIR"), "/browser.rs"));
4
5struct Entry {
6 family: Family,
7 key: &'static str,
8 version: u32,
9 name: &'static str,
10 hello: Browser,
11 platforms: &'static [(&'static str, Browser)],
12 source: &'static str,
13}
14
15impl Family {
16 pub(crate) fn samesite_checks_redirect_chain(self) -> bool {
17 FAMILY_SAMESITE_REDIRECT_CHAIN[self as usize]
18 }
19}
20
21impl std::fmt::Display for Family {
22 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23 f.write_str(FAMILY_LABELS[*self as usize])
24 }
25}
26
27impl Browser {
28 pub fn all() -> &'static [Browser] {
29 ALL
30 }
31
32 fn entry(self) -> &'static Entry {
33 &ENTRIES[self as usize]
34 }
35
36 pub(crate) fn profile_key(&self) -> (&'static str, u32) {
37 let entry = self.entry();
38 (entry.key, entry.version)
39 }
40
41 #[must_use]
42 pub fn get(family: Family, version: u32) -> Option<Self> {
43 ALL.iter().copied().find(|browser| {
44 let entry = browser.entry();
45 entry.family == family && entry.version == version
46 })
47 }
48
49 #[must_use]
50 pub fn latest(family: Family) -> Self {
51 FAMILY_LATEST[family as usize]
52 }
53
54 #[must_use]
55 pub fn family(&self) -> Family {
56 self.entry().family
57 }
58
59 #[must_use]
60 pub fn version(&self) -> u32 {
61 self.entry().version
62 }
63
64 #[must_use]
65 pub(crate) fn hello_rep(self) -> Self {
66 self.entry().hello
67 }
68
69 #[must_use]
70 pub fn for_platform(self, platform: Platform) -> Self {
71 let key = platform.resolve().identity_key();
72 self.entry()
73 .platforms
74 .iter()
75 .find(|(name, _)| *name == key)
76 .map_or(self, |&(_, browser)| browser)
77 }
78
79 #[must_use]
80 pub fn identity(
81 self,
82 platform: Platform,
83 brand: Option<ChromiumBrand>,
84 ) -> Option<PlatformIdentity> {
85 resolve_identity(
86 self.platform_profile(platform),
87 platform,
88 brand.unwrap_or_default(),
89 )
90 .ok()
91 }
92
93 pub(crate) fn platform_profile(self, platform: Platform) -> &'static BrowserProfile {
94 self.for_platform(platform).profile()
95 }
96
97 pub(crate) fn profile_source(self) -> &'static str {
98 self.entry().source
99 }
100
101 pub(crate) fn default_browser() -> Self {
102 Self::latest(DEFAULT_FAMILY)
103 }
104
105 #[cfg(feature = "bench-internals")]
106 pub fn chromium_major(&self) -> Option<u32> {
107 self.profile().meta.chromium_major
108 }
109}
110
111impl Default for Browser {
112 fn default() -> Self {
113 Self::default_browser()
114 }
115}
116
117impl std::fmt::Display for Browser {
118 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
119 f.write_str(self.entry().name)
120 }
121}
122
123#[cfg(test)]
124mod tests;