2013-12-11 23:03:51 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set sw=2 ts=8 et tw=80 : */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#include "mozilla/net/DNSRequestParent.h"
|
|
|
|
#include "nsIDNSService.h"
|
|
|
|
#include "nsNetCID.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsICancelable.h"
|
|
|
|
#include "nsIDNSRecord.h"
|
|
|
|
#include "nsHostResolver.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2013-12-11 23:03:51 +04:00
|
|
|
|
|
|
|
using namespace mozilla::ipc;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
DNSRequestParent::DNSRequestParent()
|
2016-01-12 21:16:59 +03:00
|
|
|
: mFlags(0)
|
|
|
|
, mIPCClosed(false)
|
2013-12-11 23:03:51 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
DNSRequestParent::~DNSRequestParent()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-02-14 07:25:35 +03:00
|
|
|
DNSRequestParent::DoAsyncResolve(const nsACString &hostname,
|
|
|
|
const OriginAttributes &originAttributes,
|
|
|
|
uint32_t flags,
|
2015-02-19 08:14:00 +03:00
|
|
|
const nsACString &networkInterface)
|
2013-12-11 23:03:51 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
mFlags = flags;
|
|
|
|
nsCOMPtr<nsIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2017-06-01 23:43:44 +03:00
|
|
|
nsCOMPtr<nsIEventTarget> main = GetMainThreadEventTarget();
|
2013-12-11 23:03:51 +04:00
|
|
|
nsCOMPtr<nsICancelable> unused;
|
2017-02-14 07:25:35 +03:00
|
|
|
rv = dns->AsyncResolveExtendedNative(hostname, flags,
|
|
|
|
networkInterface, this,
|
2017-06-01 23:43:44 +03:00
|
|
|
main, originAttributes,
|
2017-02-14 07:25:35 +03:00
|
|
|
getter_AddRefs(unused));
|
2013-12-11 23:03:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv) && !mIPCClosed) {
|
2014-08-26 13:09:00 +04:00
|
|
|
mIPCClosed = true;
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << SendLookupCompleted(DNSRequestResponse(rv));
|
2013-12-11 23:03:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2014-08-26 13:09:00 +04:00
|
|
|
DNSRequestParent::RecvCancelDNSRequest(const nsCString& hostName,
|
2017-02-14 07:25:35 +03:00
|
|
|
const OriginAttributes& originAttributes,
|
2014-08-26 13:09:00 +04:00
|
|
|
const uint32_t& flags,
|
2015-02-19 08:14:00 +03:00
|
|
|
const nsCString& networkInterface,
|
2014-08-26 13:09:00 +04:00
|
|
|
const nsresult& reason)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2017-02-14 07:25:35 +03:00
|
|
|
rv = dns->CancelAsyncResolveExtendedNative(hostName, flags,
|
|
|
|
networkInterface,
|
|
|
|
this, reason,
|
|
|
|
originAttributes);
|
2014-08-26 13:09:00 +04:00
|
|
|
}
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-08-26 13:09:00 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2014-08-26 13:09:00 +04:00
|
|
|
DNSRequestParent::Recv__delete__()
|
|
|
|
{
|
|
|
|
mIPCClosed = true;
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-08-26 13:09:00 +04:00
|
|
|
}
|
|
|
|
|
2013-12-11 23:03:51 +04:00
|
|
|
void
|
|
|
|
DNSRequestParent::ActorDestroy(ActorDestroyReason why)
|
|
|
|
{
|
|
|
|
// We may still have refcount>0 if DNS hasn't called our OnLookupComplete
|
|
|
|
// yet, but child process has crashed. We must not send any more msgs
|
|
|
|
// to child, or IPDL will kill chrome process, too.
|
|
|
|
mIPCClosed = true;
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// DNSRequestParent::nsISupports
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(DNSRequestParent,
|
|
|
|
nsIDNSListener)
|
2013-12-11 23:03:51 +04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsIDNSListener functions
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DNSRequestParent::OnLookupComplete(nsICancelable *request,
|
|
|
|
nsIDNSRecord *rec,
|
|
|
|
nsresult status)
|
|
|
|
{
|
|
|
|
if (mIPCClosed) {
|
|
|
|
// nothing to do: child probably crashed
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(status)) {
|
|
|
|
MOZ_ASSERT(rec);
|
|
|
|
|
|
|
|
nsAutoCString cname;
|
|
|
|
if (mFlags & nsHostResolver::RES_CANON_NAME) {
|
|
|
|
rec->GetCanonicalName(cname);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get IP addresses for hostname (use port 80 as dummy value for NetAddr)
|
|
|
|
NetAddrArray array;
|
|
|
|
NetAddr addr;
|
|
|
|
while (NS_SUCCEEDED(rec->GetNextAddr(80, &addr))) {
|
|
|
|
array.AppendElement(addr);
|
|
|
|
}
|
|
|
|
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << SendLookupCompleted(DNSRequestResponse(DNSRecord(cname, array)));
|
2013-12-11 23:03:51 +04:00
|
|
|
} else {
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << SendLookupCompleted(DNSRequestResponse(status));
|
2013-12-11 23:03:51 +04:00
|
|
|
}
|
|
|
|
|
2014-08-26 13:09:00 +04:00
|
|
|
mIPCClosed = true;
|
2013-12-11 23:03:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|