2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-01 04:28:36 -08:00
|
|
|
#include "XMLStylesheetProcessingInstruction.h"
|
2013-02-01 04:28:37 -08:00
|
|
|
#include "mozilla/dom/XMLStylesheetProcessingInstructionBinding.h"
|
2014-03-16 23:56:53 -07:00
|
|
|
#include "nsContentUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
|
2013-02-01 04:28:36 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsISupports implementation
|
|
|
|
|
2013-02-01 04:28:36 -08:00
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(XMLStylesheetProcessingInstruction)
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_INTERFACE_TABLE_INHERITED(XMLStylesheetProcessingInstruction, nsIDOMNode,
|
|
|
|
nsIDOMProcessingInstruction,
|
|
|
|
nsIStyleSheetLinkingElement)
|
2013-01-10 01:54:46 -08:00
|
|
|
NS_INTERFACE_TABLE_TAIL_INHERITING(ProcessingInstruction)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-01 04:28:36 -08:00
|
|
|
NS_IMPL_ADDREF_INHERITED(XMLStylesheetProcessingInstruction,
|
|
|
|
ProcessingInstruction)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(XMLStylesheetProcessingInstruction,
|
|
|
|
ProcessingInstruction)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-08-01 18:29:05 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(XMLStylesheetProcessingInstruction)
|
|
|
|
|
2013-02-01 04:28:36 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(XMLStylesheetProcessingInstruction,
|
2013-01-08 12:45:06 -08:00
|
|
|
ProcessingInstruction)
|
2012-10-07 19:39:09 -07:00
|
|
|
tmp->nsStyleLinkElement::Traverse(cb);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2013-08-01 18:29:05 -07:00
|
|
|
|
2013-02-01 04:28:36 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(XMLStylesheetProcessingInstruction,
|
2013-01-08 12:45:06 -08:00
|
|
|
ProcessingInstruction)
|
2012-10-07 19:39:09 -07:00
|
|
|
tmp->nsStyleLinkElement::Unlink();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-01 04:28:36 -08:00
|
|
|
XMLStylesheetProcessingInstruction::~XMLStylesheetProcessingInstruction()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-01 04:28:37 -08:00
|
|
|
JSObject*
|
2014-04-08 15:27:17 -07:00
|
|
|
XMLStylesheetProcessingInstruction::WrapNode(JSContext *aCx)
|
2013-02-01 04:28:37 -08: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 15:27:17 -07:00
|
|
|
return XMLStylesheetProcessingInstructionBinding::Wrap(aCx, this);
|
2013-02-01 04:28:37 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsIContent
|
|
|
|
|
|
|
|
nsresult
|
2013-02-01 04:28:36 -08:00
|
|
|
XMLStylesheetProcessingInstruction::BindToTree(nsIDocument* aDocument,
|
|
|
|
nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-01-08 12:45:06 -08:00
|
|
|
nsresult rv = ProcessingInstruction::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-02-01 04:28:36 -08:00
|
|
|
void (XMLStylesheetProcessingInstruction::*update)() =
|
|
|
|
&XMLStylesheetProcessingInstruction::UpdateStyleSheetInternal;
|
2010-04-20 16:21:35 -07:00
|
|
|
nsContentUtils::AddScriptRunner(NS_NewRunnableMethod(this, update));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-01 04:28:36 -08:00
|
|
|
XMLStylesheetProcessingInstruction::UnbindFromTree(bool aDeep, bool aNullParent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocument> oldDoc = GetCurrentDoc();
|
|
|
|
|
2013-01-08 12:45:06 -08:00
|
|
|
ProcessingInstruction::UnbindFromTree(aDeep, aNullParent);
|
2013-12-02 02:26:12 -08:00
|
|
|
UpdateStyleSheetInternal(oldDoc, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDOMNode
|
|
|
|
|
2012-10-09 05:31:24 -07:00
|
|
|
void
|
2013-02-01 04:28:36 -08:00
|
|
|
XMLStylesheetProcessingInstruction::SetNodeValueInternal(const nsAString& aNodeValue,
|
|
|
|
ErrorResult& aError)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-10-21 00:38:41 -07:00
|
|
|
nsGenericDOMDataNode::SetNodeValueInternal(aNodeValue, aError);
|
2012-10-09 05:31:24 -07:00
|
|
|
if (!aError.Failed()) {
|
2013-12-02 02:26:12 -08:00
|
|
|
UpdateStyleSheetInternal(nullptr, nullptr, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsStyleLinkElement
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-01 04:28:36 -08:00
|
|
|
XMLStylesheetProcessingInstruction::GetCharset(nsAString& aCharset)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return GetAttrValue(nsGkAtoms::charset, aCharset) ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
2013-02-01 04:28:36 -08:00
|
|
|
XMLStylesheetProcessingInstruction::OverrideBaseURI(nsIURI* aNewBaseURI)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mOverriddenBaseURI = aNewBaseURI;
|
|
|
|
}
|
|
|
|
|
2009-07-28 09:07:31 -07:00
|
|
|
already_AddRefed<nsIURI>
|
2013-02-01 04:28:36 -08:00
|
|
|
XMLStylesheetProcessingInstruction::GetStyleSheetURL(bool* aIsInline)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsInline = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsAutoString href;
|
2008-11-28 13:21:55 -08:00
|
|
|
if (!GetAttrValue(nsGkAtoms::href, href)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIURI *baseURL;
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString charset;
|
2011-10-18 03:53:36 -07:00
|
|
|
nsIDocument *document = OwnerDoc();
|
2011-10-18 04:19:44 -07:00
|
|
|
baseURL = mOverriddenBaseURI ?
|
|
|
|
mOverriddenBaseURI.get() :
|
|
|
|
document->GetDocBaseURI();
|
|
|
|
charset = document->GetDocumentCharacterSet();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-07-28 09:07:31 -07:00
|
|
|
nsCOMPtr<nsIURI> aURI;
|
|
|
|
NS_NewURI(getter_AddRefs(aURI), href, charset.get(), baseURL);
|
|
|
|
return aURI.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-01 04:28:36 -08:00
|
|
|
XMLStylesheetProcessingInstruction::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
|
|
|
|
|
|
|
// xml-stylesheet PI is special only in prolog
|
|
|
|
if (!nsContentUtils::InProlog(this)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString data;
|
|
|
|
GetData(data);
|
|
|
|
|
2012-02-27 03:57:48 -08:00
|
|
|
nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::title, aTitle);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsAutoString alternate;
|
2012-02-27 03:57:48 -08:00
|
|
|
nsContentUtils::GetPseudoAttributeValue(data,
|
|
|
|
nsGkAtoms::alternate,
|
|
|
|
alternate);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// if alternate, does it have title?
|
|
|
|
if (alternate.EqualsLiteral("yes")) {
|
|
|
|
if (aTitle.IsEmpty()) { // alternates must have title
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsAlternate = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-02-27 03:57:48 -08:00
|
|
|
nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::media, aMedia);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsAutoString type;
|
2012-02-27 03:57:48 -08:00
|
|
|
nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::type, type);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsAutoString mimeType, notUsed;
|
2012-02-27 03:57:48 -08:00
|
|
|
nsContentUtils::SplitMimeType(type, mimeType, notUsed);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!mimeType.IsEmpty() && !mimeType.LowerCaseEqualsLiteral("text/css")) {
|
|
|
|
aType.Assign(type);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGenericDOMDataNode*
|
2014-06-19 19:01:40 -07:00
|
|
|
XMLStylesheetProcessingInstruction::CloneDataNode(mozilla::dom::NodeInfo *aNodeInfo,
|
2013-02-01 04:28:36 -08:00
|
|
|
bool aCloneText) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsAutoString data;
|
|
|
|
nsGenericDOMDataNode::GetData(data);
|
2014-06-19 19:01:40 -07:00
|
|
|
nsRefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
|
2013-02-01 04:28:36 -08:00
|
|
|
return new XMLStylesheetProcessingInstruction(ni.forget(), data);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-02-01 04:28:36 -08:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|