2014-02-27 13:44:52 +00:00
|
|
|
|
2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
2013-02-08 12:50:30 +00:00
|
|
|
|
|
|
|
#include "mozilla/dom/HTMLLinkElement.h"
|
|
|
|
|
2014-03-17 06:56:54 +00:00
|
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
2013-07-10 09:56:47 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-03-18 04:48:21 +00:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-04-03 04:18:36 +00:00
|
|
|
#include "mozilla/EventStates.h"
|
2013-07-10 09:56:47 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2014-05-21 17:08:12 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2014-04-03 04:18:36 +00:00
|
|
|
#include "mozilla/dom/HTMLLinkElementBinding.h"
|
2013-07-10 09:56:47 +00:00
|
|
|
#include "nsContentUtils.h"
|
1998-09-02 23:53:16 +00:00
|
|
|
#include "nsGenericHTMLElement.h"
|
2006-12-26 17:47:52 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2014-03-11 12:04:26 +00:00
|
|
|
#include "nsDOMTokenList.h"
|
2013-07-10 09:56:47 +00:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMEvent.h"
|
1999-02-23 19:18:12 +00:00
|
|
|
#include "nsIDOMStyleSheet.h"
|
2014-05-21 17:08:12 +00:00
|
|
|
#include "nsINode.h"
|
1999-02-23 19:18:12 +00:00
|
|
|
#include "nsIStyleSheet.h"
|
|
|
|
#include "nsIStyleSheetLinkingElement.h"
|
2000-07-27 23:17:53 +00:00
|
|
|
#include "nsIURL.h"
|
2001-05-19 02:59:15 +00:00
|
|
|
#include "nsNetUtil.h"
|
2005-06-15 23:52:46 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
2013-07-10 09:56:47 +00:00
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
1998-09-01 01:27:08 +00:00
|
|
|
|
2004-05-18 20:58:12 +00:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Link)
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2013-02-08 12:50:30 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
HTMLLinkElement::HTMLLinkElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2013-07-10 09:56:47 +00:00
|
|
|
: nsGenericHTMLElement(aNodeInfo)
|
2015-01-07 05:39:46 +00:00
|
|
|
, Link(this)
|
1998-09-01 01:27:08 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-08 12:50:30 +00:00
|
|
|
HTMLLinkElement::~HTMLLinkElement()
|
1998-09-01 01:27:08 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-08-02 01:29:05 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLLinkElement)
|
|
|
|
|
2013-02-08 12:50:30 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLLinkElement,
|
2012-10-08 02:39:09 +00:00
|
|
|
nsGenericHTMLElement)
|
|
|
|
tmp->nsStyleLinkElement::Traverse(cb);
|
2014-10-23 15:32:35 +00:00
|
|
|
tmp->Link::Traverse(cb);
|
2014-03-11 12:04:26 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRelList)
|
2014-05-21 17:08:12 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mImportLoader)
|
2012-10-08 02:39:09 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2013-08-02 01:29:05 +00:00
|
|
|
|
2013-02-08 12:50:30 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLLinkElement,
|
2012-10-08 02:39:09 +00:00
|
|
|
nsGenericHTMLElement)
|
|
|
|
tmp->nsStyleLinkElement::Unlink();
|
2014-10-23 15:32:35 +00:00
|
|
|
tmp->Link::Unlink();
|
2014-03-11 12:04:26 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRelList)
|
2014-05-21 17:08:12 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mImportLoader)
|
2012-10-08 02:39:09 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
1998-09-01 01:27:08 +00:00
|
|
|
|
2013-02-08 12:50:30 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(HTMLLinkElement, Element)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(HTMLLinkElement, Element)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
|
2010-01-12 13:08:43 +00:00
|
|
|
|
2013-02-08 12:50:30 +00:00
|
|
|
// QueryInterface implementation for HTMLLinkElement
|
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(HTMLLinkElement)
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_INTERFACE_TABLE_INHERITED(HTMLLinkElement,
|
|
|
|
nsIDOMHTMLLinkElement,
|
|
|
|
nsIStyleSheetLinkingElement,
|
|
|
|
Link)
|
2013-08-07 20:23:08 +00:00
|
|
|
NS_INTERFACE_TABLE_TAIL_INHERITING(nsGenericHTMLElement)
|
1998-09-01 01:27:08 +00:00
|
|
|
|
|
|
|
|
2013-02-08 12:50:30 +00:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLLinkElement)
|
1998-09-01 01:27:08 +00:00
|
|
|
|
2013-02-08 12:50:30 +00:00
|
|
|
bool
|
2013-03-17 14:42:59 +00:00
|
|
|
HTMLLinkElement::Disabled()
|
2013-02-08 12:50:30 +00:00
|
|
|
{
|
2014-06-20 10:32:49 +00:00
|
|
|
CSSStyleSheet* ss = GetSheet();
|
2013-03-17 14:42:59 +00:00
|
|
|
return ss && ss->Disabled();
|
2013-02-08 12:50:30 +00:00
|
|
|
}
|
2000-12-23 10:56:31 +00:00
|
|
|
|
1999-02-23 19:18:12 +00:00
|
|
|
NS_IMETHODIMP
|
2013-03-17 14:42:59 +00:00
|
|
|
HTMLLinkElement::GetMozDisabled(bool* aDisabled)
|
1999-02-23 19:18:12 +00:00
|
|
|
{
|
2013-03-17 14:42:59 +00:00
|
|
|
*aDisabled = Disabled();
|
|
|
|
return NS_OK;
|
2013-02-08 12:50:30 +00:00
|
|
|
}
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2013-02-08 12:50:30 +00:00
|
|
|
void
|
2013-03-17 14:42:59 +00:00
|
|
|
HTMLLinkElement::SetDisabled(bool aDisabled)
|
2013-02-08 12:50:30 +00:00
|
|
|
{
|
2014-06-20 10:32:49 +00:00
|
|
|
CSSStyleSheet* ss = GetSheet();
|
2013-03-17 14:42:59 +00:00
|
|
|
if (ss) {
|
|
|
|
ss->SetDisabled(aDisabled);
|
1999-02-23 19:18:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-08 12:50:30 +00:00
|
|
|
NS_IMETHODIMP
|
2013-03-17 14:42:59 +00:00
|
|
|
HTMLLinkElement::SetMozDisabled(bool aDisabled)
|
1999-02-23 19:18:12 +00:00
|
|
|
{
|
2013-03-17 14:42:59 +00:00
|
|
|
SetDisabled(aDisabled);
|
|
|
|
return NS_OK;
|
1999-02-23 19:18:12 +00:00
|
|
|
}
|
|
|
|
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2013-02-08 12:50:30 +00:00
|
|
|
NS_IMPL_STRING_ATTR(HTMLLinkElement, Charset, charset)
|
|
|
|
NS_IMPL_URI_ATTR(HTMLLinkElement, Href, href)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLLinkElement, Hreflang, hreflang)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLLinkElement, Media, media)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLLinkElement, Rel, rel)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLLinkElement, Rev, rev)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLLinkElement, Target, target)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLLinkElement, Type, type)
|
1998-09-01 01:27:08 +00:00
|
|
|
|
2012-06-04 23:49:57 +00:00
|
|
|
void
|
2015-02-13 01:27:39 +00:00
|
|
|
HTMLLinkElement::GetItemValueText(DOMString& aValue)
|
2012-06-04 23:49:57 +00:00
|
|
|
{
|
|
|
|
GetHref(aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-08 12:50:30 +00:00
|
|
|
HTMLLinkElement::SetItemValueText(const nsAString& aValue)
|
2012-06-04 23:49:57 +00:00
|
|
|
{
|
|
|
|
SetHref(aValue);
|
|
|
|
}
|
|
|
|
|
2005-04-05 23:54:35 +00:00
|
|
|
nsresult
|
2013-02-08 12:50:30 +00:00
|
|
|
HTMLLinkElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
2005-04-05 23:54:35 +00:00
|
|
|
{
|
2012-12-07 14:35:14 +00:00
|
|
|
Link::ResetLinkState(false, Link::ElementHasHref());
|
2009-11-23 18:48:52 +00:00
|
|
|
|
2005-04-05 23:54:35 +00:00
|
|
|
nsresult rv = nsGenericHTMLElement::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-12-02 10:26:12 +00:00
|
|
|
|
|
|
|
// Link must be inert in ShadowRoot.
|
|
|
|
if (aDocument && !GetContainingShadow()) {
|
2011-11-14 03:24:41 +00:00
|
|
|
aDocument->RegisterPendingLinkUpdate(this);
|
|
|
|
}
|
2005-04-05 23:54:35 +00:00
|
|
|
|
2013-02-08 12:50:30 +00:00
|
|
|
void (HTMLLinkElement::*update)() = &HTMLLinkElement::UpdateStyleSheetInternal;
|
2010-04-20 23:21:35 +00:00
|
|
|
nsContentUtils::AddScriptRunner(NS_NewRunnableMethod(this, update));
|
2005-04-05 23:54:35 +00:00
|
|
|
|
2014-05-21 17:08:12 +00:00
|
|
|
void (HTMLLinkElement::*updateImport)() = &HTMLLinkElement::UpdateImport;
|
|
|
|
nsContentUtils::AddScriptRunner(NS_NewRunnableMethod(this, updateImport));
|
|
|
|
|
2005-04-05 23:54:35 +00:00
|
|
|
CreateAndDispatchEvent(aDocument, NS_LITERAL_STRING("DOMLinkAdded"));
|
|
|
|
|
2009-11-23 18:48:52 +00:00
|
|
|
return rv;
|
2005-04-05 23:54:35 +00:00
|
|
|
}
|
|
|
|
|
2013-08-08 05:26:32 +00:00
|
|
|
void
|
2013-02-08 12:50:30 +00:00
|
|
|
HTMLLinkElement::LinkAdded()
|
2005-06-15 23:52:46 +00:00
|
|
|
{
|
2011-10-18 10:53:36 +00:00
|
|
|
CreateAndDispatchEvent(OwnerDoc(), NS_LITERAL_STRING("DOMLinkAdded"));
|
2005-06-15 23:52:46 +00:00
|
|
|
}
|
|
|
|
|
2013-08-08 05:26:32 +00:00
|
|
|
void
|
2013-02-08 12:50:30 +00:00
|
|
|
HTMLLinkElement::LinkRemoved()
|
2005-06-15 23:52:46 +00:00
|
|
|
{
|
2011-10-18 10:53:36 +00:00
|
|
|
CreateAndDispatchEvent(OwnerDoc(), NS_LITERAL_STRING("DOMLinkRemoved"));
|
2005-06-15 23:52:46 +00:00
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
void
|
2013-02-08 12:50:30 +00:00
|
|
|
HTMLLinkElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
2004-01-09 23:54:21 +00:00
|
|
|
{
|
2009-11-23 18:48:52 +00:00
|
|
|
// If this link is ever reinserted into a document, it might
|
|
|
|
// be under a different xml:base, so forget the cached state now.
|
2012-12-07 14:35:14 +00:00
|
|
|
Link::ResetLinkState(false, Link::ElementHasHref());
|
2004-01-09 23:54:21 +00:00
|
|
|
|
2014-10-02 19:07:24 +00:00
|
|
|
nsCOMPtr<nsIDocument> oldDoc = GetUncomposedDoc();
|
2013-12-02 10:26:12 +00:00
|
|
|
|
|
|
|
// Check for a ShadowRoot because link elements are inert in a
|
|
|
|
// ShadowRoot.
|
|
|
|
ShadowRoot* oldShadowRoot = GetBindingParent() ?
|
|
|
|
GetBindingParent()->GetShadowRoot() : nullptr;
|
|
|
|
|
2014-10-02 19:07:24 +00:00
|
|
|
OwnerDoc()->UnregisterPendingLinkUpdate(this);
|
|
|
|
|
2005-04-05 23:54:35 +00:00
|
|
|
CreateAndDispatchEvent(oldDoc, NS_LITERAL_STRING("DOMLinkRemoved"));
|
|
|
|
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
|
2013-12-02 10:26:12 +00:00
|
|
|
|
|
|
|
UpdateStyleSheetInternal(oldDoc, oldShadowRoot);
|
2014-05-21 17:08:12 +00:00
|
|
|
UpdateImport();
|
2004-01-09 23:54:21 +00:00
|
|
|
}
|
2005-04-05 23:54:35 +00:00
|
|
|
|
2012-08-28 17:10:07 +00:00
|
|
|
bool
|
2013-02-08 12:50:30 +00:00
|
|
|
HTMLLinkElement::ParseAttribute(int32_t aNamespaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
2012-08-28 17:10:07 +00:00
|
|
|
{
|
2014-04-17 11:50:54 +00:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::crossorigin) {
|
|
|
|
ParseCORSValue(aValue, aResult);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aAttribute == nsGkAtoms::sizes) {
|
|
|
|
aResult.ParseAtomArray(aValue);
|
|
|
|
return true;
|
|
|
|
}
|
2012-08-28 17:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
|
|
|
aResult);
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
void
|
2013-02-08 12:50:30 +00:00
|
|
|
HTMLLinkElement::CreateAndDispatchEvent(nsIDocument* aDoc,
|
|
|
|
const nsAString& aEventName)
|
2004-01-09 23:54:21 +00:00
|
|
|
{
|
|
|
|
if (!aDoc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// In the unlikely case that both rev is specified *and* rel=stylesheet,
|
|
|
|
// this code will cause the event to fire, on the principle that maybe the
|
2009-01-23 09:02:09 +00:00
|
|
|
// page really does want to specify that its author is a stylesheet. Since
|
2004-01-09 23:54:21 +00:00
|
|
|
// this should never actually happen and the performance hit is minimal,
|
|
|
|
// doing the "right" thing costs virtually nothing here, even if it doesn't
|
|
|
|
// make much sense.
|
2006-04-24 05:40:11 +00:00
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
2012-07-30 14:20:58 +00:00
|
|
|
{&nsGkAtoms::_empty, &nsGkAtoms::stylesheet, nullptr};
|
2006-04-24 05:40:11 +00:00
|
|
|
|
|
|
|
if (!nsContentUtils::HasNonEmptyAttr(this, kNameSpaceID_None,
|
2006-12-26 17:47:52 +00:00
|
|
|
nsGkAtoms::rev) &&
|
|
|
|
FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::rel,
|
2006-04-24 05:40:11 +00:00
|
|
|
strings, eIgnoreCase) != ATTR_VALUE_NO_MATCH)
|
2004-01-09 23:54:21 +00:00
|
|
|
return;
|
|
|
|
|
2014-03-17 06:56:54 +00:00
|
|
|
nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
|
|
|
|
new AsyncEventDispatcher(this, aEventName, true, true);
|
2011-11-16 07:50:19 +00:00
|
|
|
// Always run async in order to avoid running script when the content
|
|
|
|
// sink isn't expecting it.
|
2014-03-17 06:56:54 +00:00
|
|
|
asyncDispatcher->PostDOMEvent();
|
2004-01-09 23:54:21 +00:00
|
|
|
}
|
|
|
|
|
2014-05-21 17:08:12 +00:00
|
|
|
void
|
|
|
|
HTMLLinkElement::UpdateImport()
|
|
|
|
{
|
|
|
|
// 1. link node should be attached to the document.
|
2014-10-02 19:07:24 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc = GetUncomposedDoc();
|
2014-05-21 17:08:12 +00:00
|
|
|
if (!doc) {
|
|
|
|
// We might have been just removed from the document, so
|
|
|
|
// let's remove ourself from the list of link nodes of
|
|
|
|
// the import and reset mImportLoader.
|
|
|
|
if (mImportLoader) {
|
|
|
|
mImportLoader->RemoveLinkElement(this);
|
|
|
|
mImportLoader = nullptr;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2. rel type should be import.
|
|
|
|
nsAutoString rel;
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::rel, rel);
|
2014-07-08 02:02:03 +00:00
|
|
|
uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(rel, NodePrincipal());
|
2014-05-21 17:08:12 +00:00
|
|
|
if (!(linkTypes & eHTMLIMPORT)) {
|
|
|
|
mImportLoader = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri = GetHrefURI();
|
|
|
|
if (!uri) {
|
|
|
|
mImportLoader = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-23 12:06:28 +00:00
|
|
|
if (!nsStyleLinkElement::IsImportEnabled()) {
|
2014-06-02 11:28:55 +00:00
|
|
|
// For now imports are hidden behind a pref...
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-21 17:08:12 +00:00
|
|
|
nsRefPtr<ImportManager> manager = doc->ImportManager();
|
|
|
|
MOZ_ASSERT(manager, "ImportManager should be created lazily when needed");
|
|
|
|
|
|
|
|
{
|
|
|
|
// The load even might fire sooner than we could set mImportLoader so
|
|
|
|
// we must use async event and a scriptBlocker here.
|
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
|
|
|
// CORS check will happen at the start of the load.
|
|
|
|
mImportLoader = manager->Get(uri, this, doc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult
|
2013-02-08 12:50:30 +00:00
|
|
|
HTMLLinkElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|
|
|
nsIAtom* aPrefix, const nsAString& aValue,
|
|
|
|
bool aNotify)
|
2004-01-09 23:54:21 +00:00
|
|
|
{
|
2010-02-24 16:37:38 +00:00
|
|
|
nsresult rv = nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix,
|
|
|
|
aValue, aNotify);
|
|
|
|
|
|
|
|
// The ordering of the parent class's SetAttr call and Link::ResetLinkState
|
|
|
|
// is important here! The attribute is not set until SetAttr returns, and
|
|
|
|
// we will need the updated attribute value because notifying the document
|
|
|
|
// that content states have changed will call IntrinsicState, which will try
|
|
|
|
// to get updated information about the visitedness from Link.
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aName == nsGkAtoms::href && kNameSpaceID_None == aNameSpaceID) {
|
2012-12-07 14:35:14 +00:00
|
|
|
Link::ResetLinkState(!!aNotify, true);
|
2014-10-16 22:00:12 +00:00
|
|
|
if (IsInUncomposedDoc()) {
|
|
|
|
CreateAndDispatchEvent(OwnerDoc(), NS_LITERAL_STRING("DOMLinkChanged"));
|
|
|
|
}
|
2004-01-09 23:54:21 +00:00
|
|
|
}
|
|
|
|
|
2012-06-01 04:30:42 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
(aName == nsGkAtoms::href ||
|
|
|
|
aName == nsGkAtoms::rel ||
|
|
|
|
aName == nsGkAtoms::title ||
|
|
|
|
aName == nsGkAtoms::media ||
|
|
|
|
aName == nsGkAtoms::type)) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool dropSheet = false;
|
2014-05-21 17:08:12 +00:00
|
|
|
if (aName == nsGkAtoms::rel) {
|
2014-07-08 02:02:03 +00:00
|
|
|
uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(aValue,
|
|
|
|
NodePrincipal());
|
2014-05-21 17:08:12 +00:00
|
|
|
if (GetSheet()) {
|
|
|
|
dropSheet = !(linkTypes & nsStyleLinkElement::eSTYLESHEET);
|
|
|
|
} else if (linkTypes & eHTMLIMPORT) {
|
|
|
|
UpdateImport();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aName == nsGkAtoms::href) {
|
|
|
|
UpdateImport();
|
2007-04-25 18:48:18 +00:00
|
|
|
}
|
|
|
|
|
2013-12-02 10:26:12 +00:00
|
|
|
UpdateStyleSheetInternal(nullptr, nullptr,
|
2007-04-25 18:48:18 +00:00
|
|
|
dropSheet ||
|
2012-06-01 04:30:42 +00:00
|
|
|
(aName == nsGkAtoms::title ||
|
|
|
|
aName == nsGkAtoms::media ||
|
|
|
|
aName == nsGkAtoms::type));
|
2004-01-09 23:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-02-08 12:50:30 +00:00
|
|
|
HTMLLinkElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
|
|
|
|
bool aNotify)
|
2004-01-09 23:54:21 +00:00
|
|
|
{
|
2004-02-10 19:36:43 +00:00
|
|
|
nsresult rv = nsGenericHTMLElement::UnsetAttr(aNameSpaceID, aAttribute,
|
|
|
|
aNotify);
|
2012-06-01 04:30:42 +00:00
|
|
|
// Since removing href or rel makes us no longer link to a
|
|
|
|
// stylesheet, force updates for those too.
|
2014-05-21 17:08:12 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::href ||
|
|
|
|
aAttribute == nsGkAtoms::rel ||
|
|
|
|
aAttribute == nsGkAtoms::title ||
|
|
|
|
aAttribute == nsGkAtoms::media ||
|
|
|
|
aAttribute == nsGkAtoms::type) {
|
|
|
|
UpdateStyleSheetInternal(nullptr, nullptr, true);
|
|
|
|
}
|
|
|
|
if (aAttribute == nsGkAtoms::href ||
|
|
|
|
aAttribute == nsGkAtoms::rel) {
|
|
|
|
UpdateImport();
|
|
|
|
}
|
2004-01-09 23:54:21 +00:00
|
|
|
}
|
|
|
|
|
2010-03-03 20:55:35 +00:00
|
|
|
// The ordering of the parent class's UnsetAttr call and Link::ResetLinkState
|
|
|
|
// is important here! The attribute is not unset until UnsetAttr returns, and
|
|
|
|
// we will need the updated attribute value because notifying the document
|
|
|
|
// that content states have changed will call IntrinsicState, which will try
|
|
|
|
// to get updated information about the visitedness from Link.
|
|
|
|
if (aAttribute == nsGkAtoms::href && kNameSpaceID_None == aNameSpaceID) {
|
2012-12-07 14:35:14 +00:00
|
|
|
Link::ResetLinkState(!!aNotify, false);
|
2014-10-16 22:00:12 +00:00
|
|
|
if (IsInUncomposedDoc()) {
|
|
|
|
CreateAndDispatchEvent(OwnerDoc(), NS_LITERAL_STRING("DOMLinkChanged"));
|
|
|
|
}
|
2010-03-03 20:55:35 +00:00
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-04-23 07:31:21 +00:00
|
|
|
nsresult
|
2014-03-18 04:48:19 +00:00
|
|
|
HTMLLinkElement::PreHandleEvent(EventChainPreVisitor& aVisitor)
|
2007-04-23 07:31:21 +00:00
|
|
|
{
|
|
|
|
return PreHandleEventForAnchors(aVisitor);
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult
|
2014-03-18 04:48:20 +00:00
|
|
|
HTMLLinkElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
|
1998-09-01 01:27:08 +00:00
|
|
|
{
|
2006-03-07 17:08:51 +00:00
|
|
|
return PostHandleEventForAnchors(aVisitor);
|
1998-09-01 01:27:08 +00:00
|
|
|
}
|
1998-12-10 23:52:46 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2013-02-08 12:50:30 +00:00
|
|
|
HTMLLinkElement::IsLink(nsIURI** aURI) const
|
2007-01-04 10:53:59 +00:00
|
|
|
{
|
|
|
|
return IsHTMLLink(aURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-08 12:50:30 +00:00
|
|
|
HTMLLinkElement::GetLinkTarget(nsAString& aTarget)
|
2007-01-04 10:53:59 +00:00
|
|
|
{
|
2007-03-26 13:19:33 +00:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::target, aTarget);
|
|
|
|
if (aTarget.IsEmpty()) {
|
2007-01-04 10:53:59 +00:00
|
|
|
GetBaseTarget(aTarget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-11 12:04:26 +00:00
|
|
|
nsDOMTokenList*
|
|
|
|
HTMLLinkElement::RelList()
|
|
|
|
{
|
|
|
|
if (!mRelList) {
|
|
|
|
mRelList = new nsDOMTokenList(this, nsGkAtoms::rel);
|
|
|
|
}
|
|
|
|
return mRelList;
|
|
|
|
}
|
|
|
|
|
2009-07-13 11:48:06 +00:00
|
|
|
already_AddRefed<nsIURI>
|
2013-02-08 12:50:30 +00:00
|
|
|
HTMLLinkElement::GetHrefURI() const
|
2000-07-27 23:17:53 +00:00
|
|
|
{
|
2009-07-13 11:48:06 +00:00
|
|
|
return GetHrefURIForAnchors();
|
2000-07-27 23:17:53 +00:00
|
|
|
}
|
2000-08-22 04:14:53 +00:00
|
|
|
|
2009-07-28 16:07:31 +00:00
|
|
|
already_AddRefed<nsIURI>
|
2013-02-08 12:50:30 +00:00
|
|
|
HTMLLinkElement::GetStyleSheetURL(bool* aIsInline)
|
2002-04-05 11:29:40 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
*aIsInline = false;
|
2011-05-11 09:46:59 +00:00
|
|
|
nsAutoString href;
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::href, href);
|
|
|
|
if (href.IsEmpty()) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2011-05-11 09:46:59 +00:00
|
|
|
}
|
2013-08-24 02:42:39 +00:00
|
|
|
nsCOMPtr<nsIURI> uri = Link::GetURI();
|
|
|
|
return uri.forget();
|
2002-04-05 11:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-08 12:50:30 +00:00
|
|
|
HTMLLinkElement::GetStyleSheetInfo(nsAString& aTitle,
|
|
|
|
nsAString& aType,
|
|
|
|
nsAString& aMedia,
|
|
|
|
bool* aIsScoped,
|
|
|
|
bool* aIsAlternate)
|
2000-08-22 04:14:53 +00:00
|
|
|
{
|
2001-05-19 02:59:15 +00:00
|
|
|
aTitle.Truncate();
|
|
|
|
aType.Truncate();
|
|
|
|
aMedia.Truncate();
|
2013-01-08 23:25:47 +00:00
|
|
|
*aIsScoped = false;
|
2011-10-17 14:59:28 +00:00
|
|
|
*aIsAlternate = false;
|
2000-08-22 04:14:53 +00:00
|
|
|
|
2002-04-05 11:29:40 +00:00
|
|
|
nsAutoString rel;
|
2006-12-26 17:47:52 +00:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::rel, rel);
|
2014-07-08 02:02:03 +00:00
|
|
|
uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(rel, NodePrincipal());
|
2002-04-05 11:29:40 +00:00
|
|
|
// Is it a stylesheet link?
|
2014-02-27 13:44:52 +00:00
|
|
|
if (!(linkTypes & nsStyleLinkElement::eSTYLESHEET)) {
|
2001-05-19 02:59:15 +00:00
|
|
|
return;
|
2002-04-05 11:29:40 +00:00
|
|
|
}
|
2001-05-19 02:59:15 +00:00
|
|
|
|
2002-04-05 11:29:40 +00:00
|
|
|
nsAutoString title;
|
2006-12-26 17:47:52 +00:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::title, title);
|
2001-05-19 02:59:15 +00:00
|
|
|
title.CompressWhitespace();
|
|
|
|
aTitle.Assign(title);
|
|
|
|
|
2002-04-05 11:29:40 +00:00
|
|
|
// If alternate, does it have title?
|
2014-02-27 13:44:52 +00:00
|
|
|
if (linkTypes & nsStyleLinkElement::eALTERNATE) {
|
2001-05-19 02:59:15 +00:00
|
|
|
if (aTitle.IsEmpty()) { // alternates must have title
|
|
|
|
return;
|
|
|
|
} else {
|
2011-10-17 14:59:28 +00:00
|
|
|
*aIsAlternate = true;
|
2001-05-19 02:59:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::media, aMedia);
|
2012-03-10 05:50:34 +00:00
|
|
|
// The HTML5 spec is formulated in terms of the CSSOM spec, which specifies
|
|
|
|
// that media queries should be ASCII lowercased during serialization.
|
|
|
|
nsContentUtils::ASCIIToLower(aMedia);
|
2001-05-19 02:59:15 +00:00
|
|
|
|
|
|
|
nsAutoString mimeType;
|
|
|
|
nsAutoString notUsed;
|
2006-12-26 17:47:52 +00:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::type, aType);
|
2012-02-27 11:57:48 +00:00
|
|
|
nsContentUtils::SplitMimeType(aType, mimeType, notUsed);
|
2004-06-17 00:13:25 +00:00
|
|
|
if (!mimeType.IsEmpty() && !mimeType.LowerCaseEqualsLiteral("text/css")) {
|
2001-05-19 02:59:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we get here we assume that we're loading a css file, so set the
|
|
|
|
// type to 'text/css'
|
2004-06-17 00:13:25 +00:00
|
|
|
aType.AssignLiteral("text/css");
|
2001-05-19 02:59:15 +00:00
|
|
|
|
|
|
|
return;
|
2000-08-22 04:14:53 +00:00
|
|
|
}
|
2009-12-16 00:04:09 +00:00
|
|
|
|
2012-08-28 17:10:07 +00:00
|
|
|
CORSMode
|
2013-02-08 12:50:30 +00:00
|
|
|
HTMLLinkElement::GetCORSMode() const
|
2012-08-28 17:10:07 +00:00
|
|
|
{
|
|
|
|
return AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin));
|
|
|
|
}
|
|
|
|
|
2014-04-03 04:18:36 +00:00
|
|
|
EventStates
|
2013-02-08 12:50:30 +00:00
|
|
|
HTMLLinkElement::IntrinsicState() const
|
2009-12-16 00:04:09 +00:00
|
|
|
{
|
|
|
|
return Link::LinkState() | nsGenericHTMLElement::IntrinsicState();
|
|
|
|
}
|
2012-02-20 03:51:48 +00:00
|
|
|
|
|
|
|
size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
HTMLLinkElement::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-02-20 03:51:48 +00:00
|
|
|
{
|
|
|
|
return nsGenericHTMLElement::SizeOfExcludingThis(aMallocSizeOf) +
|
|
|
|
Link::SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
2013-02-08 12:50:30 +00:00
|
|
|
JSObject*
|
2014-04-08 22:27:17 +00:00
|
|
|
HTMLLinkElement::WrapNode(JSContext* aCx)
|
2013-02-08 12:50:30 +00:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 22:27:17 +00:00
|
|
|
return HTMLLinkElementBinding::Wrap(aCx, this);
|
2013-02-08 12:50:30 +00:00
|
|
|
}
|
|
|
|
|
2014-05-21 17:08:12 +00:00
|
|
|
already_AddRefed<nsIDocument>
|
|
|
|
HTMLLinkElement::GetImport()
|
|
|
|
{
|
2014-10-01 12:13:53 +00:00
|
|
|
return mImportLoader ? nsRefPtr<nsIDocument>(mImportLoader->GetImport()).forget() : nullptr;
|
2014-05-21 17:08:12 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 12:50:30 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|