Debian Codegraph @

third_party/rust/search/src/types.rs

raw
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 //! This module defines the types that we export across the UNIFFI interface.
6
7 use serde::Deserialize;
8
9 /// The list of possible application names that are currently supported.
10 #[derive(Clone, Debug, Default, Deserialize, PartialEq, uniffi::Enum)]
11 #[serde(rename_all = "kebab-case")]
12 pub enum SearchApplicationName {
13 FirefoxAndroid = 1,
14 FirefoxIos = 2,
15 FocusAndroid = 3,
16 FocusIos = 4,
17 // The default doesn't really matter here, so we pick desktop.
18 #[default]
19 Firefox = 5,
20 }
21
22 impl SearchApplicationName {
23 pub fn as_str(&self) -> &'static str {
24 match self {
25 SearchApplicationName::Firefox => "firefox",
26 SearchApplicationName::FirefoxAndroid => "firefox-android",
27 SearchApplicationName::FocusAndroid => "focus-android",
28 SearchApplicationName::FirefoxIos => "firefox-ios",
29 SearchApplicationName::FocusIos => "focus-ios",
30 }
31 }
32 }
33
34 /// The list of possible update channels for a user's build.
35 /// Use `default` for a self-build or an unknown channel.
36 #[derive(Clone, Debug, Default, Deserialize, PartialEq, uniffi::Enum)]
37 #[serde(rename_all = "lowercase")]
38 pub enum SearchUpdateChannel {
39 Nightly = 1,
40 Aurora = 2,
41 Beta = 3,
42 Release = 4,
43 Esr = 5,
44 #[default]
45 Default = 6,
46 }
47
48 #[derive(Clone, Debug, Default, Deserialize, PartialEq, uniffi::Enum)]
49 #[serde(rename_all = "camelCase")]
50 pub enum SearchDeviceType {
51 Smartphone = 1,
52 Tablet = 2,
53 #[default]
54 None = 3,
55 }
56
57 /// The user's environment that is used for filtering the search configuration.
58 #[derive(Clone, Debug, uniffi::Record, Default)]
59 pub struct SearchUserEnvironment {
60 /// The current locale of the application that the user is using.
61 pub locale: String,
62
63 /// The home region that the user is currently identified as being within.
64 /// On desktop & android there is a 14 day lag after detecting a region
65 /// change before the home region changes. TBD: iOS?
66 pub region: String,
67
68 /// The update channel of the user's build.
69 pub update_channel: SearchUpdateChannel,
70
71 /// The distribution id for the user's build.
72 pub distribution_id: String,
73
74 /// The search related experiment id that the user is included within. On
75 /// desktop this is the `searchConfiguration.experiment` variable.
76 pub experiment: String,
77
78 /// The application name that the user is using.
79 pub app_name: SearchApplicationName,
80
81 /// The application version that the user is using.
82 pub version: String,
83
84 /// The device type that the user is using.
85 pub device_type: SearchDeviceType,
86 }
87
88 /// Parameter definitions for search engine URLs. The name property is always
89 /// specified, along with one of value, experiment_config or search_access_point.
90 #[derive(Debug, uniffi::Record, PartialEq, Deserialize, Clone)]
91 #[serde(rename_all = "camelCase")]
92 pub struct SearchUrlParam {
93 /// The name of the parameter in the url.
94 pub name: String,
95
96 /// The parameter value, this may be a static value, or additionally contain
97 /// a parameter replacement, e.g. `{inputEncoding}`. For the partner code
98 /// parameter, this field should be `{partnerCode}`.
99 pub value: Option<String>,
100
101 /// Same as value but only used if Services.polices.isEnterprise is true. Overrides other parameters of the same name.
102 pub enterprise_value: Option<String>,
103
104 /// The value for the parameter will be derived from the equivalent experiment
105 /// configuration value.
106 /// Only desktop uses this currently.
107 pub experiment_config: Option<String>,
108 }
109
110 /// Defines an individual search engine URL.
111 #[derive(Debug, uniffi::Record, PartialEq, Deserialize, Clone, Default)]
112 pub struct SearchEngineUrl {
113 /// The PrePath and FilePath of the URL. May include variables for engines
114 /// which have a variable FilePath, e.g. `{searchTerms}` for when a search
115 /// term is within the path of the url.
116 pub base: String,
117
118 /// The HTTP method to use to send the request (`GET` or `POST`).
119 /// If the engine definition has not specified the method, it defaults to GET.
120 pub method: String,
121
122 /// The parameters for this URL.
123 pub params: Vec<SearchUrlParam>,
124
125 /// The name of the query parameter for the search term. Automatically
126 /// appended to the end of the query. This may be skipped if `{searchTerms}`
127 /// is included in the base.
128 pub search_term_param_name: Option<String>,
129 }
130
131 /// The URLs associated with the search engine.
132 #[derive(Debug, uniffi::Record, PartialEq, Deserialize, Clone, Default)]
133 pub struct SearchEngineUrls {
134 /// The URL to use for searches.
135 pub search: SearchEngineUrl,
136
137 /// The URL to use for suggestions.
138 pub suggestions: Option<SearchEngineUrl>,
139
140 /// The URL to use for trending suggestions.
141 pub trending: Option<SearchEngineUrl>,
142
143 /// The URL of the search engine homepage.
144 pub search_form: Option<SearchEngineUrl>,
145 }
146
147 /// The list of acceptable classifications for a search engine.
148 #[derive(Debug, uniffi::Enum, PartialEq, Deserialize, Clone, Default)]
149 #[serde(rename_all = "lowercase")]
150 pub enum SearchEngineClassification {
151 General = 2,
152 #[default]
153 Unknown = 1,
154 }
155
156 impl SearchEngineClassification {
157 pub fn as_str(&self) -> &'static str {
158 match self {
159 SearchEngineClassification::Unknown => "unknown",
160 SearchEngineClassification::General => "general",
161 }
162 }
163 }
164
165 /// A definition for an individual search engine to be presented to the user.
166 #[derive(Debug, uniffi::Record, PartialEq, Clone, Default)]
167 pub struct SearchEngineDefinition {
168 /// A list of aliases for this engine.
169 pub aliases: Vec<String>,
170
171 /// The character set this engine uses for queries.
172 pub charset: String,
173
174 /// The classification of search engine according to the main search types
175 /// (e.g. general, shopping, travel, dictionary). Currently, only marking as
176 /// a general search engine is supported.
177 /// On Android, only general search engines may be selected as "default"
178 /// search engines.
179 pub classification: SearchEngineClassification,
180
181 /// The identifier of the search engine. This is used as an internal
182 /// identifier, e.g. for saving the user's settings for the engine. It is
183 /// also used to form the base telemetry id and may be extended by telemetrySuffix.
184 pub identifier: String,
185
186 /// The user visible name of the search engine.
187 pub name: String,
188
189 /// This search engine is presented as an option that the user may enable.
190 /// The application should not include these in the default list of the
191 /// user's engines. If not supported, it should filter them out.
192 pub optional: bool,
193
194 /// The partner code for the engine. This will be inserted into parameters
195 /// which include `{partnerCode}`. May be the empty string.
196 pub partner_code: String,
197
198 /// Optional suffix that is appended to the search engine identifier
199 /// following a dash, i.e. `<identifier>-<suffix>`. If it is an empty string
200 /// no dash should be appended.
201 pub telemetry_suffix: String,
202
203 /// The URLs associated with the search engine.
204 pub urls: SearchEngineUrls,
205
206 /// A hint to the order that this engine should be in the engine list. This
207 /// is derived from the `engineOrders` section of the search configuration.
208 /// The higher the number, the nearer to the front it should be.
209 /// If the number is not specified, other methods of sorting may be relied
210 /// upon (e.g. alphabetical).
211 pub order_hint: Option<u32>,
212
213 /// The url used for reporting clicks.
214 pub click_url: Option<String>,
215 }
216
217 /// Details of the search engines to display to the user, generated as a result
218 /// of processing the search configuration.
219 #[derive(Debug, uniffi::Record, PartialEq)]
220 pub struct RefinedSearchConfig {
221 /// A sorted list of engines. Clients may use the engine in the order that
222 /// this list is specified, or they may implement their own order if they
223 /// have other requirements.
224 ///
225 /// The application default engines should not be assumed from this order in
226 /// case of future changes.
227 ///
228 /// The sort order is:
229 ///
230 /// * Application Default Engine
231 /// * Application Default Engine for Private Mode (if specified & different)
232 /// * Engines sorted by descending `SearchEngineDefinition.orderHint`
233 /// * Any other engines in alphabetical order (locale based comparison)
234 pub engines: Vec<SearchEngineDefinition>,
235
236 /// The identifier of the engine that should be used for the application
237 /// default engine. If this is undefined, an error has occurred, and the
238 /// application should either default to the first engine in the engines
239 /// list or otherwise handle appropriately.
240 pub app_default_engine_id: Option<String>,
241
242 /// If specified, the identifier of the engine that should be used for the
243 /// application default engine in private browsing mode.
244 /// Only desktop uses this currently.
245 pub app_private_default_engine_id: Option<String>,
246 }