michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim: sw=2 ts=2 et : michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /** michael@0: * This is the base class for all link classes. michael@0: */ michael@0: michael@0: #ifndef mozilla_dom_Link_h__ michael@0: #define mozilla_dom_Link_h__ michael@0: michael@0: #include "mozilla/IHistory.h" michael@0: #include "mozilla/MemoryReporting.h" michael@0: #include "mozilla/dom/URLSearchParams.h" michael@0: #include "nsIContent.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: class EventStates; michael@0: michael@0: namespace dom { michael@0: michael@0: class Element; michael@0: michael@0: #define MOZILLA_DOM_LINK_IMPLEMENTATION_IID \ michael@0: { 0xb25edee6, 0xdd35, 0x4f8b, \ michael@0: { 0xab, 0x90, 0x66, 0xd0, 0xbd, 0x3c, 0x22, 0xd5 } } michael@0: michael@0: class Link : public URLSearchParamsObserver michael@0: { michael@0: public: michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_LINK_IMPLEMENTATION_IID) michael@0: michael@0: /** michael@0: * aElement is the element pointer corresponding to this link. michael@0: */ michael@0: Link(Element* aElement); michael@0: virtual void SetLinkState(nsLinkState aState); michael@0: michael@0: /** michael@0: * @return NS_EVENT_STATE_VISITED if this link is visited, michael@0: * NS_EVENT_STATE_UNVISTED if this link is not visited, or 0 if this michael@0: * link is not actually a link. michael@0: */ michael@0: EventStates LinkState() const; michael@0: michael@0: /** michael@0: * @return the URI this link is for, if available. michael@0: */ michael@0: nsIURI* GetURI() const; michael@0: virtual nsIURI* GetURIExternal() const { michael@0: return GetURI(); michael@0: } michael@0: michael@0: /** michael@0: * Helper methods for modifying and obtaining parts of the URI of the Link. michael@0: */ michael@0: void SetProtocol(const nsAString &aProtocol); michael@0: void SetUsername(const nsAString &aUsername); michael@0: void SetPassword(const nsAString &aPassword); michael@0: void SetHost(const nsAString &aHost); michael@0: void SetHostname(const nsAString &aHostname); michael@0: void SetPathname(const nsAString &aPathname); michael@0: void SetSearch(const nsAString &aSearch); michael@0: void SetSearchParams(mozilla::dom::URLSearchParams& aSearchParams); michael@0: void SetPort(const nsAString &aPort); michael@0: void SetHash(const nsAString &aHash); michael@0: void GetOrigin(nsAString &aOrigin); michael@0: void GetProtocol(nsAString &_protocol); michael@0: void GetUsername(nsAString &aUsername); michael@0: void GetPassword(nsAString &aPassword); michael@0: void GetHost(nsAString &_host); michael@0: void GetHostname(nsAString &_hostname); michael@0: void GetPathname(nsAString &_pathname); michael@0: void GetSearch(nsAString &_search); michael@0: URLSearchParams* SearchParams(); michael@0: void GetPort(nsAString &_port); michael@0: void GetHash(nsAString &_hash); michael@0: michael@0: /** michael@0: * Invalidates any link caching, and resets the state to the default. michael@0: * michael@0: * @param aNotify michael@0: * true if ResetLinkState should notify the owning document about style michael@0: * changes or false if it should not. michael@0: */ michael@0: void ResetLinkState(bool aNotify, bool aHasHref); michael@0: michael@0: // This method nevers returns a null element. michael@0: Element* GetElement() const { return mElement; } michael@0: michael@0: /** michael@0: * DNS prefetch has been deferred until later, e.g. page load complete. michael@0: */ michael@0: virtual void OnDNSPrefetchDeferred() { /*do nothing*/ } michael@0: michael@0: /** michael@0: * DNS prefetch has been submitted to Host Resolver. michael@0: */ michael@0: virtual void OnDNSPrefetchRequested() { /*do nothing*/ } michael@0: michael@0: /** michael@0: * Checks if DNS Prefetching is ok michael@0: * michael@0: * @returns boolean michael@0: * Defaults to true; should be overridden for specialised cases michael@0: */ michael@0: virtual bool HasDeferredDNSPrefetchRequest() { return true; } michael@0: michael@0: virtual size_t michael@0: SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; michael@0: michael@0: bool ElementHasHref() const; michael@0: michael@0: // URLSearchParamsObserver michael@0: void URLSearchParamsUpdated() MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: virtual ~Link(); michael@0: michael@0: /** michael@0: * Return true if the link has associated URI. michael@0: */ michael@0: bool HasURI() const michael@0: { michael@0: if (HasCachedURI()) { michael@0: return true; michael@0: } michael@0: michael@0: return !!GetURI(); michael@0: } michael@0: michael@0: nsIURI* GetCachedURI() const { return mCachedURI; } michael@0: bool HasCachedURI() const { return !!mCachedURI; } michael@0: michael@0: void UpdateURLSearchParams(); michael@0: michael@0: // CC methods michael@0: void Unlink(); michael@0: void Traverse(nsCycleCollectionTraversalCallback &cb); michael@0: michael@0: private: michael@0: /** michael@0: * Unregisters from History so this node no longer gets notifications about michael@0: * changes to visitedness. michael@0: */ michael@0: void UnregisterFromHistory(); michael@0: michael@0: already_AddRefed GetURIToMutate(); michael@0: void SetHrefAttribute(nsIURI *aURI); michael@0: michael@0: void CreateSearchParamsIfNeeded(); michael@0: michael@0: void SetSearchInternal(const nsAString& aSearch); michael@0: michael@0: mutable nsCOMPtr mCachedURI; michael@0: michael@0: Element * const mElement; michael@0: michael@0: // Strong reference to History. The link has to unregister before History michael@0: // can disappear. michael@0: nsCOMPtr mHistory; michael@0: michael@0: uint16_t mLinkState; michael@0: michael@0: bool mNeedsRegistration; michael@0: michael@0: bool mRegistered; michael@0: michael@0: protected: michael@0: nsRefPtr mSearchParams; michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(Link, MOZILLA_DOM_LINK_IMPLEMENTATION_IID) michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_dom_Link_h__