2015-05-03 12:32:37 -07: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: */
|
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/. */
|
2013-02-08 04:50:30 -08:00
|
|
|
|
|
|
|
#include "mozilla/dom/HTMLLinkElement.h"
|
|
|
|
|
2014-03-16 23:56:54 -07:00
|
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
2013-07-10 02:56:47 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-03-17 21:48:21 -07:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-04-02 21:18:36 -07:00
|
|
|
#include "mozilla/EventStates.h"
|
2013-07-10 02:56:47 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2014-05-21 10:08:12 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2014-04-02 21:18:36 -07:00
|
|
|
#include "mozilla/dom/HTMLLinkElementBinding.h"
|
2013-07-10 02:56:47 -07:00
|
|
|
#include "nsContentUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsGenericHTMLElement.h"
|
|
|
|
#include "nsGkAtoms.h"
|
2014-03-11 05:04:26 -07:00
|
|
|
#include "nsDOMTokenList.h"
|
2013-07-10 02:56:47 -07:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMEvent.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMStyleSheet.h"
|
2014-05-21 10:08:12 -07:00
|
|
|
#include "nsINode.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIStyleSheet.h"
|
|
|
|
#include "nsIStyleSheetLinkingElement.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
2013-07-10 02:56:47 -07:00
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Link)
|
|
|
|
|
2013-02-08 04:50:30 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-06-19 19:01:40 -07:00
|
|
|
HTMLLinkElement::HTMLLinkElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2013-07-10 02:56:47 -07:00
|
|
|
: nsGenericHTMLElement(aNodeInfo)
|
2015-01-06 21:39:46 -08:00
|
|
|
, Link(this)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-08 04:50:30 -08:00
|
|
|
HTMLLinkElement::~HTMLLinkElement()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-08-01 18:29:05 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLLinkElement)
|
|
|
|
|
2013-02-08 04:50:30 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLLinkElement,
|
2012-10-07 19:39:09 -07:00
|
|
|
nsGenericHTMLElement)
|
|
|
|
tmp->nsStyleLinkElement::Traverse(cb);
|
2014-10-23 08:32:35 -07:00
|
|
|
tmp->Link::Traverse(cb);
|
2014-03-11 05:04:26 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRelList)
|
2014-05-21 10:08:12 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mImportLoader)
|
2012-10-07 19:39:09 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2013-08-01 18:29:05 -07:00
|
|
|
|
2013-02-08 04:50:30 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLLinkElement,
|
2012-10-07 19:39:09 -07:00
|
|
|
nsGenericHTMLElement)
|
|
|
|
tmp->nsStyleLinkElement::Unlink();
|
2014-10-23 08:32:35 -07:00
|
|
|
tmp->Link::Unlink();
|
2014-03-11 05:04:26 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRelList)
|
2014-05-21 10:08:12 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mImportLoader)
|
2012-10-07 19:39:09 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-08 04:50:30 -08:00
|
|
|
NS_IMPL_ADDREF_INHERITED(HTMLLinkElement, Element)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(HTMLLinkElement, Element)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-12 05:08:43 -08:00
|
|
|
|
2013-02-08 04:50:30 -08:00
|
|
|
// QueryInterface implementation for HTMLLinkElement
|
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(HTMLLinkElement)
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_INTERFACE_TABLE_INHERITED(HTMLLinkElement,
|
|
|
|
nsIDOMHTMLLinkElement,
|
|
|
|
nsIStyleSheetLinkingElement,
|
|
|
|
Link)
|
2013-08-07 13:23:08 -07:00
|
|
|
NS_INTERFACE_TABLE_TAIL_INHERITING(nsGenericHTMLElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2013-02-08 04:50:30 -08:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLLinkElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-08 04:50:30 -08:00
|
|
|
bool
|
2013-03-17 07:42:59 -07:00
|
|
|
HTMLLinkElement::Disabled()
|
2013-02-08 04:50:30 -08:00
|
|
|
{
|
2014-06-20 03:32:49 -07:00
|
|
|
CSSStyleSheet* ss = GetSheet();
|
2013-03-17 07:42:59 -07:00
|
|
|
return ss && ss->Disabled();
|
2013-02-08 04:50:30 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-03-17 07:42:59 -07:00
|
|
|
HTMLLinkElement::GetMozDisabled(bool* aDisabled)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-03-17 07:42:59 -07:00
|
|
|
*aDisabled = Disabled();
|
|
|
|
return NS_OK;
|
2013-02-08 04:50:30 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-08 04:50:30 -08:00
|
|
|
void
|
2013-03-17 07:42:59 -07:00
|
|
|
HTMLLinkElement::SetDisabled(bool aDisabled)
|
2013-02-08 04:50:30 -08:00
|
|
|
{
|
2014-06-20 03:32:49 -07:00
|
|
|
CSSStyleSheet* ss = GetSheet();
|
2013-03-17 07:42:59 -07:00
|
|
|
if (ss) {
|
|
|
|
ss->SetDisabled(aDisabled);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-08 04:50:30 -08:00
|
|
|
NS_IMETHODIMP
|
2013-03-17 07:42:59 -07:00
|
|
|
HTMLLinkElement::SetMozDisabled(bool aDisabled)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-03-17 07:42:59 -07:00
|
|
|
SetDisabled(aDisabled);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-08 04:50:30 -08: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)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-04 16:49:57 -07:00
|
|
|
void
|
2015-02-12 17:27:39 -08:00
|
|
|
HTMLLinkElement::GetItemValueText(DOMString& aValue)
|
2012-06-04 16:49:57 -07:00
|
|
|
{
|
|
|
|
GetHref(aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-08 04:50:30 -08:00
|
|
|
HTMLLinkElement::SetItemValueText(const nsAString& aValue)
|
2012-06-04 16:49:57 -07:00
|
|
|
{
|
|
|
|
SetHref(aValue);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2013-02-08 04:50:30 -08:00
|
|
|
HTMLLinkElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-12-07 06:35:14 -08:00
|
|
|
Link::ResetLinkState(false, Link::ElementHasHref());
|
2009-11-23 10:48:52 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = nsGenericHTMLElement::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-12-02 02:26:12 -08:00
|
|
|
|
|
|
|
// Link must be inert in ShadowRoot.
|
|
|
|
if (aDocument && !GetContainingShadow()) {
|
2011-11-13 19:24:41 -08:00
|
|
|
aDocument->RegisterPendingLinkUpdate(this);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2015-02-20 14:01:36 -08:00
|
|
|
if (IsInComposedDoc()) {
|
|
|
|
UpdatePreconnect();
|
|
|
|
}
|
|
|
|
|
2013-02-08 04:50:30 -08:00
|
|
|
void (HTMLLinkElement::*update)() = &HTMLLinkElement::UpdateStyleSheetInternal;
|
2010-04-20 16:21:35 -07:00
|
|
|
nsContentUtils::AddScriptRunner(NS_NewRunnableMethod(this, update));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-05-21 10:08:12 -07:00
|
|
|
void (HTMLLinkElement::*updateImport)() = &HTMLLinkElement::UpdateImport;
|
|
|
|
nsContentUtils::AddScriptRunner(NS_NewRunnableMethod(this, updateImport));
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
CreateAndDispatchEvent(aDocument, NS_LITERAL_STRING("DOMLinkAdded"));
|
|
|
|
|
2009-11-23 10:48:52 -08:00
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-08-07 22:26:32 -07:00
|
|
|
void
|
2013-02-08 04:50:30 -08:00
|
|
|
HTMLLinkElement::LinkAdded()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-18 03:53:36 -07:00
|
|
|
CreateAndDispatchEvent(OwnerDoc(), NS_LITERAL_STRING("DOMLinkAdded"));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-08-07 22:26:32 -07:00
|
|
|
void
|
2013-02-08 04:50:30 -08:00
|
|
|
HTMLLinkElement::LinkRemoved()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-18 03:53:36 -07:00
|
|
|
CreateAndDispatchEvent(OwnerDoc(), NS_LITERAL_STRING("DOMLinkRemoved"));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-08 04:50:30 -08:00
|
|
|
HTMLLinkElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-11-23 10:48:52 -08: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 06:35:14 -08:00
|
|
|
Link::ResetLinkState(false, Link::ElementHasHref());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2015-05-05 17:55:18 -07:00
|
|
|
// If this is reinserted back into the document it will not be
|
|
|
|
// from the parser.
|
2014-10-02 12:07:24 -07:00
|
|
|
nsCOMPtr<nsIDocument> oldDoc = GetUncomposedDoc();
|
2013-12-02 02:26:12 -08:00
|
|
|
|
|
|
|
// Check for a ShadowRoot because link elements are inert in a
|
|
|
|
// ShadowRoot.
|
|
|
|
ShadowRoot* oldShadowRoot = GetBindingParent() ?
|
|
|
|
GetBindingParent()->GetShadowRoot() : nullptr;
|
|
|
|
|
2014-10-02 12:07:24 -07:00
|
|
|
OwnerDoc()->UnregisterPendingLinkUpdate(this);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
CreateAndDispatchEvent(oldDoc, NS_LITERAL_STRING("DOMLinkRemoved"));
|
|
|
|
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
|
2013-12-02 02:26:12 -08:00
|
|
|
|
|
|
|
UpdateStyleSheetInternal(oldDoc, oldShadowRoot);
|
2014-05-21 10:08:12 -07:00
|
|
|
UpdateImport();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-28 10:10:07 -07:00
|
|
|
bool
|
2013-02-08 04:50:30 -08:00
|
|
|
HTMLLinkElement::ParseAttribute(int32_t aNamespaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
2012-08-28 10:10:07 -07:00
|
|
|
{
|
2014-04-17 04:50:54 -07:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::crossorigin) {
|
|
|
|
ParseCORSValue(aValue, aResult);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aAttribute == nsGkAtoms::sizes) {
|
|
|
|
aResult.ParseAtomArray(aValue);
|
|
|
|
return true;
|
|
|
|
}
|
2015-08-12 20:19:11 -07:00
|
|
|
|
|
|
|
if (aAttribute == nsGkAtoms::integrity) {
|
|
|
|
aResult.ParseStringOrAtom(aValue);
|
|
|
|
return true;
|
|
|
|
}
|
2012-08-28 10:10:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
|
|
|
aResult);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
2013-02-08 04:50:30 -08:00
|
|
|
HTMLLinkElement::CreateAndDispatchEvent(nsIDocument* aDoc,
|
|
|
|
const nsAString& aEventName)
|
2007-03-22 10:30:00 -07: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 01:02:09 -08:00
|
|
|
// page really does want to specify that its author is a stylesheet. Since
|
2007-03-22 10:30:00 -07: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.
|
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
2012-07-30 07:20:58 -07:00
|
|
|
{&nsGkAtoms::_empty, &nsGkAtoms::stylesheet, nullptr};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!nsContentUtils::HasNonEmptyAttr(this, kNameSpaceID_None,
|
|
|
|
nsGkAtoms::rev) &&
|
|
|
|
FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::rel,
|
|
|
|
strings, eIgnoreCase) != ATTR_VALUE_NO_MATCH)
|
|
|
|
return;
|
|
|
|
|
2014-03-16 23:56:54 -07:00
|
|
|
nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
|
|
|
|
new AsyncEventDispatcher(this, aEventName, true, true);
|
2011-11-15 23:50:19 -08:00
|
|
|
// Always run async in order to avoid running script when the content
|
|
|
|
// sink isn't expecting it.
|
2014-03-16 23:56:54 -07:00
|
|
|
asyncDispatcher->PostDOMEvent();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-05-21 10:08:12 -07:00
|
|
|
void
|
|
|
|
HTMLLinkElement::UpdateImport()
|
|
|
|
{
|
|
|
|
// 1. link node should be attached to the document.
|
2014-10-02 12:07:24 -07:00
|
|
|
nsCOMPtr<nsIDocument> doc = GetUncomposedDoc();
|
2014-05-21 10:08:12 -07: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-07 19:02:03 -07:00
|
|
|
uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(rel, NodePrincipal());
|
2014-05-21 10:08:12 -07:00
|
|
|
if (!(linkTypes & eHTMLIMPORT)) {
|
|
|
|
mImportLoader = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri = GetHrefURI();
|
|
|
|
if (!uri) {
|
|
|
|
mImportLoader = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-23 04:06:28 -08:00
|
|
|
if (!nsStyleLinkElement::IsImportEnabled()) {
|
2014-06-02 04:28:55 -07:00
|
|
|
// For now imports are hidden behind a pref...
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-21 10:08:12 -07: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-20 14:01:36 -08:00
|
|
|
void
|
|
|
|
HTMLLinkElement::UpdatePreconnect()
|
|
|
|
{
|
|
|
|
// rel type should be preconnect
|
|
|
|
nsAutoString rel;
|
|
|
|
if (!GetAttr(kNameSpaceID_None, nsGkAtoms::rel, rel)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(rel, NodePrincipal());
|
|
|
|
if (!(linkTypes & ePRECONNECT)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-05 17:55:18 -07:00
|
|
|
nsIDocument *owner = OwnerDoc();
|
|
|
|
if (owner) {
|
2015-02-20 14:01:36 -08:00
|
|
|
nsCOMPtr<nsIURI> uri = GetHrefURI();
|
|
|
|
if (uri) {
|
2015-06-19 14:11:42 -07:00
|
|
|
owner->MaybePreconnect(uri, GetCORSMode());
|
2015-02-20 14:01:36 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2013-02-08 04:50:30 -08:00
|
|
|
HTMLLinkElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|
|
|
nsIAtom* aPrefix, const nsAString& aValue,
|
|
|
|
bool aNotify)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-02-24 08:37:38 -08: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.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aName == nsGkAtoms::href && kNameSpaceID_None == aNameSpaceID) {
|
2012-12-07 06:35:14 -08:00
|
|
|
Link::ResetLinkState(!!aNotify, true);
|
2014-10-16 15:00:12 -07:00
|
|
|
if (IsInUncomposedDoc()) {
|
|
|
|
CreateAndDispatchEvent(OwnerDoc(), NS_LITERAL_STRING("DOMLinkChanged"));
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-05-31 21:30:42 -07: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-28 23:19:26 -07:00
|
|
|
bool dropSheet = false;
|
2014-05-21 10:08:12 -07:00
|
|
|
if (aName == nsGkAtoms::rel) {
|
2014-07-07 19:02:03 -07:00
|
|
|
uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(aValue,
|
|
|
|
NodePrincipal());
|
2014-05-21 10:08:12 -07:00
|
|
|
if (GetSheet()) {
|
|
|
|
dropSheet = !(linkTypes & nsStyleLinkElement::eSTYLESHEET);
|
|
|
|
} else if (linkTypes & eHTMLIMPORT) {
|
|
|
|
UpdateImport();
|
2015-02-20 14:01:36 -08:00
|
|
|
} else if ((linkTypes & ePRECONNECT) && IsInComposedDoc()) {
|
|
|
|
UpdatePreconnect();
|
2014-05-21 10:08:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aName == nsGkAtoms::href) {
|
|
|
|
UpdateImport();
|
2015-02-20 14:01:36 -08:00
|
|
|
if (IsInComposedDoc()) {
|
|
|
|
UpdatePreconnect();
|
|
|
|
}
|
2007-04-25 11:48:18 -07:00
|
|
|
}
|
|
|
|
|
2013-12-02 02:26:12 -08:00
|
|
|
UpdateStyleSheetInternal(nullptr, nullptr,
|
2007-04-25 11:48:18 -07:00
|
|
|
dropSheet ||
|
2012-05-31 21:30:42 -07:00
|
|
|
(aName == nsGkAtoms::title ||
|
|
|
|
aName == nsGkAtoms::media ||
|
|
|
|
aName == nsGkAtoms::type));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-02-08 04:50:30 -08:00
|
|
|
HTMLLinkElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
|
|
|
|
bool aNotify)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv = nsGenericHTMLElement::UnsetAttr(aNameSpaceID, aAttribute,
|
|
|
|
aNotify);
|
2012-05-31 21:30:42 -07:00
|
|
|
// Since removing href or rel makes us no longer link to a
|
|
|
|
// stylesheet, force updates for those too.
|
2014-05-21 10:08:12 -07: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();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-03 12:55:35 -08: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 06:35:14 -08:00
|
|
|
Link::ResetLinkState(!!aNotify, false);
|
2014-10-16 15:00:12 -07:00
|
|
|
if (IsInUncomposedDoc()) {
|
|
|
|
CreateAndDispatchEvent(OwnerDoc(), NS_LITERAL_STRING("DOMLinkChanged"));
|
|
|
|
}
|
2010-03-03 12:55:35 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-04-23 00:31:21 -07:00
|
|
|
nsresult
|
2014-03-17 21:48:19 -07:00
|
|
|
HTMLLinkElement::PreHandleEvent(EventChainPreVisitor& aVisitor)
|
2007-04-23 00:31:21 -07:00
|
|
|
{
|
|
|
|
return PreHandleEventForAnchors(aVisitor);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2014-03-17 21:48:20 -07:00
|
|
|
HTMLLinkElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return PostHandleEventForAnchors(aVisitor);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-02-08 04:50:30 -08:00
|
|
|
HTMLLinkElement::IsLink(nsIURI** aURI) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return IsHTMLLink(aURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-08 04:50:30 -08:00
|
|
|
HTMLLinkElement::GetLinkTarget(nsAString& aTarget)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-03-26 06:19:33 -07:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::target, aTarget);
|
|
|
|
if (aTarget.IsEmpty()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
GetBaseTarget(aTarget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-11 05:04:26 -07:00
|
|
|
nsDOMTokenList*
|
|
|
|
HTMLLinkElement::RelList()
|
|
|
|
{
|
|
|
|
if (!mRelList) {
|
|
|
|
mRelList = new nsDOMTokenList(this, nsGkAtoms::rel);
|
|
|
|
}
|
|
|
|
return mRelList;
|
|
|
|
}
|
|
|
|
|
2009-07-13 04:48:06 -07:00
|
|
|
already_AddRefed<nsIURI>
|
2013-02-08 04:50:30 -08:00
|
|
|
HTMLLinkElement::GetHrefURI() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-07-13 04:48:06 -07:00
|
|
|
return GetHrefURIForAnchors();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-07-28 09:07:31 -07:00
|
|
|
already_AddRefed<nsIURI>
|
2013-02-08 04:50:30 -08:00
|
|
|
HTMLLinkElement::GetStyleSheetURL(bool* aIsInline)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsInline = false;
|
2011-05-11 02:46:59 -07:00
|
|
|
nsAutoString href;
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::href, href);
|
|
|
|
if (href.IsEmpty()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-05-11 02:46:59 -07:00
|
|
|
}
|
2013-08-23 19:42:39 -07:00
|
|
|
nsCOMPtr<nsIURI> uri = Link::GetURI();
|
|
|
|
return uri.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-08 04:50:30 -08:00
|
|
|
HTMLLinkElement::GetStyleSheetInfo(nsAString& aTitle,
|
|
|
|
nsAString& aType,
|
|
|
|
nsAString& aMedia,
|
|
|
|
bool* aIsScoped,
|
|
|
|
bool* aIsAlternate)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aTitle.Truncate();
|
|
|
|
aType.Truncate();
|
|
|
|
aMedia.Truncate();
|
2013-01-08 15:25:47 -08:00
|
|
|
*aIsScoped = false;
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsAlternate = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsAutoString rel;
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::rel, rel);
|
2014-07-07 19:02:03 -07:00
|
|
|
uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(rel, NodePrincipal());
|
2007-03-22 10:30:00 -07:00
|
|
|
// Is it a stylesheet link?
|
2014-02-27 05:44:52 -08:00
|
|
|
if (!(linkTypes & nsStyleLinkElement::eSTYLESHEET)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString title;
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::title, title);
|
|
|
|
title.CompressWhitespace();
|
|
|
|
aTitle.Assign(title);
|
|
|
|
|
|
|
|
// If alternate, does it have title?
|
2014-02-27 05:44:52 -08:00
|
|
|
if (linkTypes & nsStyleLinkElement::eALTERNATE) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aTitle.IsEmpty()) { // alternates must have title
|
|
|
|
return;
|
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsAlternate = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::media, aMedia);
|
2012-03-09 21:50:34 -08: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);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsAutoString mimeType;
|
|
|
|
nsAutoString notUsed;
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::type, aType);
|
2012-02-27 03:57:48 -08:00
|
|
|
nsContentUtils::SplitMimeType(aType, mimeType, notUsed);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!mimeType.IsEmpty() && !mimeType.LowerCaseEqualsLiteral("text/css")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we get here we assume that we're loading a css file, so set the
|
|
|
|
// type to 'text/css'
|
|
|
|
aType.AssignLiteral("text/css");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2009-12-15 16:04:09 -08:00
|
|
|
|
2012-08-28 10:10:07 -07:00
|
|
|
CORSMode
|
2013-02-08 04:50:30 -08:00
|
|
|
HTMLLinkElement::GetCORSMode() const
|
2012-08-28 10:10:07 -07:00
|
|
|
{
|
|
|
|
return AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin));
|
|
|
|
}
|
|
|
|
|
2014-04-02 21:18:36 -07:00
|
|
|
EventStates
|
2013-02-08 04:50:30 -08:00
|
|
|
HTMLLinkElement::IntrinsicState() const
|
2009-12-15 16:04:09 -08:00
|
|
|
{
|
|
|
|
return Link::LinkState() | nsGenericHTMLElement::IntrinsicState();
|
|
|
|
}
|
2012-02-19 19:51:48 -08:00
|
|
|
|
|
|
|
size_t
|
2013-06-23 05:03:39 -07:00
|
|
|
HTMLLinkElement::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-02-19 19:51:48 -08:00
|
|
|
{
|
|
|
|
return nsGenericHTMLElement::SizeOfExcludingThis(aMallocSizeOf) +
|
|
|
|
Link::SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
2013-02-08 04:50:30 -08:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
HTMLLinkElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-02-08 04:50:30 -08:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
return HTMLLinkElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-02-08 04:50:30 -08:00
|
|
|
}
|
|
|
|
|
2014-05-21 10:08:12 -07:00
|
|
|
already_AddRefed<nsIDocument>
|
|
|
|
HTMLLinkElement::GetImport()
|
|
|
|
{
|
2014-10-01 05:13:53 -07:00
|
|
|
return mImportLoader ? nsRefPtr<nsIDocument>(mImportLoader->GetImport()).forget() : nullptr;
|
2014-05-21 10:08:12 -07:00
|
|
|
}
|
|
|
|
|
2013-02-08 04:50:30 -08:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|