nsIURIFixup.idl 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. *
  3. * This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6. #include "nsISupports.idl"
  7. interface nsIURI;
  8. interface nsIInputStream;
  9. /**
  10. * Interface indicating what we found/corrected when fixing up a URI
  11. */
  12. [scriptable, uuid(4819f183-b532-4932-ac09-b309cd853be7)]
  13. interface nsIURIFixupInfo : nsISupports
  14. {
  15. /**
  16. * Consumer that asked for fixed up URI.
  17. */
  18. attribute nsISupports consumer;
  19. /**
  20. * Our best guess as to what URI the consumer will want. Might
  21. * be null if we couldn't salvage anything (for instance, because
  22. * the input was invalid as a URI and FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP
  23. * was not passed)
  24. */
  25. readonly attribute nsIURI preferredURI;
  26. /**
  27. * The fixed-up original input, *never* using a keyword search.
  28. * (might be null if the original input was not recoverable as
  29. * a URL, e.g. "foo bar"!)
  30. */
  31. readonly attribute nsIURI fixedURI;
  32. /**
  33. * The name of the keyword search provider used to provide a keyword search;
  34. * empty string if no keyword search was done.
  35. */
  36. readonly attribute AString keywordProviderName;
  37. /**
  38. * The keyword as used for the search (post trimming etc.)
  39. * empty string if no keyword search was done.
  40. */
  41. readonly attribute AString keywordAsSent;
  42. /**
  43. * Whether we changed the protocol instead of using one from the input as-is.
  44. */
  45. readonly attribute boolean fixupChangedProtocol;
  46. /**
  47. * Whether we created an alternative URI. We might have added a prefix and/or
  48. * suffix, the contents of which are controlled by the
  49. * browser.fixup.alternate.prefix and .suffix prefs, with the defaults being
  50. * "www." and ".com", respectively.
  51. */
  52. readonly attribute boolean fixupCreatedAlternateURI;
  53. /**
  54. * The original input
  55. */
  56. readonly attribute AUTF8String originalInput;
  57. };
  58. /**
  59. * Interface implemented by objects capable of fixing up strings into URIs
  60. */
  61. [scriptable, uuid(1da7e9d4-620b-4949-849a-1cd6077b1b2d)]
  62. interface nsIURIFixup : nsISupports
  63. {
  64. /** No fixup flags. */
  65. const unsigned long FIXUP_FLAG_NONE = 0;
  66. /**
  67. * Allow the fixup to use a keyword lookup service to complete the URI.
  68. * The fixup object implementer should honour this flag and only perform
  69. * any lengthy keyword (or search) operation if it is set.
  70. */
  71. const unsigned long FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP = 1;
  72. /**
  73. * Tell the fixup to make an alternate URI from the input URI, for example
  74. * to turn foo into www.foo.com.
  75. */
  76. const unsigned long FIXUP_FLAGS_MAKE_ALTERNATE_URI = 2;
  77. /*
  78. * Fix common scheme typos.
  79. */
  80. const unsigned long FIXUP_FLAG_FIX_SCHEME_TYPOS = 8;
  81. /* NB: If adding an extra flag, 4 is free (again) */
  82. /**
  83. * Converts an internal URI (e.g. a wyciwyg URI) into one which we can
  84. * expose to the user, for example on the URL bar.
  85. *
  86. * @param aURI The URI to be converted
  87. * @return nsIURI The converted, exposable URI
  88. * @throws NS_ERROR_MALFORMED_URI when the exposable portion of aURI is malformed
  89. * @throws NS_ERROR_UNKNOWN_PROTOCOL when we can't get a protocol handler service
  90. * for the URI scheme.
  91. */
  92. nsIURI createExposableURI(in nsIURI aURI);
  93. /**
  94. * Converts the specified string into a URI, first attempting
  95. * to correct any errors in the syntax or other vagaries. Returns
  96. * a wellformed URI or nullptr if it can't.
  97. *
  98. * @param aURIText Candidate URI.
  99. * @param aFixupFlags Flags that govern ways the URI may be fixed up.
  100. * @param aPostData The POST data to submit with the returned
  101. * URI (see nsISearchSubmission).
  102. */
  103. nsIURI createFixupURI(in AUTF8String aURIText, in unsigned long aFixupFlags,
  104. [optional] out nsIInputStream aPostData);
  105. /**
  106. * Same as createFixupURI, but returns information about what it corrected
  107. * (e.g. whether we could rescue the URI or "just" generated a keyword
  108. * search URI instead).
  109. *
  110. * @param aURIText Candidate URI.
  111. * @param aFixupFlags Flags that govern ways the URI may be fixed up.
  112. * @param aPostData The POST data to submit with the returned
  113. * URI (see nsISearchSubmission).
  114. */
  115. nsIURIFixupInfo getFixupURIInfo(in AUTF8String aURIText,
  116. in unsigned long aFixupFlags,
  117. [optional] out nsIInputStream aPostData);
  118. /**
  119. * Converts the specified keyword string into a URI. Note that it's the
  120. * caller's responsibility to check whether keywords are enabled and
  121. * whether aKeyword is a sensible keyword.
  122. *
  123. * @param aKeyword The keyword string to convert into a URI
  124. * @param aPostData The POST data to submit to the returned URI
  125. * (see nsISearchSubmission).
  126. *
  127. * @throws NS_ERROR_FAILURE if the resulting URI requires submission of POST
  128. * data and aPostData is null.
  129. */
  130. nsIURIFixupInfo keywordToURI(in AUTF8String aKeyword,
  131. [optional] out nsIInputStream aPostData);
  132. /**
  133. * Returns true if the specified domain is whitelisted and false otherwise.
  134. * A whitelisted domain is relevant when we have a single word and can't be
  135. * sure whether to treat the word as a host name or should instead be
  136. * treated as a search term.
  137. *
  138. * @param aDomain A domain name to query.
  139. * @param aDotPos The position of the first '.' character in aDomain, or
  140. * -1 if no '.' character exists.
  141. */
  142. bool isDomainWhitelisted(in AUTF8String aDomain,
  143. in uint32_t aDotPos);
  144. };