netwerk/dns/DNSRequestParent.cpp

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

     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"
     9 #include "nsNetCID.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;
    19 namespace mozilla {
    20 namespace net {
    22 DNSRequestParent::DNSRequestParent()
    23   : mIPCClosed(false)
    24 {
    26 }
    28 DNSRequestParent::~DNSRequestParent()
    29 {
    31 }
    33 void
    34 DNSRequestParent::DoAsyncResolve(const nsACString &hostname, uint32_t flags)
    35 {
    36   nsresult rv;
    37   mFlags = flags;
    38   nsCOMPtr<nsIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID, &rv);
    39   if (NS_SUCCEEDED(rv)) {
    40     nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
    41     nsCOMPtr<nsICancelable> unused;
    42     rv = dns->AsyncResolve(hostname, flags, this, mainThread,
    43                            getter_AddRefs(unused));
    44   }
    46   if (NS_FAILED(rv) && !mIPCClosed) {
    47     unused << Send__delete__(this, DNSRequestResponse(rv));
    48   }
    49 }
    51 void
    52 DNSRequestParent::ActorDestroy(ActorDestroyReason why)
    53 {
    54   // We may still have refcount>0 if DNS hasn't called our OnLookupComplete
    55   // yet, but child process has crashed.  We must not send any more msgs
    56   // to child, or IPDL will kill chrome process, too.
    57   mIPCClosed = true;
    58 }
    59 //-----------------------------------------------------------------------------
    60 // DNSRequestParent::nsISupports
    61 //-----------------------------------------------------------------------------
    63 NS_IMPL_ISUPPORTS(DNSRequestParent,
    64                   nsIDNSListener)
    66 //-----------------------------------------------------------------------------
    67 // nsIDNSListener functions
    68 //-----------------------------------------------------------------------------
    70 NS_IMETHODIMP
    71 DNSRequestParent::OnLookupComplete(nsICancelable *request,
    72                                    nsIDNSRecord  *rec,
    73                                    nsresult       status)
    74 {
    75   if (mIPCClosed) {
    76     // nothing to do: child probably crashed
    77     return NS_OK;
    78   }
    80   if (NS_SUCCEEDED(status)) {
    81     MOZ_ASSERT(rec);
    83     nsAutoCString cname;
    84     if (mFlags & nsHostResolver::RES_CANON_NAME) {
    85       rec->GetCanonicalName(cname);
    86     }
    88     // Get IP addresses for hostname (use port 80 as dummy value for NetAddr)
    89     NetAddrArray array;
    90     NetAddr addr;
    91     while (NS_SUCCEEDED(rec->GetNextAddr(80, &addr))) {
    92       array.AppendElement(addr);
    93     }
    95     unused << Send__delete__(this, DNSRequestResponse(DNSRecord(cname, array)));
    96   } else {
    97     unused << Send__delete__(this, DNSRequestResponse(status));
    98   }
   100   return NS_OK;
   101 }
   105 }} // mozilla::net

mercurial