2013-11-29 08:13:44 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-05-10 05:00:28 -07:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_UDPSocketParent_h__
|
|
|
|
#define mozilla_dom_UDPSocketParent_h__
|
|
|
|
|
|
|
|
#include "mozilla/net/PUDPSocketParent.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIUDPSocket.h"
|
2013-11-29 08:13:44 -08:00
|
|
|
#include "nsIUDPSocketFilter.h"
|
2014-08-22 16:16:31 -07:00
|
|
|
#include "mozilla/net/OfflineObserver.h"
|
2015-04-08 12:35:00 -07:00
|
|
|
#include "mozilla/dom/PermissionMessageUtils.h"
|
2013-05-10 05:00:28 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
2015-05-29 07:14:14 -07:00
|
|
|
namespace net {
|
|
|
|
class PNeckoParent;
|
2015-07-13 08:25:42 -07:00
|
|
|
} // namespace net
|
2015-05-29 07:14:14 -07:00
|
|
|
|
2013-05-10 05:00:28 -07:00
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class UDPSocketParent : public mozilla::net::PUDPSocketParent
|
|
|
|
, public nsIUDPSocketListener
|
2014-08-22 16:16:31 -07:00
|
|
|
, public mozilla::net::DisconnectableParent
|
2013-05-10 05:00:28 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
NS_DECL_NSIUDPSOCKETLISTENER
|
|
|
|
|
2015-05-29 07:14:14 -07:00
|
|
|
explicit UDPSocketParent(PBackgroundParent* aManager);
|
|
|
|
explicit UDPSocketParent(PNeckoParent* aManager);
|
2013-11-29 08:13:44 -08:00
|
|
|
|
2015-04-08 12:35:00 -07:00
|
|
|
bool Init(const IPC::Principal& aPrincipal, const nsACString& aFilter);
|
2014-05-06 03:32:25 -07:00
|
|
|
|
|
|
|
virtual bool RecvBind(const UDPAddressInfo& aAddressInfo,
|
2015-03-21 09:28:04 -07:00
|
|
|
const bool& aAddressReuse, const bool& aLoopback) override;
|
2016-01-21 23:47:01 -08:00
|
|
|
virtual bool RecvConnect(const UDPAddressInfo& aAddressInfo) override;
|
2016-01-22 00:56:04 -08:00
|
|
|
void DoSendConnectResponse(const UDPAddressInfo& aAddressInfo);
|
2016-01-21 23:47:01 -08:00
|
|
|
void SendConnectResponse(nsIEventTarget *aThread,
|
|
|
|
const UDPAddressInfo& aAddressInfo);
|
|
|
|
void DoConnect(nsCOMPtr<nsIUDPSocket>& aSocket,
|
|
|
|
nsCOMPtr<nsIEventTarget>& aReturnThread,
|
|
|
|
const UDPAddressInfo& aAddressInfo);
|
2014-05-06 03:32:25 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual bool RecvOutgoingData(const UDPData& aData, const UDPSocketAddr& aAddr) override;
|
2013-05-10 05:00:28 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual bool RecvClose() override;
|
|
|
|
virtual bool RecvRequestDelete() override;
|
2014-05-06 03:32:25 -07:00
|
|
|
virtual bool RecvJoinMulticast(const nsCString& aMulticastAddress,
|
2015-03-21 09:28:04 -07:00
|
|
|
const nsCString& aInterface) override;
|
2014-05-06 03:32:25 -07:00
|
|
|
virtual bool RecvLeaveMulticast(const nsCString& aMulticastAddress,
|
2015-03-21 09:28:04 -07:00
|
|
|
const nsCString& aInterface) override;
|
|
|
|
virtual nsresult OfflineNotification(nsISupports *) override;
|
|
|
|
virtual uint32_t GetAppId() override;
|
2013-05-10 05:00:28 -07:00
|
|
|
|
|
|
|
private:
|
2014-06-23 12:56:07 -07:00
|
|
|
virtual ~UDPSocketParent();
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual void ActorDestroy(ActorDestroyReason why) override;
|
2014-05-06 03:32:25 -07:00
|
|
|
void Send(const InfallibleTArray<uint8_t>& aData, const UDPSocketAddr& aAddr);
|
|
|
|
void Send(const InputStreamParams& aStream, const UDPSocketAddr& aAddr);
|
|
|
|
nsresult BindInternal(const nsCString& aHost, const uint16_t& aPort,
|
|
|
|
const bool& aAddressReuse, const bool& aLoopback);
|
2016-01-21 23:47:01 -08:00
|
|
|
nsresult ConnectInternal(const nsCString& aHost, const uint16_t& aPort);
|
2014-05-06 03:32:25 -07:00
|
|
|
void FireInternalError(uint32_t aLineNo);
|
2016-01-21 23:47:01 -08:00
|
|
|
void SendInternalError(nsIEventTarget *aThread,
|
|
|
|
uint32_t aLineNo);
|
2013-05-10 05:00:28 -07:00
|
|
|
|
2015-05-29 07:14:14 -07:00
|
|
|
// One of these will be null and the other non-null.
|
|
|
|
PBackgroundParent* mBackgroundManager;
|
|
|
|
PNeckoParent* mNeckoManager;
|
|
|
|
|
2013-05-10 05:00:28 -07:00
|
|
|
bool mIPCOpen;
|
|
|
|
nsCOMPtr<nsIUDPSocket> mSocket;
|
2013-11-29 08:13:44 -08:00
|
|
|
nsCOMPtr<nsIUDPSocketFilter> mFilter;
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<mozilla::net::OfflineObserver> mObserver;
|
2015-04-08 12:35:00 -07:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2013-05-10 05:00:28 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // !defined(mozilla_dom_UDPSocketParent_h__)
|