1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 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/. */
8 * This is the base class for all link classes.
11 #ifndef mozilla_dom_Link_h__
12 #define mozilla_dom_Link_h__
14 #include "nsWrapperCache.h" // For nsWrapperCache::FlagsType
29 #define MOZILLA_DOM_LINK_IMPLEMENTATION_IID \
31 0xb25edee6, 0xdd35, 0x4f8b, { \
32 0xab, 0x90, 0x66, 0xd0, 0xbd, 0x3c, 0x22, 0xd5 \
36 class Link
: public nsISupports
{
38 NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_LINK_IMPLEMENTATION_IID
)
41 * aElement is the element pointer corresponding to this link.
43 explicit Link(Element
* aElement
);
46 * This constructor is only used for testing.
50 virtual void VisitedQueryFinished(bool aVisited
);
53 * @return NS_EVENT_STATE_VISITED if this link is visited,
54 * NS_EVENT_STATE_UNVISTED if this link is not visited, or 0 if this
55 * link is not actually a link.
57 EventStates
LinkState() const;
60 * @return the URI this link is for, if available.
62 nsIURI
* GetURI() const;
65 * Helper methods for modifying and obtaining parts of the URI of the Link.
67 void SetProtocol(const nsAString
& aProtocol
);
68 void SetUsername(const nsAString
& aUsername
);
69 void SetPassword(const nsAString
& aPassword
);
70 void SetHost(const nsAString
& aHost
);
71 void SetHostname(const nsAString
& aHostname
);
72 void SetPathname(const nsAString
& aPathname
);
73 void SetSearch(const nsAString
& aSearch
);
74 void SetPort(const nsAString
& aPort
);
75 void SetHash(const nsAString
& aHash
);
76 void GetOrigin(nsAString
& aOrigin
);
77 void GetProtocol(nsAString
& _protocol
);
78 void GetUsername(nsAString
& aUsername
);
79 void GetPassword(nsAString
& aPassword
);
80 void GetHost(nsAString
& _host
);
81 void GetHostname(nsAString
& _hostname
);
82 void GetPathname(nsAString
& _pathname
);
83 void GetSearch(nsAString
& _search
);
84 void GetPort(nsAString
& _port
);
85 void GetHash(nsAString
& _hash
);
88 * Invalidates any link caching, and resets the state to the default.
91 * true if ResetLinkState should notify the owning document about style
92 * changes or false if it should not.
94 void ResetLinkState(bool aNotify
, bool aHasHref
);
96 // This method nevers returns a null element.
97 Element
* GetElement() const { return mElement
; }
100 * DNS prefetch has been deferred until later, e.g. page load complete.
102 virtual void OnDNSPrefetchDeferred() { /*do nothing*/
106 * DNS prefetch has been submitted to Host Resolver.
108 virtual void OnDNSPrefetchRequested() { /*do nothing*/
112 * Checks if DNS Prefetching is ok
115 * Defaults to true; should be overridden for specialised cases
117 virtual bool HasDeferredDNSPrefetchRequest() { return true; }
119 virtual size_t SizeOfExcludingThis(mozilla::SizeOfState
& aState
) const;
121 virtual bool ElementHasHref() const;
123 // This is called by HTMLAnchorElement and HTMLLinkElement.
124 void TryDNSPrefetch();
125 void CancelDNSPrefetch(nsWrapperCache::FlagsType aDeferredFlag
,
126 nsWrapperCache::FlagsType aRequestedFlag
);
128 bool HasPendingLinkUpdate() const { return mHasPendingLinkUpdate
; }
129 void SetHasPendingLinkUpdate() { mHasPendingLinkUpdate
= true; }
130 void ClearHasPendingLinkUpdate() { mHasPendingLinkUpdate
= false; }
132 // To ensure correct mHasPendingLinkUpdate handling, we have this method
133 // similar to the one in Element. Overriders must call
134 // ClearHasPendingLinkUpdate().
135 // If you change this, change also the method in nsINode.
136 virtual void NodeInfoChanged(Document
* aOldDoc
) = 0;
138 bool IsInDNSPrefetch() { return mInDNSPrefetch
; }
139 void SetIsInDNSPrefetch() { mInDNSPrefetch
= true; }
140 void ClearIsInDNSPrefetch() { mInDNSPrefetch
= false; }
146 * Return true if the link has associated URI.
148 bool HasURI() const {
149 if (HasCachedURI()) {
156 nsIURI
* GetCachedURI() const { return mCachedURI
; }
157 bool HasCachedURI() const { return !!mCachedURI
; }
161 * Unregisters from History so this node no longer gets notifications about
162 * changes to visitedness.
164 void UnregisterFromHistory();
166 void SetHrefAttribute(nsIURI
* aURI
);
168 mutable nsCOMPtr
<nsIURI
> mCachedURI
;
170 Element
* const mElement
;
174 bool mNeedsRegistration
: 1;
176 bool mRegistered
: 1;
178 bool mHasPendingLinkUpdate
: 1;
180 bool mInDNSPrefetch
: 1;
185 NS_DEFINE_STATIC_IID_ACCESSOR(Link
, MOZILLA_DOM_LINK_IMPLEMENTATION_IID
)
188 } // namespace mozilla
190 #endif // mozilla_dom_Link_h__