nsIChannelEventSink.idl 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* vim:set ts=4 sw=4 sts=4 cin: */
  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 nsIChannel;
  8. interface nsIAsyncVerifyRedirectCallback;
  9. /**
  10. * Implement this interface to receive control over various channel events.
  11. * Channels will try to get this interface from a channel's
  12. * notificationCallbacks or, if not available there, from the loadGroup's
  13. * notificationCallbacks.
  14. *
  15. * These methods are called before onStartRequest.
  16. */
  17. [scriptable, uuid(0197720d-37ed-4e75-8956-d0d296e4d8a6)]
  18. interface nsIChannelEventSink : nsISupports
  19. {
  20. /**
  21. * This is a temporary redirect. New requests for this resource should
  22. * continue to use the URI of the old channel.
  23. *
  24. * The new URI may be identical to the old one.
  25. */
  26. const unsigned long REDIRECT_TEMPORARY = 1 << 0;
  27. /**
  28. * This is a permanent redirect. New requests for this resource should use
  29. * the URI of the new channel (This might be an HTTP 301 reponse).
  30. * If this flag is not set, this is a temporary redirect.
  31. *
  32. * The new URI may be identical to the old one.
  33. */
  34. const unsigned long REDIRECT_PERMANENT = 1 << 1;
  35. /**
  36. * This is an internal redirect, i.e. it was not initiated by the remote
  37. * server, but is specific to the channel implementation.
  38. *
  39. * The new URI may be identical to the old one.
  40. */
  41. const unsigned long REDIRECT_INTERNAL = 1 << 2;
  42. /**
  43. * This is a special-cased redirect coming from hitting HSTS upgrade
  44. * redirect from http to https only. In some cases this type of redirect
  45. * may be considered as safe despite not being the-same-origin redirect.
  46. */
  47. const unsigned long REDIRECT_STS_UPGRADE = 1 << 3;
  48. /**
  49. * Called when a redirect occurs. This may happen due to an HTTP 3xx status
  50. * code. The purpose of this method is to notify the sink that a redirect
  51. * is about to happen, but also to give the sink the right to veto the
  52. * redirect by throwing or passing a failure-code in the callback.
  53. *
  54. * Note that vetoing the redirect simply means that |newChannel| will not
  55. * be opened. It is important to understand that |oldChannel| will continue
  56. * loading as if it received a HTTP 200, which includes notifying observers
  57. * and possibly display or process content attached to the HTTP response.
  58. * If the sink wants to prevent this loading it must explicitly deal with
  59. * it, e.g. by calling |oldChannel->Cancel()|
  60. *
  61. * There is a certain freedom in implementing this method:
  62. *
  63. * If the return-value indicates success, a callback on |callback| is
  64. * required. This callback can be done from within asyncOnChannelRedirect
  65. * (effectively making the call synchronous) or at some point later
  66. * (making the call asynchronous). Repeat: A callback must be done
  67. * if this method returns successfully.
  68. *
  69. * If the return value indicates error (method throws an exception)
  70. * the redirect is vetoed and no callback must be done. Repeat: No
  71. * callback must be done if this method throws!
  72. *
  73. * @see nsIAsyncVerifyRedirectCallback::onRedirectVerifyCallback()
  74. *
  75. * @param oldChannel
  76. * The channel that's being redirected.
  77. * @param newChannel
  78. * The new channel. This channel is not opened yet.
  79. * @param flags
  80. * Flags indicating the type of redirect. A bitmask consisting
  81. * of flags from above.
  82. * One of REDIRECT_TEMPORARY and REDIRECT_PERMANENT will always be
  83. * set.
  84. * @param callback
  85. * Object to inform about the async result of this method
  86. *
  87. * @throw <any> Throwing an exception will cause the redirect to be
  88. * cancelled
  89. */
  90. void asyncOnChannelRedirect(in nsIChannel oldChannel,
  91. in nsIChannel newChannel,
  92. in unsigned long flags,
  93. in nsIAsyncVerifyRedirectCallback callback);
  94. };