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"
|
2019-03-29 18:11:04 +03:00
|
|
|
#include "mozilla/dom/DocumentInlines.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"
|
2016-08-19 03:03:49 +03:00
|
|
|
#include "nsIContentInlines.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2014-05-21 21:08:12 +04:00
|
|
|
#include "nsINode.h"
|
1999-02-23 22:18:12 +03:00
|
|
|
#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"
|
2016-05-05 06:41:24 +03:00
|
|
|
#include "nsStyleLinkElement.h"
|
2013-07-10 13:56:47 +04:00
|
|
|
#include "nsUnicharUtils.h"
|
2018-03-28 02:44:49 +03:00
|
|
|
#include "nsWindowSizes.h"
|
2018-04-20 12:47:00 +03:00
|
|
|
#include "nsIContentPolicy.h"
|
|
|
|
#include "nsMimeTypes.h"
|
|
|
|
#include "imgLoader.h"
|
|
|
|
#include "MediaContainerType.h"
|
|
|
|
#include "DecoderDoctorDiagnostics.h"
|
|
|
|
#include "DecoderTraits.h"
|
|
|
|
#include "MediaList.h"
|
|
|
|
#include "nsAttrValueInlines.h"
|
1998-09-01 05:27:08 +04:00
|
|
|
|
2015-12-01 20:22:20 +03:00
|
|
|
#define LINK_ELEMENT_FLAG_BIT(n_) \
|
|
|
|
NODE_FLAG_BIT(ELEMENT_TYPE_SPECIFIC_BITS_OFFSET + (n_))
|
|
|
|
|
|
|
|
// Link element specific bits
|
|
|
|
enum {
|
|
|
|
// Indicates that a DNS Prefetch has been requested from this Link element.
|
|
|
|
HTML_LINK_DNS_PREFETCH_REQUESTED = LINK_ELEMENT_FLAG_BIT(0),
|
|
|
|
|
|
|
|
// Indicates that a DNS Prefetch was added to the deferral queue
|
|
|
|
HTML_LINK_DNS_PREFETCH_DEFERRED = LINK_ELEMENT_FLAG_BIT(1)
|
|
|
|
};
|
|
|
|
|
|
|
|
#undef LINK_ELEMENT_FLAG_BIT
|
|
|
|
|
|
|
|
ASSERT_NODE_FLAGS_SPACE(ELEMENT_TYPE_SPECIFIC_BITS_OFFSET + 2);
|
|
|
|
|
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
|
|
|
|
2018-09-21 23:45:49 +03:00
|
|
|
HTMLLinkElement::HTMLLinkElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
|
|
|
: nsGenericHTMLElement(std::move(aNodeInfo)), 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-03-11 16:04:26 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRelList)
|
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-03-11 16:04:26 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRelList)
|
2012-10-08 06:39:09 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
1998-09-01 05:27:08 +04:00
|
|
|
|
2017-09-01 02:29:22 +03:00
|
|
|
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(HTMLLinkElement,
|
|
|
|
nsGenericHTMLElement,
|
|
|
|
nsIStyleSheetLinkingElement, Link)
|
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
|
|
|
|
2019-04-19 16:31:05 +03:00
|
|
|
bool HTMLLinkElement::Disabled() const {
|
|
|
|
if (StaticPrefs::dom_link_disabled_attribute_enabled()) {
|
|
|
|
return GetBoolAttr(nsGkAtoms::disabled);
|
|
|
|
}
|
2016-10-14 14:25:38 +03:00
|
|
|
StyleSheet* 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
|
|
|
|
2019-04-19 16:31:05 +03:00
|
|
|
void HTMLLinkElement::SetDisabled(bool aDisabled, ErrorResult& aRv) {
|
|
|
|
if (StaticPrefs::dom_link_disabled_attribute_enabled()) {
|
|
|
|
return SetHTMLBoolAttr(nsGkAtoms::disabled, aDisabled, aRv);
|
|
|
|
}
|
2016-10-14 14:25:38 +03:00
|
|
|
if (StyleSheet* ss = GetSheet()) {
|
2013-03-17 18:42:59 +04:00
|
|
|
ss->SetDisabled(aDisabled);
|
1999-02-23 22:18:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-01 20:22:20 +03:00
|
|
|
void HTMLLinkElement::OnDNSPrefetchRequested() {
|
|
|
|
UnsetFlags(HTML_LINK_DNS_PREFETCH_DEFERRED);
|
|
|
|
SetFlags(HTML_LINK_DNS_PREFETCH_REQUESTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLLinkElement::OnDNSPrefetchDeferred() {
|
|
|
|
UnsetFlags(HTML_LINK_DNS_PREFETCH_REQUESTED);
|
|
|
|
SetFlags(HTML_LINK_DNS_PREFETCH_DEFERRED);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HTMLLinkElement::HasDeferredDNSPrefetchRequest() {
|
|
|
|
return HasFlag(HTML_LINK_DNS_PREFETCH_DEFERRED);
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsresult HTMLLinkElement::BindToTree(Document* aDocument, nsIContent* aParent,
|
2018-07-31 21:18:38 +03:00
|
|
|
nsIContent* aBindingParent) {
|
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);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-12-02 14:26:12 +04:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
if (Document* doc = GetComposedDoc()) {
|
2019-04-10 21:44:42 +03:00
|
|
|
if (!doc->NodePrincipal()->IsSystemPrincipal()) {
|
2019-03-29 19:01:37 +03:00
|
|
|
doc->RegisterPendingLinkUpdate(this);
|
|
|
|
}
|
2017-07-10 16:05:56 +03:00
|
|
|
TryDNSPrefetchOrPreconnectOrPrefetchOrPreloadOrPrerender();
|
2015-02-21 01:01:36 +03:00
|
|
|
}
|
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
void (HTMLLinkElement::*update)() =
|
|
|
|
&HTMLLinkElement::UpdateStyleSheetInternal;
|
2017-06-12 22:34:10 +03:00
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
NewRunnableMethod("dom::HTMLLinkElement::BindToTree", this, update));
|
2005-04-06 03:54:35 +04:00
|
|
|
|
2019-04-10 21:44:42 +03:00
|
|
|
if (aDocument && AttrValueIs(kNameSpaceID_None, nsGkAtoms::rel,
|
|
|
|
nsGkAtoms::localization, eIgnoreCase)) {
|
2018-09-07 04:28:40 +03:00
|
|
|
aDocument->LocalizationLinkAdded(this);
|
|
|
|
}
|
|
|
|
|
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-02-08 16:50:30 +04:00
|
|
|
void HTMLLinkElement::LinkAdded() {
|
2011-10-18 14:53:36 +04:00
|
|
|
CreateAndDispatchEvent(OwnerDoc(), NS_LITERAL_STRING("DOMLinkAdded"));
|
2005-06-16 03:52:46 +04:00
|
|
|
}
|
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
void HTMLLinkElement::LinkRemoved() {
|
2011-10-18 14:53:36 +04:00
|
|
|
CreateAndDispatchEvent(OwnerDoc(), NS_LITERAL_STRING("DOMLinkRemoved"));
|
2005-06-16 03:52:46 +04:00
|
|
|
}
|
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
void HTMLLinkElement::UnbindFromTree(bool aDeep, bool aNullParent) {
|
2015-12-01 20:22:20 +03:00
|
|
|
// Cancel any DNS prefetches
|
|
|
|
// Note: Must come before ResetLinkState. If called after, it will recreate
|
|
|
|
// mCachedURI based on data that is invalid - due to a call to GetHostname.
|
|
|
|
CancelDNSPrefetch(HTML_LINK_DNS_PREFETCH_DEFERRED,
|
|
|
|
HTML_LINK_DNS_PREFETCH_REQUESTED);
|
2017-07-10 16:05:56 +03:00
|
|
|
CancelPrefetchOrPreload();
|
2015-12-01 20:22:20 +03:00
|
|
|
|
2018-12-13 18:16:52 +03:00
|
|
|
// Without removing the link state we risk a dangling pointer
|
|
|
|
// in the mStyledLinks hashtable
|
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.
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* oldDoc = GetUncomposedDoc();
|
2018-06-22 02:12:42 +03:00
|
|
|
ShadowRoot* oldShadowRoot = GetContainingShadow();
|
2013-12-02 14:26:12 +04:00
|
|
|
|
2019-01-30 22:58:41 +03:00
|
|
|
// We want to update the localization but only if the
|
|
|
|
// link is removed from a DOM change, and not
|
|
|
|
// because the document is going away.
|
|
|
|
bool ignore;
|
|
|
|
if (oldDoc && oldDoc->GetScriptHandlingObject(ignore) &&
|
|
|
|
this->AttrValueIs(kNameSpaceID_None, nsGkAtoms::rel,
|
|
|
|
nsGkAtoms::localization, eIgnoreCase)) {
|
2018-09-07 04:28:40 +03:00
|
|
|
oldDoc->LocalizationLinkRemoved(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
|
|
|
|
2018-04-24 13:50:35 +03:00
|
|
|
Unused << UpdateStyleSheetInternal(oldDoc, oldShadowRoot);
|
2004-01-10 02:54:21 +03:00
|
|
|
}
|
2005-04-06 03:54:35 +04:00
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
bool HTMLLinkElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2013-02-08 16:50:30 +04:00
|
|
|
nsAttrValue& aResult) {
|
2014-04-17 15:50:54 +04:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::crossorigin) {
|
|
|
|
ParseCORSValue(aValue, aResult);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-10 16:05:56 +03:00
|
|
|
if (aAttribute == nsGkAtoms::as) {
|
|
|
|
ParseAsValue(aValue, aResult);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-04-17 15:50:54 +04:00
|
|
|
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,
|
2017-11-02 06:35:52 +03:00
|
|
|
aMaybeScriptedPrincipal, aResult);
|
2012-08-28 21:10:07 +04:00
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
void HTMLLinkElement::CreateAndDispatchEvent(Document* aDoc,
|
2013-02-08 16:50:30 +04:00
|
|
|
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.
|
2017-12-07 21:13:50 +03:00
|
|
|
static Element::AttrValuesArray strings[] = {nsGkAtoms::_empty,
|
2018-04-03 06:21:06 +03:00
|
|
|
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, strings,
|
2006-04-24 09:40:11 +04:00
|
|
|
eIgnoreCase) != ATTR_VALUE_NO_MATCH)
|
2004-01-10 02:54:21 +03:00
|
|
|
return;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AsyncEventDispatcher> asyncDispatcher = new AsyncEventDispatcher(
|
2018-06-25 19:23:50 +03:00
|
|
|
this, aEventName, CanBubble::eYes, ChromeOnlyDispatch::eYes);
|
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
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsresult HTMLLinkElement::BeforeSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
2017-03-16 21:50:41 +03:00
|
|
|
const nsAttrValueOrString* aValue,
|
|
|
|
bool aNotify) {
|
2015-12-01 20:22:20 +03:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
(aName == nsGkAtoms::href || aName == nsGkAtoms::rel)) {
|
|
|
|
CancelDNSPrefetch(HTML_LINK_DNS_PREFETCH_DEFERRED,
|
|
|
|
HTML_LINK_DNS_PREFETCH_REQUESTED);
|
2017-07-10 16:05:56 +03:00
|
|
|
CancelPrefetchOrPreload();
|
2015-12-01 20:22:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsGenericHTMLElement::BeforeSetAttr(aNameSpaceID, aName, aValue,
|
|
|
|
aNotify);
|
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsresult HTMLLinkElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
2017-05-19 00:09:01 +03:00
|
|
|
const nsAttrValue* aValue,
|
2017-10-10 00:33:38 +03:00
|
|
|
const nsAttrValue* aOldValue,
|
|
|
|
nsIPrincipal* aSubjectPrincipal,
|
|
|
|
bool aNotify) {
|
2015-09-23 04:19:49 +03:00
|
|
|
// It's safe to call ResetLinkState here because our new attr value has
|
|
|
|
// already been set or unset. ResetLinkState needs 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) {
|
2015-09-23 04:19:49 +03:00
|
|
|
bool hasHref = aValue;
|
|
|
|
Link::ResetLinkState(!!aNotify, hasHref);
|
2014-10-17 02:00:12 +04:00
|
|
|
if (IsInUncomposedDoc()) {
|
|
|
|
CreateAndDispatchEvent(OwnerDoc(), NS_LITERAL_STRING("DOMLinkChanged"));
|
|
|
|
}
|
2004-01-10 02:54:21 +03:00
|
|
|
}
|
|
|
|
|
2017-10-06 05:40:48 +03:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::href) {
|
|
|
|
mTriggeringPrincipal = nsContentUtils::GetAttrTriggeringPrincipal(
|
|
|
|
this, aValue ? aValue->GetStringValue() : EmptyString(),
|
|
|
|
aSubjectPrincipal);
|
|
|
|
}
|
|
|
|
|
2018-09-07 04:28:40 +03:00
|
|
|
// If a link's `rel` attribute was changed from or to `localization`,
|
|
|
|
// update the list of localization links.
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::rel) {
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* doc = GetComposedDoc();
|
2018-09-07 04:28:40 +03:00
|
|
|
if (doc) {
|
|
|
|
if ((aValue && aValue->Equals(nsGkAtoms::localization, eIgnoreCase)) &&
|
|
|
|
(!aOldValue ||
|
|
|
|
!aOldValue->Equals(nsGkAtoms::localization, eIgnoreCase))) {
|
|
|
|
doc->LocalizationLinkAdded(this);
|
|
|
|
} else if ((aOldValue &&
|
|
|
|
aOldValue->Equals(nsGkAtoms::localization, eIgnoreCase)) &&
|
|
|
|
(!aValue ||
|
|
|
|
!aValue->Equals(nsGkAtoms::localization, eIgnoreCase))) {
|
|
|
|
doc->LocalizationLinkRemoved(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the link has `rel=localization` and its `href` attribute is changed,
|
|
|
|
// update the list of localization links.
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::href &&
|
|
|
|
AttrValueIs(kNameSpaceID_None, nsGkAtoms::rel, nsGkAtoms::localization,
|
|
|
|
eIgnoreCase)) {
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* doc = GetComposedDoc();
|
2018-09-07 04:28:40 +03:00
|
|
|
if (doc) {
|
|
|
|
if (aOldValue) {
|
|
|
|
doc->LocalizationLinkRemoved(this);
|
|
|
|
}
|
|
|
|
if (aValue) {
|
|
|
|
doc->LocalizationLinkAdded(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-23 04:19:49 +03:00
|
|
|
if (aValue) {
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
(aName == nsGkAtoms::href || aName == nsGkAtoms::rel ||
|
|
|
|
aName == nsGkAtoms::title || aName == nsGkAtoms::media ||
|
2017-07-10 16:05:56 +03:00
|
|
|
aName == nsGkAtoms::type || aName == nsGkAtoms::as ||
|
2019-04-19 16:31:05 +03:00
|
|
|
aName == nsGkAtoms::crossorigin ||
|
|
|
|
(aName == nsGkAtoms::disabled &&
|
|
|
|
StaticPrefs::dom_link_disabled_attribute_enabled()))) {
|
2015-09-23 04:19:49 +03:00
|
|
|
bool dropSheet = false;
|
|
|
|
if (aName == nsGkAtoms::rel) {
|
|
|
|
nsAutoString value;
|
|
|
|
aValue->ToString(value);
|
2017-06-12 17:36:02 +03:00
|
|
|
uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(value);
|
2015-09-23 04:19:49 +03:00
|
|
|
if (GetSheet()) {
|
|
|
|
dropSheet = !(linkTypes & nsStyleLinkElement::eSTYLESHEET);
|
|
|
|
}
|
2014-05-21 21:08:12 +04:00
|
|
|
}
|
|
|
|
|
2015-12-01 20:22:20 +03:00
|
|
|
if ((aName == nsGkAtoms::rel || aName == nsGkAtoms::href) &&
|
2016-02-26 04:41:00 +03:00
|
|
|
IsInComposedDoc()) {
|
2017-07-10 16:05:56 +03:00
|
|
|
TryDNSPrefetchOrPreconnectOrPrefetchOrPreloadOrPrerender();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((aName == nsGkAtoms::as || aName == nsGkAtoms::type ||
|
|
|
|
aName == nsGkAtoms::crossorigin || aName == nsGkAtoms::media) &&
|
|
|
|
IsInComposedDoc()) {
|
|
|
|
UpdatePreload(aName, aValue, aOldValue);
|
2015-12-01 20:22:20 +03:00
|
|
|
}
|
|
|
|
|
2018-04-24 13:50:35 +03:00
|
|
|
const bool forceUpdate =
|
|
|
|
dropSheet || aName == nsGkAtoms::title || aName == nsGkAtoms::media ||
|
2019-04-19 16:31:05 +03:00
|
|
|
aName == nsGkAtoms::type || aName == nsGkAtoms::disabled;
|
2018-04-24 13:50:35 +03:00
|
|
|
|
|
|
|
Unused << UpdateStyleSheetInternal(
|
|
|
|
nullptr, nullptr, forceUpdate ? ForceUpdate::Yes : ForceUpdate::No);
|
2014-05-21 21:08:12 +04:00
|
|
|
}
|
2015-09-23 04:19:49 +03:00
|
|
|
} else {
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
2019-04-19 16:31:05 +03:00
|
|
|
if (aName == nsGkAtoms::disabled &&
|
|
|
|
StaticPrefs::dom_link_disabled_attribute_enabled()) {
|
|
|
|
mExplicitlyEnabled = true;
|
|
|
|
}
|
|
|
|
// Since removing href or rel makes us no longer link to a stylesheet,
|
|
|
|
// force updates for those too.
|
2015-09-23 04:19:49 +03:00
|
|
|
if (aName == nsGkAtoms::href || aName == nsGkAtoms::rel ||
|
|
|
|
aName == nsGkAtoms::title || aName == nsGkAtoms::media ||
|
2019-04-19 16:31:05 +03:00
|
|
|
aName == nsGkAtoms::type ||
|
|
|
|
(aName == nsGkAtoms::disabled &&
|
|
|
|
StaticPrefs::dom_link_disabled_attribute_enabled())) {
|
2018-04-24 13:50:35 +03:00
|
|
|
Unused << UpdateStyleSheetInternal(nullptr, nullptr, ForceUpdate::Yes);
|
2015-09-23 04:19:49 +03:00
|
|
|
}
|
2017-07-10 16:05:56 +03:00
|
|
|
if ((aName == nsGkAtoms::as || aName == nsGkAtoms::type ||
|
|
|
|
aName == nsGkAtoms::crossorigin || aName == nsGkAtoms::media) &&
|
|
|
|
IsInComposedDoc()) {
|
|
|
|
UpdatePreload(aName, aValue, aOldValue);
|
|
|
|
}
|
2014-10-17 02:00:12 +04:00
|
|
|
}
|
2010-03-03 23:55:35 +03:00
|
|
|
}
|
|
|
|
|
2015-09-23 04:19:49 +03:00
|
|
|
return nsGenericHTMLElement::AfterSetAttr(
|
2017-10-10 00:33:38 +03:00
|
|
|
aNameSpaceID, aName, aValue, aOldValue, aSubjectPrincipal, aNotify);
|
2004-01-10 02:54:21 +03:00
|
|
|
}
|
|
|
|
|
2016-10-21 05:11:07 +03:00
|
|
|
void HTMLLinkElement::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
|
2018-04-05 20:42:41 +03:00
|
|
|
GetEventTargetParentForAnchors(aVisitor);
|
2007-04-23 11:31:21 +04:00
|
|
|
}
|
|
|
|
|
2014-03-18 08:48:20 +04:00
|
|
|
nsresult HTMLLinkElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
|
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
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
bool HTMLLinkElement::IsLink(nsIURI** aURI) const { return IsHTMLLink(aURI); }
|
2007-01-04 13:53:59 +03:00
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
void HTMLLinkElement::GetLinkTarget(nsAString& aTarget) {
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-05 06:41:24 +03:00
|
|
|
static const DOMTokenListSupportedToken sSupportedRelValues[] = {
|
|
|
|
// Keep this in sync with ToLinkMask in nsStyleLinkElement.cpp.
|
2017-10-17 19:38:10 +03:00
|
|
|
// "preload" must come first because it can be disabled.
|
2017-10-11 10:20:00 +03:00
|
|
|
"preload", "prefetch", "dns-prefetch", "stylesheet", "next",
|
|
|
|
"alternate", "preconnect", "icon", "search", nullptr};
|
2017-10-17 19:38:10 +03:00
|
|
|
|
2014-03-11 16:04:26 +04:00
|
|
|
nsDOMTokenList* HTMLLinkElement::RelList() {
|
|
|
|
if (!mRelList) {
|
2017-10-11 10:20:00 +03:00
|
|
|
if (Preferences::GetBool("network.preload")) {
|
|
|
|
mRelList = new nsDOMTokenList(this, nsGkAtoms::rel, sSupportedRelValues);
|
|
|
|
} else {
|
2017-10-17 19:38:10 +03:00
|
|
|
mRelList =
|
|
|
|
new nsDOMTokenList(this, nsGkAtoms::rel, &sSupportedRelValues[1]);
|
2017-10-11 10:20:00 +03:00
|
|
|
}
|
2014-03-11 16:04:26 +04:00
|
|
|
}
|
|
|
|
return mRelList;
|
|
|
|
}
|
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
already_AddRefed<nsIURI> HTMLLinkElement::GetHrefURI() const {
|
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
|
|
|
|
2018-05-06 14:20:03 +03:00
|
|
|
Maybe<nsStyleLinkElement::SheetInfo> HTMLLinkElement::GetStyleSheetInfo() {
|
2002-04-05 15:29:40 +04:00
|
|
|
nsAutoString rel;
|
2006-12-26 20:47:52 +03:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::rel, rel);
|
2017-06-12 17:36:02 +03:00
|
|
|
uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(rel);
|
2014-02-27 17:44:52 +04:00
|
|
|
if (!(linkTypes & nsStyleLinkElement::eSTYLESHEET)) {
|
2018-05-06 14:20:03 +03:00
|
|
|
return Nothing();
|
2002-04-05 15:29:40 +04:00
|
|
|
}
|
2001-05-19 06:59:15 +04:00
|
|
|
|
2018-05-08 07:51:34 +03:00
|
|
|
if (!IsCSSMimeTypeAttribute(*this)) {
|
|
|
|
return Nothing();
|
|
|
|
}
|
|
|
|
|
2019-04-19 16:31:05 +03:00
|
|
|
if (StaticPrefs::dom_link_disabled_attribute_enabled() && Disabled()) {
|
|
|
|
return Nothing();
|
|
|
|
}
|
|
|
|
|
2002-04-05 15:29:40 +04:00
|
|
|
nsAutoString title;
|
2018-05-08 07:51:34 +03:00
|
|
|
nsAutoString media;
|
|
|
|
GetTitleAndMediaForElement(*this, title, media);
|
2001-05-19 06:59:15 +04:00
|
|
|
|
2018-05-06 14:20:03 +03:00
|
|
|
bool alternate = linkTypes & nsStyleLinkElement::eALTERNATE;
|
|
|
|
if (alternate && title.IsEmpty()) {
|
|
|
|
// alternates must have title.
|
|
|
|
return Nothing();
|
2001-05-19 06:59:15 +04:00
|
|
|
}
|
|
|
|
|
2018-05-06 14:20:03 +03:00
|
|
|
nsAutoString href;
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::href, href);
|
|
|
|
if (href.IsEmpty()) {
|
|
|
|
return Nothing();
|
|
|
|
}
|
2009-12-16 03:04:09 +03:00
|
|
|
|
2018-05-06 14:20:03 +03:00
|
|
|
nsCOMPtr<nsIURI> uri = Link::GetURI();
|
|
|
|
nsCOMPtr<nsIPrincipal> prin = mTriggeringPrincipal;
|
2018-05-08 07:11:56 +03:00
|
|
|
return Some(SheetInfo{
|
2018-05-06 14:20:03 +03:00
|
|
|
*OwnerDoc(),
|
|
|
|
this,
|
|
|
|
uri.forget(),
|
|
|
|
prin.forget(),
|
|
|
|
GetReferrerPolicyAsEnum(),
|
|
|
|
GetCORSMode(),
|
|
|
|
title,
|
|
|
|
media,
|
2018-05-06 16:06:52 +03:00
|
|
|
alternate ? HasAlternateRel::Yes : HasAlternateRel::No,
|
2018-05-06 14:20:03 +03:00
|
|
|
IsInline::No,
|
2019-04-19 16:31:05 +03:00
|
|
|
mExplicitlyEnabled ? IsExplicitlyEnabled::Yes : IsExplicitlyEnabled::No,
|
2018-05-06 14:20:03 +03:00
|
|
|
});
|
2012-08-28 21:10:07 +04:00
|
|
|
}
|
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
EventStates HTMLLinkElement::IntrinsicState() const {
|
2009-12-16 03:04:09 +03:00
|
|
|
return Link::LinkState() | nsGenericHTMLElement::IntrinsicState();
|
|
|
|
}
|
2012-02-20 07:51:48 +04:00
|
|
|
|
2017-08-25 07:47:54 +03:00
|
|
|
void HTMLLinkElement::AddSizeOfExcludingThis(nsWindowSizes& aSizes,
|
Bug 1387956 - Overhaul ComputedValues measurement, and add style structs measurement. r=bholley.
This patch moves measurement of ComputedValues objects from Rust to C++.
Measurement now happens (a) via DOM elements and (b) remaining elements via
the frame tree. Likewise for the style structs hanging off ComputedValues
objects.
Here is an example of the output.
> ├──27,600,448 B (26.49%) -- active/window(https://en.wikipedia.org/wiki/Barack_Obama)
> │ ├──12,772,544 B (12.26%) -- layout
> │ │ ├───4,483,744 B (04.30%) -- frames
> │ │ │ ├──1,653,552 B (01.59%) ── nsInlineFrame
> │ │ │ ├──1,415,760 B (01.36%) ── nsTextFrame
> │ │ │ ├────431,376 B (00.41%) ── nsBlockFrame
> │ │ │ ├────340,560 B (00.33%) ── nsHTMLScrollFrame
> │ │ │ ├────302,544 B (00.29%) ── nsContinuingTextFrame
> │ │ │ ├────156,408 B (00.15%) ── nsBulletFrame
> │ │ │ ├─────73,024 B (00.07%) ── nsPlaceholderFrame
> │ │ │ ├─────27,656 B (00.03%) ── sundries
> │ │ │ ├─────23,520 B (00.02%) ── nsTableCellFrame
> │ │ │ ├─────16,704 B (00.02%) ── nsImageFrame
> │ │ │ ├─────15,488 B (00.01%) ── nsTableRowFrame
> │ │ │ ├─────13,776 B (00.01%) ── nsTableColFrame
> │ │ │ └─────13,376 B (00.01%) ── nsTableFrame
> │ │ ├───3,412,192 B (03.28%) -- servo-style-structs
> │ │ │ ├──1,288,224 B (01.24%) ── Display
> │ │ │ ├────742,400 B (00.71%) ── Position
> │ │ │ ├────308,736 B (00.30%) ── Font
> │ │ │ ├────226,512 B (00.22%) ── Background
> │ │ │ ├────218,304 B (00.21%) ── TextReset
> │ │ │ ├────214,896 B (00.21%) ── Text
> │ │ │ ├────130,560 B (00.13%) ── Border
> │ │ │ ├─────81,408 B (00.08%) ── UIReset
> │ │ │ ├─────61,440 B (00.06%) ── Padding
> │ │ │ ├─────38,176 B (00.04%) ── UserInterface
> │ │ │ ├─────29,232 B (00.03%) ── Margin
> │ │ │ ├─────21,824 B (00.02%) ── sundries
> │ │ │ ├─────20,080 B (00.02%) ── Color
> │ │ │ ├─────20,080 B (00.02%) ── Column
> │ │ │ └─────10,320 B (00.01%) ── Effects
> │ │ ├───2,227,680 B (02.14%) -- computed-values
> │ │ │ ├──1,182,928 B (01.14%) ── non-dom
> │ │ │ └──1,044,752 B (01.00%) ── dom
> │ │ ├───1,500,016 B (01.44%) ── text-runs
> │ │ ├─────492,640 B (00.47%) ── line-boxes
> │ │ ├─────326,688 B (00.31%) ── frame-properties
> │ │ ├─────301,760 B (00.29%) ── pres-shell
> │ │ ├──────27,648 B (00.03%) ── pres-contexts
> │ │ └─────────176 B (00.00%) ── style-sets
The 'servo-style-structs' and 'computed-values' sub-trees are new. (Prior to
this patch, ComputedValues under DOM elements were tallied under the the
'dom/element-nodes' sub-tree, and ComputedValues not under DOM element were
ignored.) 'servo-style-structs/sundries' aggregates all the style structs that
are smaller than 8 KiB.
Other notable things done by the patch are as follows.
- It significantly changes the signatures of the methods measuring nsINode and
its subclasses, in order to handle the tallying of style structs separately
from element-nodes. Likewise for nsIFrame.
- It renames the 'layout/style-structs' sub-tree as
'layout/gecko-style-structs', to clearly distinguish it from the new
'layout/servo-style-structs' sub-tree.
- It adds some FFI functions to access various Rust-side data structures from
C++ code.
- There is a nasty hack used twice to measure Arcs, by stepping backwards from
an interior pointer to a base pointer. It works, but I want to replace it
with something better eventually. The "XXX WARNING" comments have details.
- It makes DMD print a line to the console if it sees a pointer it doesn't
recognise. This is useful for detecting when we are measuring an interior
pointer instead of a base pointer, which is bad but easy to do when Arcs are
involved.
- It removes the Rust code for measuring CVs, because it's now all done on the
C++ side.
MozReview-Commit-ID: BKebACLKtCi
--HG--
extra : rebase_source : 4d9a8c6b198a0ff025b811759a6bfa9f33a260ba
2017-08-11 09:37:33 +03:00
|
|
|
size_t* aNodeSize) const {
|
2017-08-25 07:47:54 +03:00
|
|
|
nsGenericHTMLElement::AddSizeOfExcludingThis(aSizes, aNodeSize);
|
|
|
|
*aNodeSize += Link::SizeOfExcludingThis(aSizes.mState);
|
2012-02-20 07:51:48 +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
|
|
|
JSObject* HTMLLinkElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return HTMLLinkElement_Binding::Wrap(aCx, this, aGivenProto);
|
2013-02-08 16:50:30 +04:00
|
|
|
}
|
|
|
|
|
2017-07-10 16:05:56 +03:00
|
|
|
void HTMLLinkElement::GetAs(nsAString& aResult) {
|
|
|
|
GetEnumAttr(nsGkAtoms::as, EmptyCString().get(), aResult);
|
|
|
|
}
|
|
|
|
|
2018-04-20 12:47:00 +03:00
|
|
|
// We will use official mime-types from:
|
|
|
|
// https://www.iana.org/assignments/media-types/media-types.xhtml#font
|
|
|
|
// We do not support old deprecated mime-types for preload feature.
|
|
|
|
// (We currectly do not support font/collection)
|
|
|
|
static uint32_t StyleLinkElementFontMimeTypesNum = 5;
|
|
|
|
static const char* StyleLinkElementFontMimeTypes[] = {
|
|
|
|
"font/otf", "font/sfnt", "font/ttf", "font/woff", "font/woff2"};
|
|
|
|
|
|
|
|
bool IsFontMimeType(const nsAString& aType) {
|
|
|
|
if (aType.IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
for (uint32_t i = 0; i < StyleLinkElementFontMimeTypesNum; i++) {
|
|
|
|
if (aType.EqualsASCII(StyleLinkElementFontMimeTypes[i])) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HTMLLinkElement::CheckPreloadAttrs(const nsAttrValue& aAs,
|
|
|
|
const nsAString& aType,
|
|
|
|
const nsAString& aMedia,
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* aDocument) {
|
2018-04-20 12:47:00 +03:00
|
|
|
nsContentPolicyType policyType = Link::AsValueToContentPolicy(aAs);
|
|
|
|
if (policyType == nsIContentPolicy::TYPE_INVALID) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if media attribute is valid.
|
|
|
|
if (!aMedia.IsEmpty()) {
|
|
|
|
RefPtr<MediaList> mediaList = MediaList::Create(aMedia);
|
2019-04-04 14:25:31 +03:00
|
|
|
if (!mediaList->Matches(*aDocument)) {
|
2018-04-20 12:47:00 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aType.IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString type = nsString(aType);
|
|
|
|
ToLowerCase(type);
|
|
|
|
|
|
|
|
if (policyType == nsIContentPolicy::TYPE_OTHER) {
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} else if (policyType == nsIContentPolicy::TYPE_MEDIA) {
|
|
|
|
if (aAs.GetEnumValue() == DESTINATION_TRACK) {
|
|
|
|
if (type.EqualsASCII("text/vtt")) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Maybe<MediaContainerType> mimeType = MakeMediaContainerType(aType);
|
|
|
|
if (!mimeType) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
DecoderDoctorDiagnostics diagnostics;
|
|
|
|
CanPlayStatus status =
|
|
|
|
DecoderTraits::CanHandleContainerType(*mimeType, &diagnostics);
|
|
|
|
// Preload if this return CANPLAY_YES and CANPLAY_MAYBE.
|
|
|
|
if (status == CANPLAY_NO) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (policyType == nsIContentPolicy::TYPE_FONT) {
|
|
|
|
if (IsFontMimeType(type)) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (policyType == nsIContentPolicy::TYPE_IMAGE) {
|
|
|
|
if (imgLoader::SupportImageWithMimeType(
|
|
|
|
NS_ConvertUTF16toUTF8(type).get(),
|
|
|
|
AcceptedMimeTypes::IMAGES_AND_DOCUMENTS)) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (policyType == nsIContentPolicy::TYPE_SCRIPT) {
|
|
|
|
if (nsContentUtils::IsJavascriptMIMEType(type)) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (policyType == nsIContentPolicy::TYPE_STYLESHEET) {
|
|
|
|
if (type.EqualsASCII("text/css")) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-08 16:50:30 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|