зеркало из https://github.com/mozilla/gecko-dev.git
Bug 935838 - Add per app network traffic statistics to the UDP socket. r=sicking, r=mayhemer
This commit is contained in:
Родитель
0a25452d9a
Коммит
9441d5b1f1
|
@ -396,8 +396,19 @@ UDPSocket::InitLocal(const nsAString& aLocalAddress,
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner(), &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPrincipal> principal = global->PrincipalOrNull();
|
||||
if (!principal) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (aLocalAddress.IsEmpty()) {
|
||||
rv = sock->Init(aLocalPort, /* loopback = */ false, mAddressReuse, /* optionalArgc = */ 1);
|
||||
rv = sock->Init(aLocalPort, /* loopback = */ false, principal,
|
||||
mAddressReuse, /* optionalArgc = */ 1);
|
||||
} else {
|
||||
PRNetAddr prAddr;
|
||||
PR_InitializeNetAddr(PR_IpAddrAny, aLocalPort, &prAddr);
|
||||
|
@ -405,7 +416,8 @@ UDPSocket::InitLocal(const nsAString& aLocalAddress,
|
|||
|
||||
mozilla::net::NetAddr addr;
|
||||
PRNetAddrToNetAddr(&prAddr, &addr);
|
||||
rv = sock->InitWithAddress(&addr, mAddressReuse, /* optionalArgc = */ 1);
|
||||
rv = sock->InitWithAddress(&addr, principal, mAddressReuse,
|
||||
/* optionalArgc = */ 1);
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
|
@ -471,7 +483,18 @@ UDPSocket::InitRemote(const nsAString& aLocalAddress,
|
|||
|
||||
mListenerProxy = new ListenerProxy(this);
|
||||
|
||||
nsCOMPtr<nsIGlobalObject> obj = do_QueryInterface(GetOwner(), &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPrincipal> principal = obj->PrincipalOrNull();
|
||||
if (!principal) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
rv = sock->Bind(mListenerProxy,
|
||||
principal,
|
||||
NS_ConvertUTF16toUTF8(aLocalAddress),
|
||||
aLocalPort,
|
||||
mAddressReuse,
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "mozilla/unused.h"
|
||||
#include "mozilla/ipc/InputStreamUtils.h"
|
||||
#include "mozilla/net/NeckoChild.h"
|
||||
#include "mozilla/dom/PermissionMessageUtils.h"
|
||||
|
||||
using mozilla::net::gNeckoChild;
|
||||
|
||||
|
@ -63,6 +64,7 @@ UDPSocketChild::~UDPSocketChild()
|
|||
|
||||
NS_IMETHODIMP
|
||||
UDPSocketChild::Bind(nsIUDPSocketInternal* aSocket,
|
||||
nsIPrincipal* aPrincipal,
|
||||
const nsACString& aHost,
|
||||
uint16_t aPort,
|
||||
bool aAddressReuse,
|
||||
|
@ -73,7 +75,8 @@ UDPSocketChild::Bind(nsIUDPSocketInternal* aSocket,
|
|||
mSocket = aSocket;
|
||||
AddIPDLReference();
|
||||
|
||||
gNeckoChild->SendPUDPSocketConstructor(this, mFilterName);
|
||||
gNeckoChild->SendPUDPSocketConstructor(this, IPC::Principal(aPrincipal),
|
||||
mFilterName);
|
||||
|
||||
SendBind(UDPAddressInfo(nsCString(aHost), aPort), aAddressReuse, aLoopback);
|
||||
return NS_OK;
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#include "nsNetUtil.h"
|
||||
#include "mozilla/dom/ContentParent.h"
|
||||
#include "mozilla/dom/TabParent.h"
|
||||
#include "nsIPermissionManager.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
@ -65,19 +67,40 @@ UDPSocketParent::OfflineNotification(nsISupports *aSubject)
|
|||
uint32_t
|
||||
UDPSocketParent::GetAppId()
|
||||
{
|
||||
uint32_t appId = nsIScriptSecurityManager::UNKNOWN_APP_ID;
|
||||
const PContentParent *content = Manager()->Manager();
|
||||
const InfallibleTArray<PBrowserParent*>& browsers = content->ManagedPBrowserParent();
|
||||
if (browsers.Length() > 0) {
|
||||
TabParent *tab = TabParent::GetFrom(browsers[0]);
|
||||
appId = tab->OwnAppId();
|
||||
uint32_t appId;
|
||||
if (!mPrincipal || NS_FAILED(mPrincipal->GetAppId(&appId))) {
|
||||
return nsIScriptSecurityManager::UNKNOWN_APP_ID;
|
||||
}
|
||||
return appId;
|
||||
}
|
||||
|
||||
bool
|
||||
UDPSocketParent::Init(const nsACString& aFilter)
|
||||
UDPSocketParent::Init(const IPC::Principal& aPrincipal,
|
||||
const nsACString& aFilter)
|
||||
{
|
||||
mPrincipal = aPrincipal;
|
||||
if (net::UsingNeckoIPCSecurity() &&
|
||||
mPrincipal &&
|
||||
!ContentParent::IgnoreIPCPrincipal()) {
|
||||
if (!AssertAppPrincipal(Manager()->Manager(), mPrincipal)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPermissionManager> permMgr =
|
||||
services::GetPermissionManager();
|
||||
if (!permMgr) {
|
||||
NS_WARNING("No PermissionManager available!");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t permission = nsIPermissionManager::DENY_ACTION;
|
||||
permMgr->TestExactPermissionFromPrincipal(mPrincipal, "udp-socket",
|
||||
&permission);
|
||||
if (permission != nsIPermissionManager::ALLOW_ACTION) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!aFilter.IsEmpty()) {
|
||||
nsAutoCString contractId(NS_NETWORK_UDP_SOCKET_FILTER_HANDLER_PREFIX);
|
||||
contractId.Append(aFilter);
|
||||
|
@ -96,6 +119,12 @@ UDPSocketParent::Init(const nsACString& aFilter)
|
|||
return false;
|
||||
}
|
||||
}
|
||||
// We don't have browser actors in xpcshell, and hence can't run automated
|
||||
// tests without this loophole.
|
||||
if (net::UsingNeckoIPCSecurity() && !mFilter &&
|
||||
(!mPrincipal || ContentParent::IgnoreIPCPrincipal())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -105,14 +134,6 @@ bool
|
|||
UDPSocketParent::RecvBind(const UDPAddressInfo& aAddressInfo,
|
||||
const bool& aAddressReuse, const bool& aLoopback)
|
||||
{
|
||||
// We don't have browser actors in xpcshell, and hence can't run automated
|
||||
// tests without this loophole.
|
||||
if (net::UsingNeckoIPCSecurity() && !mFilter &&
|
||||
!AssertAppProcessPermission(Manager()->Manager(), "udp-socket")) {
|
||||
FireInternalError(__LINE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (NS_FAILED(BindInternal(aAddressInfo.addr(), aAddressInfo.port(), aAddressReuse, aLoopback))) {
|
||||
FireInternalError(__LINE__);
|
||||
return true;
|
||||
|
@ -152,7 +173,8 @@ UDPSocketParent::BindInternal(const nsCString& aHost, const uint16_t& aPort,
|
|||
}
|
||||
|
||||
if (aHost.IsEmpty()) {
|
||||
rv = sock->Init(aPort, false, aAddressReuse, /* optional_argc = */ 1);
|
||||
rv = sock->Init(aPort, false, mPrincipal, aAddressReuse,
|
||||
/* optional_argc = */ 1);
|
||||
} else {
|
||||
PRNetAddr prAddr;
|
||||
PR_InitializeNetAddr(PR_IpAddrAny, aPort, &prAddr);
|
||||
|
@ -163,7 +185,8 @@ UDPSocketParent::BindInternal(const nsCString& aHost, const uint16_t& aPort,
|
|||
|
||||
mozilla::net::NetAddr addr;
|
||||
PRNetAddrToNetAddr(&prAddr, &addr);
|
||||
rv = sock->InitWithAddress(&addr, aAddressReuse, /* optional_argc = */ 1);
|
||||
rv = sock->InitWithAddress(&addr, mPrincipal, aAddressReuse,
|
||||
/* optional_argc = */ 1);
|
||||
}
|
||||
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "nsIUDPSocket.h"
|
||||
#include "nsIUDPSocketFilter.h"
|
||||
#include "mozilla/net/OfflineObserver.h"
|
||||
#include "mozilla/dom/PermissionMessageUtils.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
@ -26,7 +27,7 @@ public:
|
|||
|
||||
UDPSocketParent();
|
||||
|
||||
bool Init(const nsACString& aFilter);
|
||||
bool Init(const IPC::Principal& aPrincipal, const nsACString& aFilter);
|
||||
|
||||
virtual bool RecvBind(const UDPAddressInfo& aAddressInfo,
|
||||
const bool& aAddressReuse, const bool& aLoopback) override;
|
||||
|
@ -57,6 +58,7 @@ private:
|
|||
nsCOMPtr<nsIUDPSocket> mSocket;
|
||||
nsCOMPtr<nsIUDPSocketFilter> mFilter;
|
||||
nsRefPtr<mozilla::net::OfflineObserver> mObserver;
|
||||
nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
interface nsIUDPSocketInternal;
|
||||
interface nsIInputStream;
|
||||
interface nsIPrincipal;
|
||||
|
||||
%{ C++
|
||||
namespace mozilla {
|
||||
|
@ -18,7 +19,7 @@ union NetAddr;
|
|||
native NetAddr(mozilla::net::NetAddr);
|
||||
[ptr] native NetAddrPtr(mozilla::net::NetAddr);
|
||||
|
||||
[scriptable, uuid(36ec5264-6a58-4cf2-ad9a-185292e0d1d1)]
|
||||
[scriptable, uuid(dd636fc5-05a0-401c-832f-2c07f3477c60)]
|
||||
interface nsIUDPSocketChild : nsISupports
|
||||
{
|
||||
readonly attribute unsigned short localPort;
|
||||
|
@ -26,7 +27,8 @@ interface nsIUDPSocketChild : nsISupports
|
|||
attribute AUTF8String filterName;
|
||||
|
||||
// Tell the chrome process to bind the UDP socket to a given local host and port
|
||||
void bind(in nsIUDPSocketInternal socket, in AUTF8String host, in unsigned short port,
|
||||
void bind(in nsIUDPSocketInternal socket, in nsIPrincipal principal,
|
||||
in AUTF8String host, in unsigned short port,
|
||||
in bool addressReuse, in bool loopback);
|
||||
|
||||
// Tell the chrome process to perform equivalent operations to all following methods
|
||||
|
|
|
@ -1733,7 +1733,7 @@ this.PushService = {
|
|||
|
||||
this._udpServer = Cc["@mozilla.org/network/udp-socket;1"]
|
||||
.createInstance(Ci.nsIUDPSocket);
|
||||
this._udpServer.init(-1, false);
|
||||
this._udpServer.init(-1, false, Services.scriptSecurityManager.getSystemPrincipal());
|
||||
this._udpServer.asyncListen(this);
|
||||
debug("listenForUDPWakeup listening on " + this._udpServer.port);
|
||||
|
||||
|
|
|
@ -1078,7 +1078,7 @@ void NrSocketIpc::create_m(const nsACString &host, const uint16_t port) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (NS_FAILED(socket_child_->Bind(proxy, host, port,
|
||||
if (NS_FAILED(socket_child_->Bind(proxy, nullptr, host, port,
|
||||
/* reuse = */ false,
|
||||
/* loopback = */ false))) {
|
||||
err_ = true;
|
||||
|
|
|
@ -11,6 +11,7 @@ interface nsIUDPMessage;
|
|||
interface nsISocketTransport;
|
||||
interface nsIOutputStream;
|
||||
interface nsIInputStream;
|
||||
interface nsIPrincipal;
|
||||
|
||||
%{ C++
|
||||
#include "nsTArrayForwardDeclare.h"
|
||||
|
@ -29,7 +30,7 @@ native NetAddr(mozilla::net::NetAddr);
|
|||
*
|
||||
* An interface to a UDP socket that can accept incoming connections.
|
||||
*/
|
||||
[scriptable, uuid(8f28299c-f2ac-468a-8223-190335006bbc)]
|
||||
[scriptable, uuid(e0377f7b-34a9-4d0f-8191-7e0cba77a52f)]
|
||||
interface nsIUDPSocket : nsISupports
|
||||
{
|
||||
/**
|
||||
|
@ -45,11 +46,16 @@ interface nsIUDPSocket : nsISupports
|
|||
* local loopback interface. Otherwise, it will accept connections
|
||||
* from any interface. To specify a particular network interface,
|
||||
* use initWithAddress.
|
||||
* @param aPrincipal
|
||||
* The principal connected to this socket.
|
||||
* @param aAddressReuse
|
||||
* If true, the socket is allowed to be bound to an address that is
|
||||
* already in use. Default is true.
|
||||
*/
|
||||
[optional_argc] void init(in long aPort, in boolean aLoopbackOnly, [optional] in boolean aAddressReuse);
|
||||
[optional_argc] void init(in long aPort,
|
||||
in boolean aLoopbackOnly,
|
||||
in nsIPrincipal aPrincipal,
|
||||
[optional] in boolean aAddressReuse);
|
||||
|
||||
/**
|
||||
* initWithAddress
|
||||
|
@ -59,11 +65,15 @@ interface nsIUDPSocket : nsISupports
|
|||
*
|
||||
* @param aAddr
|
||||
* The address to which this UDP socket should be bound.
|
||||
* @param aPrincipal
|
||||
* The principal connected to this socket.
|
||||
* @param aAddressReuse
|
||||
* If true, the socket is allowed to be bound to an address that is
|
||||
* already in use. Default is true.
|
||||
*/
|
||||
[noscript, optional_argc] void initWithAddress([const] in NetAddrPtr aAddr, [optional] in boolean aAddressReuse);
|
||||
[noscript, optional_argc] void initWithAddress([const] in NetAddrPtr aAddr,
|
||||
in nsIPrincipal aPrincipal,
|
||||
[optional] in boolean aAddressReuse);
|
||||
|
||||
/**
|
||||
* close
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "nsAutoPtr.h"
|
||||
#include "nsError.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "prnetdb.h"
|
||||
#include "prio.h"
|
||||
#include "nsNetAddr.h"
|
||||
|
@ -28,6 +29,10 @@
|
|||
#include "nsIDNSService.h"
|
||||
#include "nsICancelable.h"
|
||||
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
#include "NetStatistics.h"
|
||||
#endif
|
||||
|
||||
using namespace mozilla::net;
|
||||
using namespace mozilla;
|
||||
|
||||
|
@ -440,6 +445,8 @@ nsUDPMessage::GetDataAsTArray()
|
|||
nsUDPSocket::nsUDPSocket()
|
||||
: mLock("nsUDPSocket.mLock")
|
||||
, mFD(nullptr)
|
||||
, mAppId(NECKO_UNKNOWN_APP_ID)
|
||||
, mIsInBrowserElement(false)
|
||||
, mAttached(false)
|
||||
, mByteReadCount(0)
|
||||
, mByteWriteCount(0)
|
||||
|
@ -474,6 +481,7 @@ void
|
|||
nsUDPSocket::AddOutputBytes(uint64_t aBytes)
|
||||
{
|
||||
mByteWriteCount += aBytes;
|
||||
SaveNetworkStats(false);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -661,6 +669,7 @@ nsUDPSocket::OnSocketReady(PRFileDesc *fd, int16_t outFlags)
|
|||
return;
|
||||
}
|
||||
mByteReadCount += count;
|
||||
SaveNetworkStats(false);
|
||||
|
||||
FallibleTArray<uint8_t> data;
|
||||
if(!data.AppendElements(buff, count)){
|
||||
|
@ -710,6 +719,7 @@ nsUDPSocket::OnSocketDetached(PRFileDesc *fd)
|
|||
}
|
||||
mFD = nullptr;
|
||||
}
|
||||
SaveNetworkStats(true);
|
||||
|
||||
if (mListener)
|
||||
{
|
||||
|
@ -746,7 +756,8 @@ NS_IMPL_ISUPPORTS(nsUDPSocket, nsIUDPSocket)
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUDPSocket::Init(int32_t aPort, bool aLoopbackOnly, bool aAddressReuse, uint8_t aOptionalArgc)
|
||||
nsUDPSocket::Init(int32_t aPort, bool aLoopbackOnly, nsIPrincipal *aPrincipal,
|
||||
bool aAddressReuse, uint8_t aOptionalArgc)
|
||||
{
|
||||
NetAddr addr;
|
||||
|
||||
|
@ -761,11 +772,12 @@ nsUDPSocket::Init(int32_t aPort, bool aLoopbackOnly, bool aAddressReuse, uint8_t
|
|||
else
|
||||
addr.inet.ip = htonl(INADDR_ANY);
|
||||
|
||||
return InitWithAddress(&addr, aAddressReuse, aOptionalArgc);
|
||||
return InitWithAddress(&addr, aPrincipal, aAddressReuse, aOptionalArgc);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUDPSocket::InitWithAddress(const NetAddr *aAddr, bool aAddressReuse, uint8_t aOptionalArgc)
|
||||
nsUDPSocket::InitWithAddress(const NetAddr *aAddr, nsIPrincipal *aPrincipal,
|
||||
bool aAddressReuse, uint8_t aOptionalArgc)
|
||||
{
|
||||
NS_ENSURE_TRUE(mFD == nullptr, NS_ERROR_ALREADY_INITIALIZED);
|
||||
|
||||
|
@ -782,6 +794,27 @@ nsUDPSocket::InitWithAddress(const NetAddr *aAddr, bool aAddressReuse, uint8_t a
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (aPrincipal) {
|
||||
nsresult rv = aPrincipal->GetAppId(&mAppId);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = aPrincipal->GetIsInBrowserElement(&mIsInBrowserElement);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
if (mAppId != NECKO_UNKNOWN_APP_ID) {
|
||||
nsCOMPtr<nsINetworkInterface> activeNetwork;
|
||||
GetActiveNetworkInterface(activeNetwork);
|
||||
mActiveNetwork =
|
||||
new nsMainThreadPtrHolder<nsINetworkInterface>(activeNetwork);
|
||||
}
|
||||
#endif
|
||||
|
||||
uint16_t port;
|
||||
if (NS_FAILED(net::GetPort(aAddr, &port))) {
|
||||
NS_WARNING("invalid bind address");
|
||||
|
@ -850,6 +883,7 @@ nsUDPSocket::Close()
|
|||
PR_Close(mFD);
|
||||
mFD = nullptr;
|
||||
}
|
||||
SaveNetworkStats(true);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
@ -877,6 +911,34 @@ nsUDPSocket::GetLocalAddr(nsINetAddr * *aResult)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsUDPSocket::SaveNetworkStats(bool aEnforce)
|
||||
{
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
if (!mActiveNetwork || mAppId == NECKO_UNKNOWN_APP_ID) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mByteReadCount == 0 && mByteWriteCount == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t total = mByteReadCount + mByteWriteCount;
|
||||
if (aEnforce || total > NETWORK_STATS_THRESHOLD) {
|
||||
// Create the event to save the network statistics.
|
||||
// the event is then dispathed to the main thread.
|
||||
nsRefPtr<nsRunnable> event =
|
||||
new SaveNetworkStatsEvent(mAppId, mIsInBrowserElement, mActiveNetwork,
|
||||
mByteReadCount, mByteWriteCount, false);
|
||||
NS_DispatchToMainThread(event);
|
||||
|
||||
// Reset the counters after saving.
|
||||
mByteReadCount = 0;
|
||||
mByteWriteCount = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUDPSocket::GetAddress(NetAddr *aResult)
|
||||
{
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
#include "nsAutoPtr.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
#include "nsINetworkManager.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class nsUDPSocket final : public nsASocketHandler
|
||||
|
@ -50,11 +54,15 @@ private:
|
|||
const PRNetAddr& aIface);
|
||||
nsresult SetMulticastInterfaceInternal(const PRNetAddr& aIface);
|
||||
|
||||
void SaveNetworkStats(bool aEnforce);
|
||||
|
||||
// lock protects access to mListener;
|
||||
// so mListener is not cleared while being used/locked.
|
||||
mozilla::Mutex mLock;
|
||||
PRFileDesc *mFD;
|
||||
mozilla::net::NetAddr mAddr;
|
||||
uint32_t mAppId;
|
||||
bool mIsInBrowserElement;
|
||||
nsCOMPtr<nsIUDPSocketListener> mListener;
|
||||
nsCOMPtr<nsIEventTarget> mListenerTarget;
|
||||
bool mAttached;
|
||||
|
@ -62,6 +70,9 @@ private:
|
|||
|
||||
uint64_t mByteReadCount;
|
||||
uint64_t mByteWriteCount;
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
nsMainThreadPtrHandle<nsINetworkInterface> mActiveNetwork;
|
||||
#endif
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
@ -251,7 +251,8 @@ NeckoChild::DeallocPTCPServerSocketChild(PTCPServerSocketChild* child)
|
|||
}
|
||||
|
||||
PUDPSocketChild*
|
||||
NeckoChild::AllocPUDPSocketChild(const nsCString& aFilter)
|
||||
NeckoChild::AllocPUDPSocketChild(const Principal& aPrincipal,
|
||||
const nsCString& aFilter)
|
||||
{
|
||||
NS_NOTREACHED("AllocPUDPSocket should not be called");
|
||||
return nullptr;
|
||||
|
|
|
@ -51,7 +51,8 @@ protected:
|
|||
const uint16_t& aBacklog,
|
||||
const nsString& aBinaryType) override;
|
||||
virtual bool DeallocPTCPServerSocketChild(PTCPServerSocketChild*) override;
|
||||
virtual PUDPSocketChild* AllocPUDPSocketChild(const nsCString& aFilter) override;
|
||||
virtual PUDPSocketChild* AllocPUDPSocketChild(const Principal& aPrincipal,
|
||||
const nsCString& aFilter) override;
|
||||
virtual bool DeallocPUDPSocketChild(PUDPSocketChild*) override;
|
||||
virtual PDNSRequestChild* AllocPDNSRequestChild(const nsCString& aHost,
|
||||
const uint32_t& aFlags,
|
||||
|
|
|
@ -480,7 +480,8 @@ NeckoParent::DeallocPTCPServerSocketParent(PTCPServerSocketParent* actor)
|
|||
}
|
||||
|
||||
PUDPSocketParent*
|
||||
NeckoParent::AllocPUDPSocketParent(const nsCString& /* unused */)
|
||||
NeckoParent::AllocPUDPSocketParent(const Principal& /* unused */,
|
||||
const nsCString& /* unused */)
|
||||
{
|
||||
nsRefPtr<UDPSocketParent> p = new UDPSocketParent();
|
||||
|
||||
|
@ -489,9 +490,10 @@ NeckoParent::AllocPUDPSocketParent(const nsCString& /* unused */)
|
|||
|
||||
bool
|
||||
NeckoParent::RecvPUDPSocketConstructor(PUDPSocketParent* aActor,
|
||||
const Principal& aPrincipal,
|
||||
const nsCString& aFilter)
|
||||
{
|
||||
return static_cast<UDPSocketParent*>(aActor)->Init(aFilter);
|
||||
return static_cast<UDPSocketParent*>(aActor)->Init(aPrincipal, aFilter);
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -149,8 +149,11 @@ protected:
|
|||
const uint16_t& aBacklog,
|
||||
const nsString& aBinaryType) override;
|
||||
virtual bool DeallocPTCPServerSocketParent(PTCPServerSocketParent*) override;
|
||||
virtual PUDPSocketParent* AllocPUDPSocketParent(const nsCString& aFilter) override;
|
||||
virtual bool RecvPUDPSocketConstructor(PUDPSocketParent*, const nsCString& aFilter) override;
|
||||
virtual PUDPSocketParent* AllocPUDPSocketParent(const Principal& aPrincipal,
|
||||
const nsCString& aFilter) override;
|
||||
virtual bool RecvPUDPSocketConstructor(PUDPSocketParent*,
|
||||
const Principal& aPrincipal,
|
||||
const nsCString& aFilter) override;
|
||||
virtual bool DeallocPUDPSocketParent(PUDPSocketParent*) override;
|
||||
virtual PDNSRequestParent* AllocPDNSRequestParent(const nsCString& aHost,
|
||||
const uint32_t& aFlags,
|
||||
|
|
|
@ -31,6 +31,7 @@ include PBrowserOrId;
|
|||
|
||||
using class IPC::SerializedLoadContext from "SerializedLoadContext.h";
|
||||
using mozilla::dom::TabId from "mozilla/dom/ipc/IdType.h";
|
||||
using class IPC::Principal from "mozilla/dom/PermissionMessageUtils.h";
|
||||
|
||||
namespace mozilla {
|
||||
namespace net {
|
||||
|
@ -67,7 +68,7 @@ parent:
|
|||
|
||||
PWebSocket(PBrowserOrId browser, SerializedLoadContext loadContext);
|
||||
PTCPServerSocket(uint16_t localPort, uint16_t backlog, nsString binaryType);
|
||||
PUDPSocket(nsCString filter);
|
||||
PUDPSocket(Principal principal, nsCString filter);
|
||||
|
||||
PDNSRequest(nsCString hostName, uint32_t flags, nsCString networkInterface);
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "nsIInputStream.h"
|
||||
#include "nsINetAddr.h"
|
||||
#include "nsITimer.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "mozilla/net/DNS.h"
|
||||
#include "prerror.h"
|
||||
|
||||
|
@ -272,8 +273,16 @@ main(int32_t argc, char *argv[])
|
|||
// Create UDPServerListener to process UDP packets
|
||||
nsRefPtr<UDPServerListener> serverListener = new UDPServerListener();
|
||||
|
||||
nsCOMPtr<nsIScriptSecurityManager> secman =
|
||||
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, -1);
|
||||
|
||||
nsCOMPtr<nsIPrincipal> systemPrincipal;
|
||||
rv = secman->GetSystemPrincipal(getter_AddRefs(systemPrincipal));
|
||||
NS_ENSURE_SUCCESS(rv, -1);
|
||||
|
||||
// Bind server socket to 0.0.0.0
|
||||
rv = server->Init(0, false, true, 0);
|
||||
rv = server->Init(0, false, systemPrincipal, true, 0);
|
||||
NS_ENSURE_SUCCESS(rv, -1);
|
||||
int32_t serverPort;
|
||||
server->GetPort(&serverPort);
|
||||
|
@ -281,7 +290,7 @@ main(int32_t argc, char *argv[])
|
|||
|
||||
// Bind clinet on arbitrary port
|
||||
nsRefPtr<UDPClientListener> clientListener = new UDPClientListener();
|
||||
client->Init(0, false, true, 0);
|
||||
client->Init(0, false, systemPrincipal, true, 0);
|
||||
client->AsyncListen(clientListener);
|
||||
|
||||
// Write data to server
|
||||
|
|
|
@ -6,6 +6,7 @@ const UDPSocket = CC("@mozilla.org/network/udp-socket;1",
|
|||
"nsIUDPSocket",
|
||||
"init");
|
||||
const { Promise: promise } = Cu.import("resource://gre/modules/Promise.jsm", {});
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const ADDRESS_TEST1 = "224.0.0.200";
|
||||
const ADDRESS_TEST2 = "224.0.0.201";
|
||||
|
@ -32,7 +33,8 @@ function setup() {
|
|||
}
|
||||
|
||||
function createSocketAndJoin(addr) {
|
||||
let socket = new UDPSocket(-1, false);
|
||||
let socket = new UDPSocket(-1, false,
|
||||
Services.scriptSecurityManager.getSystemPrincipal());
|
||||
socket.joinMulticast(addr);
|
||||
return socket;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
"use strict";
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const HELLO_WORLD = "Hello World";
|
||||
|
||||
add_test(function test_udp_message_raw_data() {
|
||||
|
@ -11,7 +13,7 @@ add_test(function test_udp_message_raw_data() {
|
|||
|
||||
let socket = Cc["@mozilla.org/network/udp-socket;1"].createInstance(Ci.nsIUDPSocket);
|
||||
|
||||
socket.init(-1, true);
|
||||
socket.init(-1, true, Services.scriptSecurityManager.getSystemPrincipal());
|
||||
do_print("Port assigned : " + socket.port);
|
||||
socket.asyncListen({
|
||||
QueryInterface : XPCOMUtils.generateQI([Ci.nsIUDPSocketListener]),
|
||||
|
@ -38,7 +40,7 @@ add_test(function test_udp_send_stream() {
|
|||
|
||||
let socket = Cc["@mozilla.org/network/udp-socket;1"].createInstance(Ci.nsIUDPSocket);
|
||||
|
||||
socket.init(-1, true);
|
||||
socket.init(-1, true, Services.scriptSecurityManager.getSystemPrincipal());
|
||||
socket.asyncListen({
|
||||
QueryInterface : XPCOMUtils.generateQI([Ci.nsIUDPSocketListener]),
|
||||
onPacketReceived : function(aSocket, aMessage){
|
||||
|
|
|
@ -78,7 +78,7 @@ function log(msg) {
|
|||
function Transport(port) {
|
||||
EventEmitter.decorate(this);
|
||||
try {
|
||||
this.socket = new UDPSocket(port, false);
|
||||
this.socket = new UDPSocket(port, false, Services.scriptSecurityManager.getSystemPrincipal());
|
||||
this.socket.joinMulticast(ADDRESS);
|
||||
this.socket.asyncListen(this);
|
||||
} catch(e) {
|
||||
|
|
|
@ -144,7 +144,7 @@ var SimpleServiceDiscovery = {
|
|||
// Perform a UDP broadcast to search for SSDP devices
|
||||
let socket = Cc["@mozilla.org/network/udp-socket;1"].createInstance(Ci.nsIUDPSocket);
|
||||
try {
|
||||
socket.init(SSDP_PORT, false);
|
||||
socket.init(SSDP_PORT, false, Services.scriptSecurityManager.getSystemPrincipal());
|
||||
socket.joinMulticast(SSDP_ADDRESS);
|
||||
socket.asyncListen(this);
|
||||
} catch (e) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче