2013-11-29 16:13:44 +00: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 12:00:28 +00: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"
|
2016-02-11 09:18:46 +00:00
|
|
|
#include "nsISocketFilter.h"
|
2014-08-22 23:16:31 +00:00
|
|
|
#include "mozilla/net/OfflineObserver.h"
|
2015-04-08 19:35:00 +00:00
|
|
|
#include "mozilla/dom/PermissionMessageUtils.h"
|
2013-05-10 12:00:28 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
2015-05-29 14:14:14 +00:00
|
|
|
namespace net {
|
|
|
|
class PNeckoParent;
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace net
|
2015-05-29 14:14:14 +00:00
|
|
|
|
2013-05-10 12:00:28 +00:00
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class UDPSocketParent : public mozilla::net::PUDPSocketParent
|
|
|
|
, public nsIUDPSocketListener
|
2014-08-22 23:16:31 +00:00
|
|
|
, public mozilla::net::DisconnectableParent
|
2013-05-10 12:00:28 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
NS_DECL_NSIUDPSOCKETLISTENER
|
|
|
|
|
2015-05-29 14:14:14 +00:00
|
|
|
explicit UDPSocketParent(PBackgroundParent* aManager);
|
|
|
|
explicit UDPSocketParent(PNeckoParent* aManager);
|
2013-11-29 16:13:44 +00:00
|
|
|
|
2015-04-08 19:35:00 +00:00
|
|
|
bool Init(const IPC::Principal& aPrincipal, const nsACString& aFilter);
|
2014-05-06 10:32:25 +00:00
|
|
|
|
|
|
|
virtual bool RecvBind(const UDPAddressInfo& aAddressInfo,
|
2016-03-02 05:46:50 +00:00
|
|
|
const bool& aAddressReuse, const bool& aLoopback,
|
2016-04-08 23:51:21 +00:00
|
|
|
const uint32_t& recvBufferSize,
|
|
|
|
const uint32_t& sendBufferSize) override;
|
2016-01-22 07:47:01 +00:00
|
|
|
virtual bool RecvConnect(const UDPAddressInfo& aAddressInfo) override;
|
2016-01-22 08:56:04 +00:00
|
|
|
void DoSendConnectResponse(const UDPAddressInfo& aAddressInfo);
|
2016-01-22 07:47:01 +00:00
|
|
|
void SendConnectResponse(nsIEventTarget *aThread,
|
|
|
|
const UDPAddressInfo& aAddressInfo);
|
|
|
|
void DoConnect(nsCOMPtr<nsIUDPSocket>& aSocket,
|
|
|
|
nsCOMPtr<nsIEventTarget>& aReturnThread,
|
|
|
|
const UDPAddressInfo& aAddressInfo);
|
2014-05-06 10:32:25 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool RecvOutgoingData(const UDPData& aData, const UDPSocketAddr& aAddr) override;
|
2013-05-10 12:00:28 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool RecvClose() override;
|
|
|
|
virtual bool RecvRequestDelete() override;
|
2014-05-06 10:32:25 +00:00
|
|
|
virtual bool RecvJoinMulticast(const nsCString& aMulticastAddress,
|
2015-03-21 16:28:04 +00:00
|
|
|
const nsCString& aInterface) override;
|
2014-05-06 10:32:25 +00:00
|
|
|
virtual bool RecvLeaveMulticast(const nsCString& aMulticastAddress,
|
2015-03-21 16:28:04 +00:00
|
|
|
const nsCString& aInterface) override;
|
|
|
|
virtual nsresult OfflineNotification(nsISupports *) override;
|
|
|
|
virtual uint32_t GetAppId() override;
|
2013-05-10 12:00:28 +00:00
|
|
|
|
|
|
|
private:
|
2014-06-23 19:56:07 +00:00
|
|
|
virtual ~UDPSocketParent();
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void ActorDestroy(ActorDestroyReason why) override;
|
2014-05-06 10:32:25 +00: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,
|
2016-03-02 05:46:50 +00:00
|
|
|
const bool& aAddressReuse, const bool& aLoopback,
|
2016-04-08 23:51:21 +00:00
|
|
|
const uint32_t& recvBufferSize,
|
|
|
|
const uint32_t& sendBufferSize);
|
2016-01-22 07:47:01 +00:00
|
|
|
nsresult ConnectInternal(const nsCString& aHost, const uint16_t& aPort);
|
2014-05-06 10:32:25 +00:00
|
|
|
void FireInternalError(uint32_t aLineNo);
|
2016-01-22 07:47:01 +00:00
|
|
|
void SendInternalError(nsIEventTarget *aThread,
|
|
|
|
uint32_t aLineNo);
|
2013-05-10 12:00:28 +00:00
|
|
|
|
2015-05-29 14:14:14 +00:00
|
|
|
// One of these will be null and the other non-null.
|
|
|
|
PBackgroundParent* mBackgroundManager;
|
|
|
|
PNeckoParent* mNeckoManager;
|
|
|
|
|
2013-05-10 12:00:28 +00:00
|
|
|
bool mIPCOpen;
|
|
|
|
nsCOMPtr<nsIUDPSocket> mSocket;
|
2016-02-11 09:18:46 +00:00
|
|
|
nsCOMPtr<nsISocketFilter> mFilter;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::net::OfflineObserver> mObserver;
|
2015-04-08 19:35:00 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2013-05-10 12:00:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // !defined(mozilla_dom_UDPSocketParent_h__)
|