Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "nsISupports.idl" |
michael@0 | 6 | |
michael@0 | 7 | interface nsIURI; |
michael@0 | 8 | interface nsIInputStream; |
michael@0 | 9 | |
michael@0 | 10 | [scriptable, uuid(5799251f-5b55-4df7-a9e7-0c27812c469a)] |
michael@0 | 11 | interface nsISearchSubmission : nsISupports |
michael@0 | 12 | { |
michael@0 | 13 | /** |
michael@0 | 14 | * The POST data associated with a search submission, wrapped in a MIME |
michael@0 | 15 | * input stream. May be null. |
michael@0 | 16 | */ |
michael@0 | 17 | readonly attribute nsIInputStream postData; |
michael@0 | 18 | |
michael@0 | 19 | /** |
michael@0 | 20 | * The URI to submit a search to. |
michael@0 | 21 | */ |
michael@0 | 22 | readonly attribute nsIURI uri; |
michael@0 | 23 | }; |
michael@0 | 24 | |
michael@0 | 25 | [scriptable, uuid(77de6680-57ec-4105-a183-cc7cf7e84b09)] |
michael@0 | 26 | interface nsISearchEngine : nsISupports |
michael@0 | 27 | { |
michael@0 | 28 | /** |
michael@0 | 29 | * Gets a nsISearchSubmission object that contains information about what to |
michael@0 | 30 | * send to the search engine, including the URI and postData, if applicable. |
michael@0 | 31 | * |
michael@0 | 32 | * @param data |
michael@0 | 33 | * Data to add to the submission object. |
michael@0 | 34 | * i.e. the search terms. |
michael@0 | 35 | * |
michael@0 | 36 | * @param responseType [optional] |
michael@0 | 37 | * The MIME type that we'd like to receive in response |
michael@0 | 38 | * to this submission. If null, will default to "text/html". |
michael@0 | 39 | * |
michael@0 | 40 | * @param purpose [optional] |
michael@0 | 41 | * A string meant to indicate the context of the search request. This |
michael@0 | 42 | * allows the search service to provide a different nsISearchSubmission |
michael@0 | 43 | * depending on e.g. where the search is triggered in the UI. |
michael@0 | 44 | * |
michael@0 | 45 | * @returns A nsISearchSubmission object that contains information about what |
michael@0 | 46 | * to send to the search engine. If no submission can be |
michael@0 | 47 | * obtained for the given responseType, returns null. |
michael@0 | 48 | */ |
michael@0 | 49 | nsISearchSubmission getSubmission(in AString data, |
michael@0 | 50 | [optional] in AString responseType, |
michael@0 | 51 | [optional] in AString purpose); |
michael@0 | 52 | |
michael@0 | 53 | /** |
michael@0 | 54 | * Adds a parameter to the search engine's submission data. This should only |
michael@0 | 55 | * be called on engines created via addEngineWithDetails. |
michael@0 | 56 | * |
michael@0 | 57 | * @param name |
michael@0 | 58 | * The parameter's name. Must not be null. |
michael@0 | 59 | * |
michael@0 | 60 | * @param value |
michael@0 | 61 | * The value to pass. If value is "{searchTerms}", it will be |
michael@0 | 62 | * substituted with the user-entered data when retrieving the |
michael@0 | 63 | * submission. Must not be null. |
michael@0 | 64 | * |
michael@0 | 65 | * @param responseType |
michael@0 | 66 | * Since an engine can have several different request URLs, |
michael@0 | 67 | * differentiated by response types, this parameter selects |
michael@0 | 68 | * a request to add parameters to. If null, will default |
michael@0 | 69 | * to "text/html" |
michael@0 | 70 | * |
michael@0 | 71 | * @throws NS_ERROR_FAILURE if the search engine is read-only. |
michael@0 | 72 | * @throws NS_ERROR_INVALID_ARG if name or value are null. |
michael@0 | 73 | */ |
michael@0 | 74 | void addParam(in AString name, in AString value, in AString responseType); |
michael@0 | 75 | |
michael@0 | 76 | /** |
michael@0 | 77 | * Determines whether the engine can return responses in the given |
michael@0 | 78 | * MIME type. Returns true if the engine spec has a URL with the |
michael@0 | 79 | * given responseType, false otherwise. |
michael@0 | 80 | * |
michael@0 | 81 | * @param responseType |
michael@0 | 82 | * The MIME type to check for |
michael@0 | 83 | */ |
michael@0 | 84 | boolean supportsResponseType(in AString responseType); |
michael@0 | 85 | |
michael@0 | 86 | /** |
michael@0 | 87 | * Returns a string with the URL to an engine's icon matching both width and |
michael@0 | 88 | * height. Returns null if icon with specified dimensions is not found. |
michael@0 | 89 | * |
michael@0 | 90 | * @param width |
michael@0 | 91 | * Width of the requested icon. |
michael@0 | 92 | * @param height |
michael@0 | 93 | * Height of the requested icon. |
michael@0 | 94 | */ |
michael@0 | 95 | AString getIconURLBySize(in long width, in long height); |
michael@0 | 96 | |
michael@0 | 97 | /** |
michael@0 | 98 | * Gets an array of all available icons. Each entry is an object with |
michael@0 | 99 | * width, height and url properties. width and height are numeric and |
michael@0 | 100 | * represent the icon's dimensions. url is a string with the URL for |
michael@0 | 101 | * the icon. |
michael@0 | 102 | */ |
michael@0 | 103 | jsval getIcons(); |
michael@0 | 104 | |
michael@0 | 105 | /** |
michael@0 | 106 | * Supported search engine types. |
michael@0 | 107 | */ |
michael@0 | 108 | const unsigned long TYPE_MOZSEARCH = 1; |
michael@0 | 109 | const unsigned long TYPE_SHERLOCK = 2; |
michael@0 | 110 | const unsigned long TYPE_OPENSEARCH = 3; |
michael@0 | 111 | |
michael@0 | 112 | /** |
michael@0 | 113 | * Supported search engine data types. |
michael@0 | 114 | */ |
michael@0 | 115 | const unsigned long DATA_XML = 1; |
michael@0 | 116 | const unsigned long DATA_TEXT = 2; |
michael@0 | 117 | |
michael@0 | 118 | /** |
michael@0 | 119 | * An optional shortcut alias for the engine. |
michael@0 | 120 | * When non-null, this is a unique identifier. |
michael@0 | 121 | */ |
michael@0 | 122 | attribute AString alias; |
michael@0 | 123 | |
michael@0 | 124 | /** |
michael@0 | 125 | * A text description describing the engine. |
michael@0 | 126 | */ |
michael@0 | 127 | readonly attribute AString description; |
michael@0 | 128 | |
michael@0 | 129 | /** |
michael@0 | 130 | * Whether the engine should be hidden from the user. |
michael@0 | 131 | */ |
michael@0 | 132 | attribute boolean hidden; |
michael@0 | 133 | |
michael@0 | 134 | /** |
michael@0 | 135 | * A nsIURI corresponding to the engine's icon, stored locally. May be null. |
michael@0 | 136 | */ |
michael@0 | 137 | readonly attribute nsIURI iconURI; |
michael@0 | 138 | |
michael@0 | 139 | /** |
michael@0 | 140 | * The display name of the search engine. This is a unique identifier. |
michael@0 | 141 | */ |
michael@0 | 142 | readonly attribute AString name; |
michael@0 | 143 | |
michael@0 | 144 | /** |
michael@0 | 145 | * A URL string pointing to the engine's search form. |
michael@0 | 146 | */ |
michael@0 | 147 | readonly attribute AString searchForm; |
michael@0 | 148 | |
michael@0 | 149 | /** |
michael@0 | 150 | * The search engine type. |
michael@0 | 151 | */ |
michael@0 | 152 | readonly attribute long type; |
michael@0 | 153 | |
michael@0 | 154 | /** |
michael@0 | 155 | * An optional unique identifier for this search engine within the context of |
michael@0 | 156 | * the distribution, as provided by the distributing entity. |
michael@0 | 157 | */ |
michael@0 | 158 | readonly attribute AString identifier; |
michael@0 | 159 | |
michael@0 | 160 | /** |
michael@0 | 161 | * Gets a string representing the hostname from which search results for a |
michael@0 | 162 | * given responseType are returned, minus the leading "www." (if present). |
michael@0 | 163 | * This can be specified as an url attribute in the engine description file, |
michael@0 | 164 | * but will default to host from the <Url>'s template otherwise. |
michael@0 | 165 | * |
michael@0 | 166 | * @param responseType [optional] |
michael@0 | 167 | * The MIME type to get resultDomain for. Defaults to "text/html". |
michael@0 | 168 | * |
michael@0 | 169 | * @return the resultDomain for the given responseType. |
michael@0 | 170 | */ |
michael@0 | 171 | AString getResultDomain([optional] in AString responseType); |
michael@0 | 172 | }; |
michael@0 | 173 | |
michael@0 | 174 | [scriptable, uuid(9fc39136-f08b-46d3-b232-96f4b7b0e235)] |
michael@0 | 175 | interface nsISearchInstallCallback : nsISupports |
michael@0 | 176 | { |
michael@0 | 177 | const unsigned long ERROR_UNKNOWN_FAILURE = 0x1; |
michael@0 | 178 | const unsigned long ERROR_DUPLICATE_ENGINE = 0x2; |
michael@0 | 179 | |
michael@0 | 180 | /** |
michael@0 | 181 | * Called to indicate that the engine addition process succeeded. |
michael@0 | 182 | * |
michael@0 | 183 | * @param engine |
michael@0 | 184 | * The nsISearchEngine object that was added (will not be null). |
michael@0 | 185 | */ |
michael@0 | 186 | void onSuccess(in nsISearchEngine engine); |
michael@0 | 187 | |
michael@0 | 188 | /** |
michael@0 | 189 | * Called to indicate that the engine addition process failed. |
michael@0 | 190 | * |
michael@0 | 191 | * @param errorCode |
michael@0 | 192 | * One of the ERROR_* values described above indicating the cause of |
michael@0 | 193 | * the failure. |
michael@0 | 194 | */ |
michael@0 | 195 | void onError(in unsigned long errorCode); |
michael@0 | 196 | }; |
michael@0 | 197 | |
michael@0 | 198 | /** |
michael@0 | 199 | * Callback for asynchronous initialization of nsIBrowserSearchService |
michael@0 | 200 | */ |
michael@0 | 201 | [scriptable, function, uuid(02256156-16e4-47f1-9979-76ff98ceb590)] |
michael@0 | 202 | interface nsIBrowserSearchInitObserver : nsISupports |
michael@0 | 203 | { |
michael@0 | 204 | /** |
michael@0 | 205 | * Called once initialization of the browser search service is complete. |
michael@0 | 206 | * |
michael@0 | 207 | * @param aStatus The status of that service. |
michael@0 | 208 | */ |
michael@0 | 209 | void onInitComplete(in nsresult aStatus); |
michael@0 | 210 | }; |
michael@0 | 211 | |
michael@0 | 212 | [scriptable, uuid(939d74a4-5b01-463c-80c7-4301f0c0f9ef)] |
michael@0 | 213 | interface nsIBrowserSearchService : nsISupports |
michael@0 | 214 | { |
michael@0 | 215 | /** |
michael@0 | 216 | * Start asynchronous initialization. |
michael@0 | 217 | * |
michael@0 | 218 | * The callback is triggered once initialization is complete, which may be |
michael@0 | 219 | * immediately, if initialization has already been completed by some previous |
michael@0 | 220 | * call to this method. The callback is always invoked asynchronously. |
michael@0 | 221 | * |
michael@0 | 222 | * @param aObserver An optional object observing the end of initialization. |
michael@0 | 223 | */ |
michael@0 | 224 | void init([optional] in nsIBrowserSearchInitObserver aObserver); |
michael@0 | 225 | |
michael@0 | 226 | /** |
michael@0 | 227 | * Determine whether initialization has been completed. |
michael@0 | 228 | * |
michael@0 | 229 | * Clients of the service can use this attribute to quickly determine whether |
michael@0 | 230 | * initialization is complete, and decide to trigger some immediate treatment, |
michael@0 | 231 | * to launch asynchronous initialization or to bailout. |
michael@0 | 232 | * |
michael@0 | 233 | * Note that this attribute does not indicate that initialization has succeeded. |
michael@0 | 234 | * |
michael@0 | 235 | * @return |true| if the search service is now initialized, |false| if |
michael@0 | 236 | * initialization has not been triggered yet. |
michael@0 | 237 | */ |
michael@0 | 238 | readonly attribute bool isInitialized; |
michael@0 | 239 | |
michael@0 | 240 | /** |
michael@0 | 241 | * Adds a new search engine from the file at the supplied URI, optionally |
michael@0 | 242 | * asking the user for confirmation first. If a confirmation dialog is |
michael@0 | 243 | * shown, it will offer the option to begin using the newly added engine |
michael@0 | 244 | * right away. |
michael@0 | 245 | * |
michael@0 | 246 | * @param engineURL |
michael@0 | 247 | * The URL to the search engine's description file. |
michael@0 | 248 | * |
michael@0 | 249 | * @param dataType |
michael@0 | 250 | * An integer representing the plugin file format. Must be one |
michael@0 | 251 | * of the supported search engine data types defined above. |
michael@0 | 252 | * |
michael@0 | 253 | * @param iconURL |
michael@0 | 254 | * A URL string to an icon file to be used as the search engine's |
michael@0 | 255 | * icon. This value may be overridden by an icon specified in the |
michael@0 | 256 | * engine description file. |
michael@0 | 257 | * |
michael@0 | 258 | * @param confirm |
michael@0 | 259 | * A boolean value indicating whether the user should be asked for |
michael@0 | 260 | * confirmation before this engine is added to the list. If this |
michael@0 | 261 | * value is false, the engine will be added to the list upon successful |
michael@0 | 262 | * load, but it will not be selected as the current engine. |
michael@0 | 263 | * |
michael@0 | 264 | * @param callback |
michael@0 | 265 | * A nsISearchInstallCallback that will be notified when the |
michael@0 | 266 | * addition is complete, or if the addition fails. It will not be |
michael@0 | 267 | * called if addEngine throws an exception. |
michael@0 | 268 | * |
michael@0 | 269 | * @throws NS_ERROR_FAILURE if the type is invalid, or if the description |
michael@0 | 270 | * file cannot be successfully loaded. |
michael@0 | 271 | */ |
michael@0 | 272 | void addEngine(in AString engineURL, in long dataType, in AString iconURL, |
michael@0 | 273 | in boolean confirm, [optional] in nsISearchInstallCallback callback); |
michael@0 | 274 | |
michael@0 | 275 | /** |
michael@0 | 276 | * Adds a new search engine, without asking the user for confirmation and |
michael@0 | 277 | * without starting to use it right away. |
michael@0 | 278 | * |
michael@0 | 279 | * @param name |
michael@0 | 280 | * The search engine's name. Must be unique. Must not be null. |
michael@0 | 281 | * |
michael@0 | 282 | * @param iconURL |
michael@0 | 283 | * Optional: A URL string pointing to the icon to be used to represent |
michael@0 | 284 | * the engine. |
michael@0 | 285 | * |
michael@0 | 286 | * @param alias |
michael@0 | 287 | * Optional: A unique shortcut that can be used to retrieve the |
michael@0 | 288 | * search engine. |
michael@0 | 289 | * |
michael@0 | 290 | * @param description |
michael@0 | 291 | * Optional: a description of the search engine. |
michael@0 | 292 | * |
michael@0 | 293 | * @param method |
michael@0 | 294 | * The HTTP request method used when submitting a search query. |
michael@0 | 295 | * Must be a case insensitive value of either "get" or "post". |
michael@0 | 296 | * |
michael@0 | 297 | * @param url |
michael@0 | 298 | * The URL to which search queries should be sent. |
michael@0 | 299 | * Must not be null. |
michael@0 | 300 | */ |
michael@0 | 301 | void addEngineWithDetails(in AString name, |
michael@0 | 302 | in AString iconURL, |
michael@0 | 303 | in AString alias, |
michael@0 | 304 | in AString description, |
michael@0 | 305 | in AString method, |
michael@0 | 306 | in AString url); |
michael@0 | 307 | |
michael@0 | 308 | /** |
michael@0 | 309 | * Un-hides all engines installed in the directory corresponding to |
michael@0 | 310 | * the directory service's NS_APP_SEARCH_DIR key. (i.e. the set of |
michael@0 | 311 | * engines returned by getDefaultEngines) |
michael@0 | 312 | */ |
michael@0 | 313 | void restoreDefaultEngines(); |
michael@0 | 314 | |
michael@0 | 315 | /** |
michael@0 | 316 | * Returns an engine with the specified alias. |
michael@0 | 317 | * |
michael@0 | 318 | * @param alias |
michael@0 | 319 | * The search engine's alias. |
michael@0 | 320 | * @returns The corresponding nsISearchEngine object, or null if it doesn't |
michael@0 | 321 | * exist. |
michael@0 | 322 | */ |
michael@0 | 323 | nsISearchEngine getEngineByAlias(in AString alias); |
michael@0 | 324 | |
michael@0 | 325 | /** |
michael@0 | 326 | * Returns an engine with the specified name. |
michael@0 | 327 | * |
michael@0 | 328 | * @param aEngineName |
michael@0 | 329 | * The name of the engine. |
michael@0 | 330 | * @returns The corresponding nsISearchEngine object, or null if it doesn't |
michael@0 | 331 | * exist. |
michael@0 | 332 | */ |
michael@0 | 333 | nsISearchEngine getEngineByName(in AString aEngineName); |
michael@0 | 334 | |
michael@0 | 335 | /** |
michael@0 | 336 | * Returns an array of all installed search engines. |
michael@0 | 337 | * |
michael@0 | 338 | * @returns an array of nsISearchEngine objects. |
michael@0 | 339 | */ |
michael@0 | 340 | void getEngines( |
michael@0 | 341 | [optional] out unsigned long engineCount, |
michael@0 | 342 | [retval, array, size_is(engineCount)] out nsISearchEngine engines); |
michael@0 | 343 | |
michael@0 | 344 | /** |
michael@0 | 345 | * Returns an array of all installed search engines whose hidden attribute is |
michael@0 | 346 | * false. |
michael@0 | 347 | * |
michael@0 | 348 | * @returns an array of nsISearchEngine objects. |
michael@0 | 349 | */ |
michael@0 | 350 | void getVisibleEngines( |
michael@0 | 351 | [optional] out unsigned long engineCount, |
michael@0 | 352 | [retval, array, size_is(engineCount)] out nsISearchEngine engines); |
michael@0 | 353 | |
michael@0 | 354 | /** |
michael@0 | 355 | * Returns an array of all default search engines. This includes all loaded |
michael@0 | 356 | * engines that aren't in the user's profile directory |
michael@0 | 357 | * (NS_APP_USER_SEARCH_DIR). |
michael@0 | 358 | * |
michael@0 | 359 | * @returns an array of nsISearchEngine objects. |
michael@0 | 360 | */ |
michael@0 | 361 | void getDefaultEngines( |
michael@0 | 362 | [optional] out unsigned long engineCount, |
michael@0 | 363 | [retval, array, size_is(engineCount)] out nsISearchEngine engines); |
michael@0 | 364 | |
michael@0 | 365 | /** |
michael@0 | 366 | * Moves a visible search engine. |
michael@0 | 367 | * |
michael@0 | 368 | * @param engine |
michael@0 | 369 | * The engine to move. |
michael@0 | 370 | * @param newIndex |
michael@0 | 371 | * The engine's new index in the set of visible engines. |
michael@0 | 372 | * |
michael@0 | 373 | * @throws NS_ERROR_FAILURE if newIndex is out of bounds, or if engine is |
michael@0 | 374 | * hidden. |
michael@0 | 375 | */ |
michael@0 | 376 | void moveEngine(in nsISearchEngine engine, in long newIndex); |
michael@0 | 377 | |
michael@0 | 378 | /** |
michael@0 | 379 | * Removes the search engine. If the search engine is installed in a global |
michael@0 | 380 | * location, this will just hide the engine. If the engine is in the user's |
michael@0 | 381 | * profile directory, it will be removed from disk. |
michael@0 | 382 | * |
michael@0 | 383 | * @param engine |
michael@0 | 384 | * The engine to remove. |
michael@0 | 385 | */ |
michael@0 | 386 | void removeEngine(in nsISearchEngine engine); |
michael@0 | 387 | |
michael@0 | 388 | /** |
michael@0 | 389 | * The default search engine. Returns the first visible engine if the default |
michael@0 | 390 | * engine is hidden. May be null if there are no visible search engines. |
michael@0 | 391 | */ |
michael@0 | 392 | attribute nsISearchEngine defaultEngine; |
michael@0 | 393 | |
michael@0 | 394 | /** |
michael@0 | 395 | * The currently active search engine. May be null if there are no visible |
michael@0 | 396 | * search engines. |
michael@0 | 397 | */ |
michael@0 | 398 | attribute nsISearchEngine currentEngine; |
michael@0 | 399 | }; |
michael@0 | 400 | |
michael@0 | 401 | %{ C++ |
michael@0 | 402 | /** |
michael@0 | 403 | * The observer topic to listen to for actions performed on installed |
michael@0 | 404 | * search engines. |
michael@0 | 405 | */ |
michael@0 | 406 | #define SEARCH_ENGINE_TOPIC "browser-search-engine-modified" |
michael@0 | 407 | |
michael@0 | 408 | /** |
michael@0 | 409 | * Sent when an engine is removed from the data store. |
michael@0 | 410 | */ |
michael@0 | 411 | #define SEARCH_ENGINE_REMOVED "engine-removed" |
michael@0 | 412 | |
michael@0 | 413 | /** |
michael@0 | 414 | * Sent when an engine is changed. This includes when the engine's "hidden" |
michael@0 | 415 | * property is changed. |
michael@0 | 416 | */ |
michael@0 | 417 | #define SEARCH_ENGINE_CHANGED "engine-changed" |
michael@0 | 418 | |
michael@0 | 419 | /** |
michael@0 | 420 | * Sent when an engine is added to the list of available engines. |
michael@0 | 421 | */ |
michael@0 | 422 | #define SEARCH_ENGINE_ADDED "engine-added" |
michael@0 | 423 | |
michael@0 | 424 | /** |
michael@0 | 425 | * Sent when a search engine being installed from a remote plugin description |
michael@0 | 426 | * file is completely loaded. This is used internally by the search service as |
michael@0 | 427 | * an indication of when the engine can be added to the internal store, and |
michael@0 | 428 | * therefore should not be used to detect engine availability. It is always |
michael@0 | 429 | * followed by an "added" notification. |
michael@0 | 430 | */ |
michael@0 | 431 | #define SEARCH_ENGINE_LOADED "engine-loaded" |
michael@0 | 432 | |
michael@0 | 433 | /** |
michael@0 | 434 | * Sent when the "current" engine is changed. |
michael@0 | 435 | */ |
michael@0 | 436 | #define SEARCH_ENGINE_CURRENT "engine-current"; |
michael@0 | 437 | |
michael@0 | 438 | /** |
michael@0 | 439 | * Sent when the "default" engine is changed. |
michael@0 | 440 | */ |
michael@0 | 441 | #define SEARCH_ENGINE_DEFAULT "engine-default"; |
michael@0 | 442 | |
michael@0 | 443 | |
michael@0 | 444 | |
michael@0 | 445 | %} |