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"
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2014-10-23 08:32:35 -07:00
|
|
|
#include "mozilla/dom/URLSearchParams.h"
|
2014-08-18 07:44:50 -07:00
|
|
|
#include "nsIContent.h" // for nsLinkState
|
2009-10-13 15:13:41 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
2014-04-02 21:18:36 -07:00
|
|
|
|
|
|
|
class EventStates;
|
|
|
|
|
2009-10-13 15:13:41 -07:00
|
|
|
namespace dom {
|
|
|
|
|
2012-11-14 14:10:07 -08:00
|
|
|
class Element;
|
|
|
|
|
2013-08-23 19:42:39 -07:00
|
|
|
#define MOZILLA_DOM_LINK_IMPLEMENTATION_IID \
|
|
|
|
{ 0xb25edee6, 0xdd35, 0x4f8b, \
|
|
|
|
{ 0xab, 0x90, 0x66, 0xd0, 0xbd, 0x3c, 0x22, 0xd5 } }
|
2010-02-24 08:37:03 -08:00
|
|
|
|
2014-10-23 08:32:35 -07:00
|
|
|
class Link : public URLSearchParamsObserver
|
2009-10-13 15:13:41 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-02-24 08:37:03 -08:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
|
|
|
|
|
2011-05-31 18:46:57 -07:00
|
|
|
/**
|
|
|
|
* aElement is the element pointer corresponding to this link.
|
|
|
|
*/
|
2014-09-01 17:49:25 -07:00
|
|
|
explicit Link(Element* aElement);
|
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.
|
|
|
|
*/
|
2014-04-02 21:18:36 -07:00
|
|
|
EventStates 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.
|
|
|
|
*/
|
2013-08-23 19:42:39 -07:00
|
|
|
nsIURI* GetURI() const;
|
|
|
|
virtual nsIURI* GetURIExternal() const {
|
2010-03-13 02:32:19 -08:00
|
|
|
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.
|
|
|
|
*/
|
2014-07-11 16:30:27 -07:00
|
|
|
void SetProtocol(const nsAString &aProtocol, ErrorResult& aError);
|
|
|
|
void SetUsername(const nsAString &aUsername, ErrorResult& aError);
|
|
|
|
void SetPassword(const nsAString &aPassword, ErrorResult& aError);
|
|
|
|
void SetHost(const nsAString &aHost, ErrorResult& aError);
|
|
|
|
void SetHostname(const nsAString &aHostname, ErrorResult& aError);
|
|
|
|
void SetPathname(const nsAString &aPathname, ErrorResult& aError);
|
|
|
|
void SetSearch(const nsAString &aSearch, ErrorResult& aError);
|
2014-10-23 08:32:35 -07:00
|
|
|
void SetSearchParams(mozilla::dom::URLSearchParams& aSearchParams);
|
2014-07-11 16:30:27 -07:00
|
|
|
void SetPort(const nsAString &aPort, ErrorResult& aError);
|
|
|
|
void SetHash(const nsAString &aHash, ErrorResult& aError);
|
|
|
|
void GetOrigin(nsAString &aOrigin, ErrorResult& aError);
|
|
|
|
void GetProtocol(nsAString &_protocol, ErrorResult& aError);
|
|
|
|
void GetUsername(nsAString &aUsername, ErrorResult& aError);
|
|
|
|
void GetPassword(nsAString &aPassword, ErrorResult& aError);
|
|
|
|
void GetHost(nsAString &_host, ErrorResult& aError);
|
|
|
|
void GetHostname(nsAString &_hostname, ErrorResult& aError);
|
|
|
|
void GetPathname(nsAString &_pathname, ErrorResult& aError);
|
|
|
|
void GetSearch(nsAString &_search, ErrorResult& aError);
|
2014-10-23 08:32:35 -07:00
|
|
|
URLSearchParams* SearchParams();
|
2014-07-11 16:30:27 -07:00
|
|
|
void GetPort(nsAString &_port, ErrorResult& aError);
|
|
|
|
void GetHash(nsAString &_hash, ErrorResult& aError);
|
2009-11-09 10:00:54 -08:00
|
|
|
|
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
|
|
|
*/
|
2012-12-07 06:35:14 -08:00
|
|
|
void ResetLinkState(bool aNotify, bool aHasHref);
|
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
|
2013-06-23 05:03:39 -07:00
|
|
|
SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
2012-02-19 19:51:48 -08:00
|
|
|
|
2012-12-07 06:35:14 -08:00
|
|
|
bool ElementHasHref() const;
|
|
|
|
|
2014-10-23 08:32:35 -07:00
|
|
|
// URLSearchParamsObserver
|
|
|
|
void URLSearchParamsUpdated(URLSearchParams* aSearchParams) MOZ_OVERRIDE;
|
|
|
|
|
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
|
|
|
|
{
|
2013-08-23 19:42:39 -07:00
|
|
|
if (HasCachedURI()) {
|
2012-05-22 20:03:32 -07:00
|
|
|
return true;
|
2013-08-23 19:42:39 -07:00
|
|
|
}
|
2012-05-22 20:03:32 -07:00
|
|
|
|
2013-08-23 19:42:39 -07:00
|
|
|
return !!GetURI();
|
2012-05-22 20:03:32 -07:00
|
|
|
}
|
|
|
|
|
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; }
|
|
|
|
|
2014-10-23 08:32:35 -07:00
|
|
|
void UpdateURLSearchParams();
|
|
|
|
|
|
|
|
// CC methods
|
|
|
|
void Unlink();
|
|
|
|
void Traverse(nsCycleCollectionTraversalCallback &cb);
|
|
|
|
|
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);
|
|
|
|
|
2014-10-23 08:32:35 -07:00
|
|
|
void CreateSearchParamsIfNeeded();
|
|
|
|
|
|
|
|
void SetSearchInternal(const nsAString& aSearch);
|
|
|
|
|
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
|
|
|
|
2012-12-07 06:35:14 -08:00
|
|
|
bool mNeedsRegistration;
|
|
|
|
|
2012-04-20 14:48:54 -07:00
|
|
|
bool mRegistered;
|
2014-10-23 08:32:35 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
nsRefPtr<URLSearchParams> mSearchParams;
|
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__
|