nsIBrowserSearchService.idl 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  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. #include "nsISupports.idl"
  5. interface nsIURI;
  6. interface nsIInputStream;
  7. [scriptable, uuid(72599f7a-3712-4b93-90e9-86127006cd68)]
  8. interface nsISearchSubmission : nsISupports
  9. {
  10. /**
  11. * The POST data associated with a search submission, wrapped in a MIME
  12. * input stream. May be null.
  13. */
  14. readonly attribute nsIInputStream postData;
  15. /**
  16. * The URI to submit a search to.
  17. */
  18. readonly attribute nsIURI uri;
  19. /**
  20. * The POST data associated with a search submission as an
  21. * application/x-www-form-urlencoded string. May be null.
  22. */
  23. readonly attribute AString postDataString;
  24. };
  25. [scriptable, uuid(620bd920-0491-48c8-99a8-d6047e64802d)]
  26. interface nsISearchEngine : nsISupports
  27. {
  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.
  31. *
  32. * @param data
  33. * Data to add to the submission object.
  34. * i.e. the search terms.
  35. *
  36. * @param responseType [optional]
  37. * The MIME type that we'd like to receive in response
  38. * to this submission. If null, will default to "text/html".
  39. *
  40. * @param purpose [optional]
  41. * A string meant to indicate the context of the search request. This
  42. * allows the search service to provide a different nsISearchSubmission
  43. * depending on e.g. where the search is triggered in the UI.
  44. *
  45. * @returns A nsISearchSubmission object that contains information about what
  46. * to send to the search engine. If no submission can be
  47. * obtained for the given responseType, returns null.
  48. */
  49. nsISearchSubmission getSubmission(in AString data,
  50. [optional] in AString responseType,
  51. [optional] in AString purpose);
  52. /**
  53. * Adds a parameter to the search engine's submission data. This should only
  54. * be called on engines created via addEngineWithDetails.
  55. *
  56. * @param name
  57. * The parameter's name. Must not be null.
  58. *
  59. * @param value
  60. * The value to pass. If value is "{searchTerms}", it will be
  61. * substituted with the user-entered data when retrieving the
  62. * submission. Must not be null.
  63. *
  64. * @param responseType
  65. * Since an engine can have several different request URLs,
  66. * differentiated by response types, this parameter selects
  67. * a request to add parameters to. If null, will default
  68. * to "text/html"
  69. *
  70. * @throws NS_ERROR_FAILURE if the search engine is read-only.
  71. * @throws NS_ERROR_INVALID_ARG if name or value are null.
  72. */
  73. void addParam(in AString name, in AString value, in AString responseType);
  74. /**
  75. * Determines whether the engine can return responses in the given
  76. * MIME type. Returns true if the engine spec has a URL with the
  77. * given responseType, false otherwise.
  78. *
  79. * @param responseType
  80. * The MIME type to check for
  81. */
  82. boolean supportsResponseType(in AString responseType);
  83. /**
  84. * Returns a string with the URL to an engine's icon matching both width and
  85. * height. Returns null if icon with specified dimensions is not found.
  86. *
  87. * @param width
  88. * Width of the requested icon.
  89. * @param height
  90. * Height of the requested icon.
  91. */
  92. AString getIconURLBySize(in long width, in long height);
  93. /**
  94. * Gets an array of all available icons. Each entry is an object with
  95. * width, height and url properties. width and height are numeric and
  96. * represent the icon's dimensions. url is a string with the URL for
  97. * the icon.
  98. */
  99. jsval getIcons();
  100. /**
  101. * Opens a speculative connection to the engine's search URI
  102. * (and suggest URI, if different) to reduce request latency
  103. *
  104. * @param options
  105. * An object that must contain the following fields:
  106. * {window} the content window for the window performing the search
  107. *
  108. * @throws NS_ERROR_INVALID_ARG if options is omitted or lacks required
  109. * elemeents
  110. */
  111. void speculativeConnect(in jsval options);
  112. /**
  113. * An optional shortcut alias for the engine.
  114. * When non-null, this is a unique identifier.
  115. */
  116. attribute AString alias;
  117. /**
  118. * A text description describing the engine.
  119. */
  120. readonly attribute AString description;
  121. /**
  122. * Whether the engine should be hidden from the user.
  123. */
  124. attribute boolean hidden;
  125. /**
  126. * A nsIURI corresponding to the engine's icon, stored locally. May be null.
  127. */
  128. readonly attribute nsIURI iconURI;
  129. /**
  130. * The display name of the search engine. This is a unique identifier.
  131. */
  132. readonly attribute AString name;
  133. /**
  134. * A URL string pointing to the engine's search form.
  135. */
  136. readonly attribute AString searchForm;
  137. /**
  138. * An optional unique identifier for this search engine within the context of
  139. * the distribution, as provided by the distributing entity.
  140. */
  141. readonly attribute AString identifier;
  142. /**
  143. * Gets a string representing the hostname from which search results for a
  144. * given responseType are returned, minus the leading "www." (if present).
  145. * This can be specified as an url attribute in the engine description file,
  146. * but will default to host from the <Url>'s template otherwise.
  147. *
  148. * @param responseType [optional]
  149. * The MIME type to get resultDomain for. Defaults to "text/html".
  150. *
  151. * @return the resultDomain for the given responseType.
  152. */
  153. AString getResultDomain([optional] in AString responseType);
  154. };
  155. [scriptable, uuid(0dc93e51-a7bf-4a16-862d-4b3469ff6206)]
  156. interface nsISearchParseSubmissionResult : nsISupports
  157. {
  158. /**
  159. * The search engine associated with the URL passed in to
  160. * nsISearchEngine::parseSubmissionURL, or null if the URL does not represent
  161. * a search submission.
  162. */
  163. readonly attribute nsISearchEngine engine;
  164. /**
  165. * String containing the sought terms. This can be an empty string in case no
  166. * terms were specified or the URL does not represent a search submission.
  167. */
  168. readonly attribute AString terms;
  169. /**
  170. * The offset of the string |terms| in the URL passed in to
  171. * nsISearchEngine::parseSubmissionURL, or -1 if the URL does not represent
  172. * a search submission.
  173. */
  174. readonly attribute long termsOffset;
  175. /**
  176. * The length of the |terms| in the original encoding of the URL passed in to
  177. * nsISearchEngine::parseSubmissionURL. If the search term in the original
  178. * URL is encoded then this will be bigger than |terms.length|.
  179. */
  180. readonly attribute long termsLength;
  181. };
  182. [scriptable, uuid(9fc39136-f08b-46d3-b232-96f4b7b0e235)]
  183. interface nsISearchInstallCallback : nsISupports
  184. {
  185. const unsigned long ERROR_UNKNOWN_FAILURE = 0x1;
  186. const unsigned long ERROR_DUPLICATE_ENGINE = 0x2;
  187. /**
  188. * Called to indicate that the engine addition process succeeded.
  189. *
  190. * @param engine
  191. * The nsISearchEngine object that was added (will not be null).
  192. */
  193. void onSuccess(in nsISearchEngine engine);
  194. /**
  195. * Called to indicate that the engine addition process failed.
  196. *
  197. * @param errorCode
  198. * One of the ERROR_* values described above indicating the cause of
  199. * the failure.
  200. */
  201. void onError(in unsigned long errorCode);
  202. };
  203. /**
  204. * Callback for asynchronous initialization of nsIBrowserSearchService
  205. */
  206. [scriptable, function, uuid(02256156-16e4-47f1-9979-76ff98ceb590)]
  207. interface nsIBrowserSearchInitObserver : nsISupports
  208. {
  209. /**
  210. * Called once initialization of the browser search service is complete.
  211. *
  212. * @param aStatus The status of that service.
  213. */
  214. void onInitComplete(in nsresult aStatus);
  215. };
  216. [scriptable, uuid(150ef720-bbe2-4169-b9f3-ef7ec0654ced)]
  217. interface nsIBrowserSearchService : nsISupports
  218. {
  219. /**
  220. * Start asynchronous initialization.
  221. *
  222. * The callback is triggered once initialization is complete, which may be
  223. * immediately, if initialization has already been completed by some previous
  224. * call to this method. The callback is always invoked asynchronously.
  225. *
  226. * @param aObserver An optional object observing the end of initialization.
  227. */
  228. void init([optional] in nsIBrowserSearchInitObserver aObserver);
  229. /**
  230. * Determine whether initialization has been completed.
  231. *
  232. * Clients of the service can use this attribute to quickly determine whether
  233. * initialization is complete, and decide to trigger some immediate treatment,
  234. * to launch asynchronous initialization or to bailout.
  235. *
  236. * Note that this attribute does not indicate that initialization has succeeded.
  237. *
  238. * @return |true| if the search service is now initialized, |false| if
  239. * initialization has not been triggered yet.
  240. */
  241. readonly attribute bool isInitialized;
  242. /**
  243. * Resets the default engine to its original value.
  244. */
  245. void resetToOriginalDefaultEngine();
  246. /**
  247. * Checks if an EngineURL of type URLTYPE_SEARCH_HTML exists for
  248. * any engine, with a matching method, template URL, and query params.
  249. *
  250. * @param method
  251. * The HTTP request method used when submitting a search query.
  252. * Must be a case insensitive value of either "get" or "post".
  253. *
  254. * @param url
  255. * The URL to which search queries should be sent.
  256. * Must not be null.
  257. *
  258. * @param formData
  259. * The un-sorted form data used as query params.
  260. */
  261. boolean hasEngineWithURL(in AString method, in AString url, in jsval formData);
  262. /**
  263. * Adds a new search engine from the file at the supplied URI, optionally
  264. * asking the user for confirmation first. If a confirmation dialog is
  265. * shown, it will offer the option to begin using the newly added engine
  266. * right away.
  267. *
  268. * @param engineURL
  269. * The URL to the search engine's description file.
  270. *
  271. * @param dataType
  272. * Obsolete, the value is ignored.
  273. *
  274. * @param iconURL
  275. * A URL string to an icon file to be used as the search engine's
  276. * icon. This value may be overridden by an icon specified in the
  277. * engine description file.
  278. *
  279. * @param confirm
  280. * A boolean value indicating whether the user should be asked for
  281. * confirmation before this engine is added to the list. If this
  282. * value is false, the engine will be added to the list upon successful
  283. * load, but it will not be selected as the current engine.
  284. *
  285. * @param callback
  286. * A nsISearchInstallCallback that will be notified when the
  287. * addition is complete, or if the addition fails. It will not be
  288. * called if addEngine throws an exception.
  289. *
  290. * @throws NS_ERROR_FAILURE if the description file cannot be successfully
  291. * loaded.
  292. */
  293. void addEngine(in AString engineURL, in long dataType, in AString iconURL,
  294. in boolean confirm, [optional] in nsISearchInstallCallback callback);
  295. /**
  296. * Adds a new search engine, without asking the user for confirmation and
  297. * without starting to use it right away.
  298. *
  299. * @param name
  300. * The search engine's name. Must be unique. Must not be null.
  301. *
  302. * @param iconURL
  303. * Optional: A URL string pointing to the icon to be used to represent
  304. * the engine.
  305. *
  306. * @param alias
  307. * Optional: A unique shortcut that can be used to retrieve the
  308. * search engine.
  309. *
  310. * @param description
  311. * Optional: a description of the search engine.
  312. *
  313. * @param method
  314. * The HTTP request method used when submitting a search query.
  315. * Must be a case insensitive value of either "get" or "post".
  316. *
  317. * @param url
  318. * The URL to which search queries should be sent.
  319. * Must not be null.
  320. *
  321. * @param extensionID [optional]
  322. * Optional: The correct extensionID if called by an add-on.
  323. */
  324. void addEngineWithDetails(in AString name,
  325. in AString iconURL,
  326. in AString alias,
  327. in AString description,
  328. in AString method,
  329. in AString url,
  330. [optional] in AString extensionID);
  331. /**
  332. * Un-hides all engines installed in the directory corresponding to
  333. * the directory service's NS_APP_SEARCH_DIR key. (i.e. the set of
  334. * engines returned by getDefaultEngines)
  335. */
  336. void restoreDefaultEngines();
  337. /**
  338. * Returns an engine with the specified alias.
  339. *
  340. * @param alias
  341. * The search engine's alias.
  342. * @returns The corresponding nsISearchEngine object, or null if it doesn't
  343. * exist.
  344. */
  345. nsISearchEngine getEngineByAlias(in AString alias);
  346. /**
  347. * Returns an engine with the specified name.
  348. *
  349. * @param aEngineName
  350. * The name of the engine.
  351. * @returns The corresponding nsISearchEngine object, or null if it doesn't
  352. * exist.
  353. */
  354. nsISearchEngine getEngineByName(in AString aEngineName);
  355. /**
  356. * Returns an array of all installed search engines.
  357. *
  358. * @returns an array of nsISearchEngine objects.
  359. */
  360. void getEngines(
  361. [optional] out unsigned long engineCount,
  362. [retval, array, size_is(engineCount)] out nsISearchEngine engines);
  363. /**
  364. * Returns an array of all installed search engines whose hidden attribute is
  365. * false.
  366. *
  367. * @returns an array of nsISearchEngine objects.
  368. */
  369. void getVisibleEngines(
  370. [optional] out unsigned long engineCount,
  371. [retval, array, size_is(engineCount)] out nsISearchEngine engines);
  372. /**
  373. * Returns an array of all default search engines. This includes all loaded
  374. * engines that aren't in the user's profile directory
  375. * (NS_APP_USER_SEARCH_DIR).
  376. *
  377. * @returns an array of nsISearchEngine objects.
  378. */
  379. void getDefaultEngines(
  380. [optional] out unsigned long engineCount,
  381. [retval, array, size_is(engineCount)] out nsISearchEngine engines);
  382. /**
  383. * Moves a visible search engine.
  384. *
  385. * @param engine
  386. * The engine to move.
  387. * @param newIndex
  388. * The engine's new index in the set of visible engines.
  389. *
  390. * @throws NS_ERROR_FAILURE if newIndex is out of bounds, or if engine is
  391. * hidden.
  392. */
  393. void moveEngine(in nsISearchEngine engine, in long newIndex);
  394. /**
  395. * Removes the search engine. If the search engine is installed in a global
  396. * location, this will just hide the engine. If the engine is in the user's
  397. * profile directory, it will be removed from disk.
  398. *
  399. * @param engine
  400. * The engine to remove.
  401. */
  402. void removeEngine(in nsISearchEngine engine);
  403. /**
  404. * The original Engine object that is the default for this region,
  405. * ignoring changes the user may have subsequently made.
  406. */
  407. readonly attribute nsISearchEngine originalDefaultEngine;
  408. /**
  409. * Alias for the currentEngine attribute, kept for add-on compatibility.
  410. */
  411. attribute nsISearchEngine defaultEngine;
  412. /**
  413. * The currently active search engine.
  414. * Unless the application doesn't ship any search plugin, this should never
  415. * be null. If the currently active engine is removed, this attribute will
  416. * fallback first to the original default engine if it's not hidden, then to
  417. * the first visible engine, and as a last resort it will unhide the original
  418. * default engine.
  419. */
  420. attribute nsISearchEngine currentEngine;
  421. /**
  422. * Gets a representation of the default engine in an anonymized JSON
  423. * string suitable for recording in the Telemetry environment.
  424. *
  425. * @return an object containing anonymized info about the default engine:
  426. * name, loadPath, submissionURL (for default engines).
  427. */
  428. jsval getDefaultEngineInfo();
  429. /**
  430. * Determines if the provided URL represents results from a search engine, and
  431. * provides details about the match.
  432. *
  433. * The lookup mechanism checks whether the domain name and path of the
  434. * provided HTTP or HTTPS URL matches one of the known values for the visible
  435. * search engines. The match does not depend on which of the schemes is used.
  436. * The expected URI parameter for the search terms must exist in the query
  437. * string, but other parameters are ignored.
  438. *
  439. * @param url
  440. * String containing the URL to parse, for example
  441. * "https://www.google.com/search?q=terms".
  442. */
  443. nsISearchParseSubmissionResult parseSubmissionURL(in AString url);
  444. };
  445. %{ C++
  446. /**
  447. * The observer topic to listen to for actions performed on installed
  448. * search engines.
  449. */
  450. #define SEARCH_ENGINE_TOPIC "browser-search-engine-modified"
  451. /**
  452. * Sent when an engine is removed from the data store.
  453. */
  454. #define SEARCH_ENGINE_REMOVED "engine-removed"
  455. /**
  456. * Sent when an engine is changed. This includes when the engine's "hidden"
  457. * property is changed.
  458. */
  459. #define SEARCH_ENGINE_CHANGED "engine-changed"
  460. /**
  461. * Sent when an engine is added to the list of available engines.
  462. */
  463. #define SEARCH_ENGINE_ADDED "engine-added"
  464. /**
  465. * Sent when a search engine being installed from a remote plugin description
  466. * file is completely loaded. This is used internally by the search service as
  467. * an indication of when the engine can be added to the internal store, and
  468. * therefore should not be used to detect engine availability. It is always
  469. * followed by an "added" notification.
  470. */
  471. #define SEARCH_ENGINE_LOADED "engine-loaded"
  472. /**
  473. * Sent when the "current" engine is changed.
  474. */
  475. #define SEARCH_ENGINE_CURRENT "engine-current";
  476. /**
  477. * Sent when the "default" engine is changed.
  478. */
  479. #define SEARCH_ENGINE_DEFAULT "engine-default";
  480. %}