search/
types.rs

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
7use 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")]
12pub 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
22impl 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")]
38pub 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")]
50pub 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)]
59pub 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")]
92pub 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)]
112pub 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    /// The display name of the URL, if any. This is useful if the URL
131    /// corresponds to a brand name distinct from the engine's brand name.
132    #[uniffi(default = None)]
133    pub display_name: Option<String>,
134
135    /// Indicates the date until which the URL is considered new
136    /// (format: YYYY-MM-DD).
137    #[uniffi(default = None)]
138    pub is_new_until: Option<String>,
139
140    /// Whether the engine's partner code should be excluded from telemetry when
141    /// this URL is visited.
142    #[uniffi(default = false)]
143    pub exclude_partner_code_from_telemetry: bool,
144
145    /// If this URL performs searches only for certain MIME types, they should
146    /// be listed here. If `None`, it's assumed the content type is text or not
147    /// relevant. This field is intended to be used for URLs like visual search,
148    /// which might support certain image types and not others. Consumers can
149    /// use it to determine whether search UI corresponding to the URL should be
150    /// shown to the user in a given context.
151    #[uniffi(default = None)]
152    pub accepted_content_types: Option<Vec<String>>,
153}
154
155/// The URLs associated with the search engine.
156#[derive(Debug, uniffi::Record, PartialEq, Deserialize, Clone, Default)]
157pub struct SearchEngineUrls {
158    /// The URL to use for searches.
159    pub search: SearchEngineUrl,
160
161    /// The URL to use for suggestions.
162    pub suggestions: Option<SearchEngineUrl>,
163
164    /// The URL to use for trending suggestions.
165    pub trending: Option<SearchEngineUrl>,
166
167    /// The URL of the search engine homepage.
168    pub search_form: Option<SearchEngineUrl>,
169
170    /// The URL to use for visual searches.
171    pub visual_search: Option<SearchEngineUrl>,
172}
173
174/// The list of acceptable classifications for a search engine.
175#[derive(Debug, uniffi::Enum, PartialEq, Deserialize, Clone, Default)]
176#[serde(rename_all = "lowercase")]
177pub enum SearchEngineClassification {
178    General = 2,
179    #[default]
180    Unknown = 1,
181}
182
183impl SearchEngineClassification {
184    pub fn as_str(&self) -> &'static str {
185        match self {
186            SearchEngineClassification::Unknown => "unknown",
187            SearchEngineClassification::General => "general",
188        }
189    }
190}
191
192/// A definition for an individual search engine to be presented to the user.
193#[derive(Debug, uniffi::Record, PartialEq, Clone, Default)]
194pub struct SearchEngineDefinition {
195    /// A list of aliases for this engine.
196    pub aliases: Vec<String>,
197
198    /// The character set this engine uses for queries.
199    pub charset: String,
200
201    /// The classification of search engine according to the main search types
202    /// (e.g. general, shopping, travel, dictionary). Currently, only marking as
203    /// a general search engine is supported.
204    /// On Android, only general search engines may be selected as "default"
205    /// search engines.
206    pub classification: SearchEngineClassification,
207
208    /// The identifier of the search engine. This is used as an internal
209    /// identifier, e.g. for saving the user's settings for the engine. It is
210    /// also used to form the base telemetry id and may be extended by telemetrySuffix.
211    pub identifier: String,
212
213    /// Indicates the date until which the engine variant or subvariant is considered new
214    /// (format: YYYY-MM-DD).
215    pub is_new_until: Option<String>,
216
217    /// The user visible name of the search engine.
218    pub name: String,
219
220    /// This search engine is presented as an option that the user may enable.
221    /// The application should not include these in the default list of the
222    /// user's engines. If not supported, it should filter them out.
223    pub optional: bool,
224
225    /// The partner code for the engine. This will be inserted into parameters
226    /// which include `{partnerCode}`. May be the empty string.
227    pub partner_code: String,
228
229    /// Optional suffix that is appended to the search engine identifier
230    /// following a dash, i.e. `<identifier>-<suffix>`. If it is an empty string
231    /// no dash should be appended.
232    pub telemetry_suffix: String,
233
234    /// The URLs associated with the search engine.
235    pub urls: SearchEngineUrls,
236
237    /// A hint to the order that this engine should be in the engine list. This
238    /// is derived from the `engineOrders` section of the search configuration.
239    /// The higher the number, the nearer to the front it should be.
240    /// If the number is not specified, other methods of sorting may be relied
241    /// upon (e.g. alphabetical).
242    pub order_hint: Option<u32>,
243
244    /// The url used for reporting clicks.
245    pub click_url: Option<String>,
246}
247
248/// Details of the search engines to display to the user, generated as a result
249/// of processing the search configuration.
250#[derive(Debug, uniffi::Record, PartialEq)]
251pub struct RefinedSearchConfig {
252    /// A sorted list of engines. Clients may use the engine in the order that
253    /// this list is specified, or they may implement their own order if they
254    /// have other requirements.
255    ///
256    /// The application default engines should not be assumed from this order in
257    /// case of future changes.
258    ///
259    /// The sort order is:
260    ///
261    /// * Application Default Engine
262    /// * Application Default Engine for Private Mode (if specified & different)
263    /// * Engines sorted by descending `SearchEngineDefinition.orderHint`
264    /// * Any other engines in alphabetical order (locale based comparison)
265    pub engines: Vec<SearchEngineDefinition>,
266
267    /// The identifier of the engine that should be used for the application
268    /// default engine. If this is undefined, an error has occurred, and the
269    /// application should either default to the first engine in the engines
270    /// list or otherwise handle appropriately.
271    pub app_default_engine_id: Option<String>,
272
273    /// If specified, the identifier of the engine that should be used for the
274    /// application default engine in private browsing mode.
275    /// Only desktop uses this currently.
276    pub app_private_default_engine_id: Option<String>,
277}