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, Default)]
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
131/// The URLs associated with the search engine.
132#[derive(Debug, uniffi::Record, PartialEq, Deserialize, Clone, Default)]
133pub 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")]
150pub enum SearchEngineClassification {
151    General = 2,
152    #[default]
153    Unknown = 1,
154}
155
156impl 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)]
167pub 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    /// Indicates the date until which the engine variant or subvariant is considered new
187    /// (format: YYYY-MM-DD).
188    pub is_new_until: Option<String>,
189
190    /// The user visible name of the search engine.
191    pub name: String,
192
193    /// This search engine is presented as an option that the user may enable.
194    /// The application should not include these in the default list of the
195    /// user's engines. If not supported, it should filter them out.
196    pub optional: bool,
197
198    /// The partner code for the engine. This will be inserted into parameters
199    /// which include `{partnerCode}`. May be the empty string.
200    pub partner_code: String,
201
202    /// Optional suffix that is appended to the search engine identifier
203    /// following a dash, i.e. `<identifier>-<suffix>`. If it is an empty string
204    /// no dash should be appended.
205    pub telemetry_suffix: String,
206
207    /// The URLs associated with the search engine.
208    pub urls: SearchEngineUrls,
209
210    /// A hint to the order that this engine should be in the engine list. This
211    /// is derived from the `engineOrders` section of the search configuration.
212    /// The higher the number, the nearer to the front it should be.
213    /// If the number is not specified, other methods of sorting may be relied
214    /// upon (e.g. alphabetical).
215    pub order_hint: Option<u32>,
216
217    /// The url used for reporting clicks.
218    pub click_url: Option<String>,
219}
220
221/// Details of the search engines to display to the user, generated as a result
222/// of processing the search configuration.
223#[derive(Debug, uniffi::Record, PartialEq)]
224pub struct RefinedSearchConfig {
225    /// A sorted list of engines. Clients may use the engine in the order that
226    /// this list is specified, or they may implement their own order if they
227    /// have other requirements.
228    ///
229    /// The application default engines should not be assumed from this order in
230    /// case of future changes.
231    ///
232    /// The sort order is:
233    ///
234    /// * Application Default Engine
235    /// * Application Default Engine for Private Mode (if specified & different)
236    /// * Engines sorted by descending `SearchEngineDefinition.orderHint`
237    /// * Any other engines in alphabetical order (locale based comparison)
238    pub engines: Vec<SearchEngineDefinition>,
239
240    /// The identifier of the engine that should be used for the application
241    /// default engine. If this is undefined, an error has occurred, and the
242    /// application should either default to the first engine in the engines
243    /// list or otherwise handle appropriately.
244    pub app_default_engine_id: Option<String>,
245
246    /// If specified, the identifier of the engine that should be used for the
247    /// application default engine in private browsing mode.
248    /// Only desktop uses this currently.
249    pub app_private_default_engine_id: Option<String>,
250}