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