Bug 935838 - Add per app network traffic statistics to the UDP socket. r=sicking, r=mayhemer

This commit is contained in:
Dragana Damjanovic 2015-03-06 06:38:00 -05:00
Родитель c318ae4e07
Коммит a2a4213345
20 изменённых файлов: 206 добавлений и 41 удалений

Просмотреть файл

@ -387,8 +387,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);
@ -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<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(this, principal,
NS_ConvertUTF16toUTF8(aLocalAddress), aLocalPort,
mAddressReuse, mLoopback);
if (NS_FAILED(rv)) {
return rv;
}

Просмотреть файл

@ -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,46 @@ 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();
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<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);
@ -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))) {

Просмотреть файл

@ -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<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(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

Просмотреть файл

@ -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);

Просмотреть файл

@ -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

Просмотреть файл

@ -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<uint8_t> 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<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");
@ -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<nsRunnable> event =
new SaveNetworkStatsEvent(mAppId, mIsInBrowserElement, mActiveNetwork,
mByteReadCount, mByteWriteCount, false);
NS_DispatchToMainThread(event);
// Reset the counters after saving.
mByteReadCount = 0;
mByteWriteCount = 0;
}
#endif
}
namespace {
//-----------------------------------------------------------------------------
// SocketListenerProxy

Просмотреть файл

@ -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<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
};
//-----------------------------------------------------------------------------

Просмотреть файл

@ -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;

Просмотреть файл

@ -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,

Просмотреть файл

@ -455,7 +455,8 @@ NeckoParent::DeallocPTCPServerSocketParent(PTCPServerSocketParent* actor)
}
PUDPSocketParent*
NeckoParent::AllocPUDPSocketParent(const nsCString& /* unused */)
NeckoParent::AllocPUDPSocketParent(const Principal& /* unused */,
const nsCString& /* unused */)
{
nsRefPtr<UDPSocketParent> 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<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) 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,

Просмотреть файл

@ -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);

Просмотреть файл

@ -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) {