Bug 542632 - Protect nsGenericHTMLElement::GetHrefURIForAnchors

Also makes DNS prefetching take mozilla::dom::Link instead of nsIContent.
r=bz
This commit is contained in:
Shawn Wilsher 2010-02-24 08:37:03 -08:00
Родитель 99f6189b56
Коммит d5bd2fe739
8 изменённых файлов: 49 добавлений и 28 удалений

Просмотреть файл

@ -49,9 +49,15 @@
namespace mozilla {
namespace dom {
#define MOZILLA_DOM_LINK_IMPLEMENTATION_IID \
{ 0x0c032581, 0x1c8a, 0x4fff, \
{ 0xbe, 0x9a, 0xfb, 0x6e, 0x2e, 0xe4, 0x22, 0x2e } }
class Link : public nsISupports
{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
static const nsLinkState defaultState = eLinkState_Unknown;
Link();
virtual nsLinkState GetLinkState() const;
@ -123,6 +129,8 @@ private:
nsIContent *mContent;
};
NS_DEFINE_STATIC_IID_ACCESSOR(Link, MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -198,9 +198,6 @@ public:
nsresult PostHandleEventForAnchors(nsEventChainPostVisitor& aVisitor);
PRBool IsHTMLLink(nsIURI** aURI) const;
// Used by A, AREA, LINK, and STYLE.
already_AddRefed<nsIURI> GetHrefURIForAnchors() const;
// As above, but makes sure to return a URI object that we can mutate with
// impunity without changing our current URI. That is, if the URI is cached
// it clones it and returns the clone.
@ -723,6 +720,9 @@ protected:
return value > 0 ? eTrue : (value == 0 ? eFalse : eInherit);
}
// Used by A, AREA, LINK, and STYLE.
already_AddRefed<nsIURI> GetHrefURIForAnchors() const;
private:
/**
* Returns whether this element is an editable root. There are two types of

Просмотреть файл

@ -152,11 +152,12 @@ NS_IMPL_RELEASE_INHERITED(nsHTMLAnchorElement, nsGenericElement)
// QueryInterface implementation for nsHTMLAnchorElement
NS_INTERFACE_TABLE_HEAD(nsHTMLAnchorElement)
NS_HTML_CONTENT_INTERFACE_TABLE4(nsHTMLAnchorElement,
NS_HTML_CONTENT_INTERFACE_TABLE5(nsHTMLAnchorElement,
nsIDOMHTMLAnchorElement,
nsIDOMNSHTMLAnchorElement,
nsIDOMNSHTMLAnchorElement2,
nsILink)
nsILink,
Link)
NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(nsHTMLAnchorElement,
nsGenericHTMLElement)
NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLAnchorElement)

Просмотреть файл

@ -137,11 +137,12 @@ NS_IMPL_RELEASE_INHERITED(nsHTMLAreaElement, nsGenericElement)
// QueryInterface implementation for nsHTMLAreaElement
NS_INTERFACE_TABLE_HEAD(nsHTMLAreaElement)
NS_HTML_CONTENT_INTERFACE_TABLE4(nsHTMLAreaElement,
NS_HTML_CONTENT_INTERFACE_TABLE5(nsHTMLAreaElement,
nsIDOMHTMLAreaElement,
nsIDOMNSHTMLAreaElement,
nsIDOMNSHTMLAreaElement2,
nsILink)
nsILink,
Link)
NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(nsHTMLAreaElement,
nsGenericHTMLElement)
NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLAreaElement)

Просмотреть файл

@ -53,9 +53,11 @@
#include "nsGkAtoms.h"
#include "nsIDocument.h"
#include "nsThreadUtils.h"
#include "nsGenericHTMLElement.h"
#include "nsITimer.h"
#include "nsIObserverService.h"
#include "mozilla/dom/Link.h"
using namespace mozilla::dom;
static NS_DEFINE_CID(kDNSServiceCID, NS_DNSSERVICE_CID);
PRBool sDisablePrefetchHTTPSPref;
@ -125,7 +127,7 @@ nsHTMLDNSPrefetch::IsAllowed (nsIDocument *aDocument)
}
nsresult
nsHTMLDNSPrefetch::Prefetch(nsGenericHTMLElement *aElement, PRUint16 flags)
nsHTMLDNSPrefetch::Prefetch(Link *aElement, PRUint16 flags)
{
if (!(sInitialized && sPrefetches && sDNSService && sDNSListener))
return NS_ERROR_NOT_AVAILABLE;
@ -134,19 +136,19 @@ nsHTMLDNSPrefetch::Prefetch(nsGenericHTMLElement *aElement, PRUint16 flags)
}
nsresult
nsHTMLDNSPrefetch::PrefetchLow(nsGenericHTMLElement *aElement)
nsHTMLDNSPrefetch::PrefetchLow(Link *aElement)
{
return Prefetch(aElement, nsIDNSService::RESOLVE_PRIORITY_LOW);
}
nsresult
nsHTMLDNSPrefetch::PrefetchMedium(nsGenericHTMLElement *aElement)
nsHTMLDNSPrefetch::PrefetchMedium(Link *aElement)
{
return Prefetch(aElement, nsIDNSService::RESOLVE_PRIORITY_MEDIUM);
}
nsresult
nsHTMLDNSPrefetch::PrefetchHigh(nsGenericHTMLElement *aElement)
nsHTMLDNSPrefetch::PrefetchHigh(Link *aElement)
{
return Prefetch(aElement, 0);
}
@ -229,7 +231,7 @@ nsHTMLDNSPrefetch::nsDeferrals::Flush()
}
nsresult
nsHTMLDNSPrefetch::nsDeferrals::Add(PRUint16 flags, nsGenericHTMLElement *aElement)
nsHTMLDNSPrefetch::nsDeferrals::Add(PRUint16 flags, Link *aElement)
{
// The FIFO has no lock, so it can only be accessed on main thread
NS_ASSERTION(NS_IsMainThread(), "nsDeferrals::Add must be on main thread");
@ -259,12 +261,11 @@ nsHTMLDNSPrefetch::nsDeferrals::SubmitQueue()
while (mHead != mTail) {
nsCOMPtr<nsIContent> content = do_QueryReferent(mEntries[mTail].mElement);
if (content && content->GetOwnerDoc()) {
nsCOMPtr<nsIURI> hrefURI;
hrefURI =
nsGenericHTMLElement::FromContent(content)->GetHrefURIForAnchors();
nsCOMPtr<Link> link = do_QueryInterface(content);
nsCOMPtr<nsIURI> hrefURI(link ? link->GetURI() : nsnull);
if (hrefURI)
hrefURI->GetAsciiHost(hostName);
if (!hostName.IsEmpty()) {
nsCOMPtr<nsICancelable> tmpOutstanding;

Просмотреть файл

@ -49,8 +49,12 @@
#include "nsIObserver.h"
class nsIDocument;
class nsGenericHTMLElement;
class nsITimer;
namespace mozilla {
namespace dom {
class Link;
} // namespace dom
} // namespace mozilla
class nsHTMLDNSPrefetch
{
@ -71,16 +75,16 @@ public:
// 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.
static nsresult PrefetchHigh(nsGenericHTMLElement *aElement);
static nsresult PrefetchMedium(nsGenericHTMLElement *aElement);
static nsresult PrefetchLow(nsGenericHTMLElement *aElement);
static nsresult PrefetchHigh(mozilla::dom::Link *aElement);
static nsresult PrefetchMedium(mozilla::dom::Link *aElement);
static nsresult PrefetchLow(mozilla::dom::Link *aElement);
static nsresult PrefetchHigh(nsAString &host);
static nsresult PrefetchMedium(nsAString &host);
static nsresult PrefetchLow(nsAString &host);
private:
static nsresult Prefetch(nsAString &host, PRUint16 flags);
static nsresult Prefetch(nsGenericHTMLElement *aElement, PRUint16 flags);
static nsresult Prefetch(mozilla::dom::Link *aElement, PRUint16 flags);
public:
class nsListener : public nsIDNSListener
@ -107,7 +111,7 @@ public:
nsDeferrals();
void Activate();
nsresult Add(PRUint16 flags, nsGenericHTMLElement *aElement);
nsresult Add(PRUint16 flags, mozilla::dom::Link *aElement);
private:
~nsDeferrals();

Просмотреть файл

@ -148,11 +148,12 @@ NS_IMPL_RELEASE_INHERITED(nsHTMLLinkElement, nsGenericElement)
// QueryInterface implementation for nsHTMLLinkElement
NS_INTERFACE_TABLE_HEAD(nsHTMLLinkElement)
NS_HTML_CONTENT_INTERFACE_TABLE4(nsHTMLLinkElement,
NS_HTML_CONTENT_INTERFACE_TABLE5(nsHTMLLinkElement,
nsIDOMHTMLLinkElement,
nsIDOMLinkStyle,
nsILink,
nsIStyleSheetLinkingElement)
nsIStyleSheetLinkingElement,
Link)
NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(nsHTMLLinkElement,
nsGenericHTMLElement)
NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLLinkElement)
@ -375,7 +376,7 @@ already_AddRefed<nsIURI>
nsHTMLLinkElement::GetStyleSheetURL(PRBool* aIsInline)
{
*aIsInline = PR_FALSE;
return GetHrefURIForAnchors();
return Link::GetURI();
}
void

Просмотреть файл

@ -61,8 +61,13 @@ NS_IMPL_ADDREF_INHERITED(nsSVGAElement, nsSVGAElementBase)
NS_IMPL_RELEASE_INHERITED(nsSVGAElement, nsSVGAElementBase)
NS_INTERFACE_TABLE_HEAD(nsSVGAElement)
NS_NODE_INTERFACE_TABLE5(nsSVGAElement, nsIDOMNode, nsIDOMElement,
nsIDOMSVGElement, nsIDOMSVGAElement, nsILink)
NS_NODE_INTERFACE_TABLE6(nsSVGAElement,
nsIDOMNode,
nsIDOMElement,
nsIDOMSVGElement,
nsIDOMSVGAElement,
nsILink,
Link)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGAElement)
NS_INTERFACE_MAP_END_INHERITING(nsSVGAElementBase)