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__
|
|
|
|
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2014-08-18 18:44:50 +04:00
|
|
|
#include "nsIContent.h" // for nsLinkState
|
2017-08-03 11:50:00 +03:00
|
|
|
#include "nsIContentPolicy.h"
|
2009-10-14 02:13:41 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2014-04-03 08:18:36 +04:00
|
|
|
|
|
|
|
class EventStates;
|
2018-03-28 02:44:49 +03:00
|
|
|
class SizeOfState;
|
2014-04-03 08:18:36 +04:00
|
|
|
|
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 \
|
2018-11-30 13:46:48 +03:00
|
|
|
{ \
|
2013-08-24 06:42:39 +04:00
|
|
|
0xb25edee6, 0xdd35, 0x4f8b, { \
|
|
|
|
0xab, 0x90, 0x66, 0xd0, 0xbd, 0x3c, 0x22, 0xd5 \
|
|
|
|
} \
|
|
|
|
}
|
2010-02-24 19:37:03 +03:00
|
|
|
|
2015-11-23 23:05:26 +03:00
|
|
|
class Link : public nsISupports {
|
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.
|
|
|
|
*/
|
2019-05-01 11:47:10 +03:00
|
|
|
explicit Link(Element* aElement);
|
2016-11-11 22:22:01 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This constructor is only used for testing.
|
|
|
|
*/
|
|
|
|
explicit Link();
|
|
|
|
|
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.
|
|
|
|
*/
|
2019-05-01 11:47:10 +03:00
|
|
|
nsIURI* GetURI() const;
|
|
|
|
virtual nsIURI* GetURIExternal() const { 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.
|
|
|
|
*/
|
2019-05-01 11:47:10 +03:00
|
|
|
void SetProtocol(const nsAString& aProtocol);
|
|
|
|
void SetUsername(const nsAString& aUsername);
|
|
|
|
void SetPassword(const nsAString& aPassword);
|
|
|
|
void SetHost(const nsAString& aHost);
|
|
|
|
void SetHostname(const nsAString& aHostname);
|
|
|
|
void SetPathname(const nsAString& aPathname);
|
|
|
|
void SetSearch(const nsAString& aSearch);
|
|
|
|
void SetPort(const nsAString& aPort);
|
|
|
|
void SetHash(const nsAString& aHash);
|
|
|
|
void GetOrigin(nsAString& aOrigin);
|
|
|
|
void GetProtocol(nsAString& _protocol);
|
|
|
|
void GetUsername(nsAString& aUsername);
|
|
|
|
void GetPassword(nsAString& aPassword);
|
|
|
|
void GetHost(nsAString& _host);
|
|
|
|
void GetHostname(nsAString& _hostname);
|
|
|
|
void GetPathname(nsAString& _pathname);
|
|
|
|
void GetSearch(nsAString& _search);
|
|
|
|
void GetPort(nsAString& _port);
|
|
|
|
void GetHash(nsAString& _hash);
|
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);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2011-11-14 07:24:41 +04:00
|
|
|
// This method nevers returns a null element.
|
2019-05-01 11:47:10 +03:00
|
|
|
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*/
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2012-01-21 03:14:46 +04:00
|
|
|
/**
|
|
|
|
* DNS prefetch has been submitted to Host Resolver.
|
|
|
|
*/
|
|
|
|
virtual void OnDNSPrefetchRequested() { /*do nothing*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if DNS Prefetching is ok
|
2017-07-06 15:00:35 +03:00
|
|
|
*
|
2012-01-21 03:14:46 +04:00
|
|
|
* @returns boolean
|
|
|
|
* Defaults to true; should be overridden for specialised cases
|
|
|
|
*/
|
|
|
|
virtual bool HasDeferredDNSPrefetchRequest() { return true; }
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual size_t SizeOfExcludingThis(mozilla::SizeOfState& aState) const;
|
2012-02-20 07:51:48 +04:00
|
|
|
|
2017-05-06 22:32:14 +03:00
|
|
|
virtual bool ElementHasHref() const;
|
2012-12-07 18:35:14 +04:00
|
|
|
|
2019-08-15 17:10:08 +03:00
|
|
|
// This is called by HTMLAnchorElement and HTMLLinkElement.
|
2015-12-01 20:22:20 +03:00
|
|
|
void TryDNSPrefetch();
|
|
|
|
void CancelDNSPrefetch(nsWrapperCache::FlagsType aDeferredFlag,
|
|
|
|
nsWrapperCache::FlagsType aRequestedFlag);
|
|
|
|
|
2017-07-07 13:06:52 +03:00
|
|
|
bool HasPendingLinkUpdate() const { return mHasPendingLinkUpdate; }
|
2017-04-15 18:55:05 +03:00
|
|
|
void SetHasPendingLinkUpdate() { mHasPendingLinkUpdate = true; }
|
|
|
|
void ClearHasPendingLinkUpdate() { mHasPendingLinkUpdate = false; }
|
|
|
|
|
|
|
|
// To ensure correct mHasPendingLinkUpdate handling, we have this method
|
|
|
|
// similar to the one in Element. Overriders must call
|
|
|
|
// ClearHasPendingLinkUpdate().
|
|
|
|
// If you change this, change also the method in Element.
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual void NodeInfoChanged(Document* aOldDoc) = 0;
|
2017-04-15 18:55:05 +03:00
|
|
|
|
2017-04-19 13:06:36 +03:00
|
|
|
bool IsInDNSPrefetch() { return mInDNSPrefetch; }
|
|
|
|
void SetIsInDNSPrefetch() { mInDNSPrefetch = true; }
|
|
|
|
void ClearIsInDNSPrefetch() { mInDNSPrefetch = false; }
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsIURI* GetCachedURI() const { return mCachedURI; }
|
2010-06-16 20:59:26 +04:00
|
|
|
bool HasCachedURI() const { return !!mCachedURI; }
|
|
|
|
|
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();
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void SetHrefAttribute(nsIURI* aURI);
|
2009-11-09 21:00:54 +03:00
|
|
|
|
2009-11-09 21:00:54 +03:00
|
|
|
mutable nsCOMPtr<nsIURI> mCachedURI;
|
2009-11-23 21:48:52 +03:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
Element* const mElement;
|
2010-08-05 21:07:46 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t mLinkState;
|
2012-04-21 01:48:54 +04:00
|
|
|
|
2017-04-15 18:55:05 +03:00
|
|
|
bool mNeedsRegistration : 1;
|
|
|
|
|
|
|
|
bool mRegistered : 1;
|
2012-12-07 18:35:14 +04:00
|
|
|
|
2017-04-15 18:55:05 +03:00
|
|
|
bool mHasPendingLinkUpdate : 1;
|
2017-04-19 13:06:36 +03:00
|
|
|
|
|
|
|
bool mInDNSPrefetch : 1;
|
2017-07-21 06:39:14 +03:00
|
|
|
|
|
|
|
bool mHistory : 1;
|
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)
|
|
|
|
|
2017-07-10 16:05:56 +03:00
|
|
|
enum ASDestination : uint8_t {
|
|
|
|
DESTINATION_INVALID,
|
|
|
|
DESTINATION_AUDIO,
|
|
|
|
DESTINATION_DOCUMENT,
|
|
|
|
DESTINATION_EMBED,
|
|
|
|
DESTINATION_FONT,
|
|
|
|
DESTINATION_IMAGE,
|
|
|
|
DESTINATION_MANIFEST,
|
|
|
|
DESTINATION_OBJECT,
|
|
|
|
DESTINATION_REPORT,
|
|
|
|
DESTINATION_SCRIPT,
|
|
|
|
DESTINATION_SERVICEWORKER,
|
|
|
|
DESTINATION_SHAREDWORKER,
|
|
|
|
DESTINATION_STYLE,
|
|
|
|
DESTINATION_TRACK,
|
|
|
|
DESTINATION_VIDEO,
|
|
|
|
DESTINATION_WORKER,
|
|
|
|
DESTINATION_XSLT,
|
|
|
|
DESTINATION_FETCH
|
|
|
|
};
|
|
|
|
|
2009-10-14 02:13:41 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_Link_h__
|