1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 ts=8 et tw=80 : */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/net/DNSRequestParent.h"
8 #include "nsIDNSService.h"
10 #include "nsThreadUtils.h"
11 #include "nsIServiceManager.h"
12 #include "nsICancelable.h"
13 #include "nsIDNSRecord.h"
14 #include "nsHostResolver.h"
15 #include "mozilla/unused.h"
17 using namespace mozilla::ipc
;
22 DNSRequestParent::DNSRequestParent()
28 DNSRequestParent::~DNSRequestParent()
34 DNSRequestParent::DoAsyncResolve(const nsACString
&hostname
, uint32_t flags
,
35 const nsACString
&networkInterface
)
39 nsCOMPtr
<nsIDNSService
> dns
= do_GetService(NS_DNSSERVICE_CONTRACTID
, &rv
);
40 if (NS_SUCCEEDED(rv
)) {
41 nsCOMPtr
<nsIThread
> mainThread
= do_GetMainThread();
42 nsCOMPtr
<nsICancelable
> unused
;
43 rv
= dns
->AsyncResolveExtended(hostname
, flags
, networkInterface
, this,
44 mainThread
, getter_AddRefs(unused
));
47 if (NS_FAILED(rv
) && !mIPCClosed
) {
49 unused
<< SendLookupCompleted(DNSRequestResponse(rv
));
54 DNSRequestParent::RecvCancelDNSRequest(const nsCString
& hostName
,
55 const uint32_t& flags
,
56 const nsCString
& networkInterface
,
57 const nsresult
& reason
)
60 nsCOMPtr
<nsIDNSService
> dns
= do_GetService(NS_DNSSERVICE_CONTRACTID
, &rv
);
61 if (NS_SUCCEEDED(rv
)) {
62 rv
= dns
->CancelAsyncResolveExtended(hostName
, flags
, networkInterface
,
69 DNSRequestParent::Recv__delete__()
76 DNSRequestParent::ActorDestroy(ActorDestroyReason why
)
78 // We may still have refcount>0 if DNS hasn't called our OnLookupComplete
79 // yet, but child process has crashed. We must not send any more msgs
80 // to child, or IPDL will kill chrome process, too.
83 //-----------------------------------------------------------------------------
84 // DNSRequestParent::nsISupports
85 //-----------------------------------------------------------------------------
87 NS_IMPL_ISUPPORTS(DNSRequestParent
,
90 //-----------------------------------------------------------------------------
91 // nsIDNSListener functions
92 //-----------------------------------------------------------------------------
95 DNSRequestParent::OnLookupComplete(nsICancelable
*request
,
100 // nothing to do: child probably crashed
104 if (NS_SUCCEEDED(status
)) {
108 if (mFlags
& nsHostResolver::RES_CANON_NAME
) {
109 rec
->GetCanonicalName(cname
);
112 // Get IP addresses for hostname (use port 80 as dummy value for NetAddr)
115 while (NS_SUCCEEDED(rec
->GetNextAddr(80, &addr
))) {
116 array
.AppendElement(addr
);
119 unused
<< SendLookupCompleted(DNSRequestResponse(DNSRecord(cname
, array
)));
121 unused
<< SendLookupCompleted(DNSRequestResponse(status
));