1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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 "mozilla/IHistory.h"
15 #include "mozilla/MemoryReporting.h"
16 #include "nsEventStates.h"
17 #include "nsIContent.h"
24 #define MOZILLA_DOM_LINK_IMPLEMENTATION_IID \
25 { 0xb25edee6, 0xdd35, 0x4f8b, \
26 { 0xab, 0x90, 0x66, 0xd0, 0xbd, 0x3c, 0x22, 0xd5 } }
28 class Link
: public nsISupports
31 NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_LINK_IMPLEMENTATION_IID
)
34 * aElement is the element pointer corresponding to this link.
36 Link(Element
* aElement
);
37 virtual void SetLinkState(nsLinkState aState
);
40 * @return NS_EVENT_STATE_VISITED if this link is visited,
41 * NS_EVENT_STATE_UNVISTED if this link is not visited, or 0 if this
42 * link is not actually a link.
44 nsEventStates
LinkState() const;
47 * @return the URI this link is for, if available.
49 nsIURI
* GetURI() const;
50 virtual nsIURI
* GetURIExternal() const {
55 * Helper methods for modifying and obtaining parts of the URI of the Link.
57 void SetProtocol(const nsAString
&aProtocol
);
58 void SetUsername(const nsAString
&aUsername
);
59 void SetPassword(const nsAString
&aPassword
);
60 void SetHost(const nsAString
&aHost
);
61 void SetHostname(const nsAString
&aHostname
);
62 void SetPathname(const nsAString
&aPathname
);
63 void SetSearch(const nsAString
&aSearch
);
64 void SetPort(const nsAString
&aPort
);
65 void SetHash(const nsAString
&aHash
);
66 void GetOrigin(nsAString
&aOrigin
);
67 void GetProtocol(nsAString
&_protocol
);
68 void GetUsername(nsAString
&aUsername
);
69 void GetPassword(nsAString
&aPassword
);
70 void GetHost(nsAString
&_host
);
71 void GetHostname(nsAString
&_hostname
);
72 void GetPathname(nsAString
&_pathname
);
73 void GetSearch(nsAString
&_search
);
74 void GetPort(nsAString
&_port
);
75 void GetHash(nsAString
&_hash
);
78 * Invalidates any link caching, and resets the state to the default.
81 * true if ResetLinkState should notify the owning document about style
82 * changes or false if it should not.
84 void ResetLinkState(bool aNotify
, bool aHasHref
);
86 // This method nevers returns a null element.
87 Element
* GetElement() const { return mElement
; }
90 * DNS prefetch has been deferred until later, e.g. page load complete.
92 virtual void OnDNSPrefetchDeferred() { /*do nothing*/ }
95 * DNS prefetch has been submitted to Host Resolver.
97 virtual void OnDNSPrefetchRequested() { /*do nothing*/ }
100 * Checks if DNS Prefetching is ok
103 * Defaults to true; should be overridden for specialised cases
105 virtual bool HasDeferredDNSPrefetchRequest() { return true; }
108 SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf
) const;
110 bool ElementHasHref() const;
116 * Return true if the link has associated URI.
120 if (HasCachedURI()) {
127 nsIURI
* GetCachedURI() const { return mCachedURI
; }
128 bool HasCachedURI() const { return !!mCachedURI
; }
132 * Unregisters from History so this node no longer gets notifications about
133 * changes to visitedness.
135 void UnregisterFromHistory();
137 already_AddRefed
<nsIURI
> GetURIToMutate();
138 void SetHrefAttribute(nsIURI
*aURI
);
140 mutable nsCOMPtr
<nsIURI
> mCachedURI
;
142 Element
* const mElement
;
144 // Strong reference to History. The link has to unregister before History
146 nsCOMPtr
<IHistory
> mHistory
;
150 bool mNeedsRegistration
;
155 NS_DEFINE_STATIC_IID_ACCESSOR(Link
, MOZILLA_DOM_LINK_IMPLEMENTATION_IID
)
158 } // namespace mozilla
160 #endif // mozilla_dom_Link_h__