Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / dom / base / Link.h
blobb604457126fd201daf60401fe3f9f11e5195d5f7
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/. */
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 "nsWrapperCache.h" // For nsWrapperCache::FlagsType
15 #include "nsCOMPtr.h"
16 #include "mozilla/dom/RustTypes.h"
18 class nsIURI;
20 namespace mozilla {
22 class SizeOfState;
24 namespace dom {
26 class Document;
27 class Element;
28 struct BindContext;
30 #define MOZILLA_DOM_LINK_IMPLEMENTATION_IID \
31 { \
32 0xb25edee6, 0xdd35, 0x4f8b, { \
33 0xab, 0x90, 0x66, 0xd0, 0xbd, 0x3c, 0x22, 0xd5 \
34 } \
37 class Link : public nsISupports {
38 public:
39 NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
41 enum class State : uint8_t {
42 Unvisited = 0,
43 Visited,
44 NotLink,
47 /**
48 * aElement is the element pointer corresponding to this link.
50 explicit Link(Element* aElement);
52 /**
53 * This constructor is only used for testing.
55 explicit Link();
57 virtual void VisitedQueryFinished(bool aVisited);
59 /**
60 * @return the URI this link is for, if available.
62 nsIURI* GetURI() const;
64 /**
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);
87 /**
88 * Invalidates any link caching, and resets the state to the default.
90 * @param aNotify
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);
95 void ResetLinkState(bool aNotify) {
96 ResetLinkState(aNotify, ElementHasHref());
98 void BindToTree(const BindContext&);
99 void UnbindFromTree() { ResetLinkState(false); }
101 // This method nevers returns a null element.
102 Element* GetElement() const { return mElement; }
104 virtual size_t SizeOfExcludingThis(mozilla::SizeOfState& aState) const;
106 virtual bool ElementHasHref() const;
108 bool HasPendingLinkUpdate() const { return mHasPendingLinkUpdate; }
109 void SetHasPendingLinkUpdate() { mHasPendingLinkUpdate = true; }
110 void ClearHasPendingLinkUpdate() { mHasPendingLinkUpdate = false; }
111 void TriggerLinkUpdate(bool aNotify);
113 // To ensure correct mHasPendingLinkUpdate handling, we have this method
114 // similar to the one in Element. Overriders must call
115 // ClearHasPendingLinkUpdate().
116 // If you change this, change also the method in nsINode.
117 virtual void NodeInfoChanged(Document* aOldDoc) = 0;
119 protected:
120 virtual ~Link();
122 nsIURI* GetCachedURI() const { return mCachedURI; }
123 bool HasCachedURI() const { return !!mCachedURI; }
125 private:
127 * Unregisters from History and the document so this node no longer gets
128 * notifications about changes to visitedness.
130 void Unregister();
131 void SetLinkState(State, bool aNotify);
132 void SetHrefAttribute(nsIURI* aURI);
134 mutable nsCOMPtr<nsIURI> mCachedURI;
136 Element* const mElement;
138 bool mNeedsRegistration : 1;
139 bool mRegistered : 1;
140 bool mHasPendingLinkUpdate : 1;
141 const bool mHistory : 1;
144 NS_DEFINE_STATIC_IID_ACCESSOR(Link, MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
146 } // namespace dom
147 } // namespace mozilla
149 #endif // mozilla_dom_Link_h__