content/base/src/Link.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * vim: sw=2 ts=2 et :
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 /**
michael@0 8 * This is the base class for all link classes.
michael@0 9 */
michael@0 10
michael@0 11 #ifndef mozilla_dom_Link_h__
michael@0 12 #define mozilla_dom_Link_h__
michael@0 13
michael@0 14 #include "mozilla/IHistory.h"
michael@0 15 #include "mozilla/MemoryReporting.h"
michael@0 16 #include "mozilla/dom/URLSearchParams.h"
michael@0 17 #include "nsIContent.h"
michael@0 18
michael@0 19 namespace mozilla {
michael@0 20
michael@0 21 class EventStates;
michael@0 22
michael@0 23 namespace dom {
michael@0 24
michael@0 25 class Element;
michael@0 26
michael@0 27 #define MOZILLA_DOM_LINK_IMPLEMENTATION_IID \
michael@0 28 { 0xb25edee6, 0xdd35, 0x4f8b, \
michael@0 29 { 0xab, 0x90, 0x66, 0xd0, 0xbd, 0x3c, 0x22, 0xd5 } }
michael@0 30
michael@0 31 class Link : public URLSearchParamsObserver
michael@0 32 {
michael@0 33 public:
michael@0 34 NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
michael@0 35
michael@0 36 /**
michael@0 37 * aElement is the element pointer corresponding to this link.
michael@0 38 */
michael@0 39 Link(Element* aElement);
michael@0 40 virtual void SetLinkState(nsLinkState aState);
michael@0 41
michael@0 42 /**
michael@0 43 * @return NS_EVENT_STATE_VISITED if this link is visited,
michael@0 44 * NS_EVENT_STATE_UNVISTED if this link is not visited, or 0 if this
michael@0 45 * link is not actually a link.
michael@0 46 */
michael@0 47 EventStates LinkState() const;
michael@0 48
michael@0 49 /**
michael@0 50 * @return the URI this link is for, if available.
michael@0 51 */
michael@0 52 nsIURI* GetURI() const;
michael@0 53 virtual nsIURI* GetURIExternal() const {
michael@0 54 return GetURI();
michael@0 55 }
michael@0 56
michael@0 57 /**
michael@0 58 * Helper methods for modifying and obtaining parts of the URI of the Link.
michael@0 59 */
michael@0 60 void SetProtocol(const nsAString &aProtocol);
michael@0 61 void SetUsername(const nsAString &aUsername);
michael@0 62 void SetPassword(const nsAString &aPassword);
michael@0 63 void SetHost(const nsAString &aHost);
michael@0 64 void SetHostname(const nsAString &aHostname);
michael@0 65 void SetPathname(const nsAString &aPathname);
michael@0 66 void SetSearch(const nsAString &aSearch);
michael@0 67 void SetSearchParams(mozilla::dom::URLSearchParams& aSearchParams);
michael@0 68 void SetPort(const nsAString &aPort);
michael@0 69 void SetHash(const nsAString &aHash);
michael@0 70 void GetOrigin(nsAString &aOrigin);
michael@0 71 void GetProtocol(nsAString &_protocol);
michael@0 72 void GetUsername(nsAString &aUsername);
michael@0 73 void GetPassword(nsAString &aPassword);
michael@0 74 void GetHost(nsAString &_host);
michael@0 75 void GetHostname(nsAString &_hostname);
michael@0 76 void GetPathname(nsAString &_pathname);
michael@0 77 void GetSearch(nsAString &_search);
michael@0 78 URLSearchParams* SearchParams();
michael@0 79 void GetPort(nsAString &_port);
michael@0 80 void GetHash(nsAString &_hash);
michael@0 81
michael@0 82 /**
michael@0 83 * Invalidates any link caching, and resets the state to the default.
michael@0 84 *
michael@0 85 * @param aNotify
michael@0 86 * true if ResetLinkState should notify the owning document about style
michael@0 87 * changes or false if it should not.
michael@0 88 */
michael@0 89 void ResetLinkState(bool aNotify, bool aHasHref);
michael@0 90
michael@0 91 // This method nevers returns a null element.
michael@0 92 Element* GetElement() const { return mElement; }
michael@0 93
michael@0 94 /**
michael@0 95 * DNS prefetch has been deferred until later, e.g. page load complete.
michael@0 96 */
michael@0 97 virtual void OnDNSPrefetchDeferred() { /*do nothing*/ }
michael@0 98
michael@0 99 /**
michael@0 100 * DNS prefetch has been submitted to Host Resolver.
michael@0 101 */
michael@0 102 virtual void OnDNSPrefetchRequested() { /*do nothing*/ }
michael@0 103
michael@0 104 /**
michael@0 105 * Checks if DNS Prefetching is ok
michael@0 106 *
michael@0 107 * @returns boolean
michael@0 108 * Defaults to true; should be overridden for specialised cases
michael@0 109 */
michael@0 110 virtual bool HasDeferredDNSPrefetchRequest() { return true; }
michael@0 111
michael@0 112 virtual size_t
michael@0 113 SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
michael@0 114
michael@0 115 bool ElementHasHref() const;
michael@0 116
michael@0 117 // URLSearchParamsObserver
michael@0 118 void URLSearchParamsUpdated() MOZ_OVERRIDE;
michael@0 119
michael@0 120 protected:
michael@0 121 virtual ~Link();
michael@0 122
michael@0 123 /**
michael@0 124 * Return true if the link has associated URI.
michael@0 125 */
michael@0 126 bool HasURI() const
michael@0 127 {
michael@0 128 if (HasCachedURI()) {
michael@0 129 return true;
michael@0 130 }
michael@0 131
michael@0 132 return !!GetURI();
michael@0 133 }
michael@0 134
michael@0 135 nsIURI* GetCachedURI() const { return mCachedURI; }
michael@0 136 bool HasCachedURI() const { return !!mCachedURI; }
michael@0 137
michael@0 138 void UpdateURLSearchParams();
michael@0 139
michael@0 140 // CC methods
michael@0 141 void Unlink();
michael@0 142 void Traverse(nsCycleCollectionTraversalCallback &cb);
michael@0 143
michael@0 144 private:
michael@0 145 /**
michael@0 146 * Unregisters from History so this node no longer gets notifications about
michael@0 147 * changes to visitedness.
michael@0 148 */
michael@0 149 void UnregisterFromHistory();
michael@0 150
michael@0 151 already_AddRefed<nsIURI> GetURIToMutate();
michael@0 152 void SetHrefAttribute(nsIURI *aURI);
michael@0 153
michael@0 154 void CreateSearchParamsIfNeeded();
michael@0 155
michael@0 156 void SetSearchInternal(const nsAString& aSearch);
michael@0 157
michael@0 158 mutable nsCOMPtr<nsIURI> mCachedURI;
michael@0 159
michael@0 160 Element * const mElement;
michael@0 161
michael@0 162 // Strong reference to History. The link has to unregister before History
michael@0 163 // can disappear.
michael@0 164 nsCOMPtr<IHistory> mHistory;
michael@0 165
michael@0 166 uint16_t mLinkState;
michael@0 167
michael@0 168 bool mNeedsRegistration;
michael@0 169
michael@0 170 bool mRegistered;
michael@0 171
michael@0 172 protected:
michael@0 173 nsRefPtr<URLSearchParams> mSearchParams;
michael@0 174 };
michael@0 175
michael@0 176 NS_DEFINE_STATIC_IID_ACCESSOR(Link, MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
michael@0 177
michael@0 178 } // namespace dom
michael@0 179 } // namespace mozilla
michael@0 180
michael@0 181 #endif // mozilla_dom_Link_h__

mercurial