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/. */
|
2002-09-04 10:57:25 +04:00
|
|
|
|
2013-02-01 16:28:36 +04:00
|
|
|
#include "XMLStylesheetProcessingInstruction.h"
|
2014-03-17 10:56:53 +04:00
|
|
|
#include "nsContentUtils.h"
|
2002-09-04 10:57:25 +04:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
|
2013-02-01 16:28:36 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2002-09-04 10:57:25 +04:00
|
|
|
|
|
|
|
// nsISupports implementation
|
|
|
|
|
2017-09-01 02:29:22 +03:00
|
|
|
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(XMLStylesheetProcessingInstruction,
|
|
|
|
ProcessingInstruction,
|
|
|
|
nsIStyleSheetLinkingElement)
|
2002-09-04 10:57:25 +04:00
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(XMLStylesheetProcessingInstruction)
|
|
|
|
|
2013-02-01 16:28:36 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(
|
|
|
|
XMLStylesheetProcessingInstruction, ProcessingInstruction)
|
2012-10-08 06:39:09 +04:00
|
|
|
tmp->nsStyleLinkElement::Traverse(cb);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2013-08-02 05:29:05 +04:00
|
|
|
|
2013-02-01 16:28:36 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(
|
|
|
|
XMLStylesheetProcessingInstruction, ProcessingInstruction)
|
2012-10-08 06:39:09 +04:00
|
|
|
tmp->nsStyleLinkElement::Unlink();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2013-02-01 16:28:36 +04:00
|
|
|
XMLStylesheetProcessingInstruction::~XMLStylesheetProcessingInstruction() {}
|
2002-09-04 10:57:25 +04:00
|
|
|
|
|
|
|
// nsIContent
|
|
|
|
|
2013-02-01 16:28:36 +04:00
|
|
|
nsresult XMLStylesheetProcessingInstruction::BindToTree(
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* aDocument, nsIContent* aParent, nsIContent* aBindingParent) {
|
2013-01-09 00:45:06 +04:00
|
|
|
nsresult rv =
|
|
|
|
ProcessingInstruction::BindToTree(aDocument, aParent, aBindingParent);
|
2005-04-06 03:54:35 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-02-01 16:28:36 +04:00
|
|
|
void (XMLStylesheetProcessingInstruction::*update)() =
|
|
|
|
&XMLStylesheetProcessingInstruction::UpdateStyleSheetInternal;
|
2017-06-12 22:34:10 +03:00
|
|
|
nsContentUtils::AddScriptRunner(NewRunnableMethod(
|
|
|
|
"dom::XMLStylesheetProcessingInstruction::BindToTree", this, update));
|
2005-04-06 03:54:35 +04:00
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
return rv;
|
2005-04-06 03:54:35 +04:00
|
|
|
}
|
|
|
|
|
2013-02-01 16:28:36 +04:00
|
|
|
void XMLStylesheetProcessingInstruction::UnbindFromTree(bool aDeep,
|
|
|
|
bool aNullParent) {
|
2019-01-02 16:05:23 +03:00
|
|
|
nsCOMPtr<Document> oldDoc = GetUncomposedDoc();
|
2004-01-10 02:54:21 +03:00
|
|
|
|
2013-01-09 00:45:06 +04:00
|
|
|
ProcessingInstruction::UnbindFromTree(aDeep, aNullParent);
|
2018-04-24 13:50:35 +03:00
|
|
|
Unused << UpdateStyleSheetInternal(oldDoc, nullptr);
|
2002-09-04 10:57:25 +04:00
|
|
|
}
|
|
|
|
|
2018-05-30 05:58:49 +03:00
|
|
|
// nsINode
|
2002-09-04 10:57:25 +04:00
|
|
|
|
2013-02-01 16:28:36 +04:00
|
|
|
void XMLStylesheetProcessingInstruction::SetNodeValueInternal(
|
|
|
|
const nsAString& aNodeValue, ErrorResult& aError) {
|
2018-03-19 22:18:06 +03:00
|
|
|
CharacterData::SetNodeValueInternal(aNodeValue, aError);
|
2012-10-09 16:31:24 +04:00
|
|
|
if (!aError.Failed()) {
|
2018-04-24 13:50:35 +03:00
|
|
|
Unused << UpdateStyleSheetInternal(nullptr, nullptr, ForceUpdate::Yes);
|
2002-09-04 10:57:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsStyleLinkElement
|
|
|
|
|
2013-02-01 16:28:36 +04:00
|
|
|
void XMLStylesheetProcessingInstruction::GetCharset(nsAString& aCharset) {
|
2018-02-02 16:21:32 +03:00
|
|
|
if (!GetAttrValue(nsGkAtoms::charset, aCharset)) {
|
|
|
|
aCharset.Truncate();
|
|
|
|
}
|
2002-09-04 10:57:25 +04:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* virtual */
|
|
|
|
void XMLStylesheetProcessingInstruction::OverrideBaseURI(nsIURI* aNewBaseURI) {
|
2006-12-18 06:59:46 +03:00
|
|
|
mOverriddenBaseURI = aNewBaseURI;
|
|
|
|
}
|
|
|
|
|
2018-05-08 07:11:56 +03:00
|
|
|
Maybe<nsStyleLinkElement::SheetInfo>
|
2018-05-06 14:20:03 +03:00
|
|
|
XMLStylesheetProcessingInstruction::GetStyleSheetInfo() {
|
|
|
|
// xml-stylesheet PI is special only in prolog
|
|
|
|
if (!nsContentUtils::InProlog(this)) {
|
|
|
|
return Nothing();
|
|
|
|
}
|
2002-09-04 10:57:25 +04:00
|
|
|
|
|
|
|
nsAutoString href;
|
2008-11-29 00:21:55 +03:00
|
|
|
if (!GetAttrValue(nsGkAtoms::href, href)) {
|
2018-05-06 14:20:03 +03:00
|
|
|
return Nothing();
|
2002-09-04 10:57:25 +04:00
|
|
|
}
|
|
|
|
|
2006-03-17 17:38:57 +03:00
|
|
|
nsAutoString data;
|
|
|
|
GetData(data);
|
2002-09-04 10:57:25 +04:00
|
|
|
|
2018-05-06 14:20:03 +03:00
|
|
|
nsAutoString title;
|
|
|
|
nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::title, title);
|
2002-09-04 10:57:25 +04:00
|
|
|
|
2018-05-06 14:20:03 +03:00
|
|
|
nsAutoString alternateAttr;
|
2012-02-27 15:57:48 +04:00
|
|
|
nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::alternate,
|
2018-05-06 14:20:03 +03:00
|
|
|
alternateAttr);
|
2006-03-17 17:38:57 +03:00
|
|
|
|
2018-05-06 14:20:03 +03:00
|
|
|
bool alternate = alternateAttr.EqualsLiteral("yes");
|
|
|
|
if (alternate && title.IsEmpty()) {
|
|
|
|
// alternates must have title
|
|
|
|
return Nothing();
|
2002-09-04 10:57:25 +04:00
|
|
|
}
|
|
|
|
|
2018-05-06 14:20:03 +03:00
|
|
|
nsAutoString media;
|
|
|
|
nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::media, media);
|
2002-09-04 10:57:25 +04:00
|
|
|
|
2017-12-22 00:43:24 +03:00
|
|
|
// Make sure the type handling here matches
|
|
|
|
// nsXMLContentSink::HandleProcessingInstruction
|
2006-03-17 17:38:57 +03:00
|
|
|
nsAutoString type;
|
2012-02-27 15:57:48 +04:00
|
|
|
nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::type, type);
|
2002-09-04 10:57:25 +04:00
|
|
|
|
2006-03-17 17:38:57 +03:00
|
|
|
nsAutoString mimeType, notUsed;
|
2012-02-27 15:57:48 +04:00
|
|
|
nsContentUtils::SplitMimeType(type, mimeType, notUsed);
|
2004-06-17 04:13:25 +04:00
|
|
|
if (!mimeType.IsEmpty() && !mimeType.LowerCaseEqualsLiteral("text/css")) {
|
2018-05-06 14:20:03 +03:00
|
|
|
return Nothing();
|
2002-09-04 10:57:25 +04:00
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* doc = OwnerDoc();
|
2018-05-06 14:20:03 +03:00
|
|
|
nsIURI* baseURL =
|
|
|
|
mOverriddenBaseURI ? mOverriddenBaseURI.get() : doc->GetDocBaseURI();
|
|
|
|
auto encoding = doc->GetDocumentCharacterSet();
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
NS_NewURI(getter_AddRefs(uri), href, encoding, baseURL);
|
2018-05-08 07:11:56 +03:00
|
|
|
return Some(SheetInfo{
|
2018-05-06 14:20:03 +03:00
|
|
|
*doc,
|
|
|
|
this,
|
|
|
|
uri.forget(),
|
|
|
|
nullptr,
|
|
|
|
net::RP_Unset,
|
|
|
|
CORS_NONE,
|
|
|
|
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,
|
|
|
|
});
|
2002-09-04 10:57:25 +04:00
|
|
|
}
|
|
|
|
|
2018-03-19 22:50:16 +03:00
|
|
|
already_AddRefed<CharacterData>
|
2014-06-20 06:01:40 +04:00
|
|
|
XMLStylesheetProcessingInstruction::CloneDataNode(
|
|
|
|
mozilla::dom::NodeInfo* aNodeInfo, bool aCloneText) const {
|
2005-09-11 21:15:08 +04:00
|
|
|
nsAutoString data;
|
2018-03-19 22:18:06 +03:00
|
|
|
GetData(data);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
|
2018-03-19 22:50:16 +03:00
|
|
|
return do_AddRef(new XMLStylesheetProcessingInstruction(ni.forget(), data));
|
2005-09-11 21:15:08 +04:00
|
|
|
}
|
|
|
|
|
2013-02-01 16:28:36 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|