diff --git a/dom/network/UDPSocket.cpp b/dom/network/UDPSocket.cpp index 6f21860cafb6..e621a0ea8e5b 100644 --- a/dom/network/UDPSocket.cpp +++ b/dom/network/UDPSocket.cpp @@ -387,8 +387,19 @@ UDPSocket::InitLocal(const nsAString& aLocalAddress, return rv; } + nsCOMPtr global = do_QueryInterface(GetOwner(), &rv); + if (NS_FAILED(rv)) { + return rv; + } + + nsCOMPtr 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); @@ -396,7 +407,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; @@ -458,7 +470,19 @@ UDPSocket::InitRemote(const nsAString& aLocalAddress, return rv; } - rv = sock->Bind(this, NS_ConvertUTF16toUTF8(aLocalAddress), aLocalPort, mAddressReuse, mLoopback); + nsCOMPtr obj = do_QueryInterface(GetOwner(), &rv); + if (NS_FAILED(rv)) { + return rv; + } + + nsCOMPtr principal = obj->PrincipalOrNull(); + if (!principal) { + return NS_ERROR_FAILURE; + } + + rv = sock->Bind(this, principal, + NS_ConvertUTF16toUTF8(aLocalAddress), aLocalPort, + mAddressReuse, mLoopback); if (NS_FAILED(rv)) { return rv; } diff --git a/dom/network/UDPSocketChild.cpp b/dom/network/UDPSocketChild.cpp index eb6a86f503d9..889c6bb315fd 100644 --- a/dom/network/UDPSocketChild.cpp +++ b/dom/network/UDPSocketChild.cpp @@ -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; diff --git a/dom/network/UDPSocketParent.cpp b/dom/network/UDPSocketParent.cpp index dc742013f441..caaf0aeebd26 100644 --- a/dom/network/UDPSocketParent.cpp +++ b/dom/network/UDPSocketParent.cpp @@ -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,46 @@ UDPSocketParent::OfflineNotification(nsISupports *aSubject) uint32_t UDPSocketParent::GetAppId() { - uint32_t appId = nsIScriptSecurityManager::UNKNOWN_APP_ID; - const PContentParent *content = Manager()->Manager(); - const InfallibleTArray& browsers = content->ManagedPBrowserParent(); - if (browsers.Length() > 0) { - TabParent *tab = TabParent::GetFrom(browsers[0]); - appId = tab->OwnAppId(); + if (!mPrincipal) { + return nsIScriptSecurityManager::UNKNOWN_APP_ID; } + + uint32_t appId = nsIScriptSecurityManager::UNKNOWN_APP_ID; + nsresult rv = mPrincipal->GetAppId(&appId); + if (NS_FAILED(rv)) { + appId = 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 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); @@ -107,10 +136,9 @@ UDPSocketParent::RecvBind(const UDPAddressInfo& aAddressInfo, { // 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")) { + if (net::UsingNeckoIPCSecurity() && !mFilter) { FireInternalError(__LINE__); - return false; + return true; } if (NS_FAILED(BindInternal(aAddressInfo.addr(), aAddressInfo.port(), aAddressReuse, aLoopback))) { @@ -152,7 +180,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 +192,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))) { diff --git a/dom/network/UDPSocketParent.h b/dom/network/UDPSocketParent.h index de7ae2a72603..3ea4da67b0ce 100644 --- a/dom/network/UDPSocketParent.h +++ b/dom/network/UDPSocketParent.h @@ -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) MOZ_OVERRIDE; @@ -57,6 +58,7 @@ private: nsCOMPtr mSocket; nsCOMPtr mFilter; nsRefPtr mObserver; + nsCOMPtr mPrincipal; }; } // namespace dom diff --git a/dom/network/interfaces/nsIUDPSocketChild.idl b/dom/network/interfaces/nsIUDPSocketChild.idl index 773c02d05fa3..2f5af69cf9fd 100644 --- a/dom/network/interfaces/nsIUDPSocketChild.idl +++ b/dom/network/interfaces/nsIUDPSocketChild.idl @@ -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(d24536f1-dc03-4ef4-a347-647625def206)] 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 diff --git a/dom/push/PushService.jsm b/dom/push/PushService.jsm index f9bf019958a4..e34be9852445 100644 --- a/dom/push/PushService.jsm +++ b/dom/push/PushService.jsm @@ -1684,7 +1684,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); diff --git a/media/mtransport/nr_socket_prsock.cpp b/media/mtransport/nr_socket_prsock.cpp index 5fe41bed7578..04bad9d39dd6 100644 --- a/media/mtransport/nr_socket_prsock.cpp +++ b/media/mtransport/nr_socket_prsock.cpp @@ -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; diff --git a/netwerk/base/nsIUDPSocket.idl b/netwerk/base/nsIUDPSocket.idl index 1a1cb92329f8..d2ff4ae7424a 100644 --- a/netwerk/base/nsIUDPSocket.idl +++ b/netwerk/base/nsIUDPSocket.idl @@ -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 diff --git a/netwerk/base/nsUDPSocket.cpp b/netwerk/base/nsUDPSocket.cpp index b8a71033e548..25eb73a0477e 100644 --- a/netwerk/base/nsUDPSocket.cpp +++ b/netwerk/base/nsUDPSocket.cpp @@ -14,6 +14,7 @@ #include "nsAutoPtr.h" #include "nsError.h" #include "nsNetCID.h" +#include "nsNetUtil.h" #include "prnetdb.h" #include "prio.h" #include "nsNetAddr.h" @@ -27,6 +28,10 @@ #include "nsIDNSService.h" #include "nsICancelable.h" +#ifdef MOZ_WIDGET_GONK +#include "NetStatistics.h" +#endif + using namespace mozilla::net; using namespace mozilla; @@ -254,6 +259,8 @@ nsUDPMessage::GetDataAsTArray() nsUDPSocket::nsUDPSocket() : mLock("nsUDPSocket.mLock") , mFD(nullptr) + , mAppId(NECKO_UNKNOWN_APP_ID) + , mIsInBrowserElement(false) , mAttached(false) , mByteReadCount(0) , mByteWriteCount(0) @@ -286,6 +293,7 @@ void nsUDPSocket::AddOutputBytes(uint64_t aBytes) { mByteWriteCount += aBytes; + SaveNetworkStats(false); } void @@ -473,6 +481,7 @@ nsUDPSocket::OnSocketReady(PRFileDesc *fd, int16_t outFlags) return; } mByteReadCount += count; + SaveNetworkStats(false); FallibleTArray data; if(!data.AppendElements(buff, count)){ @@ -520,6 +529,7 @@ nsUDPSocket::OnSocketDetached(PRFileDesc *fd) PR_Close(mFD); mFD = nullptr; } + SaveNetworkStats(true); if (mListener) { @@ -556,7 +566,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; @@ -571,11 +582,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); @@ -592,6 +604,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 activeNetwork; + GetActiveNetworkInterface(activeNetwork); + mActiveNetwork = + new nsMainThreadPtrHolder(activeNetwork); + } +#endif + uint16_t port; if (NS_FAILED(net::GetPort(aAddr, &port))) { NS_WARNING("invalid bind address"); @@ -658,6 +691,7 @@ nsUDPSocket::Close() PR_Close(mFD); mFD = nullptr; } + SaveNetworkStats(true); return NS_OK; } } @@ -693,6 +727,34 @@ nsUDPSocket::GetAddress(NetAddr *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 event = + new SaveNetworkStatsEvent(mAppId, mIsInBrowserElement, mActiveNetwork, + mByteReadCount, mByteWriteCount, false); + NS_DispatchToMainThread(event); + + // Reset the counters after saving. + mByteReadCount = 0; + mByteWriteCount = 0; + } +#endif +} + namespace { //----------------------------------------------------------------------------- // SocketListenerProxy diff --git a/netwerk/base/nsUDPSocket.h b/netwerk/base/nsUDPSocket.h index 63a768d4afc9..4417c956832c 100644 --- a/netwerk/base/nsUDPSocket.h +++ b/netwerk/base/nsUDPSocket.h @@ -12,6 +12,10 @@ #include "nsAutoPtr.h" #include "nsCycleCollectionParticipant.h" +#ifdef MOZ_WIDGET_GONK +#include "nsINetworkManager.h" +#endif + //----------------------------------------------------------------------------- class nsUDPSocket MOZ_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 mListener; nsCOMPtr mListenerTarget; bool mAttached; @@ -62,6 +70,9 @@ private: uint64_t mByteReadCount; uint64_t mByteWriteCount; +#ifdef MOZ_WIDGET_GONK + nsMainThreadPtrHandle mActiveNetwork; +#endif }; //----------------------------------------------------------------------------- diff --git a/netwerk/ipc/NeckoChild.cpp b/netwerk/ipc/NeckoChild.cpp index 09c0a1965c1c..c3d0cb3b214c 100644 --- a/netwerk/ipc/NeckoChild.cpp +++ b/netwerk/ipc/NeckoChild.cpp @@ -237,7 +237,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; diff --git a/netwerk/ipc/NeckoChild.h b/netwerk/ipc/NeckoChild.h index d705db0d24e1..6d9f41f2aac0 100644 --- a/netwerk/ipc/NeckoChild.h +++ b/netwerk/ipc/NeckoChild.h @@ -51,7 +51,8 @@ protected: const uint16_t& aBacklog, const nsString& aBinaryType) MOZ_OVERRIDE; virtual bool DeallocPTCPServerSocketChild(PTCPServerSocketChild*) MOZ_OVERRIDE; - virtual PUDPSocketChild* AllocPUDPSocketChild(const nsCString& aFilter) MOZ_OVERRIDE; + virtual PUDPSocketChild* AllocPUDPSocketChild(const Principal& aPrincipal, + const nsCString& aFilter) MOZ_OVERRIDE; virtual bool DeallocPUDPSocketChild(PUDPSocketChild*) MOZ_OVERRIDE; virtual PDNSRequestChild* AllocPDNSRequestChild(const nsCString& aHost, const uint32_t& aFlags, diff --git a/netwerk/ipc/NeckoParent.cpp b/netwerk/ipc/NeckoParent.cpp index 3082a8294e0b..dea62df3e415 100644 --- a/netwerk/ipc/NeckoParent.cpp +++ b/netwerk/ipc/NeckoParent.cpp @@ -455,7 +455,8 @@ NeckoParent::DeallocPTCPServerSocketParent(PTCPServerSocketParent* actor) } PUDPSocketParent* -NeckoParent::AllocPUDPSocketParent(const nsCString& /* unused */) +NeckoParent::AllocPUDPSocketParent(const Principal& /* unused */, + const nsCString& /* unused */) { nsRefPtr p = new UDPSocketParent(); @@ -464,9 +465,10 @@ NeckoParent::AllocPUDPSocketParent(const nsCString& /* unused */) bool NeckoParent::RecvPUDPSocketConstructor(PUDPSocketParent* aActor, + const Principal& aPrincipal, const nsCString& aFilter) { - return static_cast(aActor)->Init(aFilter); + return static_cast(aActor)->Init(aPrincipal, aFilter); } bool diff --git a/netwerk/ipc/NeckoParent.h b/netwerk/ipc/NeckoParent.h index fd83b6b9e21a..4dce47fc723f 100644 --- a/netwerk/ipc/NeckoParent.h +++ b/netwerk/ipc/NeckoParent.h @@ -149,8 +149,11 @@ protected: const uint16_t& aBacklog, const nsString& aBinaryType) MOZ_OVERRIDE; virtual bool DeallocPTCPServerSocketParent(PTCPServerSocketParent*) MOZ_OVERRIDE; - virtual PUDPSocketParent* AllocPUDPSocketParent(const nsCString& aFilter) MOZ_OVERRIDE; - virtual bool RecvPUDPSocketConstructor(PUDPSocketParent*, const nsCString& aFilter) MOZ_OVERRIDE; + virtual PUDPSocketParent* AllocPUDPSocketParent(const Principal& aPrincipal, + const nsCString& aFilter) MOZ_OVERRIDE; + virtual bool RecvPUDPSocketConstructor(PUDPSocketParent*, + const Principal& aPrincipal, + const nsCString& aFilter) MOZ_OVERRIDE; virtual bool DeallocPUDPSocketParent(PUDPSocketParent*) MOZ_OVERRIDE; virtual PDNSRequestParent* AllocPDNSRequestParent(const nsCString& aHost, const uint32_t& aFlags, diff --git a/netwerk/ipc/PNecko.ipdl b/netwerk/ipc/PNecko.ipdl index 8cac2aa31967..9476aa7b6e30 100644 --- a/netwerk/ipc/PNecko.ipdl +++ b/netwerk/ipc/PNecko.ipdl @@ -30,6 +30,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 { @@ -65,7 +66,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); diff --git a/netwerk/test/TestUDPSocket.cpp b/netwerk/test/TestUDPSocket.cpp index e82f9cacde62..61f6a5307c2a 100644 --- a/netwerk/test/TestUDPSocket.cpp +++ b/netwerk/test/TestUDPSocket.cpp @@ -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 serverListener = new UDPServerListener(); + nsCOMPtr secman = + do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, -1); + + nsCOMPtr 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 clientListener = new UDPClientListener(); - client->Init(0, false, true, 0); + client->Init(0, false, systemPrincipal, true, 0); client->AsyncListen(clientListener); // Write data to server diff --git a/netwerk/test/unit/test_udp_multicast.js b/netwerk/test/unit/test_udp_multicast.js index b014e2186248..c3a733b8a2f5 100644 --- a/netwerk/test/unit/test_udp_multicast.js +++ b/netwerk/test/unit/test_udp_multicast.js @@ -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; } diff --git a/netwerk/test/unit/test_udpsocket.js b/netwerk/test/unit/test_udpsocket.js index 3668fc480f8a..db7ce9eeaf8c 100644 --- a/netwerk/test/unit/test_udpsocket.js +++ b/netwerk/test/unit/test_udpsocket.js @@ -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){ diff --git a/toolkit/devtools/discovery/discovery.js b/toolkit/devtools/discovery/discovery.js index 175f659f1312..851af05227ab 100644 --- a/toolkit/devtools/discovery/discovery.js +++ b/toolkit/devtools/discovery/discovery.js @@ -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) { diff --git a/toolkit/modules/secondscreen/SimpleServiceDiscovery.jsm b/toolkit/modules/secondscreen/SimpleServiceDiscovery.jsm index 7b1f3e54d4b0..4c05b989341c 100644 --- a/toolkit/modules/secondscreen/SimpleServiceDiscovery.jsm +++ b/toolkit/modules/secondscreen/SimpleServiceDiscovery.jsm @@ -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) {