2009-10-13 15:13:41 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: sw=2 ts=2 et :
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-10-13 15:13:41 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the base class for all link classes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_Link_h__
|
|
|
|
#define mozilla_dom_Link_h__
|
|
|
|
|
2010-08-05 10:07:46 -07:00
|
|
|
#include "mozilla/IHistory.h"
|
2012-11-14 14:10:07 -08:00
|
|
|
#include "nsIContent.h"
|
2009-10-13 15:13:41 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2012-11-14 14:10:07 -08:00
|
|
|
class Element;
|
|
|
|
|
2010-02-24 08:37:03 -08:00
|
|
|
#define MOZILLA_DOM_LINK_IMPLEMENTATION_IID \
|
2012-01-20 15:14:46 -08:00
|
|
|
{ 0x7EA57721, 0xE373, 0x458E, \
|
|
|
|
{0x8F, 0x44, 0xF8, 0x96, 0x56, 0xB4, 0x14, 0xF5 } }
|
2010-02-24 08:37:03 -08:00
|
|
|
|
2009-10-13 15:13:41 -07:00
|
|
|
class Link : public nsISupports
|
|
|
|
{
|
|
|
|
public:
|
2010-02-24 08:37:03 -08:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
|
|
|
|
|
2009-10-13 15:13:41 -07:00
|
|
|
static const nsLinkState defaultState = eLinkState_Unknown;
|
2011-05-31 18:46:57 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* aElement is the element pointer corresponding to this link.
|
|
|
|
*/
|
|
|
|
Link(Element* aElement);
|
2010-02-24 08:37:38 -08:00
|
|
|
nsLinkState GetLinkState() const;
|
2009-10-13 15:13:41 -07:00
|
|
|
virtual void SetLinkState(nsLinkState aState);
|
|
|
|
|
2009-11-09 10:00:53 -08:00
|
|
|
/**
|
|
|
|
* @return NS_EVENT_STATE_VISITED if this link is visited,
|
|
|
|
* NS_EVENT_STATE_UNVISTED if this link is not visited, or 0 if this
|
|
|
|
* link is not actually a link.
|
|
|
|
*/
|
2010-10-20 04:26:32 -07:00
|
|
|
nsEventStates LinkState() const;
|
2009-11-09 10:00:53 -08:00
|
|
|
|
2009-11-09 10:00:54 -08:00
|
|
|
/**
|
|
|
|
* @return the URI this link is for, if available.
|
|
|
|
*/
|
|
|
|
already_AddRefed<nsIURI> GetURI() const;
|
2010-03-13 02:32:19 -08:00
|
|
|
virtual already_AddRefed<nsIURI> GetURIExternal() const {
|
|
|
|
return GetURI();
|
|
|
|
}
|
2009-11-09 10:00:54 -08:00
|
|
|
|
2009-11-09 10:00:54 -08:00
|
|
|
/**
|
|
|
|
* Helper methods for modifying and obtaining parts of the URI of the Link.
|
|
|
|
*/
|
|
|
|
nsresult SetProtocol(const nsAString &aProtocol);
|
|
|
|
nsresult SetHost(const nsAString &aHost);
|
|
|
|
nsresult SetHostname(const nsAString &aHostname);
|
|
|
|
nsresult SetPathname(const nsAString &aPathname);
|
|
|
|
nsresult SetSearch(const nsAString &aSearch);
|
|
|
|
nsresult SetPort(const nsAString &aPort);
|
|
|
|
nsresult SetHash(const nsAString &aHash);
|
|
|
|
nsresult GetProtocol(nsAString &_protocol);
|
|
|
|
nsresult GetHost(nsAString &_host);
|
|
|
|
nsresult GetHostname(nsAString &_hostname);
|
|
|
|
nsresult GetPathname(nsAString &_pathname);
|
|
|
|
nsresult GetSearch(nsAString &_search);
|
|
|
|
nsresult GetPort(nsAString &_port);
|
|
|
|
nsresult GetHash(nsAString &_hash);
|
|
|
|
|
2009-10-13 15:13:41 -07:00
|
|
|
/**
|
|
|
|
* Invalidates any link caching, and resets the state to the default.
|
2010-02-24 08:37:03 -08:00
|
|
|
*
|
|
|
|
* @param aNotify
|
|
|
|
* true if ResetLinkState should notify the owning document about style
|
|
|
|
* changes or false if it should not.
|
2009-10-13 15:13:41 -07:00
|
|
|
*/
|
2010-02-24 08:37:38 -08:00
|
|
|
void ResetLinkState(bool aNotify);
|
2011-11-13 19:24:41 -08:00
|
|
|
|
|
|
|
// This method nevers returns a null element.
|
|
|
|
Element* GetElement() const { return mElement; }
|
2009-10-13 15:13:41 -07:00
|
|
|
|
2012-01-20 15:14:46 -08:00
|
|
|
/**
|
|
|
|
* DNS prefetch has been deferred until later, e.g. page load complete.
|
|
|
|
*/
|
|
|
|
virtual void OnDNSPrefetchDeferred() { /*do nothing*/ }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DNS prefetch has been submitted to Host Resolver.
|
|
|
|
*/
|
|
|
|
virtual void OnDNSPrefetchRequested() { /*do nothing*/ }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if DNS Prefetching is ok
|
|
|
|
*
|
|
|
|
* @returns boolean
|
|
|
|
* Defaults to true; should be overridden for specialised cases
|
|
|
|
*/
|
|
|
|
virtual bool HasDeferredDNSPrefetchRequest() { return true; }
|
|
|
|
|
2012-02-19 19:51:48 -08:00
|
|
|
virtual size_t
|
|
|
|
SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
|
|
|
|
|
2010-02-24 08:37:03 -08:00
|
|
|
protected:
|
2009-12-15 16:01:53 -08:00
|
|
|
virtual ~Link();
|
|
|
|
|
2012-05-22 20:03:32 -07:00
|
|
|
/**
|
|
|
|
* Return true if the link has associated URI.
|
|
|
|
*/
|
|
|
|
bool HasURI() const
|
|
|
|
{
|
|
|
|
if (mCachedURI)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri(GetURI());
|
|
|
|
return !!uri;
|
|
|
|
}
|
|
|
|
|
2012-05-23 23:57:16 -07:00
|
|
|
nsIURI* GetCachedURI() const { return mCachedURI; }
|
2010-06-16 09:59:26 -07:00
|
|
|
bool HasCachedURI() const { return !!mCachedURI; }
|
|
|
|
|
2009-11-09 10:00:54 -08:00
|
|
|
private:
|
2009-11-23 10:48:52 -08:00
|
|
|
/**
|
|
|
|
* Unregisters from History so this node no longer gets notifications about
|
|
|
|
* changes to visitedness.
|
|
|
|
*/
|
|
|
|
void UnregisterFromHistory();
|
|
|
|
|
2009-11-09 10:00:54 -08:00
|
|
|
already_AddRefed<nsIURI> GetURIToMutate();
|
|
|
|
void SetHrefAttribute(nsIURI *aURI);
|
|
|
|
|
2009-11-09 10:00:54 -08:00
|
|
|
mutable nsCOMPtr<nsIURI> mCachedURI;
|
2009-11-23 10:48:52 -08:00
|
|
|
|
2011-05-31 18:46:57 -07:00
|
|
|
Element * const mElement;
|
2010-08-05 10:07:46 -07:00
|
|
|
|
|
|
|
// Strong reference to History. The link has to unregister before History
|
|
|
|
// can disappear.
|
|
|
|
nsCOMPtr<IHistory> mHistory;
|
2012-04-20 14:48:54 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t mLinkState;
|
2012-04-20 14:48:54 -07:00
|
|
|
|
|
|
|
bool mRegistered;
|
2009-10-13 15:13:41 -07:00
|
|
|
};
|
|
|
|
|
2010-02-24 08:37:03 -08:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(Link, MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
|
|
|
|
|
2009-10-13 15:13:41 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_Link_h__
|