Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/Link.h
Line
Count
Source (jump to first uncovered line)
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/. */
6
7
/**
8
 * This is the base class for all link classes.
9
 */
10
11
#ifndef mozilla_dom_Link_h__
12
#define mozilla_dom_Link_h__
13
14
#include "mozilla/MemoryReporting.h"
15
#include "nsIContent.h" // for nsLinkState
16
#include "nsIContentPolicy.h"
17
18
namespace mozilla {
19
20
class EventStates;
21
class SizeOfState;
22
23
namespace dom {
24
25
class Element;
26
27
#define MOZILLA_DOM_LINK_IMPLEMENTATION_IID               \
28
{ 0xb25edee6, 0xdd35, 0x4f8b,                             \
29
  { 0xab, 0x90, 0x66, 0xd0, 0xbd, 0x3c, 0x22, 0xd5 } }
30
31
class Link : public nsISupports
32
{
33
public:
34
  NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
35
36
  /**
37
   * aElement is the element pointer corresponding to this link.
38
   */
39
  explicit Link(Element* aElement);
40
41
  /**
42
   * This constructor is only used for testing.
43
   */
44
  explicit Link();
45
46
  virtual void SetLinkState(nsLinkState aState);
47
48
  /**
49
   * @return NS_EVENT_STATE_VISITED if this link is visited,
50
   *         NS_EVENT_STATE_UNVISTED if this link is not visited, or 0 if this
51
   *         link is not actually a link.
52
   */
53
  EventStates LinkState() const;
54
55
  /**
56
   * @return the URI this link is for, if available.
57
   */
58
  nsIURI* GetURI() const;
59
0
  virtual nsIURI* GetURIExternal() const {
60
0
    return GetURI();
61
0
  }
62
63
  /**
64
   * Helper methods for modifying and obtaining parts of the URI of the Link.
65
   */
66
  void SetProtocol(const nsAString &aProtocol);
67
  void SetUsername(const nsAString &aUsername);
68
  void SetPassword(const nsAString &aPassword);
69
  void SetHost(const nsAString &aHost);
70
  void SetHostname(const nsAString &aHostname);
71
  void SetPathname(const nsAString &aPathname);
72
  void SetSearch(const nsAString &aSearch);
73
  void SetPort(const nsAString &aPort);
74
  void SetHash(const nsAString &aHash);
75
  void GetOrigin(nsAString &aOrigin);
76
  void GetProtocol(nsAString &_protocol);
77
  void GetUsername(nsAString &aUsername);
78
  void GetPassword(nsAString &aPassword);
79
  void GetHost(nsAString &_host);
80
  void GetHostname(nsAString &_hostname);
81
  void GetPathname(nsAString &_pathname);
82
  void GetSearch(nsAString &_search);
83
  void GetPort(nsAString &_port);
84
  void GetHash(nsAString &_hash);
85
86
  /**
87
   * Invalidates any link caching, and resets the state to the default.
88
   *
89
   * @param aNotify
90
   *        true if ResetLinkState should notify the owning document about style
91
   *        changes or false if it should not.
92
   */
93
  void ResetLinkState(bool aNotify, bool aHasHref);
94
95
  // This method nevers returns a null element.
96
0
  Element* GetElement() const { return mElement; }
97
98
  /**
99
   * DNS prefetch has been deferred until later, e.g. page load complete.
100
   */
101
0
  virtual void OnDNSPrefetchDeferred() { /*do nothing*/ }
102
103
  /**
104
   * DNS prefetch has been submitted to Host Resolver.
105
   */
106
0
  virtual void OnDNSPrefetchRequested() { /*do nothing*/ }
107
108
  /**
109
   * Checks if DNS Prefetching is ok
110
   *
111
   * @returns boolean
112
   *          Defaults to true; should be overridden for specialised cases
113
   */
114
0
  virtual bool HasDeferredDNSPrefetchRequest() { return true; }
115
116
  virtual size_t
117
    SizeOfExcludingThis(mozilla::SizeOfState& aState) const;
118
119
  virtual bool ElementHasHref() const;
120
121
  // This is called by HTMLAnchorElement.
122
  void TryDNSPrefetch();
123
  void CancelDNSPrefetch(nsWrapperCache::FlagsType aDeferredFlag,
124
                         nsWrapperCache::FlagsType aRequestedFlag);
125
126
  // This is called by HTMLLinkElement.
127
  void TryDNSPrefetchOrPreconnectOrPrefetchOrPreloadOrPrerender();
128
  void UpdatePreload(nsAtom* aName, const nsAttrValue* aValue,
129
                     const nsAttrValue* aOldValue);
130
  void CancelPrefetchOrPreload();
131
132
0
  bool HasPendingLinkUpdate() const { return mHasPendingLinkUpdate; }
133
0
  void SetHasPendingLinkUpdate() { mHasPendingLinkUpdate = true; }
134
0
  void ClearHasPendingLinkUpdate() { mHasPendingLinkUpdate = false; }
135
136
  // To ensure correct mHasPendingLinkUpdate handling, we have this method
137
  // similar to the one in Element. Overriders must call
138
  // ClearHasPendingLinkUpdate().
139
  // If you change this, change also the method in Element.
140
  virtual void NodeInfoChanged(nsIDocument* aOldDoc) = 0;
141
142
0
  bool IsInDNSPrefetch() { return mInDNSPrefetch; }
143
0
  void SetIsInDNSPrefetch() { mInDNSPrefetch = true; }
144
0
  void ClearIsInDNSPrefetch() { mInDNSPrefetch = false; }
145
146
  static void ParseAsValue(const nsAString& aValue, nsAttrValue& aResult);
147
  static nsContentPolicyType AsValueToContentPolicy(const nsAttrValue& aValue);
148
protected:
149
  virtual ~Link();
150
151
  /**
152
   * Return true if the link has associated URI.
153
   */
154
  bool HasURI() const
155
0
  {
156
0
    if (HasCachedURI()) {
157
0
      return true;
158
0
    }
159
0
160
0
    return !!GetURI();
161
0
  }
162
163
0
  nsIURI* GetCachedURI() const { return mCachedURI; }
164
0
  bool HasCachedURI() const { return !!mCachedURI; }
165
166
private:
167
  /**
168
   * Unregisters from History so this node no longer gets notifications about
169
   * changes to visitedness.
170
   */
171
  void UnregisterFromHistory();
172
173
  void SetHrefAttribute(nsIURI *aURI);
174
175
  void GetContentPolicyMimeTypeMedia(nsAttrValue& aAsAttr,
176
                                     nsContentPolicyType& aPolicyType,
177
                                     nsString& aMimeType,
178
                                     nsAString& aMedia);
179
180
  mutable nsCOMPtr<nsIURI> mCachedURI;
181
182
  Element * const mElement;
183
184
  uint16_t mLinkState;
185
186
  bool mNeedsRegistration : 1;
187
188
  bool mRegistered : 1;
189
190
  bool mHasPendingLinkUpdate : 1;
191
192
  bool mInDNSPrefetch : 1;
193
194
  bool mHistory: 1;
195
};
196
197
NS_DEFINE_STATIC_IID_ACCESSOR(Link, MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
198
199
enum ASDestination : uint8_t {
200
  DESTINATION_INVALID,
201
  DESTINATION_AUDIO,
202
  DESTINATION_DOCUMENT,
203
  DESTINATION_EMBED,
204
  DESTINATION_FONT,
205
  DESTINATION_IMAGE,
206
  DESTINATION_MANIFEST,
207
  DESTINATION_OBJECT,
208
  DESTINATION_REPORT,
209
  DESTINATION_SCRIPT,
210
  DESTINATION_SERVICEWORKER,
211
  DESTINATION_SHAREDWORKER,
212
  DESTINATION_STYLE,
213
  DESTINATION_TRACK,
214
  DESTINATION_VIDEO,
215
  DESTINATION_WORKER,
216
  DESTINATION_XSLT,
217
  DESTINATION_FETCH
218
};
219
220
} // namespace dom
221
} // namespace mozilla
222
223
#endif // mozilla_dom_Link_h__