2002-09-04 06:57:25 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2002-09-04 06:57:25 +00:00
|
|
|
|
2013-02-01 12:28:36 +00:00
|
|
|
#include "XMLStylesheetProcessingInstruction.h"
|
2013-02-01 12:28:37 +00:00
|
|
|
#include "mozilla/dom/XMLStylesheetProcessingInstructionBinding.h"
|
2014-03-17 06:56:53 +00:00
|
|
|
#include "nsContentUtils.h"
|
2002-09-04 06:57:25 +00:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
|
2013-02-01 12:28:36 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2002-09-04 06:57:25 +00:00
|
|
|
|
|
|
|
// nsISupports implementation
|
|
|
|
|
2013-02-01 12:28:36 +00:00
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(XMLStylesheetProcessingInstruction)
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_INTERFACE_TABLE_INHERITED(XMLStylesheetProcessingInstruction, nsIDOMNode,
|
|
|
|
nsIDOMProcessingInstruction,
|
|
|
|
nsIStyleSheetLinkingElement)
|
2013-01-10 09:54:46 +00:00
|
|
|
NS_INTERFACE_TABLE_TAIL_INHERITING(ProcessingInstruction)
|
2002-09-04 06:57:25 +00:00
|
|
|
|
2013-02-01 12:28:36 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(XMLStylesheetProcessingInstruction,
|
|
|
|
ProcessingInstruction)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(XMLStylesheetProcessingInstruction,
|
|
|
|
ProcessingInstruction)
|
2002-09-04 06:57:25 +00:00
|
|
|
|
2013-08-02 01:29:05 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(XMLStylesheetProcessingInstruction)
|
|
|
|
|
2013-02-01 12:28:36 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(XMLStylesheetProcessingInstruction,
|
2013-01-08 20:45:06 +00:00
|
|
|
ProcessingInstruction)
|
2012-10-08 02:39:09 +00:00
|
|
|
tmp->nsStyleLinkElement::Traverse(cb);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2013-08-02 01:29:05 +00:00
|
|
|
|
2013-02-01 12:28:36 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(XMLStylesheetProcessingInstruction,
|
2013-01-08 20:45:06 +00:00
|
|
|
ProcessingInstruction)
|
2012-10-08 02:39:09 +00:00
|
|
|
tmp->nsStyleLinkElement::Unlink();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2002-09-04 06:57:25 +00:00
|
|
|
|
2013-02-01 12:28:36 +00:00
|
|
|
XMLStylesheetProcessingInstruction::~XMLStylesheetProcessingInstruction()
|
2002-09-04 06:57:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-01 12:28:37 +00:00
|
|
|
JSObject*
|
2014-04-08 22:27:17 +00:00
|
|
|
XMLStylesheetProcessingInstruction::WrapNode(JSContext *aCx)
|
2013-02-01 12:28:37 +00:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 22:27:17 +00:00
|
|
|
return XMLStylesheetProcessingInstructionBinding::Wrap(aCx, this);
|
2013-02-01 12:28:37 +00:00
|
|
|
}
|
|
|
|
|
2002-09-04 06:57:25 +00:00
|
|
|
// nsIContent
|
|
|
|
|
2005-04-05 23:54:35 +00:00
|
|
|
nsresult
|
2013-02-01 12:28:36 +00:00
|
|
|
XMLStylesheetProcessingInstruction::BindToTree(nsIDocument* aDocument,
|
|
|
|
nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
2005-04-05 23:54:35 +00:00
|
|
|
{
|
2013-01-08 20:45:06 +00:00
|
|
|
nsresult rv = ProcessingInstruction::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
2005-04-05 23:54:35 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-02-01 12:28:36 +00:00
|
|
|
void (XMLStylesheetProcessingInstruction::*update)() =
|
|
|
|
&XMLStylesheetProcessingInstruction::UpdateStyleSheetInternal;
|
2010-04-20 23:21:35 +00:00
|
|
|
nsContentUtils::AddScriptRunner(NS_NewRunnableMethod(this, update));
|
2005-04-05 23:54:35 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
void
|
2013-02-01 12:28:36 +00:00
|
|
|
XMLStylesheetProcessingInstruction::UnbindFromTree(bool aDeep, bool aNullParent)
|
2002-09-04 06:57:25 +00:00
|
|
|
{
|
2004-08-10 10:22:36 +00:00
|
|
|
nsCOMPtr<nsIDocument> oldDoc = GetCurrentDoc();
|
2004-01-09 23:54:21 +00:00
|
|
|
|
2013-01-08 20:45:06 +00:00
|
|
|
ProcessingInstruction::UnbindFromTree(aDeep, aNullParent);
|
2013-12-02 10:26:12 +00:00
|
|
|
UpdateStyleSheetInternal(oldDoc, nullptr);
|
2002-09-04 06:57:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDOMNode
|
|
|
|
|
2012-10-09 12:31:24 +00:00
|
|
|
void
|
2013-02-01 12:28:36 +00:00
|
|
|
XMLStylesheetProcessingInstruction::SetNodeValueInternal(const nsAString& aNodeValue,
|
|
|
|
ErrorResult& aError)
|
2002-09-04 06:57:25 +00:00
|
|
|
{
|
2012-10-21 07:38:41 +00:00
|
|
|
nsGenericDOMDataNode::SetNodeValueInternal(aNodeValue, aError);
|
2012-10-09 12:31:24 +00:00
|
|
|
if (!aError.Failed()) {
|
2013-12-02 10:26:12 +00:00
|
|
|
UpdateStyleSheetInternal(nullptr, nullptr, true);
|
2002-09-04 06:57:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsStyleLinkElement
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-01 12:28:36 +00:00
|
|
|
XMLStylesheetProcessingInstruction::GetCharset(nsAString& aCharset)
|
2002-09-04 06:57:25 +00:00
|
|
|
{
|
2006-03-17 14:38:57 +00:00
|
|
|
return GetAttrValue(nsGkAtoms::charset, aCharset) ? NS_OK : NS_ERROR_FAILURE;
|
2002-09-04 06:57:25 +00:00
|
|
|
}
|
|
|
|
|
2006-12-18 03:59:46 +00:00
|
|
|
/* virtual */ void
|
2013-02-01 12:28:36 +00:00
|
|
|
XMLStylesheetProcessingInstruction::OverrideBaseURI(nsIURI* aNewBaseURI)
|
2006-12-18 03:59:46 +00:00
|
|
|
{
|
|
|
|
mOverriddenBaseURI = aNewBaseURI;
|
|
|
|
}
|
|
|
|
|
2009-07-28 16:07:31 +00:00
|
|
|
already_AddRefed<nsIURI>
|
2013-02-01 12:28:36 +00:00
|
|
|
XMLStylesheetProcessingInstruction::GetStyleSheetURL(bool* aIsInline)
|
2002-09-04 06:57:25 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
*aIsInline = false;
|
2002-09-04 06:57:25 +00:00
|
|
|
|
|
|
|
nsAutoString href;
|
2008-11-28 21:21:55 +00:00
|
|
|
if (!GetAttrValue(nsGkAtoms::href, href)) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2002-09-04 06:57:25 +00:00
|
|
|
}
|
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
nsIURI *baseURL;
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString charset;
|
2011-10-18 10:53:36 +00:00
|
|
|
nsIDocument *document = OwnerDoc();
|
2011-10-18 11:19:44 +00:00
|
|
|
baseURL = mOverriddenBaseURI ?
|
|
|
|
mOverriddenBaseURI.get() :
|
|
|
|
document->GetDocBaseURI();
|
|
|
|
charset = document->GetDocumentCharacterSet();
|
2003-10-22 06:09:48 +00:00
|
|
|
|
2009-07-28 16:07:31 +00:00
|
|
|
nsCOMPtr<nsIURI> aURI;
|
|
|
|
NS_NewURI(getter_AddRefs(aURI), href, charset.get(), baseURL);
|
|
|
|
return aURI.forget();
|
2002-09-04 06:57:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-01 12:28:36 +00:00
|
|
|
XMLStylesheetProcessingInstruction::GetStyleSheetInfo(nsAString& aTitle,
|
|
|
|
nsAString& aType,
|
|
|
|
nsAString& aMedia,
|
|
|
|
bool* aIsScoped,
|
|
|
|
bool* aIsAlternate)
|
2002-09-04 06:57:25 +00:00
|
|
|
{
|
|
|
|
aTitle.Truncate();
|
|
|
|
aType.Truncate();
|
|
|
|
aMedia.Truncate();
|
2013-01-08 23:25:47 +00:00
|
|
|
*aIsScoped = false;
|
2011-10-17 14:59:28 +00:00
|
|
|
*aIsAlternate = false;
|
2002-09-04 06:57:25 +00:00
|
|
|
|
|
|
|
// xml-stylesheet PI is special only in prolog
|
|
|
|
if (!nsContentUtils::InProlog(this)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-03-17 14:38:57 +00:00
|
|
|
nsAutoString data;
|
|
|
|
GetData(data);
|
2002-09-04 06:57:25 +00:00
|
|
|
|
2012-02-27 11:57:48 +00:00
|
|
|
nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::title, aTitle);
|
2002-09-04 06:57:25 +00:00
|
|
|
|
2006-03-17 14:38:57 +00:00
|
|
|
nsAutoString alternate;
|
2012-02-27 11:57:48 +00:00
|
|
|
nsContentUtils::GetPseudoAttributeValue(data,
|
|
|
|
nsGkAtoms::alternate,
|
|
|
|
alternate);
|
2002-09-04 06:57:25 +00:00
|
|
|
|
|
|
|
// if alternate, does it have title?
|
2004-05-22 22:15:22 +00:00
|
|
|
if (alternate.EqualsLiteral("yes")) {
|
2002-09-04 06:57:25 +00:00
|
|
|
if (aTitle.IsEmpty()) { // alternates must have title
|
|
|
|
return;
|
|
|
|
}
|
2006-03-17 14:38:57 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
*aIsAlternate = true;
|
2002-09-04 06:57:25 +00:00
|
|
|
}
|
|
|
|
|
2012-02-27 11:57:48 +00:00
|
|
|
nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::media, aMedia);
|
2002-09-04 06:57:25 +00:00
|
|
|
|
2006-03-17 14:38:57 +00:00
|
|
|
nsAutoString type;
|
2012-02-27 11:57:48 +00:00
|
|
|
nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::type, type);
|
2002-09-04 06:57:25 +00:00
|
|
|
|
2006-03-17 14:38:57 +00:00
|
|
|
nsAutoString mimeType, notUsed;
|
2012-02-27 11:57:48 +00:00
|
|
|
nsContentUtils::SplitMimeType(type, mimeType, notUsed);
|
2004-06-17 00:13:25 +00:00
|
|
|
if (!mimeType.IsEmpty() && !mimeType.LowerCaseEqualsLiteral("text/css")) {
|
2002-09-04 06:57:25 +00:00
|
|
|
aType.Assign(type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we get here we assume that we're loading a css file, so set the
|
|
|
|
// type to 'text/css'
|
2004-06-17 00:13:25 +00:00
|
|
|
aType.AssignLiteral("text/css");
|
2002-09-04 06:57:25 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-09-11 17:15:08 +00:00
|
|
|
nsGenericDOMDataNode*
|
2014-06-20 02:01:40 +00:00
|
|
|
XMLStylesheetProcessingInstruction::CloneDataNode(mozilla::dom::NodeInfo *aNodeInfo,
|
2013-02-01 12:28:36 +00:00
|
|
|
bool aCloneText) const
|
2005-09-11 17:15:08 +00:00
|
|
|
{
|
|
|
|
nsAutoString data;
|
2005-09-12 07:34:25 +00:00
|
|
|
nsGenericDOMDataNode::GetData(data);
|
2014-06-20 02:01:40 +00:00
|
|
|
nsRefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
|
2013-02-01 12:28:36 +00:00
|
|
|
return new XMLStylesheetProcessingInstruction(ni.forget(), data);
|
2005-09-11 17:15:08 +00:00
|
|
|
}
|
|
|
|
|
2013-02-01 12:28:36 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|