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
|
|
|
|
2009-01-12 18:36:55 +03:00
|
|
|
class nsITimer;
|
2010-02-24 19:37:03 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2019-01-02 16:05:23 +03:00
|
|
|
class Document;
|
2010-02-24 19:37:03 +03:00
|
|
|
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
|
|
|
|
|
2017-07-06 15:00:35 +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
|
2017-07-06 15:00:35 +03:00
|
|
|
// with the context the prefetch will not be performed.
|
2019-05-01 11:47:10 +03:00
|
|
|
static bool IsAllowed(mozilla::dom::Document* aDocument);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2008-11-04 18:22:04 +03:00
|
|
|
static nsresult Initialize();
|
|
|
|
static nsresult Shutdown();
|
2017-07-06 15:00:35 +03:00
|
|
|
|
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
|
2017-07-06 15:00:35 +03:00
|
|
|
// complete, while the string versions submit the lookup to
|
2008-12-05 23:53:24 +03:00
|
|
|
// the DNS system immediately. The URI version is somewhat lighter
|
2017-07-06 15:00:35 +03:00
|
|
|
// weight, but its request is also more likely to be dropped due to a
|
2008-12-05 23:53:24 +03:00
|
|
|
// full queue and it may only be used from the main thread.
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
static nsresult PrefetchHigh(mozilla::dom::Link* aElement);
|
|
|
|
static nsresult PrefetchMedium(mozilla::dom::Link* aElement);
|
|
|
|
static nsresult PrefetchLow(mozilla::dom::Link* aElement);
|
2018-09-22 23:54:11 +03:00
|
|
|
static nsresult PrefetchHigh(
|
2019-05-01 11:47:10 +03:00
|
|
|
const nsAString& host, bool isHttps,
|
|
|
|
const mozilla::OriginAttributes& aOriginAttributes);
|
2018-09-22 23:54:11 +03:00
|
|
|
static nsresult PrefetchMedium(
|
2019-05-01 11:47:10 +03:00
|
|
|
const nsAString& host, bool isHttps,
|
|
|
|
const mozilla::OriginAttributes& aOriginAttributes);
|
2018-09-22 23:54:11 +03:00
|
|
|
static nsresult PrefetchLow(
|
2019-05-01 11:47:10 +03:00
|
|
|
const nsAString& host, bool isHttps,
|
|
|
|
const mozilla::OriginAttributes& aOriginAttributes);
|
2018-09-22 23:54:11 +03:00
|
|
|
static nsresult CancelPrefetchLow(
|
2019-05-01 11:47:10 +03:00
|
|
|
const nsAString& host, bool isHttps,
|
|
|
|
const mozilla::OriginAttributes& aOriginAttributes, nsresult aReason);
|
|
|
|
static nsresult CancelPrefetchLow(mozilla::dom::Link* aElement,
|
2012-01-21 03:14:46 +04:00
|
|
|
nsresult aReason);
|
2008-12-05 23:53:24 +03:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
static void LinkDestroyed(mozilla::dom::Link* aLink);
|
2017-04-19 13:06:36 +03:00
|
|
|
|
2008-11-04 18:22:04 +03:00
|
|
|
private:
|
2019-05-01 11:47:10 +03:00
|
|
|
static nsresult Prefetch(const nsAString& host, bool isHttps,
|
|
|
|
const mozilla::OriginAttributes& aOriginAttributes,
|
2017-02-15 05:39:40 +03:00
|
|
|
uint16_t flags);
|
2019-05-01 11:47:10 +03:00
|
|
|
static nsresult Prefetch(mozilla::dom::Link* aElement, uint16_t flags);
|
2018-09-22 23:54:11 +03:00
|
|
|
static nsresult CancelPrefetch(
|
2019-05-01 11:47:10 +03:00
|
|
|
const nsAString& hostname, bool isHttps,
|
|
|
|
const mozilla::OriginAttributes& aOriginAttributes, uint16_t flags,
|
2012-01-21 03:14:46 +04:00
|
|
|
nsresult aReason);
|
2019-05-01 11:47:10 +03:00
|
|
|
static nsresult CancelPrefetch(mozilla::dom::Link* aElement, uint16_t flags,
|
2012-01-21 03:14:46 +04:00
|
|
|
nsresult aReason);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
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() {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-01-12 18:38:32 +03:00
|
|
|
private:
|
|
|
|
~nsListener() {}
|
|
|
|
};
|
2017-07-06 15:00:35 +03:00
|
|
|
|
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();
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2008-12-05 23:53:24 +03:00
|
|
|
void Activate();
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult Add(uint16_t flags, mozilla::dom::Link* aElement);
|
2017-07-06 15:00:35 +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();
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2008-12-05 23:53:24 +03:00
|
|
|
void SubmitQueue();
|
2017-07-06 15:00:35 +03:00
|
|
|
|
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;
|
2019-05-01 11:47:10 +03:00
|
|
|
static void Tick(nsITimer* aTimer, void* aClosure);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
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);
|
2017-07-06 15:00:35 +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.
|
2019-05-01 11:47:10 +03:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
#endif
|