/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

include protocol PContent;
include protocol PHttpChannel;
include protocol PCacheEntryWriteHandle;
include protocol PCookieService;
include protocol PBrowser;
#ifdef MOZ_WIDGET_ANDROID
include protocol PGeckoViewContentChannel;
#endif
include protocol PWebSocket;
include protocol PWebSocketEventListener;
include protocol PTCPSocket;
include protocol PTCPServerSocket;
include protocol PUDPSocket;
include protocol PDNSRequest;
include protocol PTransportProvider;
include protocol PStunAddrsRequest;
include protocol PWebrtcTCPSocket;
include protocol PSocketProcessBridge;
include protocol PDocumentChannel;

include IPCStream;
include NeckoChannelParams;
include protocol PAltDataOutputStream;

include "mozilla/dom/PermissionMessageUtils.h";

using mozilla::dom::MaybeDiscardedBrowsingContext from "mozilla/dom/BrowsingContext.h";
using class IPC::SerializedLoadContext from "SerializedLoadContext.h";
using mozilla::dom::TabId from "mozilla/dom/ipc/IdType.h";
using nsIDNSService::DNSFlags from "nsIDNSService.h";
[RefCounted] using class nsIInputStream from "mozilla/ipc/IPCStreamUtils.h";
[RefCounted] using class nsIURI from "mozilla/ipc/URIUtils.h";
[RefCounted] using class nsIPrincipal from "nsIPrincipal.h";


namespace mozilla {
namespace net {

struct HTMLDNSPrefetchArgs {
  nsString hostname;
  bool isHttps;
  OriginAttributes originAttributes;
  DNSFlags flags;
};

//-------------------------------------------------------------------
[NestedUpTo=inside_cpow] sync protocol PNecko
{
  manager PContent;
  manages PHttpChannel;
  manages PCacheEntryWriteHandle;
  manages PCookieService;
  manages PWebSocket;
  manages PWebSocketEventListener;
  manages PTCPSocket;
  manages PTCPServerSocket;
  manages PUDPSocket;
  manages PDNSRequest;
#ifdef MOZ_WIDGET_ANDROID
  manages PGeckoViewContentChannel;
#endif
  manages PTransportProvider;
  manages PAltDataOutputStream;
  manages PStunAddrsRequest;
  manages PWebrtcTCPSocket;
  manages PDocumentChannel;

parent:
  async __delete__();

  [Nested=inside_cpow] async PCookieService();
  async PHttpChannel(nullable PBrowser browser,
                     SerializedLoadContext loadContext,
                     HttpChannelCreationArgs args);

  async PWebSocket(nullable PBrowser browser, SerializedLoadContext loadContext,
                   uint32_t aSerialID);
  async PTCPServerSocket(uint16_t localPort, uint16_t backlog, bool useArrayBuffers);
  async PUDPSocket(nullable nsIPrincipal principal, nsCString filter);

  async PDNSRequest(nsCString hostName, nsCString trrServer, int32_t port,
                    uint16_t type, OriginAttributes originAttributes,
                    DNSFlags flags);

  async PDocumentChannel(MaybeDiscardedBrowsingContext browsingContext,
                         DocumentChannelCreationArgs args);

  async PWebSocketEventListener(uint64_t aInnerWindowID);

  async SpeculativeConnect(nullable PBrowser browser,
                           SerializedLoadContext loadContext,
                           nullable nsIURI uri,
                           nullable nsIPrincipal principal,
                           OriginAttributes? originAttributes,
                           bool anonymous);
  async HTMLDNSPrefetch(nsString hostname, bool isHttps,
                        OriginAttributes originAttributes, DNSFlags flags);
  async HTMLDNSPrefetchBatch(HTMLDNSPrefetchArgs[] prefetches);
  async CancelHTMLDNSPrefetch(nsString hostname, bool isHttps,
                              OriginAttributes originAttributes,
                              DNSFlags flags, nsresult reason);

  /**
   * Establish a connection between generic redirect channels which do not need
   * specialized nsIParentChannel handling.
   */
  async ConnectBaseChannel(uint32_t channelId);

#ifdef MOZ_WIDGET_ANDROID
  async PGeckoViewContentChannel(nullable PBrowser browser,
                                 SerializedLoadContext loadContext,
                                 GeckoViewContentChannelArgs args);
#endif

  /**
   * When a nsFileChannel is opened within the content process, we notify
   * "file-channel-opened" in the parent process using this IPC message.
   */
  async NotifyFileChannelOpened(FileChannelInfo info);

  async RequestContextLoadBegin(uint64_t rcid);
  async RequestContextAfterDOMContentLoaded(uint64_t rcid);
  async RemoveRequestContext(uint64_t rcid);

  async PCacheEntryWriteHandle(PHttpChannel channel);

  async PAltDataOutputStream(nsCString type, int64_t predictedSize, PHttpChannel? channel, PCacheEntryWriteHandle? handle);


  async PStunAddrsRequest();

  /* tabId is only required for web-proxy support, which isn't always needed */
  async PWebrtcTCPSocket(TabId? tabId);

  /**
   * WebExtension-specific remote resource loading
   */
  async GetExtensionStream(nullable nsIURI uri) returns (nullable nsIInputStream stream);
  async GetExtensionFD(nullable nsIURI uri) returns (FileDescriptor fd);

  async InitSocketProcessBridge()
    returns (Endpoint<PSocketProcessBridgeChild> endpoint);
  async ResetSocketProcessBridge();

  async EnsureHSTSData()
    returns (bool result);

  /**
   * Page thumbnails remote resource loading
   */
  async GetPageThumbStream(nullable nsIURI uri, LoadInfoArgs loadInfo) returns (RemoteStreamInfo? info);
  async GetPageIconStream(nullable nsIURI uri, LoadInfoArgs loadInfo) returns (RemoteStreamInfo? info);

  /**
   * New Tab wallpaper remote resource loading
   */
  async GetMozNewTabWallpaperStream(nullable nsIURI uri, LoadInfoArgs loadInfo) returns (RemoteStreamInfo? info);

child:
  async SpeculativeConnectRequest();

  // Using medium high priority to deliver this notification possibly sooner than we
  // enter poll() on the child process with infinite timeout.
  [Priority=mediumhigh] async NetworkChangeNotification(nsCString type);

  async PTransportProvider();

  async SetTRRDomain(nsCString domain);

both:
  // Actually we need PTCPSocket() for parent. But ipdl disallows us having different
  // signatures on parent and child. So when constructing the parent side object, we just
  // leave host/port unused.
  async PTCPSocket(nsString host, uint16_t port);
};


} // namespace net
} // namespace mozilla
