nsINetworkInterceptController.idl 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* -*- Mode: C++; tab-width: 4; 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. #include "nsIContentPolicyBase.idl"
  7. interface nsIChannel;
  8. interface nsIConsoleReportCollector;
  9. interface nsIOutputStream;
  10. interface nsIURI;
  11. %{C++
  12. #include "nsIConsoleReportCollector.h"
  13. namespace mozilla {
  14. class TimeStamp;
  15. namespace dom {
  16. class ChannelInfo;
  17. }
  18. }
  19. %}
  20. native TimeStamp(mozilla::TimeStamp);
  21. [ptr] native ChannelInfo(mozilla::dom::ChannelInfo);
  22. /**
  23. * Interface to allow implementors of nsINetworkInterceptController to control the behaviour
  24. * of intercepted channels without tying implementation details of the interception to
  25. * the actual channel. nsIInterceptedChannel is expected to be implemented by objects
  26. * which do not implement nsIChannel.
  27. */
  28. [scriptable, uuid(f4b82975-6a86-4cc4-87fe-9a1fd430c86d)]
  29. interface nsIInterceptedChannel : nsISupports
  30. {
  31. /**
  32. * Instruct a channel that has been intercepted to continue with the original
  33. * network request.
  34. */
  35. void resetInterception();
  36. /**
  37. * Set the status and reason for the forthcoming synthesized response.
  38. * Multiple calls overwrite existing values.
  39. */
  40. void synthesizeStatus(in uint16_t status, in ACString reason);
  41. /**
  42. * Attach a header name/value pair to the forthcoming synthesized response.
  43. * Overwrites any existing header value.
  44. */
  45. void synthesizeHeader(in ACString name, in ACString value);
  46. /**
  47. * Instruct a channel that has been intercepted that a response has been
  48. * synthesized and can now be read. No further header modification is allowed
  49. * after this point. The caller may optionally pass a spec for a URL that
  50. * this response originates from; an empty string will cause the original
  51. * intercepted request's URL to be used instead.
  52. */
  53. void finishSynthesizedResponse(in ACString finalURLSpec);
  54. /**
  55. * Cancel the pending intercepted request.
  56. * @return NS_ERROR_FAILURE if the response has already been synthesized or
  57. * the original request has been instructed to continue.
  58. */
  59. void cancel(in nsresult status);
  60. /**
  61. * The synthesized response body to be produced.
  62. */
  63. readonly attribute nsIOutputStream responseBody;
  64. /**
  65. * The underlying channel object that was intercepted.
  66. */
  67. readonly attribute nsIChannel channel;
  68. /**
  69. * The URL of the underlying channel object, corrected for a potential
  70. * secure upgrade.
  71. */
  72. readonly attribute nsIURI secureUpgradedChannelURI;
  73. /**
  74. * This method allows to override the channel info for the channel.
  75. */
  76. [noscript]
  77. void setChannelInfo(in ChannelInfo channelInfo);
  78. /**
  79. * Get the internal load type from the underlying channel.
  80. */
  81. [noscript]
  82. readonly attribute nsContentPolicyType internalContentPolicyType;
  83. [noscript]
  84. readonly attribute nsIConsoleReportCollector consoleReportCollector;
  85. /**
  86. * Save the timestamps of various service worker interception phases.
  87. */
  88. [noscript]
  89. void SetLaunchServiceWorkerStart(in TimeStamp aTimeStamp);
  90. [noscript]
  91. void SetLaunchServiceWorkerEnd(in TimeStamp aTimeStamp);
  92. [noscript]
  93. void SetDispatchFetchEventStart(in TimeStamp aTimeStamp);
  94. [noscript]
  95. void SetDispatchFetchEventEnd(in TimeStamp aTimeStamp);
  96. [noscript]
  97. void SetHandleFetchEventStart(in TimeStamp aTimeStamp);
  98. [noscript]
  99. void SetHandleFetchEventEnd(in TimeStamp aTimeStamp);
  100. [noscript]
  101. void SaveTimeStampsToUnderlyingChannel();
  102. %{C++
  103. already_AddRefed<nsIConsoleReportCollector>
  104. GetConsoleReportCollector()
  105. {
  106. nsCOMPtr<nsIConsoleReportCollector> reporter;
  107. GetConsoleReportCollector(getter_AddRefs(reporter));
  108. return reporter.forget();
  109. }
  110. %}
  111. /**
  112. * Allow the ServiceWorkerManager to set an RAII-style object on the
  113. * intercepted channel that should be released once the channel is
  114. * torn down.
  115. */
  116. [noscript]
  117. void setReleaseHandle(in nsISupports aHandle);
  118. };
  119. /**
  120. * Interface to allow consumers to attach themselves to a channel's
  121. * notification callbacks/loadgroup and determine if a given channel
  122. * request should be intercepted before any network request is initiated.
  123. */
  124. [scriptable, uuid(70d2b4fe-a552-48cd-8d93-1d8437a56b53)]
  125. interface nsINetworkInterceptController : nsISupports
  126. {
  127. /**
  128. * Returns true if a channel should avoid initiating any network
  129. * requests until specifically instructed to do so.
  130. *
  131. * @param aURI the URI being requested by a channel
  132. * @param aIsNavigate True if the request is for a navigation, false for a fetch.
  133. */
  134. bool shouldPrepareForIntercept(in nsIURI aURI, in bool aIsNonSubresourceRequest);
  135. /**
  136. * Notification when a given intercepted channel is prepared to accept a synthesized
  137. * response via the provided stream.
  138. *
  139. * @param aChannel the controlling interface for a channel that has been intercepted
  140. */
  141. void channelIntercepted(in nsIInterceptedChannel aChannel);
  142. };