nsIIOService.idl 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "nsISupports.idl"
  6. interface nsIProtocolHandler;
  7. interface nsIChannel;
  8. interface nsIURI;
  9. interface nsIFile;
  10. interface nsIDOMNode;
  11. interface nsIPrincipal;
  12. interface nsILoadInfo;
  13. /**
  14. * nsIIOService provides a set of network utility functions. This interface
  15. * duplicates many of the nsIProtocolHandler methods in a protocol handler
  16. * independent way (e.g., NewURI inspects the scheme in order to delegate
  17. * creation of the new URI to the appropriate protocol handler). nsIIOService
  18. * also provides a set of URL parsing utility functions. These are provided
  19. * as a convenience to the programmer and in some cases to improve performance
  20. * by eliminating intermediate data structures and interfaces.
  21. */
  22. [scriptable, uuid(4286de5a-b2ea-446f-8f70-e2a461f42694)]
  23. interface nsIIOService : nsISupports
  24. {
  25. /**
  26. * Returns a protocol handler for a given URI scheme.
  27. *
  28. * @param aScheme the URI scheme
  29. * @return reference to corresponding nsIProtocolHandler
  30. */
  31. nsIProtocolHandler getProtocolHandler(in string aScheme);
  32. /**
  33. * Returns the protocol flags for a given scheme.
  34. *
  35. * @param aScheme the URI scheme
  36. * @return value of corresponding nsIProtocolHandler::protocolFlags
  37. */
  38. unsigned long getProtocolFlags(in string aScheme);
  39. /**
  40. * This method constructs a new URI by determining the scheme of the
  41. * URI spec, and then delegating the construction of the URI to the
  42. * protocol handler for that scheme. QueryInterface can be used on
  43. * the resulting URI object to obtain a more specific type of URI.
  44. *
  45. * @see nsIProtocolHandler::newURI
  46. */
  47. nsIURI newURI(in AUTF8String aSpec,
  48. [optional] in string aOriginCharset,
  49. [optional] in nsIURI aBaseURI);
  50. /**
  51. * This method constructs a new URI from a nsIFile.
  52. *
  53. * @param aFile specifies the file path
  54. * @return reference to a new nsIURI object
  55. *
  56. * Note: in the future, for perf reasons we should allow
  57. * callers to specify whether this is a file or directory by
  58. * splitting this into newDirURI() and newActualFileURI().
  59. */
  60. nsIURI newFileURI(in nsIFile aFile);
  61. /**
  62. * Creates a channel for a given URI.
  63. *
  64. * @param aURI
  65. * nsIURI from which to make a channel
  66. * @param aLoadingNode
  67. * @param aLoadingPrincipal
  68. * @param aTriggeringPrincipal
  69. * @param aSecurityFlags
  70. * @param aContentPolicyType
  71. * These will be used as values for the nsILoadInfo object on the
  72. * created channel. For details, see nsILoadInfo in nsILoadInfo.idl
  73. * @return reference to the new nsIChannel object
  74. *
  75. * Please note, if you provide both a loadingNode and a loadingPrincipal,
  76. * then loadingPrincipal must be equal to loadingNode->NodePrincipal().
  77. * But less error prone is to just supply a loadingNode.
  78. *
  79. * Keep in mind that URIs coming from a webpage should *never* use the
  80. * systemPrincipal as the loadingPrincipal.
  81. */
  82. nsIChannel newChannelFromURI2(in nsIURI aURI,
  83. in nsIDOMNode aLoadingNode,
  84. in nsIPrincipal aLoadingPrincipal,
  85. in nsIPrincipal aTriggeringPrincipal,
  86. in unsigned long aSecurityFlags,
  87. in unsigned long aContentPolicyType);
  88. /**
  89. * Equivalent to newChannelFromURI2(aURI, aLoadingNode, ...)
  90. */
  91. nsIChannel newChannelFromURIWithLoadInfo(in nsIURI aURI,
  92. in nsILoadInfo aLoadInfo);
  93. /**
  94. * Equivalent to newChannelFromURI2(newURI(...))
  95. */
  96. nsIChannel newChannel2(in AUTF8String aSpec,
  97. in string aOriginCharset,
  98. in nsIURI aBaseURI,
  99. in nsIDOMNode aLoadingNode,
  100. in nsIPrincipal aLoadingPrincipal,
  101. in nsIPrincipal aTriggeringPrincipal,
  102. in unsigned long aSecurityFlags,
  103. in unsigned long aContentPolicyType);
  104. /**
  105. * ***** DEPRECATED *****
  106. * Please use NewChannelFromURI2()
  107. *
  108. * Creates a channel for a given URI.
  109. *
  110. * @param aURI nsIURI from which to make a channel
  111. * @return reference to the new nsIChannel object
  112. */
  113. nsIChannel newChannelFromURI(in nsIURI aURI);
  114. /**
  115. * ***** DEPRECATED *****
  116. * Please use newChannel2().
  117. *
  118. * Equivalent to newChannelFromURI(newURI(...))
  119. */
  120. nsIChannel newChannel(in AUTF8String aSpec,
  121. in string aOriginCharset,
  122. in nsIURI aBaseURI);
  123. /**
  124. * Returns true if networking is in "offline" mode. When in offline mode,
  125. * attempts to access the network will fail (although this does not
  126. * necessarily correlate with whether there is actually a network
  127. * available -- that's hard to detect without causing the dialer to
  128. * come up).
  129. *
  130. * Changing this fires observer notifications ... see below.
  131. */
  132. attribute boolean offline;
  133. /**
  134. * Returns false if there are no interfaces for a network request
  135. */
  136. readonly attribute boolean connectivity;
  137. /**
  138. * Checks if a port number is banned. This involves consulting a list of
  139. * unsafe ports, corresponding to network services that may be easily
  140. * exploitable. If the given port is considered unsafe, then the protocol
  141. * handler (corresponding to aScheme) will be asked whether it wishes to
  142. * override the IO service's decision to block the port. This gives the
  143. * protocol handler ultimate control over its own security policy while
  144. * ensuring reasonable, default protection.
  145. *
  146. * @see nsIProtocolHandler::allowPort
  147. */
  148. boolean allowPort(in long aPort, in string aScheme);
  149. /**
  150. * Utility to extract the scheme from a URL string, consistently and
  151. * according to spec (see RFC 2396).
  152. *
  153. * NOTE: Most URL parsing is done via nsIURI, and in fact the scheme
  154. * can also be extracted from a URL string via nsIURI. This method
  155. * is provided purely as an optimization.
  156. *
  157. * @param aSpec the URL string to parse
  158. * @return URL scheme
  159. *
  160. * @throws NS_ERROR_MALFORMED_URI if URL string is not of the right form.
  161. */
  162. ACString extractScheme(in AUTF8String urlString);
  163. };
  164. %{C++
  165. /**
  166. * We send notifications through nsIObserverService with topic
  167. * NS_IOSERVICE_GOING_OFFLINE_TOPIC and data NS_IOSERVICE_OFFLINE
  168. * when 'offline' has changed from false to true, and we are about
  169. * to shut down network services such as DNS. When those
  170. * services have been shut down, we send a notification with
  171. * topic NS_IOSERVICE_OFFLINE_STATUS_TOPIC and data
  172. * NS_IOSERVICE_OFFLINE.
  173. *
  174. * When 'offline' changes from true to false, then after
  175. * network services have been restarted, we send a notification
  176. * with topic NS_IOSERVICE_OFFLINE_STATUS_TOPIC and data
  177. * NS_IOSERVICE_ONLINE.
  178. */
  179. #define NS_IOSERVICE_GOING_OFFLINE_TOPIC "network:offline-about-to-go-offline"
  180. #define NS_IOSERVICE_OFFLINE_STATUS_TOPIC "network:offline-status-changed"
  181. #define NS_IOSERVICE_OFFLINE "offline"
  182. #define NS_IOSERVICE_ONLINE "online"
  183. %}
  184. [builtinclass, uuid(6633c0bf-d97a-428f-8ece-cb6a655fb95a)]
  185. interface nsIIOServiceInternal : nsISupports
  186. {
  187. /**
  188. * This is an internal method that should only be called from ContentChild
  189. * in order to pass the connectivity state from the chrome process to the
  190. * content process. It throws if called outside the content process.
  191. */
  192. void SetConnectivity(in boolean connectivity);
  193. /**
  194. * An internal method to asynchronously run our notifications that happen
  195. * when we wake from sleep
  196. */
  197. void NotifyWakeup();
  198. };