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
|
|
|
|
|
|
|
#include "Link.h"
|
|
|
|
|
2011-04-21 10:35:52 -07:00
|
|
|
#include "nsEventStates.h"
|
2009-11-09 10:00:54 -08:00
|
|
|
#include "nsIURL.h"
|
2012-02-19 19:51:48 -08:00
|
|
|
#include "nsISizeOf.h"
|
2009-11-09 10:00:54 -08:00
|
|
|
|
|
|
|
#include "nsEscape.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsString.h"
|
2009-12-15 16:04:07 -08:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2009-11-09 10:00:53 -08:00
|
|
|
|
2010-08-05 10:07:46 -07:00
|
|
|
#include "mozilla/Services.h"
|
2009-11-23 10:48:52 -08:00
|
|
|
|
2009-10-13 15:13:41 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2011-05-31 18:46:57 -07:00
|
|
|
Link::Link(Element *aElement)
|
2012-04-20 14:48:54 -07:00
|
|
|
: mElement(aElement)
|
2010-08-05 10:07:46 -07:00
|
|
|
, mHistory(services::GetHistoryService())
|
2012-04-20 14:48:54 -07:00
|
|
|
, mLinkState(defaultState)
|
|
|
|
, mRegistered(false)
|
2009-10-13 15:13:41 -07:00
|
|
|
{
|
2011-05-31 18:46:57 -07:00
|
|
|
NS_ABORT_IF_FALSE(mElement, "Must have an element");
|
2009-10-13 15:13:41 -07:00
|
|
|
}
|
|
|
|
|
2009-12-15 16:01:53 -08:00
|
|
|
Link::~Link()
|
|
|
|
{
|
|
|
|
UnregisterFromHistory();
|
|
|
|
}
|
|
|
|
|
2009-10-13 15:13:41 -07:00
|
|
|
nsLinkState
|
|
|
|
Link::GetLinkState() const
|
|
|
|
{
|
2009-11-23 10:48:52 -08:00
|
|
|
NS_ASSERTION(mRegistered,
|
|
|
|
"Getting the link state of an unregistered Link!");
|
|
|
|
NS_ASSERTION(mLinkState != eLinkState_Unknown,
|
|
|
|
"Getting the link state with an unknown value!");
|
2012-04-20 14:48:54 -07:00
|
|
|
return nsLinkState(mLinkState);
|
2009-10-13 15:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Link::SetLinkState(nsLinkState aState)
|
|
|
|
{
|
2009-11-23 10:48:52 -08:00
|
|
|
NS_ASSERTION(mRegistered,
|
|
|
|
"Setting the link state of an unregistered Link!");
|
2009-12-15 16:04:07 -08:00
|
|
|
NS_ASSERTION(mLinkState != aState,
|
|
|
|
"Setting state to the currently set state!");
|
|
|
|
|
|
|
|
// Set our current state as appropriate.
|
2009-10-13 15:13:41 -07:00
|
|
|
mLinkState = aState;
|
2009-11-23 10:48:52 -08:00
|
|
|
|
|
|
|
// Per IHistory interface documentation, we are no longer registered.
|
|
|
|
mRegistered = false;
|
2009-12-15 16:04:07 -08:00
|
|
|
|
2011-05-31 18:46:57 -07:00
|
|
|
NS_ABORT_IF_FALSE(LinkState() == NS_EVENT_STATE_VISITED ||
|
|
|
|
LinkState() == NS_EVENT_STATE_UNVISITED,
|
|
|
|
"Unexpected state obtained from LinkState()!");
|
|
|
|
|
|
|
|
// Tell the element to update its visited state
|
|
|
|
mElement->UpdateState(true);
|
2009-10-13 15:13:41 -07:00
|
|
|
}
|
|
|
|
|
2010-10-20 04:26:32 -07:00
|
|
|
nsEventStates
|
2009-11-09 10:00:53 -08:00
|
|
|
Link::LinkState() const
|
|
|
|
{
|
2009-11-23 10:48:52 -08:00
|
|
|
// We are a constant method, but we are just lazily doing things and have to
|
|
|
|
// track that state. Cast away that constness!
|
|
|
|
Link *self = const_cast<Link *>(this);
|
|
|
|
|
|
|
|
// If we are not in the document, default to not visited.
|
2011-05-31 18:46:57 -07:00
|
|
|
Element *element = self->mElement;
|
|
|
|
if (!element->IsInDoc()) {
|
2009-11-23 10:48:52 -08:00
|
|
|
self->mLinkState = eLinkState_Unvisited;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have not yet registered for notifications and are in an unknown
|
|
|
|
// state, register now!
|
|
|
|
if (!mRegistered && mLinkState == eLinkState_Unknown) {
|
|
|
|
// First, make sure the href attribute has a valid link (bug 23209).
|
|
|
|
nsCOMPtr<nsIURI> hrefURI(GetURI());
|
|
|
|
if (!hrefURI) {
|
|
|
|
self->mLinkState = eLinkState_NotLink;
|
2010-10-20 04:26:32 -07:00
|
|
|
return nsEventStates();
|
2009-11-23 10:48:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// We have a good href, so register with History.
|
2010-08-05 10:07:46 -07:00
|
|
|
nsresult rv = mHistory->RegisterVisitedCallback(hrefURI, self);
|
2009-11-23 10:48:52 -08:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
self->mRegistered = true;
|
|
|
|
|
|
|
|
// Assume that we are not visited until we are told otherwise.
|
|
|
|
self->mLinkState = eLinkState_Unvisited;
|
2010-02-24 08:37:03 -08:00
|
|
|
|
|
|
|
// And make sure we are in the document's link map.
|
2011-05-31 18:46:57 -07:00
|
|
|
nsIDocument *doc = element->GetCurrentDoc();
|
2010-02-24 08:37:03 -08:00
|
|
|
if (doc) {
|
2010-02-24 08:37:03 -08:00
|
|
|
doc->AddStyleRelevantLink(self);
|
2010-02-24 08:37:03 -08:00
|
|
|
}
|
2009-11-23 10:48:52 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, return our known state.
|
2009-11-09 10:00:53 -08:00
|
|
|
if (mLinkState == eLinkState_Visited) {
|
|
|
|
return NS_EVENT_STATE_VISITED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mLinkState == eLinkState_Unvisited) {
|
|
|
|
return NS_EVENT_STATE_UNVISITED;
|
|
|
|
}
|
|
|
|
|
2010-10-20 04:26:32 -07:00
|
|
|
return nsEventStates();
|
2009-11-09 10:00:53 -08:00
|
|
|
}
|
|
|
|
|
2009-11-09 10:00:54 -08:00
|
|
|
already_AddRefed<nsIURI>
|
|
|
|
Link::GetURI() const
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri(mCachedURI);
|
|
|
|
|
|
|
|
// If we have this URI cached, use it.
|
|
|
|
if (uri) {
|
|
|
|
return uri.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise obtain it.
|
|
|
|
Link *self = const_cast<Link *>(this);
|
2011-05-31 18:46:57 -07:00
|
|
|
Element *element = self->mElement;
|
|
|
|
uri = element->GetHrefURI();
|
2009-11-09 10:00:54 -08:00
|
|
|
|
|
|
|
// We want to cache the URI if the node is in the document.
|
2011-05-31 18:46:57 -07:00
|
|
|
if (uri && element->IsInDoc()) {
|
2009-11-09 10:00:54 -08:00
|
|
|
mCachedURI = uri;
|
|
|
|
}
|
|
|
|
|
|
|
|
return uri.forget();
|
|
|
|
}
|
|
|
|
|
2009-11-09 10:00:54 -08:00
|
|
|
nsresult
|
|
|
|
Link::SetProtocol(const nsAString &aProtocol)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri(GetURIToMutate());
|
|
|
|
if (!uri) {
|
|
|
|
// Ignore failures to be compatible with NS4.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAString::const_iterator start, end;
|
|
|
|
aProtocol.BeginReading(start);
|
|
|
|
aProtocol.EndReading(end);
|
|
|
|
nsAString::const_iterator iter(start);
|
|
|
|
(void)FindCharInReadable(':', iter, end);
|
|
|
|
(void)uri->SetScheme(NS_ConvertUTF16toUTF8(Substring(start, iter)));
|
|
|
|
|
|
|
|
SetHrefAttribute(uri);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Link::SetHost(const nsAString &aHost)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri(GetURIToMutate());
|
|
|
|
if (!uri) {
|
|
|
|
// Ignore failures to be compatible with NS4.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We cannot simply call nsIURI::SetHost because that would treat the name as
|
|
|
|
// an IPv6 address (like http:://[server:443]/). We also cannot call
|
|
|
|
// nsIURI::SetHostPort because that isn't implemented. Sadfaces.
|
|
|
|
|
|
|
|
// First set the hostname.
|
|
|
|
nsAString::const_iterator start, end;
|
|
|
|
aHost.BeginReading(start);
|
|
|
|
aHost.EndReading(end);
|
|
|
|
nsAString::const_iterator iter(start);
|
|
|
|
(void)FindCharInReadable(':', iter, end);
|
|
|
|
NS_ConvertUTF16toUTF8 host(Substring(start, iter));
|
|
|
|
(void)uri->SetHost(host);
|
|
|
|
|
|
|
|
// Also set the port if needed.
|
|
|
|
if (iter != end) {
|
|
|
|
iter++;
|
|
|
|
if (iter != end) {
|
|
|
|
nsAutoString portStr(Substring(iter, end));
|
|
|
|
nsresult rv;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t port = portStr.ToInteger(&rv);
|
2009-11-09 10:00:54 -08:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
(void)uri->SetPort(port);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
SetHrefAttribute(uri);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Link::SetHostname(const nsAString &aHostname)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri(GetURIToMutate());
|
|
|
|
if (!uri) {
|
|
|
|
// Ignore failures to be compatible with NS4.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
(void)uri->SetHost(NS_ConvertUTF16toUTF8(aHostname));
|
|
|
|
SetHrefAttribute(uri);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Link::SetPathname(const nsAString &aPathname)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri(GetURIToMutate());
|
|
|
|
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
|
|
|
if (!url) {
|
|
|
|
// Ignore failures to be compatible with NS4.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
(void)url->SetFilePath(NS_ConvertUTF16toUTF8(aPathname));
|
|
|
|
SetHrefAttribute(uri);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Link::SetSearch(const nsAString &aSearch)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri(GetURIToMutate());
|
|
|
|
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
|
|
|
if (!url) {
|
|
|
|
// Ignore failures to be compatible with NS4.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
(void)url->SetQuery(NS_ConvertUTF16toUTF8(aSearch));
|
|
|
|
SetHrefAttribute(uri);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Link::SetPort(const nsAString &aPort)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri(GetURIToMutate());
|
|
|
|
if (!uri) {
|
|
|
|
// Ignore failures to be compatible with NS4.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsAutoString portStr(aPort);
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t port = portStr.ToInteger(&rv);
|
2009-11-09 10:00:54 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
(void)uri->SetPort(port);
|
|
|
|
SetHrefAttribute(uri);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Link::SetHash(const nsAString &aHash)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri(GetURIToMutate());
|
2011-05-21 18:12:46 -07:00
|
|
|
if (!uri) {
|
2009-11-09 10:00:54 -08:00
|
|
|
// Ignore failures to be compatible with NS4.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-21 18:12:46 -07:00
|
|
|
(void)uri->SetRef(NS_ConvertUTF16toUTF8(aHash));
|
2009-11-09 10:00:54 -08:00
|
|
|
SetHrefAttribute(uri);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Link::GetProtocol(nsAString &_protocol)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri(GetURI());
|
|
|
|
if (!uri) {
|
|
|
|
_protocol.AssignLiteral("http");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCAutoString scheme;
|
|
|
|
(void)uri->GetScheme(scheme);
|
|
|
|
CopyASCIItoUTF16(scheme, _protocol);
|
|
|
|
}
|
|
|
|
_protocol.Append(PRUnichar(':'));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Link::GetHost(nsAString &_host)
|
|
|
|
{
|
|
|
|
_host.Truncate();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri(GetURI());
|
|
|
|
if (!uri) {
|
|
|
|
// Do not throw! Not having a valid URI should result in an empty string.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCAutoString hostport;
|
|
|
|
nsresult rv = uri->GetHostPort(hostport);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
CopyUTF8toUTF16(hostport, _host);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Link::GetHostname(nsAString &_hostname)
|
|
|
|
{
|
|
|
|
_hostname.Truncate();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri(GetURI());
|
|
|
|
if (!uri) {
|
|
|
|
// Do not throw! Not having a valid URI should result in an empty string.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCAutoString host;
|
|
|
|
nsresult rv = uri->GetHost(host);
|
|
|
|
// Note that failure to get the host from the URI is not necessarily a bad
|
|
|
|
// thing. Some URIs do not have a host.
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
CopyUTF8toUTF16(host, _hostname);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Link::GetPathname(nsAString &_pathname)
|
|
|
|
{
|
|
|
|
_pathname.Truncate();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri(GetURI());
|
|
|
|
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
|
|
|
if (!url) {
|
|
|
|
// Do not throw! Not having a valid URI or URL should result in an empty
|
|
|
|
// string.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCAutoString file;
|
|
|
|
nsresult rv = url->GetFilePath(file);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
CopyUTF8toUTF16(file, _pathname);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Link::GetSearch(nsAString &_search)
|
|
|
|
{
|
|
|
|
_search.Truncate();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri(GetURI());
|
|
|
|
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
|
|
|
if (!url) {
|
|
|
|
// Do not throw! Not having a valid URI or URL should result in an empty
|
|
|
|
// string.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCAutoString search;
|
|
|
|
nsresult rv = url->GetQuery(search);
|
|
|
|
if (NS_SUCCEEDED(rv) && !search.IsEmpty()) {
|
|
|
|
CopyUTF8toUTF16(NS_LITERAL_CSTRING("?") + search, _search);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Link::GetPort(nsAString &_port)
|
|
|
|
{
|
|
|
|
_port.Truncate();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri(GetURI());
|
|
|
|
if (!uri) {
|
|
|
|
// Do not throw! Not having a valid URI should result in an empty string.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t port;
|
2009-11-09 10:00:54 -08:00
|
|
|
nsresult rv = uri->GetPort(&port);
|
|
|
|
// Note that failure to get the port from the URI is not necessarily a bad
|
|
|
|
// thing. Some URIs do not have a port.
|
|
|
|
if (NS_SUCCEEDED(rv) && port != -1) {
|
|
|
|
nsAutoString portStr;
|
|
|
|
portStr.AppendInt(port, 10);
|
|
|
|
_port.Assign(portStr);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Link::GetHash(nsAString &_hash)
|
|
|
|
{
|
|
|
|
_hash.Truncate();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri(GetURI());
|
2011-05-21 18:12:46 -07:00
|
|
|
if (!uri) {
|
|
|
|
// Do not throw! Not having a valid URI should result in an empty
|
2009-11-09 10:00:54 -08:00
|
|
|
// string.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCAutoString ref;
|
2011-05-21 18:12:46 -07:00
|
|
|
nsresult rv = uri->GetRef(ref);
|
2009-11-09 10:00:54 -08:00
|
|
|
if (NS_SUCCEEDED(rv) && !ref.IsEmpty()) {
|
|
|
|
NS_UnescapeURL(ref); // XXX may result in random non-ASCII bytes!
|
|
|
|
_hash.Assign(PRUnichar('#'));
|
|
|
|
AppendUTF8toUTF16(ref, _hash);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-10-13 15:13:41 -07:00
|
|
|
void
|
2010-02-24 08:37:03 -08:00
|
|
|
Link::ResetLinkState(bool aNotify)
|
2009-10-13 15:13:41 -07:00
|
|
|
{
|
2010-02-24 08:37:03 -08:00
|
|
|
// If we are in our default state, bail early.
|
|
|
|
if (mLinkState == defaultState) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-31 18:46:57 -07:00
|
|
|
Element *element = mElement;
|
2009-10-13 15:13:41 -07:00
|
|
|
|
2010-03-09 10:21:25 -08:00
|
|
|
// Tell the document to forget about this link if we were a link before.
|
2011-05-31 18:46:57 -07:00
|
|
|
nsIDocument *doc = element->GetCurrentDoc();
|
2010-03-09 10:21:25 -08:00
|
|
|
if (doc && mLinkState != eLinkState_NotLink) {
|
2010-02-24 08:37:03 -08:00
|
|
|
doc->ForgetLink(this);
|
2009-10-13 15:13:41 -07:00
|
|
|
}
|
2009-11-09 10:00:54 -08:00
|
|
|
|
2009-11-23 10:48:52 -08:00
|
|
|
UnregisterFromHistory();
|
|
|
|
|
2009-11-09 10:00:54 -08:00
|
|
|
// Update our state back to the default.
|
2009-10-13 15:13:41 -07:00
|
|
|
mLinkState = defaultState;
|
2009-11-09 10:00:54 -08:00
|
|
|
|
|
|
|
// Get rid of our cached URI.
|
2012-07-30 07:20:58 -07:00
|
|
|
mCachedURI = nullptr;
|
2010-02-24 08:37:03 -08:00
|
|
|
|
2011-05-31 18:46:57 -07:00
|
|
|
// We have to be very careful here: if aNotify is false we do NOT
|
|
|
|
// want to call UpdateState, because that will call into LinkState()
|
|
|
|
// and try to start off loads, etc. But ResetLinkState is called
|
|
|
|
// with aNotify false when things are in inconsistent states, so
|
|
|
|
// we'll get confused in that situation. Instead, just silently
|
|
|
|
// update the link state on mElement.
|
|
|
|
if (aNotify) {
|
|
|
|
mElement->UpdateState(aNotify);
|
|
|
|
} else {
|
|
|
|
mElement->UpdateLinkState(nsEventStates());
|
2010-02-24 08:37:03 -08:00
|
|
|
}
|
2009-10-13 15:13:41 -07:00
|
|
|
}
|
|
|
|
|
2009-11-23 10:48:52 -08:00
|
|
|
void
|
|
|
|
Link::UnregisterFromHistory()
|
|
|
|
{
|
|
|
|
// If we are not registered, we have nothing to do.
|
|
|
|
if (!mRegistered) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-12-15 16:01:53 -08:00
|
|
|
NS_ASSERTION(mCachedURI, "mRegistered is true, but we have no cached URI?!");
|
2009-11-23 10:48:52 -08:00
|
|
|
|
|
|
|
// And tell History to stop tracking us.
|
2010-08-05 10:07:46 -07:00
|
|
|
nsresult rv = mHistory->UnregisterVisitedCallback(mCachedURI, this);
|
2009-11-23 10:48:52 -08:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "This should only fail if we misuse the API!");
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mRegistered = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-09 10:00:54 -08:00
|
|
|
already_AddRefed<nsIURI>
|
|
|
|
Link::GetURIToMutate()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri(GetURI());
|
|
|
|
if (!uri) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-11-09 10:00:54 -08:00
|
|
|
}
|
|
|
|
nsCOMPtr<nsIURI> clone;
|
|
|
|
(void)uri->Clone(getter_AddRefs(clone));
|
|
|
|
return clone.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Link::SetHrefAttribute(nsIURI *aURI)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aURI, "Null URI is illegal!");
|
|
|
|
|
|
|
|
nsCAutoString href;
|
|
|
|
(void)aURI->GetSpec(href);
|
2011-05-31 18:46:57 -07:00
|
|
|
(void)mElement->SetAttr(kNameSpaceID_None, nsGkAtoms::href,
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ConvertUTF8toUTF16(href), true);
|
2009-11-09 10:00:54 -08:00
|
|
|
}
|
|
|
|
|
2012-02-19 19:51:48 -08:00
|
|
|
size_t
|
|
|
|
Link::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
size_t n = 0;
|
|
|
|
|
|
|
|
if (mCachedURI) {
|
|
|
|
nsCOMPtr<nsISizeOf> iface = do_QueryInterface(mCachedURI);
|
|
|
|
if (iface) {
|
|
|
|
n += iface->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The following members don't need to be measured:
|
|
|
|
// - mElement, because it is a pointer-to-self used to avoid QIs
|
|
|
|
// - mHistory, because it is non-owning
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2009-10-13 15:13:41 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|