2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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-14 02:13:41 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the base class for all link classes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_Link_h__
|
|
|
|
#define mozilla_dom_Link_h__
|
|
|
|
|
2010-08-05 21:07:46 +04:00
|
|
|
#include "mozilla/IHistory.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2014-10-23 19:32:35 +04:00
|
|
|
#include "mozilla/dom/URLSearchParams.h"
|
2014-08-18 18:44:50 +04:00
|
|
|
#include "nsIContent.h" // for nsLinkState
|
2009-10-14 02:13:41 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2014-04-03 08:18:36 +04:00
|
|
|
|
|
|
|
class EventStates;
|
|
|
|
|
2009-10-14 02:13:41 +04:00
|
|
|
namespace dom {
|
|
|
|
|
2012-11-15 02:10:07 +04:00
|
|
|
class Element;
|
|
|
|
|
2013-08-24 06:42:39 +04:00
|
|
|
#define MOZILLA_DOM_LINK_IMPLEMENTATION_IID \
|
|
|
|
{ 0xb25edee6, 0xdd35, 0x4f8b, \
|
|
|
|
{ 0xab, 0x90, 0x66, 0xd0, 0xbd, 0x3c, 0x22, 0xd5 } }
|
2010-02-24 19:37:03 +03:00
|
|
|
|
2014-10-23 19:32:35 +04:00
|
|
|
class Link : public URLSearchParamsObserver
|
2009-10-14 02:13:41 +04:00
|
|
|
{
|
|
|
|
public:
|
2010-02-24 19:37:03 +03:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
|
|
|
|
|
2011-06-01 05:46:57 +04:00
|
|
|
/**
|
|
|
|
* aElement is the element pointer corresponding to this link.
|
|
|
|
*/
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit Link(Element* aElement);
|
2009-10-14 02:13:41 +04:00
|
|
|
virtual void SetLinkState(nsLinkState aState);
|
|
|
|
|
2009-11-09 21:00:53 +03: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-03 08:18:36 +04:00
|
|
|
EventStates LinkState() const;
|
2009-11-09 21:00:53 +03:00
|
|
|
|
2009-11-09 21:00:54 +03:00
|
|
|
/**
|
|
|
|
* @return the URI this link is for, if available.
|
|
|
|
*/
|
2013-08-24 06:42:39 +04:00
|
|
|
nsIURI* GetURI() const;
|
|
|
|
virtual nsIURI* GetURIExternal() const {
|
2010-03-13 13:32:19 +03:00
|
|
|
return GetURI();
|
|
|
|
}
|
2009-11-09 21:00:54 +03:00
|
|
|
|
2009-11-09 21:00:54 +03:00
|
|
|
/**
|
|
|
|
* Helper methods for modifying and obtaining parts of the URI of the Link.
|
|
|
|
*/
|
2014-07-12 03:30:27 +04: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);
|
|
|
|
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 19:32:35 +04:00
|
|
|
URLSearchParams* SearchParams();
|
2014-07-12 03:30:27 +04:00
|
|
|
void GetPort(nsAString &_port, ErrorResult& aError);
|
|
|
|
void GetHash(nsAString &_hash, ErrorResult& aError);
|
2009-11-09 21:00:54 +03:00
|
|
|
|
2009-10-14 02:13:41 +04:00
|
|
|
/**
|
|
|
|
* Invalidates any link caching, and resets the state to the default.
|
2010-02-24 19:37:03 +03:00
|
|
|
*
|
|
|
|
* @param aNotify
|
|
|
|
* true if ResetLinkState should notify the owning document about style
|
|
|
|
* changes or false if it should not.
|
2009-10-14 02:13:41 +04:00
|
|
|
*/
|
2012-12-07 18:35:14 +04:00
|
|
|
void ResetLinkState(bool aNotify, bool aHasHref);
|
2011-11-14 07:24:41 +04:00
|
|
|
|
|
|
|
// This method nevers returns a null element.
|
|
|
|
Element* GetElement() const { return mElement; }
|
2009-10-14 02:13:41 +04:00
|
|
|
|
2012-01-21 03:14:46 +04: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-20 07:51:48 +04:00
|
|
|
virtual size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
2012-02-20 07:51:48 +04:00
|
|
|
|
2012-12-07 18:35:14 +04:00
|
|
|
bool ElementHasHref() const;
|
|
|
|
|
2014-10-23 19:32:35 +04:00
|
|
|
// URLSearchParamsObserver
|
2015-03-21 19:28:04 +03:00
|
|
|
void URLSearchParamsUpdated(URLSearchParams* aSearchParams) override;
|
2014-10-23 19:32:35 +04:00
|
|
|
|
2010-02-24 19:37:03 +03:00
|
|
|
protected:
|
2009-12-16 03:01:53 +03:00
|
|
|
virtual ~Link();
|
|
|
|
|
2012-05-23 07:03:32 +04:00
|
|
|
/**
|
|
|
|
* Return true if the link has associated URI.
|
|
|
|
*/
|
|
|
|
bool HasURI() const
|
|
|
|
{
|
2013-08-24 06:42:39 +04:00
|
|
|
if (HasCachedURI()) {
|
2012-05-23 07:03:32 +04:00
|
|
|
return true;
|
2013-08-24 06:42:39 +04:00
|
|
|
}
|
2012-05-23 07:03:32 +04:00
|
|
|
|
2013-08-24 06:42:39 +04:00
|
|
|
return !!GetURI();
|
2012-05-23 07:03:32 +04:00
|
|
|
}
|
|
|
|
|
2012-05-24 10:57:16 +04:00
|
|
|
nsIURI* GetCachedURI() const { return mCachedURI; }
|
2010-06-16 20:59:26 +04:00
|
|
|
bool HasCachedURI() const { return !!mCachedURI; }
|
|
|
|
|
2014-10-23 19:32:35 +04:00
|
|
|
void UpdateURLSearchParams();
|
|
|
|
|
|
|
|
// CC methods
|
|
|
|
void Unlink();
|
|
|
|
void Traverse(nsCycleCollectionTraversalCallback &cb);
|
|
|
|
|
2009-11-09 21:00:54 +03:00
|
|
|
private:
|
2009-11-23 21:48:52 +03:00
|
|
|
/**
|
|
|
|
* Unregisters from History so this node no longer gets notifications about
|
|
|
|
* changes to visitedness.
|
|
|
|
*/
|
|
|
|
void UnregisterFromHistory();
|
|
|
|
|
2009-11-09 21:00:54 +03:00
|
|
|
already_AddRefed<nsIURI> GetURIToMutate();
|
|
|
|
void SetHrefAttribute(nsIURI *aURI);
|
|
|
|
|
2014-10-23 19:32:35 +04:00
|
|
|
void CreateSearchParamsIfNeeded();
|
|
|
|
|
|
|
|
void SetSearchInternal(const nsAString& aSearch);
|
|
|
|
|
2009-11-09 21:00:54 +03:00
|
|
|
mutable nsCOMPtr<nsIURI> mCachedURI;
|
2009-11-23 21:48:52 +03:00
|
|
|
|
2011-06-01 05:46:57 +04:00
|
|
|
Element * const mElement;
|
2010-08-05 21:07:46 +04:00
|
|
|
|
|
|
|
// Strong reference to History. The link has to unregister before History
|
|
|
|
// can disappear.
|
|
|
|
nsCOMPtr<IHistory> mHistory;
|
2012-04-21 01:48:54 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t mLinkState;
|
2012-04-21 01:48:54 +04:00
|
|
|
|
2012-12-07 18:35:14 +04:00
|
|
|
bool mNeedsRegistration;
|
|
|
|
|
2012-04-21 01:48:54 +04:00
|
|
|
bool mRegistered;
|
2014-10-23 19:32:35 +04:00
|
|
|
|
|
|
|
protected:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<URLSearchParams> mSearchParams;
|
2009-10-14 02:13:41 +04:00
|
|
|
};
|
|
|
|
|
2010-02-24 19:37:03 +03:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(Link, MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
|
|
|
|
|
2009-10-14 02:13:41 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_Link_h__
|