Backed out changeset f0a2aa2ffe6d (bug 1832704) for causing xpc failures in toolkit...
[gecko.git] / toolkit / components / search / nsISearchService.idl
blobfc98833678cd7772d136fb84e96c86761010e046
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/. */
5 #include "nsISupports.idl"
7 interface nsIURI;
8 interface nsIInputStream;
10 [scriptable, uuid(5799251f-5b55-4df7-a9e7-0c27812c469a)]
11 interface nsISearchSubmission : nsISupports
13 /**
14 * The POST data associated with a search submission, wrapped in a MIME
15 * input stream. May be null.
17 readonly attribute nsIInputStream postData;
19 /**
20 * The URI to submit a search to.
22 readonly attribute nsIURI uri;
25 [scriptable, uuid(620bd920-0491-48c8-99a8-d6047e64802d)]
26 interface nsISearchEngine : nsISupports
28 /**
29 * Gets a nsISearchSubmission object that contains information about what to
30 * send to the search engine, including the URI and postData, if applicable.
32 * @param searchTerms
33 * The search term(s) for the submission.
35 * @param responseType [optional]
36 * The MIME type that we'd like to receive in response
37 * to this submission. If null, will default to "text/html".
39 * @param purpose [optional]
40 * A string that indicates the context of the search request. This may then
41 * be used to provide different submission data depending on the context.
43 * @returns nsISearchSubmission
44 * The submission data. If no appropriate submission can be determined for
45 * the request type, this may be null.
47 nsISearchSubmission getSubmission(in AString searchTerms,
48 [optional] in AString responseType,
49 [optional] in AString purpose);
50 /**
51 * Returns the search term of a possible search result URI if and only if:
52 * - The URI has the same scheme, host, and path as the engine.
53 * - All query parameters of the URI have a matching name and value in the engine.
54 * - An exception to the equality check is the engine's termsParameterName
55 * value, which contains a placeholder, i.e. {searchTerms}.
56 * - If an engine has query parameters with "null" values, they will be ignored.
58 * @param uri
59 * A URI that may or may not be from a search result matching the engine.
61 * @returns A string representing the termsParameterName value of the URI,
62 * or an empty string if the URI isn't matched to the engine.
64 AString searchTermFromResult(in nsIURI uri);
66 /**
67 * Returns the name of the parameter used for the search terms for a submission
68 * URL of type `SearchUtils.URL_TYPE.SEARCH`.
70 * @returns A string which is the name of the parameter, or empty string
71 * if no parameter cannot be found or is not supported (e.g. POST).
73 readonly attribute AString searchUrlQueryParamName;
75 /**
76 * Returns the public suffix for the submission URL of type
77 * `SearchUtils.URL_TYPE.SEARCH`.
79 * @returns A string which is a known public suffix, or empty string
80 * if one cannot be found.
82 readonly attribute AString searchUrlPublicSuffix;
84 /**
85 * Determines whether the engine can return responses in the given
86 * MIME type. Returns true if the engine spec has a URL with the
87 * given responseType, false otherwise.
89 * @param responseType
90 * The MIME type to check for
92 boolean supportsResponseType(in AString responseType);
94 /**
95 * Returns a string with the URL to an engine's icon matching both width and
96 * height. Returns null if icon with specified dimensions is not found.
98 * @param width
99 * Width of the requested icon.
100 * @param height
101 * Height of the requested icon.
103 AString getIconURLBySize(in long width, in long height);
106 * Gets an array of all available icons. Each entry is an object with
107 * width, height and url properties. width and height are numeric and
108 * represent the icon's dimensions. url is a string with the URL for
109 * the icon.
111 jsval getIcons();
114 * Opens a speculative connection to the engine's search URI
115 * (and suggest URI, if different) to reduce request latency
117 * @param options
118 * An object that must contain the following fields:
119 * {window} the content window for the window performing the search
120 * {originAttributes} the originAttributes for performing the search
122 * @throws NS_ERROR_INVALID_ARG if options is omitted or lacks required
123 * elemeents
125 void speculativeConnect(in jsval options);
128 * An optional shortcut alias for the engine.
129 * When not an empty string, this is a unique identifier.
131 attribute AString alias;
134 * An array of aliases including the user defined alias and
135 * ones specified by the webextensions keywords field.
137 readonly attribute Array<AString> aliases;
140 * A text description describing the engine.
142 readonly attribute AString description;
145 * Whether the engine should be hidden from the user.
147 attribute boolean hidden;
150 * Whether the associated one off button should be hidden from the user.
152 attribute boolean hideOneOffButton;
155 * A nsIURI corresponding to the engine's icon, stored locally. May be null.
157 readonly attribute nsIURI iconURI;
160 * The display name of the search engine. This is a unique identifier.
162 readonly attribute AString name;
165 * The display of the search engine id. This is a unique identifier.
167 readonly attribute AString id;
170 * The searchForm URL points to the engine's organic search page. This should
171 * not contain neither search term parameters nor partner codes, but may
172 * contain parameters which set the engine in the correct way.
174 * This URL is typically the prePath and filePath of the search submission URI,
175 * but may vary for different engines. For example, some engines may use a
176 * different domain, e.g. https://sub.example.com for the search URI but
177 * https://example.org/ for the organic search page.
179 readonly attribute AString searchForm;
182 * A boolean to indicate if we should send an attribution request to Mozilla's
183 * server.
185 readonly attribute boolean sendAttributionRequest;
188 * The identifier to use for this engine when submitting to telemetry.
190 readonly attribute AString telemetryId;
193 * An optional unique identifier for this search engine within the context of
194 * the distribution, as provided by the distributing entity.
196 readonly attribute AString identifier;
199 * Whether or not this engine is provided by the application, e.g. it is
200 * in the list of configured search engines.
202 readonly attribute boolean isAppProvided;
205 * Whether or not this engine is an in-memory only search engine.
206 * These engines are typically application provided or policy engines,
207 * where they are loaded every time on SearchService initialization
208 * using the policy JSON or the extension manifest. Minimal details of the
209 * in-memory engines are saved to disk, but they are never loaded
210 * from the user's saved settings file.
212 readonly attribute boolean inMemory;
215 * Whether or not this engine is a "general" search engine, e.g. is it for
216 * generally searching the web, or does it have a specific purpose like
217 * shopping.
219 readonly attribute boolean isGeneralPurposeEngine;
222 * The domain from which search results are returned for this engine.
224 * @return the domain of the the search URL.
226 readonly attribute AString searchUrlDomain;
230 [scriptable, uuid(0dc93e51-a7bf-4a16-862d-4b3469ff6206)]
231 interface nsISearchParseSubmissionResult : nsISupports
234 * The search engine associated with the URL passed in to
235 * nsISearchEngine::parseSubmissionURL, or null if the URL does not represent
236 * a search submission.
238 readonly attribute nsISearchEngine engine;
241 * String containing the sought terms. This can be an empty string in case no
242 * terms were specified or the URL does not represent a search submission.
244 readonly attribute AString terms;
247 * The name of the query parameter used by `engine` for queries. E.g. "q".
249 readonly attribute AString termsParameterName;
252 [scriptable, uuid(0301834b-2630-440e-8b98-db8dc55f34b9)]
253 interface nsISearchService : nsISupports
255 const unsigned long ERROR_DOWNLOAD_FAILURE = 0x1;
256 const unsigned long ERROR_DUPLICATE_ENGINE = 0x2;
257 const unsigned long ERROR_ENGINE_CORRUPTED = 0x3;
259 const unsigned short CHANGE_REASON_UNKNOWN = 0x0;
260 const unsigned short CHANGE_REASON_USER = 0x1;
261 const unsigned short CHANGE_REASON_USER_PRIVATE_SPLIT = 0x2;
262 const unsigned short CHANGE_REASON_USER_SEARCHBAR = 0x3;
263 const unsigned short CHANGE_REASON_USER_SEARCHBAR_CONTEXT = 0x4;
264 const unsigned short CHANGE_REASON_ADDON_INSTALL = 0x5;
265 const unsigned short CHANGE_REASON_ADDON_UNINSTALL = 0x6;
266 const unsigned short CHANGE_REASON_CONFIG = 0x7;
267 const unsigned short CHANGE_REASON_LOCALE = 0x8;
268 const unsigned short CHANGE_REASON_REGION = 0x9;
269 const unsigned short CHANGE_REASON_EXPERIMENT = 0xA;
270 const unsigned short CHANGE_REASON_ENTERPRISE = 0xB;
271 const unsigned short CHANGE_REASON_UITOUR = 0xC;
274 * Start asynchronous initialization.
276 * The promise is resolved once initialization is complete, which may be
277 * immediately, if initialization has already been completed by some previous
278 * call to this method.
279 * This method should only be called when you need or want to wait for the
280 * full initialization of the search service.
282 Promise init();
285 * Determine whether initialization has been completed.
287 * Clients of the service can use this attribute to quickly determine whether
288 * initialization is complete, and decide to trigger some immediate treatment,
289 * to launch asynchronous initialization or to bailout.
291 * Note that this attribute does not indicate that initialization has succeeded.
293 * @return |true| if the search service is now initialized, |false| if
294 * initialization has not been triggered yet.
296 readonly attribute bool isInitialized;
299 * Determine whether initialization has been completed successfully.
302 readonly attribute bool hasSuccessfullyInitialized;
306 * Runs background checks; Designed to be run on idle.
308 Promise runBackgroundChecks();
311 * Resets the default engine to its app default engine value.
313 Promise resetToAppDefaultEngine();
316 * Adds a new Open Search engine from the file at the supplied URI.
318 * @param engineURL
319 * The URL to the search engine's description file.
321 * @param iconURL
322 * A URL string to an icon file to be used as the search engine's
323 * icon. This value may be overridden by an icon specified in the
324 * engine description file.
326 * @throws NS_ERROR_FAILURE if the description file cannot be successfully
327 * loaded.
329 Promise addOpenSearchEngine(in AString engineURL, in AString iconURL);
332 * Adds a new search engine defined by the user.
334 * @param name
335 * The name of the engine.
336 * @param url
337 * The url of the engine with %s denoting where to
338 * replace the search term.
339 * @param alias [optional]
340 * The alias to refer to the engine.
342 Promise addUserEngine(in AString name,
343 in AString url,
344 [optional] in AString alias);
347 * Adds search providers to the search service. If the search
348 * service is configured to load multiple locales for the extension,
349 * it may load more than one search engine. If called directly
350 * ensure the extension has been initialised.
352 * @param extension
353 * The extension to load from.
354 * @returns Promise that resolves when finished.
356 Promise addEnginesFromExtension(in jsval extension);
359 * Un-hides all engines in the set of engines returned by getAppProvidedEngines.
361 void restoreDefaultEngines();
364 * Returns an engine with the specified alias.
366 * @param alias
367 * The search engine's alias.
368 * @returns The corresponding nsISearchEngine object, or null if it doesn't
369 * exist.
371 Promise getEngineByAlias(in AString alias);
374 * Returns an engine with the specified name.
376 * @param aEngineName
377 * The name of the engine.
378 * @returns The corresponding nsISearchEngine object, or null if it doesn't
379 * exist.
381 nsISearchEngine getEngineByName(in AString aEngineName);
385 * Returns an engine with the specified Id.
387 * @param aEngineId
388 * The Id of the engine.
389 * @returns The corresponding nsISearchEngine object, or null if it doesn't
390 * exist.
392 nsISearchEngine getEngineById(in AString aEngineId);
395 * Returns an array of all installed search engines.
396 * The array is sorted either to the user requirements or the default order.
398 * @returns an array of nsISearchEngine objects.
400 Promise getEngines();
403 * Returns an array of all installed search engines whose hidden attribute is
404 * false.
405 * The array is sorted either to the user requirements or the default order.
407 * @returns an array of nsISearchEngine objects.
409 Promise getVisibleEngines();
412 * Returns an array of all default search engines. This includes all loaded
413 * engines that aren't in the user's profile directory.
414 * The array is sorted to the default order.
416 * @returns an array of nsISearchEngine objects.
418 Promise getAppProvidedEngines();
421 * Returns an array of search engines installed by a given extension.
423 * @returns an array of nsISearchEngine objects.
425 Promise getEnginesByExtensionID(in AString extensionID);
428 * Moves a visible search engine.
430 * @param engine
431 * The engine to move.
432 * @param newIndex
433 * The engine's new index in the set of visible engines.
435 * @throws NS_ERROR_FAILURE if newIndex is out of bounds, or if engine is
436 * hidden.
438 Promise moveEngine(in nsISearchEngine engine, in long newIndex);
441 * Removes the search engine. If the search engine is installed in a global
442 * location, this will just hide the engine. If the engine is in the user's
443 * profile directory, it will be removed from disk.
445 * @param engine
446 * The engine to remove.
448 Promise removeEngine(in nsISearchEngine engine);
451 * Notify nsSearchService that an extension has been removed. Removes any
452 * engines that are associated with that extension.
454 * @param id
455 * The id of the extension.
457 Promise removeWebExtensionEngine(in AString id);
460 * The Application Default Engine object that is the default for this region,
461 * ignoring changes the user may have subsequently made.
463 readonly attribute nsISearchEngine appDefaultEngine;
466 * The Application Default Engine object that is the default for this region when in
467 * private browsing mode, ignoring changes the user may have subsequently made.
469 readonly attribute nsISearchEngine appPrivateDefaultEngine;
472 * The currently active search engine.
473 * Unless the application doesn't ship any search plugin, this should never
474 * be null. If the currently active engine is removed, this attribute will
475 * fallback first to the application default engine if it's not hidden, then to
476 * the first visible engine, and as a last resort it will unhide the app
477 * default engine.
479 attribute nsISearchEngine defaultEngine;
481 Promise getDefault();
482 Promise setDefault(in nsISearchEngine engine, in unsigned short changeSource);
485 * The currently active search engine for private browsing mode.
486 * @see defaultEngine.
488 attribute nsISearchEngine defaultPrivateEngine;
490 Promise getDefaultPrivate();
491 Promise setDefaultPrivate(
492 in nsISearchEngine engine,
493 in unsigned short changeSource);
496 * Whether to display the "Search in Private Window" result in the urlbar.
498 readonly attribute boolean separatePrivateDefaultUrlbarResultEnabled;
501 * Allows the add-on manager to discover if a WebExtension based search engine
502 * may change the default to an application provided search engine.
503 * If that WebExtension is on the allow list, then it will override the
504 * built-in engine's urls and parameters.
506 * @param extension
507 * The extension to load from.
508 * @returns An object with two booleans:
509 * - canChangeToAppProvided: indicates if the WebExtension engine may
510 * set the named engine as default e.g. it is application provided.
511 * - canInstallEngine: indicates if the WebExtension engine may be
512 * installed, e.g. it is not an app-provided engine.
514 Promise maybeSetAndOverrideDefault(in jsval extension);
517 * Gets a representation of the default engine in an anonymized JSON
518 * string suitable for recording in the Telemetry environment.
520 * @return {object} result
521 * contains anonymized info about the default engine(s).
522 * @return {string} result.defaultSearchEngine
523 * contains the telemetry id of the default engine.
524 * @return {object} result.defaultSearchEngineData
525 * contains information about the default engine:
526 * name, loadPath, original submissionURL
527 * @return {string} [result.defaultPrivateSearchEngine]
528 * only returned if the preference for having a separate engine in private
529 * mode is turned on.
530 * contains the telemetry id of the default engine for private browsing mode.
531 * @return {object} [result.defaultPrivateSearchEngineData]
532 * only returned if the preference for having a separate engine in private
533 * mode is turned on.
534 * contains information about the default engine for private browsing mode:
535 * name, loadPath, original submissionURL
537 jsval getDefaultEngineInfo();
540 * Determines if the provided URL represents results from a search engine, and
541 * provides details about the match.
543 * The lookup mechanism checks whether the domain name and path of the
544 * provided HTTP or HTTPS URL matches one of the known values for the visible
545 * search engines. The match does not depend on which of the schemes is used.
546 * The expected URI parameter for the search terms must exist in the query
547 * string, but other parameters are ignored.
549 * @param url
550 * String containing the URL to parse, for example
551 * "https://www.google.com/search?q=terms".
553 nsISearchParseSubmissionResult parseSubmissionURL(in AString url);