2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2008-11-04 18:22:04 +03:00
|
|
|
|
2008-12-05 23:53:24 +03:00
|
|
|
#ifndef nsHTMLDNSPrefetch_h___
|
|
|
|
#define nsHTMLDNSPrefetch_h___
|
2008-11-04 18:22:04 +03:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
|
|
|
|
#include "nsIDNSListener.h"
|
2008-12-05 23:53:24 +03:00
|
|
|
#include "nsIWebProgressListener.h"
|
|
|
|
#include "nsWeakReference.h"
|
2009-01-12 18:36:55 +03:00
|
|
|
#include "nsIObserver.h"
|
2008-11-04 18:22:04 +03:00
|
|
|
|
|
|
|
class nsIDocument;
|
2009-01-12 18:36:55 +03:00
|
|
|
class nsITimer;
|
2010-02-24 19:37:03 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class Link;
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2008-11-04 18:22:04 +03:00
|
|
|
|
2010-07-26 22:49:09 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
class NeckoParent;
|
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2008-12-05 23:53:24 +03:00
|
|
|
class nsHTMLDNSPrefetch
|
2008-11-04 18:22:04 +03:00
|
|
|
{
|
|
|
|
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.
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsAllowed(nsIDocument *aDocument);
|
2008-12-05 23:53:24 +03:00
|
|
|
|
2008-11-04 18:22:04 +03:00
|
|
|
static nsresult Initialize();
|
|
|
|
static nsresult Shutdown();
|
|
|
|
|
2008-12-05 23:53:24 +03:00
|
|
|
// 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
|
|
|
|
// 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.
|
|
|
|
|
2010-02-24 19:37:03 +03:00
|
|
|
static nsresult PrefetchHigh(mozilla::dom::Link *aElement);
|
|
|
|
static nsresult PrefetchMedium(mozilla::dom::Link *aElement);
|
|
|
|
static nsresult PrefetchLow(mozilla::dom::Link *aElement);
|
2017-02-15 05:39:40 +03:00
|
|
|
static nsresult PrefetchHigh(const nsAString &host,
|
|
|
|
const mozilla::OriginAttributes &aOriginAttributes);
|
|
|
|
static nsresult PrefetchMedium(const nsAString &host,
|
|
|
|
const mozilla::OriginAttributes &aOriginAttributes);
|
|
|
|
static nsresult PrefetchLow(const nsAString &host,
|
|
|
|
const mozilla::OriginAttributes &aOriginAttributes);
|
|
|
|
static nsresult CancelPrefetchLow(const nsAString &host,
|
|
|
|
const mozilla::OriginAttributes &aOriginAttributes,
|
|
|
|
nsresult aReason);
|
2012-01-21 03:14:46 +04:00
|
|
|
static nsresult CancelPrefetchLow(mozilla::dom::Link *aElement,
|
|
|
|
nsresult aReason);
|
2008-12-05 23:53:24 +03:00
|
|
|
|
2017-04-19 13:06:36 +03:00
|
|
|
static void LinkDestroyed(mozilla::dom::Link* aLink);
|
|
|
|
|
2008-11-04 18:22:04 +03:00
|
|
|
private:
|
2017-02-15 05:39:40 +03:00
|
|
|
static nsresult Prefetch(const nsAString &host,
|
|
|
|
const mozilla::OriginAttributes &aOriginAttributes,
|
|
|
|
uint16_t flags);
|
2012-08-22 19:56:38 +04:00
|
|
|
static nsresult Prefetch(mozilla::dom::Link *aElement, uint16_t flags);
|
2012-01-21 03:14:46 +04:00
|
|
|
static nsresult CancelPrefetch(const nsAString &hostname,
|
2017-02-15 05:39:40 +03:00
|
|
|
const mozilla::OriginAttributes &aOriginAttributes,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t flags,
|
2012-01-21 03:14:46 +04:00
|
|
|
nsresult aReason);
|
|
|
|
static nsresult CancelPrefetch(mozilla::dom::Link *aElement,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t flags,
|
2012-01-21 03:14:46 +04:00
|
|
|
nsresult aReason);
|
2008-12-05 23:53:24 +03:00
|
|
|
|
|
|
|
public:
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsListener final : public nsIDNSListener
|
2009-01-12 18:38:32 +03:00
|
|
|
{
|
|
|
|
// This class exists to give a safe callback no-op DNSListener
|
|
|
|
public:
|
2013-07-19 06:21:19 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2009-01-12 18:38:32 +03:00
|
|
|
NS_DECL_NSIDNSLISTENER
|
|
|
|
|
|
|
|
nsListener() {}
|
|
|
|
private:
|
|
|
|
~nsListener() {}
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsDeferrals final: public nsIWebProgressListener
|
2015-03-27 21:52:19 +03:00
|
|
|
, public nsSupportsWeakReference
|
|
|
|
, public nsIObserver
|
2008-12-05 23:53:24 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIWEBPROGRESSLISTENER
|
2009-01-12 18:36:55 +03:00
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
2008-12-05 23:53:24 +03:00
|
|
|
nsDeferrals();
|
|
|
|
|
|
|
|
void Activate();
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult Add(uint16_t flags, mozilla::dom::Link *aElement);
|
2008-12-05 23:53:24 +03:00
|
|
|
|
2017-04-19 13:06:36 +03:00
|
|
|
void RemoveUnboundLinks();
|
|
|
|
|
2008-12-05 23:53:24 +03:00
|
|
|
private:
|
2008-12-11 22:16:00 +03:00
|
|
|
~nsDeferrals();
|
2009-01-12 18:36:55 +03:00
|
|
|
void Flush();
|
2008-12-05 23:53:24 +03:00
|
|
|
|
|
|
|
void SubmitQueue();
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t mHead;
|
|
|
|
uint16_t mTail;
|
|
|
|
uint32_t mActiveLoaderCount;
|
2009-01-12 18:36:55 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mTimerArmed;
|
2009-01-12 18:36:55 +03:00
|
|
|
static void Tick(nsITimer *aTimer, void *aClosure);
|
2008-12-05 23:53:24 +03:00
|
|
|
|
|
|
|
static const int sMaxDeferred = 512; // keep power of 2 for masking
|
|
|
|
static const int sMaxDeferredMask = (sMaxDeferred - 1);
|
2008-11-04 18:22:04 +03:00
|
|
|
|
2008-12-05 23:53:24 +03:00
|
|
|
struct deferred_entry
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t mFlags;
|
2017-04-19 13:06:36 +03:00
|
|
|
// Link implementation clears this raw pointer in its destructor.
|
|
|
|
mozilla::dom::Link* mElement;
|
2008-12-05 23:53:24 +03:00
|
|
|
} mEntries[sMaxDeferred];
|
|
|
|
};
|
2010-07-26 22:49:09 +04:00
|
|
|
|
|
|
|
friend class mozilla::net::NeckoParent;
|
2008-11-04 18:22:04 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|