Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / content / base / src / Link.h
blob0d98316f36f212de5b6d63449036fe2329aa1343
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=2 et :
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/. */
7 /**
8 * This is the base class for all link classes.
9 */
11 #ifndef mozilla_dom_Link_h__
12 #define mozilla_dom_Link_h__
14 #include "mozilla/IHistory.h"
15 #include "mozilla/MemoryReporting.h"
16 #include "mozilla/dom/URLSearchParams.h"
17 #include "nsIContent.h" // for nsLinkState
19 namespace mozilla {
21 class EventStates;
23 namespace dom {
25 class Element;
27 #define MOZILLA_DOM_LINK_IMPLEMENTATION_IID \
28 { 0xb25edee6, 0xdd35, 0x4f8b, \
29 { 0xab, 0x90, 0x66, 0xd0, 0xbd, 0x3c, 0x22, 0xd5 } }
31 class Link : public URLSearchParamsObserver
33 public:
34 NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
36 /**
37 * aElement is the element pointer corresponding to this link.
39 explicit Link(Element* aElement);
40 virtual void SetLinkState(nsLinkState aState);
42 /**
43 * @return NS_EVENT_STATE_VISITED if this link is visited,
44 * NS_EVENT_STATE_UNVISTED if this link is not visited, or 0 if this
45 * link is not actually a link.
47 EventStates LinkState() const;
49 /**
50 * @return the URI this link is for, if available.
52 nsIURI* GetURI() const;
53 virtual nsIURI* GetURIExternal() const {
54 return GetURI();
57 /**
58 * Helper methods for modifying and obtaining parts of the URI of the Link.
60 void SetProtocol(const nsAString &aProtocol, ErrorResult& aError);
61 void SetUsername(const nsAString &aUsername, ErrorResult& aError);
62 void SetPassword(const nsAString &aPassword, ErrorResult& aError);
63 void SetHost(const nsAString &aHost, ErrorResult& aError);
64 void SetHostname(const nsAString &aHostname, ErrorResult& aError);
65 void SetPathname(const nsAString &aPathname, ErrorResult& aError);
66 void SetSearch(const nsAString &aSearch, ErrorResult& aError);
67 void SetSearchParams(mozilla::dom::URLSearchParams& aSearchParams);
68 void SetPort(const nsAString &aPort, ErrorResult& aError);
69 void SetHash(const nsAString &aHash, ErrorResult& aError);
70 void GetOrigin(nsAString &aOrigin, ErrorResult& aError);
71 void GetProtocol(nsAString &_protocol, ErrorResult& aError);
72 void GetUsername(nsAString &aUsername, ErrorResult& aError);
73 void GetPassword(nsAString &aPassword, ErrorResult& aError);
74 void GetHost(nsAString &_host, ErrorResult& aError);
75 void GetHostname(nsAString &_hostname, ErrorResult& aError);
76 void GetPathname(nsAString &_pathname, ErrorResult& aError);
77 void GetSearch(nsAString &_search, ErrorResult& aError);
78 URLSearchParams* SearchParams();
79 void GetPort(nsAString &_port, ErrorResult& aError);
80 void GetHash(nsAString &_hash, ErrorResult& aError);
82 /**
83 * Invalidates any link caching, and resets the state to the default.
85 * @param aNotify
86 * true if ResetLinkState should notify the owning document about style
87 * changes or false if it should not.
89 void ResetLinkState(bool aNotify, bool aHasHref);
91 // This method nevers returns a null element.
92 Element* GetElement() const { return mElement; }
94 /**
95 * DNS prefetch has been deferred until later, e.g. page load complete.
97 virtual void OnDNSPrefetchDeferred() { /*do nothing*/ }
99 /**
100 * DNS prefetch has been submitted to Host Resolver.
102 virtual void OnDNSPrefetchRequested() { /*do nothing*/ }
105 * Checks if DNS Prefetching is ok
107 * @returns boolean
108 * Defaults to true; should be overridden for specialised cases
110 virtual bool HasDeferredDNSPrefetchRequest() { return true; }
112 virtual size_t
113 SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
115 bool ElementHasHref() const;
117 // URLSearchParamsObserver
118 void URLSearchParamsUpdated(URLSearchParams* aSearchParams) MOZ_OVERRIDE;
120 protected:
121 virtual ~Link();
124 * Return true if the link has associated URI.
126 bool HasURI() const
128 if (HasCachedURI()) {
129 return true;
132 return !!GetURI();
135 nsIURI* GetCachedURI() const { return mCachedURI; }
136 bool HasCachedURI() const { return !!mCachedURI; }
138 void UpdateURLSearchParams();
140 // CC methods
141 void Unlink();
142 void Traverse(nsCycleCollectionTraversalCallback &cb);
144 private:
146 * Unregisters from History so this node no longer gets notifications about
147 * changes to visitedness.
149 void UnregisterFromHistory();
151 already_AddRefed<nsIURI> GetURIToMutate();
152 void SetHrefAttribute(nsIURI *aURI);
154 void CreateSearchParamsIfNeeded();
156 void SetSearchInternal(const nsAString& aSearch);
158 mutable nsCOMPtr<nsIURI> mCachedURI;
160 Element * const mElement;
162 // Strong reference to History. The link has to unregister before History
163 // can disappear.
164 nsCOMPtr<IHistory> mHistory;
166 uint16_t mLinkState;
168 bool mNeedsRegistration;
170 bool mRegistered;
172 protected:
173 nsRefPtr<URLSearchParams> mSearchParams;
176 NS_DEFINE_STATIC_IID_ACCESSOR(Link, MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
178 } // namespace dom
179 } // namespace mozilla
181 #endif // mozilla_dom_Link_h__