DXR will be turned off on Tuesday, December 29th. It will redirect to Searchfox.
See the announcement on Discourse.

DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Implementation

Mercurial (c68fe15a81fc)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 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/. */


#ifndef nsHTMLDNSPrefetch_h___
#define nsHTMLDNSPrefetch_h___

#include "mozilla/OriginAttributes.h"
#include "nsCOMPtr.h"
#include "nsCOMPtr.h"
#include "nsIDNSListener.h"
#include "nsIObserver.h"
#include "nsIRequest.h"
#include "nsIWebProgressListener.h"
#include "nsString.h"
#include "nsString.h"
#include "nsWeakReference.h"

class nsITimer;
namespace mozilla {
namespace dom {
namespace dom {
class Document;
class Link;
}  // namespace dom
}  // namespace mozilla


namespace mozilla {
namespace net {
class NeckoParent;
}  // namespace net
}  // namespace mozilla
}  // namespace mozilla

class nsHTMLDNSPrefetch {
class nsHTMLDNSPrefetch {
 public:
  // The required aDocument parameter is the context requesting the prefetch -
  // under certain circumstances (e.g. headers, or security context) associated
  // with the context the prefetch will not be performed.
  static bool IsAllowed(mozilla::dom::Document* aDocument);

  static nsresult Initialize();
  static nsresult Shutdown();


  // Call one of the Prefetch* methods to start the lookup.
  //
  // The URI versions will defer DNS lookup until pageload is
  // complete, while the string versions submit the lookup to
  // the DNS system immediately. The URI version is somewhat lighter
  // the DNS system immediately. The URI version is somewhat lighter
  // weight, but its request is also more likely to be dropped due to a
  // full queue and it may only be used from the main thread.
  //
  // If you are planning to use the methods with the OriginAttributes param, be
  // sure that you pass a partitioned one. See StoragePrincipalHelper.h to know
  static nsresult PrefetchMedium(mozilla::dom::Link* aElement);
  // more.

  static nsresult PrefetchHigh(mozilla::dom::Link* aElement);
  static nsresult PrefetchMedium(mozilla::dom::Link* aElement);
  static nsresult PrefetchLow(mozilla::dom::Link* aElement);
      nsIRequest::TRRMode aTRRMode);
  static nsresult PrefetchLow(
      const nsAString& host, bool isHttps,
      const mozilla::OriginAttributes& aPartitionedPrincipalOriginAttributes,
      nsIRequest::TRRMode aTRRMode);
  static nsresult PrefetchMedium(
  static nsresult PrefetchLow(
      const nsAString& host, bool isHttps,
      const mozilla::OriginAttributes& aPartitionedPrincipalOriginAttributes,
      nsIRequest::TRRMode aTRRMode);
  static nsresult PrefetchHigh(
      const nsAString& host, bool isHttps,
      const nsAString& host, bool isHttps,
      const mozilla::OriginAttributes& aPartitionedPrincipalOriginAttributes,
      nsIRequest::TRRMode aTRRMode, nsresult aReason);
      nsIRequest::TRRMode aTRRMode);
  static nsresult CancelPrefetchLow(
      const nsAString& host, bool isHttps,
      const mozilla::OriginAttributes& aPartitionedPrincipalOriginAttributes,
      nsIRequest::TRRMode aTRRMode, nsresult aReason);
  static nsresult CancelPrefetchLow(mozilla::dom::Link* aElement,
                                    nsresult aReason);

  static void LinkDestroyed(mozilla::dom::Link* aLink);
                           uint32_t flags);

 private:
  static nsresult Prefetch(
      const nsAString& host, bool isHttps,
      const mozilla::OriginAttributes& aPartitionedPrincipalOriginAttributes,
      nsresult aReason);
      uint32_t flags);
  static nsresult Prefetch(mozilla::dom::Link* aElement, uint32_t flags);
  static nsresult CancelPrefetch(
      const nsAString& hostname, bool isHttps,
      const mozilla::OriginAttributes& aPartitionedPrincipalOriginAttributes,
  class nsListener final : public nsIDNSListener {
      uint32_t flags, nsresult aReason);
  static nsresult CancelPrefetch(mozilla::dom::Link* aElement, uint32_t flags,
                                 nsresult aReason);

 public:

  class nsListener final : public nsIDNSListener {
    // This class exists to give a safe callback no-op DNSListener
   public:
    NS_DECL_THREADSAFE_ISUPPORTS
    NS_DECL_NSIDNSLISTENER
  };

    nsListener() = default;

   private:
    ~nsListener() = default;
   public:
  };

  class nsDeferrals final : public nsIWebProgressListener,
                            public nsSupportsWeakReference,

                            public nsIObserver {
   public:
    NS_DECL_ISUPPORTS
    NS_DECL_NSIWEBPROGRESSLISTENER
    NS_DECL_NSIOBSERVER


    nsDeferrals();

    void Activate();
    nsresult Add(uint32_t flags, mozilla::dom::Link* aElement);

    void RemoveUnboundLinks();
    void SubmitQueue();

   private:
    ~nsDeferrals();
    void Flush();


    void SubmitQueue();

    uint16_t mHead;
    uint16_t mTail;
    uint32_t mActiveLoaderCount;
    static const int sMaxDeferred = 512;  // keep power of 2 for masking

    nsCOMPtr<nsITimer> mTimer;
    bool mTimerArmed;
    static void Tick(nsITimer* aTimer, void* aClosure);

      // Link implementation clears this raw pointer in its destructor.
    static const int sMaxDeferred = 512;  // keep power of 2 for masking
    static const int sMaxDeferredMask = (sMaxDeferred - 1);

    struct deferred_entry {
      uint32_t mFlags;
  friend class mozilla::net::NeckoParent;
      // Link implementation clears this raw pointer in its destructor.
      mozilla::dom::Link* mElement;
    } mEntries[sMaxDeferred];
  };

  friend class mozilla::net::NeckoParent;
};

#endif