Bug 1343743 - Part4: Pass a labeled main thread event target in nsIUDPSocketChild::bind, r=jdm

Add an event target parameter in nsIUDPSocketChild::bind, so we can use this labeled event target to dispatch runnables in UDPSocketChild.
This commit is contained in:
Kershaw Chang 2017-06-12 00:24:00 +02:00
Родитель a2f2bae579
Коммит d17d3c6887
4 изменённых файлов: 17 добавлений и 4 удалений

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

@ -498,6 +498,11 @@ UDPSocket::InitRemote(const nsAString& aLocalAddress,
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIEventTarget> target;
if (nsCOMPtr<nsIGlobalObject> global = GetOwnerGlobal()) {
target = global->EventTargetFor(TaskCategory::Other);
}
rv = sock->Bind(mListenerProxy,
principal,
NS_ConvertUTF16toUTF8(aLocalAddress),
@ -505,7 +510,8 @@ UDPSocket::InitRemote(const nsAString& aLocalAddress,
mAddressReuse,
mLoopback,
0,
0);
0,
target);
if (NS_FAILED(rv)) {
return rv;

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

@ -165,7 +165,8 @@ UDPSocketChild::Bind(nsIUDPSocketInternal* aSocket,
bool aAddressReuse,
bool aLoopback,
uint32_t recvBufferSize,
uint32_t sendBufferSize)
uint32_t sendBufferSize,
nsIEventTarget* aMainThreadEventTarget)
{
UDPSOCKET_LOG(("%s: %s:%u", __FUNCTION__, PromiseFlatCString(aHost).get(), aPort));
@ -180,6 +181,9 @@ UDPSocketChild::Bind(nsIUDPSocketInternal* aSocket,
MOZ_ASSERT(!aPrincipal);
mBackgroundManager->SendPUDPSocketConstructor(this, void_t(), mFilterName);
} else {
if (aMainThreadEventTarget) {
gNeckoChild->SetEventTargetForActor(this, aMainThreadEventTarget);
}
gNeckoChild->SendPUDPSocketConstructor(this, IPC::Principal(aPrincipal),
mFilterName);
}

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

@ -8,6 +8,7 @@
interface nsIUDPSocketInternal;
interface nsIInputStream;
interface nsIPrincipal;
interface nsIEventTarget;
%{ C++
namespace mozilla {
@ -33,7 +34,8 @@ interface nsIUDPSocketChild : nsISupports
void bind(in nsIUDPSocketInternal socket, in nsIPrincipal principal,
in AUTF8String host, in unsigned short port,
in bool addressReuse, in bool loopback, in uint32_t recvBufferSize,
in uint32_t sendBufferSize);
in uint32_t sendBufferSize,
[optional] in nsIEventTarget mainThreadTarget);
// Tell the chrome process to connect the UDP socket to a given remote host and port
void connect(in nsIUDPSocketInternal socket, in AUTF8String host, in unsigned short port);

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

@ -1580,7 +1580,8 @@ void NrUdpSocketIpc::create_i(const nsACString &host, const uint16_t port) {
/* reuse = */ false,
/* loopback = */ false,
/* recv buffer size */ minBuffSize,
/* send buffer size */ minBuffSize))) {
/* send buffer size */ minBuffSize,
/* mainThreadEventTarget */ nullptr))) {
err_ = true;
MOZ_ASSERT(false, "Failed to create UDP socket");
mon.NotifyAll();